diff --git a/doc/EventAI.txt b/doc/EventAI.txtindex 0cb2788..6484870 100644--- a/doc/EventAI.txt+++ b/doc/EventAI.txt@@ -70,7 +70,7 @@ Some events such as EVENT_T_AGGRO, EVENT_T_DEATH, EVENT_T_SPAWNED, and EVENT_T_E 8 EVENT_T_SPELLHIT SpellID, School, RepeatMin, RepeatMax Expires upon Spell hit. If (param1) is set will only expire on that spell. If (param2) will only expire on spells of that school (-1 for all). Will repeat every (Param3) and (Param4) . 9 EVENT_T_RANGE MinDist, MaxDist, RepeatMin, RepeatMax Expires when the highest threat target distance is greater than (Param1) and less than (Param2). Will repeat every (Param3) and (Param4) . 10 EVENT_T_OOC_LOS Hostile-or-Not, MaxAllowedRange, RepeatMin, RepeatMax Expires when a Unit moves within distance(MaxAllowedRange) to creature. If Param1=0 it will expire if Unit are Hostile. If Param1=1 it will only expire if Unit are not Hostile(generally determined by faction). Will repeat every (Param3) and (Param4). Does not expire when the creature is in combat.-11 EVENT_T_SPAWNED NONE Expires at initial spawn and at creature respawn (useful for setting ranged movement type)+11 EVENT_T_SPAWNED Condition, CondValue1, CondValue2 Expires at initial spawn and at creature respawn (useful for setting ranged movement type). Condition can be defined. If set, then most conditions has additional value (see enum ConditionType) 12 EVENT_T_TARGET_HP HPMax%, HPMin%, RepeatMin, RepeatMax Expires when Current Target's HP is between (Param1) and (Param2). Will repeat every (Param3) and (Param4) . 13 EVENT_T_TARGET_CASTING RepeatMin, RepeatatMax Expires when the current target is casting a spell. Will repeat every (Param1) and (Param2) . 14 EVENT_T_FRIENDLY_HP HPDeficit, Radius, RepeatMin, RepeatMax Expires when a friendly unit in radius has at least (param1) hp missing. Will repeat every (Param3) and (Param4) .@@ -249,6 +249,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+Event does not require any conditions to process, however some are expected to have condition.+NOTE: Only CONDITION_NONE, CONDITION_ZONEID and CONDITION_ACTIVE_EVENT are valid here. Others will not work, because they require acting player. ----------------------- 12 = EVENT_T_TARGET_HP:@@ -323,7 +325,11 @@ Most commonly used to cast spells that can not be casted in EVENT_T_EVADE and ot 22 = EVENT_T_RECEIVE_EMOTE: --------------------------- Expires only when creature receive emote from player. Valid text emote id's are in Mangos source (enum TextEmotes)-Event does not require any conditions to process, however many are ecpected to have condition.+Event does not require any conditions to process, however many are expected to have condition.++=========================================+Conditions+========================================= EventAI use conditions from available in Mangos (enum ConditionType) Current implemented conditions:diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cppindex 6884602..df57000 100644--- a/src/game/CreatureEventAI.cpp+++ b/src/game/CreatureEventAI.cpp@@ -84,7 +84,13 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c) for (std::list<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) { if ((*i).Event.event_type == EVENT_T_SPAWNED)- ProcessEvent(*i);+ {+ if (ConditionsCheck((*i).Event))+ {+ sLog.outDebug("CreatureEventAI: Spawned CreatureEventAI: Condition ok, processing");+ ProcessEvent(*i);+ }+ } } } Reset();@@ -1534,57 +1540,7 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote) if ((*itr).Event.event_param1 != text_emote) return;- bool bProcess = false;-- switch((*itr).Event.event_param2)- {- //enum ConditionType- case CONDITION_NONE: // 0 0- bProcess = true;- break;- case CONDITION_AURA: // spell_id effindex- if (pPlayer->HasAura((*itr).Event.event_param3,(*itr).Event.event_param4))- bProcess = true;- break;- case CONDITION_ITEM: // item_id count- if (pPlayer->HasItemCount((*itr).Event.event_param3,(*itr).Event.event_param4))- bProcess = true;- break;- case CONDITION_ITEM_EQUIPPED: // item_id count- if (pPlayer->HasItemOrGemWithIdEquipped((*itr).Event.event_param3,(*itr).Event.event_param4))- bProcess = true;- break;- case CONDITION_ZONEID: // zone_id 0- if (pPlayer->GetZoneId() == (*itr).Event.event_param3)- bProcess = true;- break;- case CONDITION_REPUTATION_RANK: // faction_id min_rank- if (pPlayer->GetReputationRank((*itr).Event.event_param3) >= (*itr).Event.event_param4)- bProcess = true;- break;- case CONDITION_TEAM: // player_team 0, (469 - Alliance 67 - Horde)- if (pPlayer->GetTeam() == (*itr).Event.event_param3)- bProcess = true;- break;- case CONDITION_SKILL: // skill_id min skill_value- if (pPlayer->HasSkill((*itr).Event.event_param3) && pPlayer->GetSkillValue((*itr).Event.event_param3) >= (*itr).Event.event_param4)- bProcess = true;- break;- case CONDITION_QUESTREWARDED: // quest_id 0- if (pPlayer->GetQuestRewardStatus((*itr).Event.event_param3))- bProcess = true;- break;- case CONDITION_QUESTTAKEN: // quest_id 0, for condition true while quest active.- if (pPlayer->GetQuestStatus((*itr).Event.event_param3) == QUEST_STATUS_INCOMPLETE)- bProcess = true;- break;- case CONDITION_ACTIVE_EVENT: // event_id 0- if (IsHolidayActive(HolidayIds((*itr).Event.event_param3)))- bProcess = true;- break;- }-- if (bProcess)+ if (ConditionsCheck((*itr).Event, pPlayer)) { sLog.outDebug("CreatureEventAI: ReceiveEmote CreatureEventAI: Condition ok, processing"); ProcessEvent(*itr, pPlayer);@@ -1592,3 +1548,87 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote) } } }++bool CreatureEventAI::ConditionsCheck(CreatureEventAI_Event& Event, Player* pPlayer)+{+ uint32 cType;+ uint32 cParam1;+ uint32 cParam2;++ switch(Event.event_type)+ {+ case EVENT_T_SPAWNED:+ cType = Event.event_param1;+ cParam1 = Event.event_param2;+ cParam2 = Event.event_param3;+ break;+ case EVENT_T_RECEIVE_EMOTE:+ cType = Event.event_param2;+ cParam1 = Event.event_param3;+ cParam2 = Event.event_param4;+ break;+ default:+ // ERROR! It must not be called for unsupported events.+ sLog.outError("EventAI: condition code called for unsupported event type %i, check CreatureEventAI.cpp", cType);+ return false;+ }++ // first, common types are checked (not requiring player)+ switch(cType)+ {+ case CONDITION_NONE: // 0 0+ return(true);+ case CONDITION_ZONEID: // zone_id 0+ if (m_creature->GetZoneId() == cParam1)+ return(true);+ break;+ case CONDITION_ACTIVE_EVENT: // event_id 0+ if (IsHolidayActive(HolidayIds(cParam1)))+ return(true);+ break;+ }++ // check player existence+ if (!pPlayer)+ return false;++ // next, player-dependent types checked+ switch(cType)+ {+ case CONDITION_AURA: // spell_id effindex+ if (pPlayer->HasAura(cParam1,cParam2))+ return(true);+ break;+ case CONDITION_ITEM: // item_id count+ if (pPlayer->HasItemCount(cParam1,cParam2))+ return(true);+ break;+ case CONDITION_ITEM_EQUIPPED: // item_id count+ if (pPlayer->HasItemOrGemWithIdEquipped(cParam1,cParam2))+ return(true);+ break;+ case CONDITION_REPUTATION_RANK: // faction_id min_rank+ if (pPlayer->GetReputationRank(cParam1) >= cParam2)+ return(true);+ break;+ case CONDITION_TEAM: // player_team 0, (469 - Alliance 67 - Horde)+ if (pPlayer->GetTeam() == cParam1)+ return(true);+ break;+ case CONDITION_SKILL: // skill_id min skill_value+ if (pPlayer->HasSkill(cParam1) && (pPlayer->GetSkillValue(cParam1) >= cParam2))+ return(true);+ break;+ case CONDITION_QUESTREWARDED: // quest_id 0+ if (pPlayer->GetQuestRewardStatus(cParam1))+ return(true);+ break;+ case CONDITION_QUESTTAKEN: // quest_id 0, for condition true while quest active.+ if (pPlayer->GetQuestStatus(cParam1) == QUEST_STATUS_INCOMPLETE)+ return(true);+ break;+ }++ // no match+ return(false);+}diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.hindex 9535962..671f2bf 100644--- a/src/game/CreatureEventAI.h+++ b/src/game/CreatureEventAI.h@@ -397,6 +397,7 @@ struct CreatureEventAI_Event CreatureEventAI_Action action[MAX_ACTIONS]; };+ //Event_Map typedef UNORDERED_MAP<uint32, std::vector<CreatureEventAI_Event> > CreatureEventAI_Event_Map;@@ -460,6 +461,8 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI void DoMeleeAttackIfReady(); bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);+ bool ConditionsCheck(CreatureEventAI_Event& Event, Player* pPlayer = NULL);+ Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff); void DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid); void DoFindFriendlyCC(std::list<Creature*>& _list, float range);