From bde5402b409d192d8933e66233f9a49e1ac062c6 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 21 May 2009 05:24:25 +0400 Subject: [PATCH] [7863] Implement for EVENT_T_SPAWNED map/zone/subzone only event conditions. Signed-off-by: VladimirMangos --- doc/EventAI.txt | 2 ++ src/game/CreatureEventAI.cpp | 35 +++++++++++++++++++++++++++------ src/game/CreatureEventAI.h | 17 +++++++++++++++- src/game/CreatureEventAIMgr.cpp | 18 ++++++++++++++++- src/shared/revision_nr.h | 2 +- 5 files changed, 65 insertions(+), 9 deletions(-) diff --git a/doc/EventAI.txt b/doc/EventAI.txt index 5609be9fc..2390bb02c 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -260,6 +260,8 @@ This Event is commonly used for NPC's who do something or say something to you w --------------------- Expires at initial spawn and at creature respawn. This Event is commonly used for setting ranged movement type or Summoning a Pet on Spawn +Parameter 1: 0: works always, 1: works on map in Parameter 2, 2: works on zone/subzone in Parameter 2 +Parameter 2: depends on Parameter 1: for 1 it is map ID, for 2 it is area ID to check ----------------------- 12 = EVENT_T_TARGET_HP: diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 98c4f2b89..5a1cf5716 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -132,10 +132,8 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c) if (!bEmptyList) { for (std::list::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) - { - if ((*i).Event.event_type == EVENT_T_SPAWNED) + if (SpawnedEventConditionsCheck((*i).Event)) ProcessEvent(*i); - } } Reset(); } @@ -797,10 +795,8 @@ void CreatureEventAI::JustRespawned() //Handle Spawned Events for (std::list::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) - { - if ((*i).Event.event_type == EVENT_T_SPAWNED) + if (SpawnedEventConditionsCheck((*i).Event)) ProcessEvent(*i); - } } void CreatureEventAI::Reset() @@ -1410,3 +1406,30 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote) } } } + +bool CreatureEventAI::SpawnedEventConditionsCheck(CreatureEventAI_Event const& event) +{ + if(event.event_type != EVENT_T_SPAWNED) + return false; + + switch (event.spawned.condition) + { + case SPAWNED_EVENT_ALWAY: + // always + return true; + case SPAWNED_EVENT_MAP: + // map ID check + return m_creature->GetMapId() == event.spawned.conditionValue1; + case SPAWNED_EVENT_ZONE: + { + // zone ID check + uint32 zone, area; + m_creature->GetZoneAndAreaId(zone,area); + return zone == event.spawned.conditionValue1 || area == event.spawned.conditionValue1; + } + default: + break; + } + + return false; +} diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 64b3f6863..5f967c51d 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -44,7 +44,7 @@ enum EventAI_Type EVENT_T_SPELLHIT = 8, // SpellID, School, RepeatMin, RepeatMax EVENT_T_RANGE = 9, // MinDist, MaxDist, RepeatMin, RepeatMax EVENT_T_OOC_LOS = 10, // NoHostile, MaxRnage, RepeatMin, RepeatMax - EVENT_T_SPAWNED = 11, // NONE + EVENT_T_SPAWNED = 11, // Condition, CondValue1 EVENT_T_TARGET_HP = 12, // HPMax%, HPMin%, RepeatMin, RepeatMax EVENT_T_TARGET_CASTING = 13, // RepeatMin, RepeatMax EVENT_T_FRIENDLY_HP = 14, // HPDeficit, Radius, RepeatMin, RepeatMax @@ -155,6 +155,13 @@ enum EventFlags EFLAG_DEBUG_ONLY = 0x80, //Event only occurs in debug build }; +enum SpawnedEventMode +{ + SPAWNED_EVENT_ALWAY = 0, + SPAWNED_EVENT_MAP = 1, + SPAWNED_EVENT_ZONE = 2 +}; + // String text additional data, used in (CreatureEventAI) struct StringTextData { @@ -431,6 +438,12 @@ struct CreatureEventAI_Event uint32 repeatMin; uint32 repeatMax; } ooc_los; + // EVENT_T_SPAWNED = 11 + struct + { + uint32 condition; + uint32 conditionValue1; + } spawned; // EVENT_T_TARGET_CASTING = 13 struct { @@ -561,6 +574,8 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI void DoMeleeAttackIfReady(); bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered); + bool SpawnedEventConditionsCheck(CreatureEventAI_Event const& event); + Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff); void DoFindFriendlyMissingBuff(std::list& _list, float range, uint32 spellid); void DoFindFriendlyCC(std::list& _list, float range); diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index e19fc35e7..b3678dad6 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -283,6 +283,23 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() if (temp.ooc_los.repeatMax < temp.ooc_los.repeatMin) sLog.outErrorDb("CreatureEventAI: Creature %u are using repeatable event(%u) with param4 < param3 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); break; + case EVENT_T_SPAWNED: + switch(temp.spawned.condition) + { + case SPAWNED_EVENT_ALWAY: + break; + case SPAWNED_EVENT_MAP: + if(!sMapStore.LookupEntry(temp.spawned.conditionValue1)) + sLog.outErrorDb("CreatureEventAI: Creature %u are using spawned event(%u) with param1 = %u 'map specific' but with not existed map (%u) in param2. Event will never repeat.", temp.creature_id, i, temp.spawned.condition, temp.spawned.conditionValue1); + break; + case SPAWNED_EVENT_ZONE: + if(!GetAreaEntryByAreaID(temp.spawned.conditionValue1)) + sLog.outErrorDb("CreatureEventAI: Creature %u are using spawned event(%u) with param1 = %u 'area specific' but with not existed area (%u) in param2. Event will never repeat.", temp.creature_id, i, temp.spawned.condition, temp.spawned.conditionValue1); + default: + sLog.outErrorDb("CreatureEventAI: Creature %u are using invalid spawned event %u mode (%u) in param1", temp.creature_id, i, temp.spawned.condition); + break; + } + break; case EVENT_T_FRIENDLY_HP: if (temp.friendly_hp.repeatMax < temp.friendly_hp.repeatMin) sLog.outErrorDb("CreatureEventAI: Creature %u are using repeatable event(%u) with param4 < param3 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); @@ -327,7 +344,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_AGGRO: case EVENT_T_DEATH: case EVENT_T_EVADE: - case EVENT_T_SPAWNED: case EVENT_T_REACHED_HOME: { if (temp.event_flags & EFLAG_REPEATABLE) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 4ba09ea19..d34146f3e 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7862" + #define REVISION_NR "7863" #endif // __REVISION_NR_H__