Entities/Unit: Nuke Map::ForceRespawn from orbit, with the following implications:

- .npc respawn no longer causes stupid things to happen (Fixes #23014)
- ::DeleteFromDB methods on Creature and GameObject rewritten to be as sensible as such a colossally stupid method can ever be. They're static now.
- .npc delete and .gobj delete ported to new argument handling, and rewritten as per above. They can no longer crash the server when used in instances, too. Yay for that.
- Adjusted various dusty cobwebbed hacks around the core (why does waypoint visualization use permanent spawns *shudder*) to still work too.
This commit is contained in:
Treeston
2019-08-18 12:12:09 +02:00
committed by Ovahlord
parent 8a1828aa43
commit f9184f026b
12 changed files with 150 additions and 182 deletions

View File

@@ -35,6 +35,7 @@
#include "InstanceScript.h"
#include "Log.h"
#include "LootMgr.h"
#include "MapManager.h"
#include "MotionMaster.h"
#include "MoveSpline.h"
#include "ObjectAccessor.h"
@@ -1647,50 +1648,55 @@ bool Creature::hasInvolvedQuest(uint32 quest_id) const
return false;
}
void Creature::DeleteFromDB()
/*static*/ bool Creature::DeleteFromDB(ObjectGuid::LowType spawnId)
{
if (!m_spawnId)
{
TC_LOG_ERROR("entities.unit", "Trying to delete not saved creature! LowGUID: %u, Entry: %u", GetGUID().GetCounter(), GetEntry());
return;
}
CreatureData const* data = sObjectMgr->GetCreatureData(spawnId);
if (!data)
return false;
// remove any scheduled respawns
GetMap()->RemoveRespawnTime(SPAWN_TYPE_CREATURE, m_spawnId);
// delete data from memory
sObjectMgr->DeleteCreatureData(m_spawnId);
// delete data and all its associations from DB
SQLTransaction trans = WorldDatabase.BeginTransaction();
sMapMgr->DoForAllMapsWithMapId(data->spawnPoint.GetMapId(),
[spawnId, trans](Map* map) -> void
{
// despawn all active creatures, and remove their respawns
std::vector<Creature*> toUnload;
for (auto const& pair : Trinity::Containers::MapEqualRange(map->GetCreatureBySpawnIdStore(), spawnId))
toUnload.push_back(pair.second);
for (Creature* creature : toUnload)
map->AddObjectToRemoveList(creature);
map->RemoveRespawnTime(SPAWN_TYPE_CREATURE, spawnId, false, trans);
}
);
// delete data from memory ...
sObjectMgr->DeleteCreatureData(spawnId);
// ... and the database
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_SPAWNGROUP_MEMBER);
stmt->setUInt8(0, uint8(SPAWN_TYPE_CREATURE));
stmt->setUInt32(1, m_spawnId);
stmt->setUInt32(1, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE_ADDON);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GAME_EVENT_CREATURE);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GAME_EVENT_MODEL_EQUIP);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);
// then delete any active instances of the creature
auto const& spawnMap = GetMap()->GetCreatureBySpawnIdStore();
for (auto it = spawnMap.find(m_spawnId); it != spawnMap.end(); it = spawnMap.find(m_spawnId))
it->second->AddObjectToRemoveList();
return true;
}
bool Creature::IsInvisibleDueToDespawn() const

View File

@@ -179,7 +179,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void SaveToDB();
// overriden in Pet
virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
virtual void DeleteFromDB(); // overriden in Pet
static bool DeleteFromDB(ObjectGuid::LowType spawnId);
Loot loot;
void StartPickPocketRefillTimer();

View File

@@ -31,6 +31,8 @@
#include "GroupMgr.h"
#include "Log.h"
#include "LootMgr.h"
#include "Map.h"
#include "MapManager.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "OutdoorPvPMgr.h"
@@ -985,26 +987,45 @@ bool GameObject::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap
return true;
}
void GameObject::DeleteFromDB()
/*static*/ bool GameObject::DeleteFromDB(ObjectGuid::LowType spawnId)
{
GetMap()->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, m_spawnId);
sObjectMgr->DeleteGameObjectData(m_spawnId);
GameObjectData const* data = sObjectMgr->GetGameObjectData(spawnId);
if (!data)
return false;
SQLTransaction trans = WorldDatabase.BeginTransaction();
sMapMgr->DoForAllMapsWithMapId(data->spawnPoint.GetMapId(),
[spawnId, trans](Map* map) -> void
{
// despawn all active objects, and remove their respawns
std::vector<GameObject*> toUnload;
for (auto const& pair : Trinity::Containers::MapEqualRange(map->GetGameObjectBySpawnIdStore(), spawnId))
toUnload.push_back(pair.second);
for (GameObject* obj : toUnload)
map->AddObjectToRemoveList(obj);
map->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, spawnId, false, trans);
}
);
// delete data from memory
sObjectMgr->DeleteGameObjectData(spawnId);
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GAMEOBJECT);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_SPAWNGROUP_MEMBER);
stmt->setUInt8(0, uint8(SPAWN_TYPE_GAMEOBJECT));
stmt->setUInt32(1, m_spawnId);
stmt->setUInt32(1, spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_EVENT_GAMEOBJECT);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(0, spawnId);
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);
return true;
}
/*********************************************************/

View File

@@ -117,7 +117,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
void SaveToDB();
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, bool = true); // arg4 is unused, only present to match the signature on Creature
void DeleteFromDB();
static bool DeleteFromDB(ObjectGuid::LowType spawnId);
void SetOwnerGUID(ObjectGuid owner)
{

View File

@@ -185,9 +185,5 @@ class TC_GAME_API Pet : public Guardian
{
ABORT();
}
void DeleteFromDB() override // override of Creature::DeleteFromDB - must not be called
{
ABORT();
}
};
#endif

View File

@@ -3173,9 +3173,9 @@ void Map::DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gr
}
}
void Map::Respawn(RespawnInfo* info, bool force, SQLTransaction dbTrans)
void Map::Respawn(RespawnInfo* info, SQLTransaction dbTrans)
{
if (!force && !CheckRespawn(info))
if (!CheckRespawn(info))
{
if (info->respawnTime)
SaveRespawnTime(info->type, info->spawnId, info->entry, info->respawnTime, info->gridId, true, true, dbTrans);
@@ -3192,11 +3192,11 @@ void Map::Respawn(RespawnInfo* info, bool force, SQLTransaction dbTrans)
DoRespawn(type, spawnId, gridId);
}
void Map::Respawn(std::vector<RespawnInfo*>& respawnData, bool force, SQLTransaction dbTrans)
void Map::Respawn(std::vector<RespawnInfo*>& respawnData, SQLTransaction dbTrans)
{
SQLTransaction trans = dbTrans ? dbTrans : CharacterDatabase.BeginTransaction();
for (RespawnInfo* info : respawnData)
Respawn(info, force, trans);
Respawn(info, trans);
if (!dbTrans)
CharacterDatabase.CommitTransaction(trans);
}

View File

@@ -788,8 +788,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
// if return value is false and info->respawnTime is nonzero, it is guaranteed to be greater than time(NULL)
bool CheckRespawn(RespawnInfo* info);
void DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gridId);
void Respawn(RespawnInfo* info, bool force = false, SQLTransaction dbTrans = nullptr);
void Respawn(std::vector<RespawnInfo*>& respawnData, bool force = false, SQLTransaction dbTrans = nullptr);
void Respawn(RespawnInfo* info, SQLTransaction dbTrans = nullptr);
void Respawn(std::vector<RespawnInfo*>& respawnData, SQLTransaction dbTrans = nullptr);
void AddRespawnInfo(RespawnInfo& info, bool replace = false);
void DeleteRespawnInfo();
void DeleteRespawnInfo(RespawnInfo* info);
@@ -815,11 +815,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
public:
void GetRespawnInfo(std::vector<RespawnInfo*>& respawnData, SpawnObjectTypeMask types) const;
RespawnInfo* GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawnId) const;
void ForceRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId)
{
if (RespawnInfo* info = GetRespawnInfo(type, spawnId))
Respawn(info, true);
}
void RemoveRespawnTime(RespawnInfo* info, bool doRespawn = false, SQLTransaction dbTrans = nullptr);
void RemoveRespawnTime(std::vector<RespawnInfo*>& respawnData, bool doRespawn = false, SQLTransaction dbTrans = nullptr);
void RemoveRespawnTime(SpawnObjectTypeMask types = SPAWN_TYPEMASK_ALL, bool doRespawn = false, SQLTransaction dbTrans = nullptr)

View File

@@ -172,56 +172,24 @@ bool OPvPCapturePoint::DelCreature(uint32 type)
return false;
}
auto bounds = m_PvP->GetMap()->GetCreatureBySpawnIdStore().equal_range(spawnId);
for (auto itr = bounds.first; itr != bounds.second; )
{
Creature* c = itr->second;
++itr;
// Don't save respawn time
c->SetRespawnTime(0);
c->RemoveCorpse();
c->AddObjectToRemoveList();
}
TC_LOG_DEBUG("outdoorpvp", "deleting opvp creature type %u", type);
// explicit removal from map
// beats me why this is needed, but with the recent removal "cleanup" some creatures stay in the map if "properly" deleted
// so this is a big fat workaround, if AddObjectToRemoveList and DoDelayedMovesAndRemoves worked correctly, this wouldn't be needed
//if (Map* map = sMapMgr->FindMap(cr->GetMapId()))
// map->Remove(cr, false);
// delete respawn time for this creature
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN);
stmt->setUInt32(0, spawnId);
stmt->setUInt16(1, m_PvP->GetMap()->GetId());
stmt->setUInt32(2, 0); // instance id, always 0 for world maps
CharacterDatabase.Execute(stmt);
sObjectMgr->DeleteCreatureData(spawnId);
m_CreatureTypes[m_Creatures[type]] = 0;
m_Creatures[type] = 0;
return true;
return Creature::DeleteFromDB(spawnId);
}
bool OPvPCapturePoint::DelObject(uint32 type)
{
if (!m_Objects[type])
uint32 spawnId = m_Objects[type];
if (!spawnId)
return false;
ObjectGuid::LowType spawnId = m_Objects[type];
auto bounds = m_PvP->GetMap()->GetGameObjectBySpawnIdStore().equal_range(spawnId);
for (auto itr = bounds.first; itr != bounds.second; )
{
GameObject* go = itr->second;
++itr;
// Don't save respawn time
go->SetRespawnTime(0);
go->Delete();
}
sObjectMgr->DeleteGameObjectData(spawnId);
m_ObjectTypes[m_Objects[type]] = 0;
m_Objects[type] = 0;
return true;
return GameObject::DeleteFromDB(spawnId);
}
bool OPvPCapturePoint::DelCapturePoint()

View File

@@ -364,42 +364,37 @@ public:
if (!id)
return false;
ObjectGuid::LowType guidLow = atoul(id);
if (!guidLow)
ObjectGuid::LowType spawnId = atoul(id);
if (!spawnId)
return false;
Player const* const player = handler->GetSession()->GetPlayer();
// force respawn to make sure we find something
player->GetMap()->ForceRespawn(SPAWN_TYPE_GAMEOBJECT, guidLow);
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object)
if (GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(spawnId))
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
Player const* const player = handler->GetSession()->GetPlayer();
if (ObjectGuid ownerGuid = object->GetOwnerGUID())
{
Unit* owner = ObjectAccessor::GetUnit(*player, ownerGuid);
if (!owner || !ownerGuid.IsPlayer())
{
handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, ownerGuid.GetCounter(), spawnId);
handler->SetSentErrorMessage(true);
return false;
}
owner->RemoveGameObject(object, false);
}
}
if (GameObject::DeleteFromDB(spawnId))
{
handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, spawnId);
return true;
}
else
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, spawnId);
handler->SetSentErrorMessage(true);
return false;
}
ObjectGuid ownerGuid = object->GetOwnerGUID();
if (ownerGuid)
{
Unit* owner = ObjectAccessor::GetUnit(*player, ownerGuid);
if (!owner || !ownerGuid.IsPlayer())
{
handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, ownerGuid.GetCounter(), guidLow);
handler->SetSentErrorMessage(true);
return false;
}
owner->RemoveGameObject(object, false);
}
object->SetRespawnTime(0); // not save respawn time
object->Delete();
object->DeleteFromDB();
handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetSpawnId());
return true;
}
//turn selected object

View File

@@ -1918,7 +1918,7 @@ public:
uint32 const gridId = Trinity::ComputeGridCoord(player->GetPositionX(), player->GetPositionY()).GetId();
for (RespawnInfo* info : data)
if (info->gridId == gridId)
player->GetMap()->ForceRespawn(info->type, info->spawnId);
player->GetMap()->RemoveRespawnTime(info, true);
}
return true;

View File

@@ -558,8 +558,7 @@ public:
static bool HandleNpcDeleteCommand(ChatHandler* handler, char const* args)
{
Creature* creature = nullptr;
ObjectGuid::LowType spawnId;
if (*args)
{
// number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
@@ -567,37 +566,39 @@ public:
if (!cId)
return false;
ObjectGuid::LowType lowguid = atoul(cId);
if (!lowguid)
spawnId = atoul(cId);
if (!spawnId)
return false;
// force respawn to make sure we find something
handler->GetSession()->GetPlayer()->GetMap()->ForceRespawn(SPAWN_TYPE_CREATURE, lowguid);
// then try to find it
creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
}
else
creature = handler->getSelectedCreature();
if (!creature || creature->IsPet() || creature->IsTotem())
{
handler->SendSysMessage(LANG_SELECT_CREATURE);
Creature* creature = handler->getSelectedCreature();
if (!creature || creature->IsPet() || creature->IsTotem())
{
handler->SendSysMessage(LANG_SELECT_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
if (TempSummon* summon = creature->ToTempSummon())
{
summon->UnSummon();
handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
return true;
}
spawnId = creature->GetSpawnId();
}
if (Creature::DeleteFromDB(spawnId))
{
handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
return true;
}
else
{
handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, spawnId);
handler->SetSentErrorMessage(true);
return false;
}
if (TempSummon* summon = creature->ToTempSummon())
summon->UnSummon();
else
{
// Delete the creature
creature->CombatStop();
creature->DeleteFromDB();
creature->AddObjectToRemoveList();
}
handler->SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
return true;
}
//del item from vendor list

View File

@@ -637,22 +637,28 @@ public:
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
target->DeleteFromDB();
target->AddObjectToRemoveList();
if (Creature::DeleteFromDB(target->GetSpawnId()))
{
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_WAYPOINT_REMOVED);
return true;
} // del
handler->SendSysMessage(LANG_WAYPOINT_REMOVED);
return true;
}
else
{
handler->SendSysMessage(LANG_WAYPOINT_NOTREMOVED);
handler->SetSentErrorMessage(true);
return false;
}
} // del
if (show == "move")
{
@@ -663,8 +669,12 @@ public:
// What to do:
// Move the visual spawnpoint
// Respawn the owner of the waypoints
target->DeleteFromDB();
target->AddObjectToRemoveList();
if (!Creature::DeleteFromDB(target->GetSpawnId()))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
handler->SetSentErrorMessage(true);
return false;
}
// re-create
Creature* wpCreature = new Creature();
@@ -837,24 +847,11 @@ public:
{
Field* fields = result2->Fetch();
uint32 wpguid = fields[0].GetUInt32();
Creature* creature = handler->GetCreatureFromPlayerMapByDbGuid(wpguid);
if (!creature)
if (!Creature::DeleteFromDB(wpguid))
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpguid);
hasError = true;
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE);
stmt->setUInt32(0, wpguid);
WorldDatabase.Execute(stmt);
}
else
{
creature->CombatStop();
creature->DeleteFromDB();
creature->AddObjectToRemoveList();
}
}
while (result2->NextRow());
@@ -1040,21 +1037,10 @@ public:
Field* fields = result->Fetch();
ObjectGuid::LowType lowguid = fields[0].GetUInt32();
Creature* creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
if (!creature)
if (!Creature::DeleteFromDB(lowguid))
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, lowguid);
hasError = true;
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE);
stmt->setUInt32(0, lowguid);
WorldDatabase.Execute(stmt);
}
else
{
creature->CombatStop();
creature->DeleteFromDB();
creature->AddObjectToRemoveList();
}
}
while (result->NextRow());