Core/GameObject: Fix crash added in c6bf7e0b1d

Thanks @jackpoz
This commit is contained in:
Gacko
2014-05-06 18:46:08 +02:00
parent b48879ab79
commit 41d9364b16
2 changed files with 7 additions and 6 deletions

View File

@@ -47,7 +47,7 @@ GameObject::GameObject() : WorldObject(false), MapObject(),
m_respawnTime = 0;
m_respawnDelayTime = 300;
m_lootState = GO_NOT_READY;
m_lootStateUnit = NULL;
m_lootStateUnitGUID = 0;
m_spawnedByDefault = true;
m_usetimes = 0;
m_spellId = 0;
@@ -561,11 +561,12 @@ void GameObject::Update(uint32 diff)
CastSpell(NULL, goInfo->trap.spellId);
SetLootState(GO_JUST_DEACTIVATED);
}
else if (m_lootStateUnit)
else if (m_lootStateUnitGUID)
if (Unit* target = Unit::GetUnit(*this, m_lootStateUnitGUID))
{
// Some traps do not have a spell but should be triggered
if (goInfo->trap.spellId)
CastSpell(m_lootStateUnit, goInfo->trap.spellId);
CastSpell(target, goInfo->trap.spellId);
// Template value or 4 seconds
m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4));
@@ -575,7 +576,7 @@ void GameObject::Update(uint32 diff)
// Battleground gameobjects have data2 == 0 && data5 == 3
if (!goInfo->trap.diameter && goInfo->trap.cooldown == 3)
if (Player* player = m_lootStateUnit->ToPlayer())
if (Player* player = target->ToPlayer())
if (Battleground* bg = player->GetBattleground())
bg->HandleTriggerBuff(GetGUID());
}
@@ -2008,7 +2009,7 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
void GameObject::SetLootState(LootState state, Unit* unit)
{
m_lootState = state;
m_lootStateUnit = unit;
m_lootStateUnitGUID = unit ? unit->GetGUID() : 0;
AI()->OnStateChanged(state, unit);
sScriptMgr->OnGameObjectLootStateChanged(this, state, unit);
if (m_model)

View File

@@ -841,7 +841,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Map
time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
uint32 m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
LootState m_lootState;
Unit* m_lootStateUnit;
uint64 m_lootStateUnitGUID; // GUID of the unit passed with SetLootState(LootState, Unit*)
bool m_spawnedByDefault;
time_t m_cooldownTime; // used as internal reaction delay time store (not state change reaction).
// For traps this: spell casting cooldown, for doors/buttons: reset time.