diff options
Diffstat (limited to 'src/server/game/AI/ScriptedAI')
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 79 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.h | 15 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp | 24 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp | 25 |
4 files changed, 63 insertions, 80 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index bde3a192642..ff1e5591fb8 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -193,6 +193,49 @@ void ScriptedAI::DoPlaySoundToSet(WorldObject* source, uint32 soundId) source->PlayDirectSound(soundId); } +void ScriptedAI::AddThreat(Unit* victim, float amount, Unit* who) +{ + if (!victim) + return; + if (!who) + who = me; + who->GetThreatManager().AddThreat(victim, amount, nullptr, true, true); +} + +void ScriptedAI::ModifyThreatByPercent(Unit* victim, int32 pct, Unit* who) +{ + if (!victim) + return; + if (!who) + who = me; + who->GetThreatManager().ModifyThreatByPercent(victim, pct); +} + +void ScriptedAI::ResetThreat(Unit* victim, Unit* who) +{ + if (!victim) + return; + if (!who) + who = me; + who->GetThreatManager().ResetThreat(victim); +} + +void ScriptedAI::ResetThreatList(Unit* who) +{ + if (!who) + who = me; + who->GetThreatManager().ResetAllThreat(); +} + +float ScriptedAI::GetThreat(Unit const* victim, Unit const* who) +{ + if (!victim) + return 0.0f; + if (!who) + who = me; + return who->GetThreatManager().GetThreat(victim); +} + Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime) { return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime); @@ -276,38 +319,6 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec return apSpell[urand(0, spellCount - 1)]; } -void ScriptedAI::DoResetThreat() -{ - if (!me->CanHaveThreatList() || me->getThreatManager().isThreatListEmpty()) - { - TC_LOG_ERROR("scripts", "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = %d)", me->GetEntry()); - return; - } - - ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList(); - - for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) - { - Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid()); - if (unit && DoGetThreat(unit)) - DoModifyThreatPercent(unit, -100); - } -} - -float ScriptedAI::DoGetThreat(Unit* unit) -{ - if (!unit) - return 0.0f; - return me->getThreatManager().getThreat(unit); -} - -void ScriptedAI::DoModifyThreatPercent(Unit* unit, int32 pct) -{ - if (!unit) - return; - me->getThreatManager().modifyThreatPercent(unit, pct); -} - void ScriptedAI::DoTeleportTo(float x, float y, float z, uint32 time) { me->Relocate(x, y, z); @@ -493,7 +504,7 @@ void BossAI::TeleportCheaters() float x, y, z; me->GetPosition(x, y, z); - ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList(); + ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList(); for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr) if (Unit* target = (*itr)->getTarget()) if (target->GetTypeId() == TYPEID_PLAYER && !CheckBoundary(target)) @@ -503,7 +514,7 @@ void BossAI::TeleportCheaters() void BossAI::JustSummoned(Creature* summon) { summons.Summon(summon); - if (me->IsInCombat()) + if (me->IsEngaged()) DoZoneInCombat(summon); } diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index bb61dfbaab0..084f05552c4 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -208,11 +208,16 @@ struct TC_GAME_API ScriptedAI : public CreatureAI //Plays a sound to all nearby players void DoPlaySoundToSet(WorldObject* source, uint32 soundId); - //Drops all threat to 0%. Does not remove players from the threat list - void DoResetThreat(); - - float DoGetThreat(Unit* unit); - void DoModifyThreatPercent(Unit* unit, int32 pct); + // Add specified amount of threat directly to victim (ignores redirection effects) - also puts victim in combat and engages them if necessary + void AddThreat(Unit* victim, float amount, Unit* who = nullptr); + // Adds/removes the specified percentage from the specified victim's threat (to who, or me if not specified) + void ModifyThreatByPercent(Unit* victim, int32 pct, Unit* who = nullptr); + // Resets the victim's threat level to who (or me if not specified) to zero + void ResetThreat(Unit* victim, Unit* who = nullptr); + // Resets the specified unit's threat list (me if not specified) - does not delete entries, just sets their threat to zero + void ResetThreatList(Unit* who = nullptr); + // Returns the threat level of victim towards who (or me if not specified) + float GetThreat(Unit const* victim, Unit const* who = nullptr); void DoTeleportTo(float x, float y, float z, uint32 time = 0); void DoTeleportTo(float const pos[4]); diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 46e4159bb4c..8f06a5df423 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -102,8 +102,7 @@ bool npc_escortAI::AssistPlayerInCombatAgainst(Unit* who) } else { - who->SetInCombatWith(me); - me->AddThreat(who, 0.0f); + me->EngageWithTarget(who); return true; } } @@ -125,24 +124,7 @@ void npc_escortAI::MoveInLineOfSight(Unit* who) { float fAttackRadius = me->GetAttackDistance(who); if (me->IsWithinDistInMap(who, fAttackRadius) && me->IsWithinLOSInMap(who)) - { - if (!me->GetVictim()) - { - // Clear distracted state on combat - if (me->HasUnitState(UNIT_STATE_DISTRACTED)) - { - me->ClearUnitState(UNIT_STATE_DISTRACTED); - me->GetMotionMaster()->Clear(); - } - - AttackStart(who); - } - else if (me->GetMap()->IsDungeon()) - { - who->SetInCombatWith(me); - me->AddThreat(who, 0.0f); - } - } + me->EngageWithTarget(who); } } } @@ -192,7 +174,7 @@ void npc_escortAI::ReturnToLastPoint() void npc_escortAI::EnterEvadeMode(EvadeReason /*why*/) { me->RemoveAllAuras(); - me->DeleteThreatList(); + me->GetThreatManager().ClearAllThreat(); me->CombatStop(true); me->SetLootRecipient(NULL); diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp index 6c38e34df97..04cd868b1da 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp @@ -51,9 +51,7 @@ void FollowerAI::AttackStart(Unit* who) if (me->Attack(who, true)) { - me->AddThreat(who, 0.0f); - me->SetInCombatWith(who); - who->SetInCombatWith(me); + me->EngageWithTarget(who); // in case it doesn't have threat+combat yet if (me->HasUnitState(UNIT_STATE_FOLLOW)) me->ClearUnitState(UNIT_STATE_FOLLOW); @@ -86,18 +84,8 @@ bool FollowerAI::AssistPlayerInCombatAgainst(Unit* who) //too far away and no free sight? if (me->IsWithinDistInMap(who, MAX_PLAYER_DISTANCE) && me->IsWithinLOSInMap(who)) { - //already fighting someone? - if (!me->GetVictim()) - { - AttackStart(who); - return true; - } - else - { - who->SetInCombatWith(me); - me->AddThreat(who, 0.0f); - return true; - } + me->EngageWithTarget(who); + return true; } return false; @@ -130,10 +118,7 @@ void FollowerAI::MoveInLineOfSight(Unit* who) AttackStart(who); } else if (me->GetMap()->IsDungeon()) - { - who->SetInCombatWith(me); - me->AddThreat(who, 0.0f); - } + me->EngageWithTarget(who); } } } @@ -175,7 +160,7 @@ void FollowerAI::JustRespawned() void FollowerAI::EnterEvadeMode(EvadeReason /*why*/) { me->RemoveAllAuras(); - me->DeleteThreatList(); + me->GetThreatManager().ClearAllThreat(); me->CombatStop(true); me->SetLootRecipient(NULL); |
