feat(Core/Creature): Implement ModifyThreatPercentTemp() function (#11521)

* feat(Core/Creature): Implement ModifyThreatTemporary function

* feat(Core/Creature): Implement ModifyThreatPercentTemp() function

* fix build
This commit is contained in:
Skjalf
2022-04-24 22:48:37 -03:00
committed by GitHub
parent f5948b5fe4
commit d8d0d5a5e4
2 changed files with 44 additions and 0 deletions

View File

@@ -201,6 +201,20 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
return true;
}
bool TemporaryThreatModifierEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
if (Unit* victim = ObjectAccessor::GetUnit(m_owner, m_threatVictimGUID))
{
if (m_owner.IsInCombatWith(victim))
{
m_owner.getThreatMgr().modifyThreatPercent(victim, -100); // Reset threat to zero.
m_owner.getThreatMgr().addThreat(victim, m_threatValue); // Set to the previous value it had, first before modification.
}
}
return true;
}
Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(), m_groupLootTimer(0), lootingGroupLowGUID(0), m_PlayerDamageReq(0), m_lootRecipientGroup(0),
m_corpseRemoveTime(0), m_respawnTime(0), m_respawnDelay(300), m_corpseDelay(60), m_wanderDistance(0.0f), m_boundaryCheckTime(2500),
m_transportCheckTimer(1000), lootPickPocketRestoreTime(0), m_reactState(REACT_AGGRESSIVE), m_defaultMovementType(IDLE_MOTION_TYPE),
@@ -3528,3 +3542,19 @@ void Creature::SetCorpseRemoveTime(uint32 delay)
{
m_corpseRemoveTime = GameTime::GetGameTime().count() + delay;
}
void Creature::ModifyThreatPercentTemp(Unit* victim, int32 percent, Milliseconds duration)
{
if (victim)
{
float currentThreat = getThreatMgr().getThreat(victim);
if (percent != 0.0f)
{
getThreatMgr().modifyThreatPercent(victim, percent);
}
TemporaryThreatModifierEvent* pEvent = new TemporaryThreatModifierEvent(*this, victim->GetGUID(), currentThreat);
m_Events.AddEvent(pEvent, m_Events.CalculateTime(duration.count()));
}
}

View File

@@ -385,6 +385,8 @@ public:
void SetAssistanceTimer(uint32 value) { m_assistanceTimer = value; }
void ModifyThreatPercentTemp(Unit* victim, int32 percent, Milliseconds duration);
protected:
bool CreateFromProto(ObjectGuid::LowType guidlow, uint32 Entry, uint32 vehId, const CreatureData* data = nullptr);
bool InitEntry(uint32 entry, const CreatureData* data = nullptr);
@@ -494,4 +496,16 @@ private:
Seconds const m_respawnTimer;
};
class TemporaryThreatModifierEvent : public BasicEvent
{
public:
TemporaryThreatModifierEvent(Creature& owner, ObjectGuid threatVictimGUID, float threatValue) : BasicEvent(), m_owner(owner), m_threatVictimGUID(threatVictimGUID), m_threatValue(threatValue) { }
bool Execute(uint64 e_time, uint32 p_time) override;
private:
Creature& m_owner;
ObjectGuid m_threatVictimGUID;
float m_threatValue;
};
#endif