[6844] Daily quest fixes.
[getmangos.git] / src / game / GlobalEvents.cpp
blob14ad2560732f778fd684c5781c2c662fbde7c088
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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 /** \file
20 \ingroup world
23 #include "Log.h"
24 #include "Database/DatabaseEnv.h"
25 #include "Platform/Define.h"
26 #include "MapManager.h"
27 #include "ObjectAccessor.h"
28 #include "GlobalEvents.h"
29 #include "ObjectDefines.h"
30 #include "Corpse.h"
32 /// Handle periodic erase of corpses and bones
33 static void CorpsesErase(bool bones,uint32 delay)
35 ///- Get the list of eligible corpses/bones to be removed
36 //No SQL injection (uint32 and enum)
37 QueryResult *result = CharacterDatabase.PQuery("SELECT guid,position_x,position_y,map,player FROM corpse WHERE UNIX_TIMESTAMP()-time > '%u' AND corpse_type %s '0'", delay, (bones ? "=" : "<>") );
39 if(result)
43 Field *fields = result->Fetch();
44 uint32 guidlow = fields[0].GetUInt32();
45 float positionX = fields[1].GetFloat();
46 float positionY = fields[2].GetFloat();
47 uint32 mapid = fields[3].GetUInt32();
48 uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER);
50 uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE);
52 sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid);
54 /// Resurrectable - convert corpses to bones
55 if(!bones)
57 if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid))
59 sLog.outDebug("Corpse %u not found in world. Delete from DB.",guidlow);
60 CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
63 else
64 ///- or delete bones
66 MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY);
68 ///- remove bones from the database
69 CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
71 } while (result->NextRow());
73 delete result;
77 /// not thread guarded variant for call from other thread
78 void CorpsesErase()
80 CorpsesErase(true, 20*MINUTE);
81 CorpsesErase(false,3*DAY);