Skip to content

Commit

Permalink
GameObject/Spell: Introduce SetDestructibleState for damageable GOs f…
Browse files Browse the repository at this point in the history
…rom TC

Shauren is the original author of this api
  • Loading branch information
killerwife committed Apr 10, 2022
1 parent 10b49a1 commit fd667e9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
31 changes: 31 additions & 0 deletions src/game/Entities/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,37 @@ void GameObject::ForceGameObjectHealth(int32 diff, Unit* caster)
SetGoAnimProgress(GetMaxHealth() ? m_useTimes * 255 / GetMaxHealth() : 255);
}

void GameObject::SetDestructibleState(GameObjectDestructibleState state, Unit* attackerOrHealer /*= nullptr*/, bool setHealth /*= false*/)
{
// the user calling this must know he is already operating on destructible gameobject
MANGOS_ASSERT(GetGoType() == GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING);

switch (state)
{
case GO_DESTRUCTIBLE_INTACT: // Set to full health
ForceGameObjectHealth(GetMaxHealth(), attackerOrHealer);
break;
case GO_DESTRUCTIBLE_DAMAGED: // Set to damaged
ForceGameObjectHealth(GetGOInfo()->destructibleBuilding.damagedNumHits, attackerOrHealer);
break;
case GO_DESTRUCTIBLE_DESTROYED: // Set to destroyed
ForceGameObjectHealth(-int32(GetHealth()), attackerOrHealer);
break;
case GO_DESTRUCTIBLE_REBUILDING: // Set to rebuilding
ForceGameObjectHealth(0, attackerOrHealer);
break;
}
}

GameObjectDestructibleState GameObject::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;
}

float GameObject::GetInteractionDistance() const
{
switch (GetGoType())
Expand Down
4 changes: 3 additions & 1 deletion src/game/Entities/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,8 @@ class GameObject : public WorldObject
// Destructible GO handling
void DealGameObjectDamage(uint32 damage, uint32 spell, Unit* caster);
void RebuildGameObject(Unit* caster);
void ForceGameObjectHealth(int32 diff, Unit* caster);
void SetDestructibleState(GameObjectDestructibleState state, Unit* attackerOrHealer = nullptr, bool setHealth = false);
GameObjectDestructibleState GetDestructibleState() const;
uint32 GetHealth() const { return m_useTimes; }
uint32 GetMaxHealth() const { return m_goInfo->destructibleBuilding.intactNumHits + m_goInfo->destructibleBuilding.damagedNumHits; }

Expand Down Expand Up @@ -1031,6 +1032,7 @@ class GameObject : public WorldObject
void TickCapturePoint();
void UpdateModel(); // updates model in case displayId were changed
void UpdateCollisionState() const; // updates state in Map's dynamic collision tree
void ForceGameObjectHealth(int32 diff, Unit* caster); // should use SetDestructibleState from outside

GridReference<GameObject> m_gridRef;
};
Expand Down
8 changes: 8 additions & 0 deletions src/game/Entities/GameObjectDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ enum GOState
GO_STATE_ACTIVE_ALTERNATIVE = 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
};

enum GameObjectDestructibleState
{
GO_DESTRUCTIBLE_INTACT = 0,
GO_DESTRUCTIBLE_DAMAGED = 1,
GO_DESTRUCTIBLE_DESTROYED = 2,
GO_DESTRUCTIBLE_REBUILDING = 3
};

#define MAX_GO_STATE 3

#endif
19 changes: 1 addition & 18 deletions src/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12716,24 +12716,7 @@ void Spell::EffectWMOChange(SpellEffectIndex effIdx)
if (!caster)
return;

switch (m_spellInfo->EffectMiscValue[effIdx])
{
case 0: // Set to full health
gameObjTarget->ForceGameObjectHealth(gameObjTarget->GetMaxHealth(), caster);
break;
case 1: // Set to damaged
gameObjTarget->ForceGameObjectHealth(gameObjTarget->GetGOInfo()->destructibleBuilding.damagedNumHits, caster);
break;
case 2: // Set to destroyed
gameObjTarget->ForceGameObjectHealth(-int32(gameObjTarget->GetHealth()), caster);
break;
case 3: // Set to rebuilding
gameObjTarget->ForceGameObjectHealth(0, caster);
break;
default:
sLog.outError("Spell::EffectWMOChange, spell Id %u with undefined change value %u", m_spellInfo->Id, m_spellInfo->EffectMiscValue[effIdx]);
break;
}
gameObjTarget->SetDestructibleState(GameObjectDestructibleState(m_spellInfo->EffectMiscValue[effIdx]), m_caster, true);
}

void Spell::EffectKillCreditPersonal(SpellEffectIndex eff_idx)
Expand Down

0 comments on commit fd667e9

Please sign in to comment.