[8057] Move code from Event AI to class Creature function for reuse in other scripting cases.

Also some outdated and wrong checks remove.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
NoFantasy 2009-06-21 03:32:54 +04:00 committed by VladimirMangos
parent 9b9fe55981
commit 400c110e1f
5 changed files with 43 additions and 37 deletions

View file

@ -1978,6 +1978,43 @@ void Creature::SendZoneUnderAttackMessage(Player* attacker)
sWorld.SendGlobalMessage(&data,NULL,(enemy_team==ALLIANCE ? HORDE : ALLIANCE));
}
void Creature::SetInCombatWithZone()
{
if (!CanHaveThreatList())
{
error_log("Creature entry %u call SetInCombatWithZone but creature cannot have threat list.", GetEntry());
return;
}
Map* pMap = GetMap();
if (!pMap->IsDungeon())
{
error_log("Creature entry %u call SetInCombatWithZone for map (id: %u) that isn't an instance.", GetEntry(), pMap->GetId());
return;
}
Map::PlayerList const &PlList = pMap->GetPlayers();
if (PlList.isEmpty())
return;
for(Map::PlayerList::const_iterator i = PlList.begin(); i != PlList.end(); ++i)
{
if (Player* pPlayer = i->getSource())
{
if (pPlayer->isGameMaster())
continue;
if (pPlayer->isAlive())
{
pPlayer->SetInCombatWith(this);
AddThreat(pPlayer, 0.0f);
}
}
}
}
void Creature::_AddCreatureSpellCooldown(uint32 spell_id, time_t end_time)
{
m_CreatureSpellCooldowns[spell_id] = end_time;

View file

@ -648,6 +648,8 @@ class MANGOS_DLL_SPEC Creature : public Unit
void SendZoneUnderAttackMessage(Player* attacker);
void SetInCombatWithZone();
bool hasQuest(uint32 quest_id) const;
bool hasInvolvedQuest(uint32 quest_id) const;

View file

@ -761,15 +761,10 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(),NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
break;
case ACTION_T_ZONE_COMBAT_PULSE:
if (!m_creature->isInCombat() || !m_creature->GetMap()->IsDungeon())
{
sLog.outErrorDb("CreatureEventAI: Event %d ACTION_T_ZONE_COMBAT_PULSE on creature out of combat or in non-dungeon map. Creature %d", EventId, m_creature->GetEntry());
return;
}
DoZoneInCombat(m_creature);
m_creature->SetInCombatWithZone();
break;
}
case ACTION_T_CALL_FOR_HELP:
{
m_creature->CallForHelp(action.call_for_help.radius);
@ -1320,33 +1315,6 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
}
}
void CreatureEventAI::DoZoneInCombat(Unit* pUnit)
{
if (!pUnit)
pUnit = m_creature;
Map *map = pUnit->GetMap();
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
{
sLog.outErrorDb("CreatureEventAI: DoZoneInCombat call for map that isn't an instance (pUnit entry = %d)", pUnit->GetTypeId() == TYPEID_UNIT ? ((Creature*)pUnit)->GetEntry() : 0);
return;
}
if (!pUnit->CanHaveThreatList() || pUnit->getThreatManager().isThreatListEmpty())
{
sLog.outErrorDb("CreatureEventAI: DoZoneInCombat called for creature that either cannot have threat list or has empty threat list (pUnit entry = %d)", pUnit->GetTypeId() == TYPEID_UNIT ? ((Creature*)pUnit)->GetEntry() : 0);
return;
}
Map::PlayerList const &PlayerList = map->GetPlayers();
for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
if (Player* i_pl = i->getSource())
if (!i_pl->isGameMaster())
pUnit->AddThreat(i_pl, 0.0f);
}
void CreatureEventAI::DoMeleeAttackIfReady()
{
//Make sure our attack is ready before checking distance

View file

@ -588,7 +588,6 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
inline Unit* SelectUnit(AttackingTarget target, uint32 position);
void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);
void DoZoneInCombat(Unit* pUnit);
void DoMeleeAttackIfReady();
bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8056"
#define REVISION_NR "8057"
#endif // __REVISION_NR_H__