[1130] Database Query Audit is now at 90 percent with this commit.
[mangos-git.git] / src / game / Corpse.cpp
blobe705d5b9c3c6e23cf2fa21c074c4186034fb3526
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Corpse.h"
21 #include "Player.h"
22 #include "UpdateMask.h"
23 #include "ObjectMgr.h"
24 #include "Database/DatabaseEnv.h"
25 #include "Opcodes.h"
26 #include "WorldSession.h"
27 #include "WorldPacket.h"
29 Corpse::Corpse() : Object()
31 m_objectType |= TYPE_CORPSE;
32 m_objectTypeId = TYPEID_CORPSE;
34 m_valuesCount = CORPSE_END;
37 void Corpse::Create( uint32 guidlow )
39 Object::_Create(guidlow, HIGHGUID_CORPSE);
42 void Corpse::Create( uint32 guidlow, Player *owner, uint32 mapid, float x, float y, float z, float ang )
44 Object::_Create(guidlow, HIGHGUID_CORPSE, mapid, x, y, z, ang, (uint8)-1);
46 SetFloatValue( OBJECT_FIELD_SCALE_X, 1 );
47 SetFloatValue( CORPSE_FIELD_POS_X, x );
48 SetFloatValue( CORPSE_FIELD_POS_Y, y );
49 SetFloatValue( CORPSE_FIELD_POS_Z, z );
50 SetFloatValue( CORPSE_FIELD_FACING, ang );
51 SetUInt64Value( CORPSE_FIELD_OWNER, owner->GetGUID() );
54 void Corpse::SaveToDB(bool bones)
57 int bflag = 0;
58 if (bones)
60 bflag = 1;
63 std::stringstream ss;
65 ss.rdbuf()->str("");
66 ss << "REPLACE INTO `corpses` (`guid`,`player`,`position_x`,`position_y`,`position_z`,`orientation`,`map`,`data`,`time`,`bones_flag`) VALUES (" << GetGUIDLow() << ", " << GetUInt64Value(CORPSE_FIELD_OWNER) << ", " << GetPositionX() << ", " << GetPositionY() << ", " << GetPositionZ() << ", " << GetOrientation() << ", " << GetMapId() << ", '";
68 for(uint16 i = 0; i < m_valuesCount; i++ )
69 ss << GetUInt32Value(i) << " ";
70 ss << "', NOW(), " << bflag << ")";
72 sDatabase.Execute( ss.str().c_str() );
75 void Corpse::DeleteFromDB()
77 sDatabase.PExecute("DELETE FROM `corpses` WHERE `guid` = '%u'",GetGUIDLow());