Core/GameObjects: Prevent repeating damage/destruction events when the gameobject is already in that state

This commit is contained in:
Shauren
2011-07-24 23:55:14 +02:00
parent 17c2c122da
commit 16a1435a0b
2 changed files with 33 additions and 5 deletions
@@ -1735,6 +1735,10 @@ void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= NULL*/, u
if (!GetGOValue()->Building.MaxHealth || !change)
return;
// prevent double destructions of the same object
if (change < 0 && !GetGOValue()->Building.Health)
return;
if (int32(GetGOValue()->Building.Health) + change <= 0)
GetGOValue()->Building.Health = 0;
else if (int32(GetGOValue()->Building.Health) + change >= int32(GetGOValue()->Building.MaxHealth))
@@ -1742,6 +1746,7 @@ void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= NULL*/, u
else
GetGOValue()->Building.Health += change;
// Set the health bar, value = 255 * healthPct;
SetGoAnimProgress(GetGOValue()->Building.Health * 255 / GetGOValue()->Building.MaxHealth);
Player* player = attackerOrHealer->GetCharmerOrOwnerPlayerOrPlayerItself();
@@ -1759,12 +1764,19 @@ void GameObject::ModifyHealth(int32 change, Unit* attackerOrHealer /*= NULL*/, u
player->GetSession()->SendPacket(&data);
}
GameObjectDestructibleState newState = GetDestructibleState();
if (!GetGOValue()->Building.Health)
SetDestructibleState(GO_DESTRUCTIBLE_DESTROYED, player, false);
newState = GO_DESTRUCTIBLE_DESTROYED;
else if (GetGOValue()->Building.Health <= GetGOInfo()->building.damagedNumHits)
SetDestructibleState(GO_DESTRUCTIBLE_DAMAGED, player, false);
newState = GO_DESTRUCTIBLE_DAMAGED;
else if (GetGOValue()->Building.Health == GetGOValue()->Building.MaxHealth)
SetDestructibleState(GO_DESTRUCTIBLE_INTACT, player, false);
newState = GO_DESTRUCTIBLE_INTACT;
if (newState == GetDestructibleState())
return;
SetDestructibleState(newState, player, false);
}
void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player* eventInvoker /*= NULL*/, bool setHealth /*= false*/)
@@ -1841,9 +1853,16 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
break;
}
case GO_DESTRUCTIBLE_REBUILDING:
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_DAMAGED | GO_FLAG_DESTROYED);
SetUInt32Value(GAMEOBJECT_DISPLAYID, m_goInfo->displayId);
{
EventInform(m_goInfo->building.rebuildingEvent);
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_DAMAGED | GO_FLAG_DESTROYED);
uint32 modelId = m_goInfo->displayId;
if (DestructibleModelDataEntry const* modelData = sDestructibleModelDataStore.LookupEntry(m_goInfo->building.destructibleData))
if (modelData->RebuildingDisplayId)
modelId = modelData->RebuildingDisplayId;
SetUInt32Value(GAMEOBJECT_DISPLAYID, modelId);
// restores to full health
if (setHealth)
{
@@ -1851,5 +1870,6 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, Player*
SetGoAnimProgress(255);
}
break;
}
}
}