diff options
-rwxr-xr-x | src/server/game/Entities/GameObject/GameObject.cpp | 30 | ||||
-rwxr-xr-x | src/server/game/Entities/GameObject/GameObject.h | 8 |
2 files changed, 33 insertions, 5 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index e1b37f73928..3a47729dea6 100755 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -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; + } } } diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 8910de9ef8e..504fc37135f 100755 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -772,6 +772,14 @@ class GameObject : public WorldObject, public GridObject<GameObject> void ModifyHealth(int32 change, Unit* attackerOrHealer = NULL, uint32 spellId = 0); // sets GameObject type 33 destruction flags and optionally default health for that state void SetDestructibleState(GameObjectDestructibleState state, Player* eventInvoker = NULL, bool setHealth = false); + GameObjectDestructibleState GetDestructibleState() const + { + if (HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_DESTROYED)) + return GO_DESTRUCTIBLE_DESTROYED; + if (HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_DAMAGED)) + return GO_DESTRUCTIBLE_DAMAGED; + return GO_DESTRUCTIBLE_INTACT; + } void EventInform(uint32 eventId); |