mirror of
https://github.com/araxiaonline/AscEmu.git
synced 2026-06-13 03:02:22 -04:00
Replace rawptr with shared_ptr for class Corpse
* refactor objmgr corpse functions * make members private * use ranged lock
This commit is contained in:
@@ -74,7 +74,7 @@ void ObjectMgr::initialize()
|
||||
void ObjectMgr::finalize()
|
||||
{
|
||||
sLogger.info("ObjectMgr : Deleting Corpses...");
|
||||
CorpseCollectorUnload();
|
||||
unloadCorpseCollector();
|
||||
|
||||
sLogger.info("ObjectMgr : Deleting Vendors...");
|
||||
for (VendorMap::iterator i = mVendors.begin(); i != mVendors.end(); ++i)
|
||||
@@ -463,6 +463,124 @@ std::shared_ptr<Charter> ObjectMgr::getCharterByItemGuid(const uint64_t _itemGui
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Corpse
|
||||
void ObjectMgr::loadCorpsesForInstance(WorldMap* _worldMap) const
|
||||
{
|
||||
if (QueryResult* result = CharacterDatabase.Query("SELECT * FROM corpses WHERE instanceid = %u", _worldMap->getInstanceId()))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
const auto corpse = std::make_shared<Corpse>(HIGHGUID_TYPE_CORPSE, fields[0].GetUInt32());
|
||||
corpse->SetPosition(fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat());
|
||||
corpse->setZoneId(fields[5].GetUInt32());
|
||||
corpse->SetMapId(fields[6].GetUInt32());
|
||||
corpse->SetInstanceID(fields[7].GetUInt32());
|
||||
corpse->setCorpseDataFromDbString(fields[8].GetString());
|
||||
|
||||
if (corpse->getDisplayId() == 0)
|
||||
continue;
|
||||
|
||||
corpse->PushToWorld(_worldMap);
|
||||
} while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Corpse> ObjectMgr::loadCorpseByGuid(const uint32_t _corpseGuid) const
|
||||
{
|
||||
if (QueryResult* result = CharacterDatabase.Query("SELECT * FROM corpses WHERE guid =%u ", _corpseGuid))
|
||||
{
|
||||
Field* field = result->Fetch();
|
||||
const auto corpse = std::make_shared<Corpse>(HIGHGUID_TYPE_CORPSE, field[0].GetUInt32());
|
||||
corpse->SetPosition(field[1].GetFloat(), field[2].GetFloat(), field[3].GetFloat(), field[4].GetFloat());
|
||||
corpse->setZoneId(field[5].GetUInt32());
|
||||
corpse->SetMapId(field[6].GetUInt32());
|
||||
corpse->setCorpseDataFromDbString(field[7].GetString());
|
||||
|
||||
if (corpse->getDisplayId() == 0)
|
||||
return nullptr;
|
||||
|
||||
corpse->setLoadedFromDB(true);
|
||||
corpse->SetInstanceID(field[8].GetUInt32());
|
||||
corpse->AddToWorld();
|
||||
|
||||
delete result;
|
||||
return corpse;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Corpse> ObjectMgr::createCorpse()
|
||||
{
|
||||
uint32_t corpseGuid = ++m_hiCorpseGuid;
|
||||
return std::make_shared<Corpse>(HIGHGUID_TYPE_CORPSE, corpseGuid);
|
||||
}
|
||||
|
||||
void ObjectMgr::addCorpse(const std::shared_ptr<Corpse>& _corpse)
|
||||
{
|
||||
std::lock_guard guard(m_corpseLock);
|
||||
m_corpses[_corpse->getGuidLow()] = _corpse;
|
||||
}
|
||||
|
||||
void ObjectMgr::removeCorpse(const std::shared_ptr<Corpse>& _corpse)
|
||||
{
|
||||
std::lock_guard guard(m_corpseLock);
|
||||
m_corpses.erase(_corpse->getGuidLow());
|
||||
}
|
||||
|
||||
std::shared_ptr<Corpse> ObjectMgr::getCorpseByGuid(uint32_t _corpseGuid)
|
||||
{
|
||||
std::lock_guard guard(m_corpseLock);
|
||||
const auto corpsePair = m_corpses.find(_corpseGuid);
|
||||
return corpsePair != m_corpses.end() ? corpsePair->second : nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Corpse> ObjectMgr::getCorpseByOwner(const uint32_t _playerGuid)
|
||||
{
|
||||
std::lock_guard guard(m_corpseLock);
|
||||
for (const auto& corpsePair : m_corpses)
|
||||
{
|
||||
WoWGuid wowGuid;
|
||||
wowGuid.Init(corpsePair.second->getOwnerGuid());
|
||||
|
||||
if (wowGuid.getGuidLowPart() == _playerGuid)
|
||||
return corpsePair.second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ObjectMgr::unloadCorpseCollector()
|
||||
{
|
||||
std::lock_guard guard(m_corpseLock);
|
||||
for (const auto& corpsePair : m_corpses)
|
||||
{
|
||||
const auto corpse = corpsePair.second;
|
||||
if (corpse->IsInWorld())
|
||||
corpse->RemoveFromWorld(false);
|
||||
}
|
||||
m_corpses.clear();
|
||||
}
|
||||
|
||||
void ObjectMgr::addCorpseDespawnTime(const std::shared_ptr<Corpse>& _corpse)
|
||||
{
|
||||
if (_corpse->IsInWorld())
|
||||
_corpse->getWorldMap()->addCorpseDespawn(_corpse->getGuid(), 600000);
|
||||
}
|
||||
|
||||
void ObjectMgr::delinkCorpseForPlayer(const Player* _player)
|
||||
{
|
||||
if (const auto corpse = getCorpseByOwner(_player->getGuidLow()))
|
||||
{
|
||||
corpse->delink();
|
||||
addCorpseDespawnTime(corpse);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Misc
|
||||
void ObjectMgr::generateDatabaseGossipMenu(Object* object, uint32_t gossipMenuId, Player* player, uint32_t forcedTextId /*= 0*/)
|
||||
@@ -1125,69 +1243,6 @@ void ObjectMgr::LoadCompletedAchievements()
|
||||
}
|
||||
#endif
|
||||
|
||||
Corpse* ObjectMgr::LoadCorpse(uint32 guid)
|
||||
{
|
||||
QueryResult* result = CharacterDatabase.Query("SELECT * FROM corpses WHERE guid =%u ", guid);
|
||||
|
||||
if (result == nullptr)
|
||||
return nullptr;
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
Corpse* pCorpse = new Corpse(HIGHGUID_TYPE_CORPSE, fields[0].GetUInt32());
|
||||
pCorpse->SetPosition(fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat());
|
||||
pCorpse->setZoneId(fields[5].GetUInt32());
|
||||
pCorpse->SetMapId(fields[6].GetUInt32());
|
||||
pCorpse->setCorpseDataFromDbString(fields[7].GetString());
|
||||
if (pCorpse->getDisplayId() == 0)
|
||||
{
|
||||
delete pCorpse;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pCorpse->setLoadedFromDB(true);
|
||||
pCorpse->SetInstanceID(fields[8].GetUInt32());
|
||||
pCorpse->AddToWorld();
|
||||
|
||||
delete result;
|
||||
|
||||
return pCorpse;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Live corpse retreival.
|
||||
/// comments: I use the same tricky method to start from the last corpse instead of the first
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
Corpse* ObjectMgr::GetCorpseByOwner(uint32 ownerguid)
|
||||
{
|
||||
Corpse* rv = nullptr;
|
||||
_corpseslock.Acquire();
|
||||
for (CorpseMap::const_iterator itr = m_corpses.begin(); itr != m_corpses.end(); ++itr)
|
||||
{
|
||||
WoWGuid wowGuid;
|
||||
wowGuid.Init(itr->second->getOwnerGuid());
|
||||
|
||||
if (wowGuid.getGuidLowPart() == ownerguid)
|
||||
{
|
||||
rv = itr->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_corpseslock.Release();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ObjectMgr::DelinkPlayerCorpses(Player* pOwner)
|
||||
{
|
||||
//dupe protection agaisnt crashs
|
||||
Corpse* c = this->GetCorpseByOwner(pOwner->getGuidLow());
|
||||
if (!c)
|
||||
return;
|
||||
sEventMgr.AddEvent(c, &Corpse::delink, EVENT_CORPSE_SPAWN_BONES, 1, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
|
||||
CorpseAddEventDespawn(c);
|
||||
}
|
||||
|
||||
#if VERSION_STRING > TBC
|
||||
void ObjectMgr::LoadAchievementRewards()
|
||||
{
|
||||
@@ -1627,35 +1682,6 @@ Item* ObjectMgr::LoadItem(uint32 lowguid)
|
||||
return pReturn;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadCorpses(WorldMap* mgr)
|
||||
{
|
||||
QueryResult* result = CharacterDatabase.Query("SELECT * FROM corpses WHERE instanceid = %u", mgr->getInstanceId());
|
||||
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
Corpse* pCorpse = new Corpse(HIGHGUID_TYPE_CORPSE, fields[0].GetUInt32());
|
||||
pCorpse->SetPosition(fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetFloat());
|
||||
pCorpse->setZoneId(fields[5].GetUInt32());
|
||||
pCorpse->SetMapId(fields[6].GetUInt32());
|
||||
pCorpse->SetInstanceID(fields[7].GetUInt32());
|
||||
pCorpse->setCorpseDataFromDbString(fields[8].GetString());
|
||||
if (pCorpse->getDisplayId() == 0)
|
||||
{
|
||||
delete pCorpse;
|
||||
continue;
|
||||
}
|
||||
|
||||
pCorpse->PushToWorld(mgr);
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
}
|
||||
}
|
||||
|
||||
#if VERSION_STRING > TBC
|
||||
AchievementCriteriaEntryList const & ObjectMgr::GetAchievementCriteriaByType(AchievementCriteriaTypes type)
|
||||
{
|
||||
@@ -1681,29 +1707,6 @@ void ObjectMgr::LoadAchievementCriteriaList()
|
||||
}
|
||||
#endif
|
||||
|
||||
void ObjectMgr::CorpseAddEventDespawn(Corpse* pCorpse)
|
||||
{
|
||||
if (!pCorpse->IsInWorld())
|
||||
delete pCorpse;
|
||||
else
|
||||
pCorpse->getWorldMap()->addCorpseDespawn(pCorpse->getGuid(), 600000);
|
||||
}
|
||||
|
||||
void ObjectMgr::CorpseCollectorUnload()
|
||||
{
|
||||
CorpseMap::const_iterator itr;
|
||||
_corpseslock.Acquire();
|
||||
for (itr = m_corpses.begin(); itr != m_corpses.end(); ++itr)
|
||||
{
|
||||
Corpse* c = itr->second;
|
||||
if (c->IsInWorld())
|
||||
c->RemoveFromWorld(false);
|
||||
delete c;
|
||||
}
|
||||
m_corpses.clear();
|
||||
_corpseslock.Release();
|
||||
}
|
||||
|
||||
Trainer* ObjectMgr::GetTrainer(uint32 Entry)
|
||||
{
|
||||
TrainerMap::iterator iter = mTrainers.find(Entry);
|
||||
@@ -2071,38 +2074,6 @@ void ObjectMgr::RemovePlayer(Player* p)
|
||||
_players.erase(p->getGuidLow());
|
||||
}
|
||||
|
||||
Corpse* ObjectMgr::CreateCorpse()
|
||||
{
|
||||
uint32 guid;
|
||||
guid = ++m_hiCorpseGuid;
|
||||
|
||||
return new Corpse(HIGHGUID_TYPE_CORPSE, guid);
|
||||
}
|
||||
|
||||
void ObjectMgr::AddCorpse(Corpse* p) //add it to global storage
|
||||
{
|
||||
_corpseslock.Acquire();
|
||||
m_corpses[p->getGuidLow()] = p;
|
||||
_corpseslock.Release();
|
||||
}
|
||||
|
||||
void ObjectMgr::RemoveCorpse(Corpse* p)
|
||||
{
|
||||
_corpseslock.Acquire();
|
||||
m_corpses.erase(p->getGuidLow());
|
||||
_corpseslock.Release();
|
||||
}
|
||||
|
||||
Corpse* ObjectMgr::GetCorpse(uint32 corpseguid)
|
||||
{
|
||||
Corpse* rv = nullptr;
|
||||
_corpseslock.Acquire();
|
||||
CorpseMap::const_iterator itr = m_corpses.find(corpseguid);
|
||||
rv = (itr != m_corpses.end()) ? itr->second : 0;
|
||||
_corpseslock.Release();
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadReputationModifierTable(const char* tablename, ReputationModMap* dmap)
|
||||
{
|
||||
QueryResult* result = WorldDatabase.Query("SELECT * FROM %s", tablename);
|
||||
|
||||
@@ -250,6 +250,27 @@ private:
|
||||
std::unordered_map<uint32, std::shared_ptr<Charter>> m_charters[NUM_CHARTER_TYPES];
|
||||
std::mutex m_charterLock;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Corpse
|
||||
public:
|
||||
void loadCorpsesForInstance(WorldMap* _worldMap) const;
|
||||
std::shared_ptr<Corpse> loadCorpseByGuid(uint32_t _corpseGuid) const;
|
||||
std::shared_ptr<Corpse> createCorpse();
|
||||
|
||||
void addCorpse(const std::shared_ptr<Corpse>&);
|
||||
void removeCorpse(const std::shared_ptr<Corpse>&);
|
||||
|
||||
std::shared_ptr<Corpse> getCorpseByGuid(uint32_t _corpseGuid);
|
||||
std::shared_ptr<Corpse> getCorpseByOwner(uint32_t _playerGuid);
|
||||
|
||||
void unloadCorpseCollector();
|
||||
void addCorpseDespawnTime(const std::shared_ptr<Corpse>& _corpse);
|
||||
void delinkCorpseForPlayer(const Player* _player);
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Corpse>> m_corpses;
|
||||
std::mutex m_corpseLock;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Misc
|
||||
public:
|
||||
@@ -277,7 +298,7 @@ public:
|
||||
typedef std::unordered_map<uint32, std::vector<CreatureItem>*> VendorMap;
|
||||
typedef std::unordered_map<uint32, Trainer*> TrainerMap;
|
||||
typedef std::unordered_map<uint32, ReputationModifier*> ReputationModMap;
|
||||
typedef std::unordered_map<uint32, Corpse*> CorpseMap;
|
||||
|
||||
|
||||
// Map typedef's
|
||||
typedef std::map<uint32, LevelInfo*> LevelMap;
|
||||
@@ -291,8 +312,7 @@ public:
|
||||
Player* GetPlayer(const char* name, bool caseSensitive = true);
|
||||
Player* GetPlayer(uint32 guid);
|
||||
|
||||
CorpseMap m_corpses;
|
||||
Mutex _corpseslock;
|
||||
|
||||
Mutex m_creatureSetMutex;
|
||||
|
||||
Item* CreateItem(uint32 entry, Player* owner);
|
||||
@@ -317,16 +337,6 @@ public:
|
||||
void RenamePlayerInfo(CachedCharacterInfo* pn, std::string oldname, std::string newname);
|
||||
void DeletePlayerInfo(uint32 guid);
|
||||
|
||||
//Corpse Stuff
|
||||
Corpse* GetCorpseByOwner(uint32 ownerguid);
|
||||
void CorpseCollectorUnload();
|
||||
void CorpseAddEventDespawn(Corpse* pCorpse);
|
||||
void DelinkPlayerCorpses(Player* pOwner);
|
||||
Corpse* CreateCorpse();
|
||||
void AddCorpse(Corpse*);
|
||||
void RemoveCorpse(Corpse*);
|
||||
Corpse* GetCorpse(uint32 corpseguid);
|
||||
|
||||
//Vendors
|
||||
std::vector<CreatureItem> *GetVendorList(uint32 entry);
|
||||
void SetVendorList(uint32 Entry, std::vector<CreatureItem>* list_);
|
||||
@@ -361,8 +371,6 @@ public:
|
||||
#endif
|
||||
void LoadPlayersInfo();
|
||||
|
||||
Corpse* LoadCorpse(uint32 guid);
|
||||
void LoadCorpses(WorldMap* mgr);
|
||||
void LoadVendors();
|
||||
void ReloadVendors();
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ void WorldMap::initialize()
|
||||
getScript()->OnLoad();
|
||||
|
||||
// load corpses
|
||||
sObjectMgr.LoadCorpses(this);
|
||||
sObjectMgr.loadCorpsesForInstance(this);
|
||||
worldstateshandler.InitWorldStates(sObjectMgr.GetWorldStatesForMap(getBaseMap()->getMapId()));
|
||||
worldstateshandler.setObserver(this);
|
||||
}
|
||||
@@ -421,7 +421,7 @@ void WorldMap::update(uint32_t t_diff)
|
||||
break;
|
||||
|
||||
_corpseDespawnTimes.pop();
|
||||
if (Corpse* pCorpse = sObjectMgr.GetCorpse(static_cast<uint32_t>(next.guid)))
|
||||
if (std::shared_ptr<Corpse> pCorpse = sObjectMgr.getCorpseByGuid(static_cast<uint32_t>(next.guid)))
|
||||
{
|
||||
if (pCorpse->getWorldMap() != this)
|
||||
break;
|
||||
|
||||
@@ -42,12 +42,12 @@ Corpse::Corpse(uint32_t high, uint32_t low)
|
||||
setScale(1);
|
||||
|
||||
if (high != 0)
|
||||
sObjectMgr.AddCorpse(this);
|
||||
sObjectMgr.addCorpse(shared_from_this());
|
||||
}
|
||||
|
||||
Corpse::~Corpse()
|
||||
{
|
||||
sObjectMgr.RemoveCorpse(this);
|
||||
sObjectMgr.removeCorpse(shared_from_this());
|
||||
}
|
||||
|
||||
void Corpse::create(Player* owner, uint32_t mapid, LocationVector lv)
|
||||
@@ -181,7 +181,7 @@ void Corpse::spawnBones()
|
||||
setItem(i, 0);
|
||||
|
||||
deleteFromDB();
|
||||
sObjectMgr.CorpseAddEventDespawn(this);
|
||||
sObjectMgr.addCorpseDespawnTime(shared_from_this());
|
||||
setCorpseState(CORPSE_STATE_BONES);
|
||||
}
|
||||
|
||||
@@ -189,6 +189,7 @@ void Corpse::delink()
|
||||
{
|
||||
setFlags(CORPSE_FLAG_BONE | CORPSE_FLAG_UNK1);
|
||||
setOwnerNotifyMap(0);
|
||||
|
||||
setCorpseState(CORPSE_STATE_BONES);
|
||||
deleteFromDB();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ enum CorpseFlags
|
||||
|
||||
struct WoWCorpse;
|
||||
|
||||
class SERVER_DECL Corpse : public Object
|
||||
class SERVER_DECL Corpse : public Object, public std::enable_shared_from_this<Corpse>
|
||||
{
|
||||
public:
|
||||
Corpse(uint32_t high, uint32_t low);
|
||||
|
||||
@@ -7437,7 +7437,7 @@ bool Player::isAllowedToCreateCorpse() const
|
||||
|
||||
void Player::createCorpse()
|
||||
{
|
||||
sObjectMgr.DelinkPlayerCorpses(this);
|
||||
sObjectMgr.delinkCorpseForPlayer(this);
|
||||
|
||||
if (!isAllowedToCreateCorpse())
|
||||
{
|
||||
@@ -7445,7 +7445,7 @@ void Player::createCorpse()
|
||||
return;
|
||||
}
|
||||
|
||||
Corpse* corpse = sObjectMgr.CreateCorpse();
|
||||
const auto corpse = sObjectMgr.createCorpse();
|
||||
corpse->SetInstanceID(GetInstanceID());
|
||||
corpse->create(this, GetMapId(), GetPosition());
|
||||
|
||||
@@ -7500,7 +7500,7 @@ void Player::createCorpse()
|
||||
|
||||
void Player::spawnCorpseBody()
|
||||
{
|
||||
if (Corpse* corpse = sObjectMgr.GetCorpseByOwner(this->getGuidLow()))
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(this->getGuidLow()))
|
||||
{
|
||||
if (!corpse->IsInWorld())
|
||||
{
|
||||
@@ -7525,15 +7525,10 @@ void Player::spawnCorpseBones()
|
||||
{
|
||||
setCorpseData({ 0, 0, 0, 0 }, 0);
|
||||
|
||||
if (Corpse* corpse = sObjectMgr.GetCorpseByOwner(getGuidLow()))
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
{
|
||||
if (corpse->IsInWorld() && corpse->getCorpseState() == CORPSE_STATE_BODY)
|
||||
{
|
||||
if (corpse->GetInstanceID() != GetInstanceID())
|
||||
sEventMgr.AddEvent(corpse, &Corpse::spawnBones, EVENT_CORPSE_SPAWN_BONES, 100, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
|
||||
else
|
||||
corpse->spawnBones();
|
||||
}
|
||||
corpse->spawnBones();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7544,7 +7539,7 @@ void Player::repopRequest()
|
||||
|
||||
if (m_corpseData.instanceId != 0)
|
||||
{
|
||||
if (auto corpse = sObjectMgr.GetCorpseByOwner(getGuidLow()))
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
corpse->resetDeathClock();
|
||||
|
||||
resurrect();
|
||||
@@ -7606,7 +7601,7 @@ void Player::repopRequest()
|
||||
spawnCorpseBody();
|
||||
|
||||
if (m_corpseData.instanceId != 0)
|
||||
if (auto corpse = sObjectMgr.GetCorpseByOwner(getGuidLow()))
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
corpse->resetDeathClock();
|
||||
|
||||
m_session->SendPacket(SmsgDeathReleaseLoc(m_mapId, m_position).serialise().get());
|
||||
@@ -10090,7 +10085,11 @@ bool Player::isAtGroupRewardDistance(Object* pRewardSource)
|
||||
if (!pRewardSource)
|
||||
return false;
|
||||
|
||||
Object* player = sObjectMgr.GetCorpseByOwner(getGuidLow());
|
||||
Object* player = nullptr;
|
||||
const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow());
|
||||
if (corpse)
|
||||
player = sObjectMgr.GetPlayer(corpse->getOwnerGuid());
|
||||
|
||||
if (!player || isAlive())
|
||||
player = this;
|
||||
|
||||
@@ -10831,12 +10830,11 @@ void Player::sendLoot(uint64_t guid, uint8_t loot_type, uint32_t mapId)
|
||||
}
|
||||
else if (wowGuid.isCorpse())
|
||||
{
|
||||
Corpse* pCorpse = sObjectMgr.GetCorpse((uint32_t)guid);
|
||||
if (!pCorpse)
|
||||
return;
|
||||
|
||||
pLoot = &pCorpse->loot;
|
||||
m_currentLoot = pCorpse->getGuid();
|
||||
if (const auto corpse = sObjectMgr.getCorpseByGuid(static_cast<uint32_t>(guid)))
|
||||
{
|
||||
pLoot = &corpse->loot;
|
||||
m_currentLoot = corpse->getGuid();
|
||||
}
|
||||
}
|
||||
else if (wowGuid.isItem())
|
||||
{
|
||||
@@ -14698,10 +14696,8 @@ void Player::loadFromDBProc(QueryResultVector& results)
|
||||
|
||||
if (!isAlive())
|
||||
{
|
||||
if (Corpse* corpse = sObjectMgr.GetCorpseByOwner(getGuidLow()))
|
||||
{
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
setCorpseData(corpse->GetPosition(), corpse->GetInstanceID());
|
||||
}
|
||||
}
|
||||
|
||||
#if VERSION_STRING > Classic
|
||||
@@ -15817,22 +15813,17 @@ void Player::completeLoading()
|
||||
}
|
||||
else if (hasPlayerFlags(PLAYER_FLAG_DEATH_WORLD_ENABLE))
|
||||
{
|
||||
Corpse* corpse = sObjectMgr.GetCorpseByOwner(getGuidLow());
|
||||
if (corpse == nullptr)
|
||||
{
|
||||
sEventMgr.AddEvent(this, &Player::repopAtGraveyard, GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), EVENT_PLAYER_CHECKFORCHEATS, 1000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
setDeathState(CORPSE);
|
||||
}
|
||||
else
|
||||
sEventMgr.AddEvent(this, &Player::repopAtGraveyard, GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), EVENT_PLAYER_CHECKFORCHEATS, 1000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
|
||||
}
|
||||
|
||||
if (isDead())
|
||||
{
|
||||
if (getCorpseInstanceId() != 0)
|
||||
{
|
||||
if (Corpse* corpse = sObjectMgr.GetCorpseByOwner(getGuidLow()))
|
||||
if (const auto corpse = sObjectMgr.getCorpseByOwner(getGuidLow()))
|
||||
corpse->resetDeathClock();
|
||||
|
||||
getSession()->SendPacket(SmsgCorpseReclaimDelay(CORPSE_RECLAIM_TIME_MS).serialise().get());
|
||||
|
||||
@@ -330,7 +330,7 @@ uint8_t WorldSession::deleteCharacter(WoWGuid guid)
|
||||
|
||||
CharacterDatabase.WaitExecute("DELETE FROM characters WHERE guid = %u", guid.getGuidLow());
|
||||
|
||||
const auto corpse = sObjectMgr.GetCorpseByOwner(guid.getGuidLow());
|
||||
const auto corpse = sObjectMgr.getCorpseByOwner(guid.getGuidLow());
|
||||
if (corpse)
|
||||
CharacterDatabase.Execute("DELETE FROM corpses WHERE guid = %u", corpse->getGuidLow());
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ Loot* WorldSession::getMoneyLootFromHighGuidType(WoWGuid wowGuid)
|
||||
}
|
||||
case HighGuid::Corpse:
|
||||
{
|
||||
if (auto corpse = sObjectMgr.GetCorpse(wowGuid.getGuidLowPart()))
|
||||
if (auto corpse = sObjectMgr.getCorpseByGuid(wowGuid.getGuidLowPart()))
|
||||
return &corpse->loot;
|
||||
|
||||
return nullptr;
|
||||
@@ -423,7 +423,7 @@ void WorldSession::doLootRelease(WoWGuid lguid)
|
||||
}
|
||||
else if (lguid.isCorpse()) // ONLY remove insignia at BG
|
||||
{
|
||||
Corpse* corpse = sObjectMgr.GetCorpse(lguid.getGuidLow());
|
||||
std::shared_ptr<Corpse> corpse = sObjectMgr.getCorpseByGuid(lguid.getGuidLow());
|
||||
if (!corpse || !corpse->IsWithinDistInMap(_player, 5.0f))
|
||||
return;
|
||||
|
||||
|
||||
@@ -1120,7 +1120,7 @@ void WorldSession::handleCorpseReclaimOpcode(WorldPacket& recvPacket)
|
||||
if (srlPacket.guid.getRawGuid() == 0)
|
||||
return;
|
||||
|
||||
auto corpse = sObjectMgr.GetCorpse(srlPacket.guid.getGuidLow());
|
||||
auto corpse = sObjectMgr.getCorpseByGuid(srlPacket.guid.getGuidLow());
|
||||
if (corpse == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ void WorldSession::handleItemNameQueryOpcode(WorldPacket& recvPacket)
|
||||
|
||||
void WorldSession::handleCorpseQueryOpcode(WorldPacket& /*recvPacket*/)
|
||||
{
|
||||
const auto corpse = sObjectMgr.GetCorpseByOwner(_player->getGuidLow());
|
||||
const auto corpse = sObjectMgr.getCorpseByOwner(_player->getGuidLow());
|
||||
if (corpse == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
@@ -2980,7 +2980,7 @@ GameObject* Spell::GetGameObjectTarget() const
|
||||
return gameObjTarget;
|
||||
}
|
||||
|
||||
Corpse* Spell::GetCorpseTarget() const
|
||||
std::shared_ptr<Corpse> Spell::GetCorpseTarget() const
|
||||
{
|
||||
return corpseTarget;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ class SERVER_DECL Spell
|
||||
Item* itemTarget = nullptr;
|
||||
GameObject* gameObjTarget = nullptr;
|
||||
Player* playerTarget = nullptr;
|
||||
Corpse* corpseTarget = nullptr;
|
||||
std::shared_ptr<Corpse> corpseTarget = nullptr;
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -634,7 +634,7 @@ class SERVER_DECL Spell
|
||||
Unit* GetUnitTarget() const;
|
||||
Player* GetPlayerTarget() const;
|
||||
GameObject* GetGameObjectTarget() const;
|
||||
Corpse* GetCorpseTarget() const;
|
||||
std::shared_ptr<Corpse> GetCorpseTarget() const;
|
||||
|
||||
uint32 chaindamage;
|
||||
|
||||
|
||||
@@ -1628,7 +1628,7 @@ SpellCastResult Spell::canCast(const bool secondCheck, uint32_t* parameter1, uin
|
||||
if (target->isCorpse())
|
||||
{
|
||||
// Player can't cast spells on corpses with bones only left
|
||||
const auto targetCorpse = sObjectMgr.GetCorpseByOwner(target->getGuidLow());
|
||||
const auto targetCorpse = sObjectMgr.getCorpseByOwner(target->getGuidLow());
|
||||
if (targetCorpse == nullptr || !targetCorpse->IsInWorld() || targetCorpse->getCorpseState() == CORPSE_STATE_BONES)
|
||||
return SPELL_FAILED_BAD_TARGETS;
|
||||
}
|
||||
@@ -5815,7 +5815,7 @@ void Spell::_updateTargetPointers(const uint64_t targetGuid)
|
||||
gameObjTarget = getCaster()->getWorldMap()->getGameObject(wowGuid.getGuidLowPart());
|
||||
break;
|
||||
case HighGuid::Corpse:
|
||||
corpseTarget = sObjectMgr.GetCorpse(wowGuid.getGuidLowPart());
|
||||
corpseTarget = sObjectMgr.getCorpseByGuid(wowGuid.getGuidLowPart());
|
||||
break;
|
||||
default:
|
||||
sLogger.failure("Spell::_updateTargetPointers : Invalid object type for spell target (low guid %u) in spell %u", wowGuid.getGuidLowPart(), getSpellInfo()->getId());
|
||||
|
||||
@@ -5384,15 +5384,15 @@ void Spell::SpellEffectAttackMe(uint8_t /*effectIndex*/)
|
||||
|
||||
void Spell::SpellEffectSkinPlayerCorpse(uint8_t /*effectIndex*/)
|
||||
{
|
||||
Corpse* corpse = nullptr;
|
||||
std::shared_ptr<Corpse> corpse = nullptr;
|
||||
if (!playerTarget)
|
||||
{
|
||||
// means we're "skinning" a corpse
|
||||
corpse = sObjectMgr.GetCorpse((uint32)m_targets.getUnitTarget()); // hacky
|
||||
corpse = sObjectMgr.getCorpseByGuid((uint32)m_targets.getUnitTarget()); // hacky
|
||||
}
|
||||
else if (playerTarget->getDeathState() == CORPSE) // repopped while we were casting
|
||||
{
|
||||
corpse = sObjectMgr.GetCorpse(playerTarget->getGuidLow());
|
||||
corpse = sObjectMgr.getCorpseByGuid(playerTarget->getGuidLow());
|
||||
}
|
||||
|
||||
if (p_caster == nullptr)
|
||||
@@ -5454,7 +5454,7 @@ void Spell::SpellEffectSkinPlayerCorpse(uint8_t /*effectIndex*/)
|
||||
p_caster->sendLoot(corpse->getGuid(), LOOT_SKINNING, corpse->GetMapId());
|
||||
|
||||
corpse->deleteFromDB();
|
||||
sObjectMgr.CorpseAddEventDespawn(corpse);
|
||||
sObjectMgr.addCorpseDespawnTime(corpse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user