diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 5ff6f1575..6b5bc14e9 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -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())); + } +} diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 364247985..5ae1f8768 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -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