diff --git a/doc/EventAI.txt b/doc/EventAI.txt index 6556e3330..71248cb60 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -62,29 +62,31 @@ Some events such as EVENT_T_AGGRO, EVENT_T_DEATH, EVENT_T_SPAWNED, and EVENT_T_E # Internal name Param usage Description ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -0 EVENT_T_TIMER InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY IN COMBAT. -1 EVENT_T_TIMER_OOC InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY OUT OF COMBAT. -2 EVENT_T_HP HPMax%, HPMin%, RepeatMin, RepeatMax Expires when the Creature's HP is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4). -3 EVENT_T_MANA ManaMax%,ManaMin% RepeatMin, RepeatMax Expires once the Creature's Mana% is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4). -4 EVENT_T_AGGRO NONE Expires ONLY upon the Creature's INITIAL Aggro at the Start of Combat (Does NOT Repeat). -5 EVENT_T_KILL RepeatMin, RepeatMax Expires upon Killing a Player. Will repeat between (Param1) and (Param2). -6 EVENT_T_DEATH NONE Expires upon the Creature's Death. (This Triggers At The Moment The Creature Dies) -7 EVENT_T_EVADE NONE Expires at the moment the Creature EnterEvadeMode(). -8 EVENT_T_SPELLHIT SpellID, Schoolmask, RepeatMin, RepeatMax Expires upon a Spell Hit on the Creature. When (param1) is set, it is the specific Spell ID used as the trigger. With (param2) specified, the expiration is limited to specific spell schools (-1 for all). Will repeat every (Param3) and (Param4). Only A Spell ID or Spell School may be Specified but NOT both. -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 between every (Param3) and (Param4). -10 EVENT_T_OOC_LOS Hostile-or-Not, MaxAllowedRange, RepeatMin, RepeatMax Expires when a unit moves within distance (MaxAllowedRange) of a creature. If (Param1) is zero it will expire only when unit is hostile, friendly otherwise (Param1 = 1), depends generally on faction. Will repeat every (Param3) and (Param4). Does not expire when the creature is in combat. -11 EVENT_T_SPAWNED NONE Expires on initial spawn and on creature respawn (useful for setting ranged movement type). -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). -15 EVENT_T_FRIENDLY_IS_CC DispelType, Radius, RepeatMin, RepeatMax Expires when a friendly unit is crowd controlled within the given radius (Param2). Will repeat every (Param3) and (Param4). -16 EVENT_T_MISSING_BUFF SpellId, Radius, RepeatMin, RepeatMax Expires when a friendly unit is missing aura(s) given by a spell (Param1) within radius (Param2). Will repeat every (Param3) and (Param4). -17 EVENT_T_SUMMONED_UNIT CreatureId, RepeatMin, RepeatMax Expires after creature with entry = (Param1) is spawned (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3). -18 EVENT_T_TARGET_MANA ManaMax%, ManaMin%, RepeatMin, RepeatMax Expires when current target's Mana is between (Param1) and (Param2). Will repeat every (Param3) and (Param4). -21 EVENT_T_REACHED_HOME NONE Expires when a creature reaches it's home (spawn) location after evade. -22 EVENT_T_RECEIVE_EMOTE EmoteId, Condition, CondValue1, CondValue2 Expires when a creature receives an emote with emote text id (enum TextEmotes) in (Param1). Conditions can be defined (Param2) with optional values (Param3,Param4), see enum ConditionType. -23 EVENT_T_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a creature has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). -24 EVENT_T_TARGET_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a target unit has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). +0 EVENT_T_TIMER InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY IN COMBAT. +1 EVENT_T_TIMER_OOC InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY OUT OF COMBAT. +2 EVENT_T_HP HPMax%, HPMin%, RepeatMin, RepeatMax Expires when the Creature's HP is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4). +3 EVENT_T_MANA ManaMax%,ManaMin% RepeatMin, RepeatMax Expires once the Creature's Mana% is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4). +4 EVENT_T_AGGRO NONE Expires ONLY upon the Creature's INITIAL Aggro at the Start of Combat (Does NOT Repeat). +5 EVENT_T_KILL RepeatMin, RepeatMax Expires upon Killing a Player. Will repeat between (Param1) and (Param2). +6 EVENT_T_DEATH NONE Expires upon the Creature's Death. (This Triggers At The Moment The Creature Dies) +7 EVENT_T_EVADE NONE Expires at the moment the Creature EnterEvadeMode(). +8 EVENT_T_SPELLHIT SpellID, Schoolmask, RepeatMin, RepeatMax Expires upon a Spell Hit on the Creature. When (param1) is set, it is the specific Spell ID used as the trigger. With (param2) specified, the expiration is limited to specific spell schools (-1 for all). Will repeat every (Param3) and (Param4). Only A Spell ID or Spell School may be Specified but NOT both. +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 between every (Param3) and (Param4). +10 EVENT_T_OOC_LOS Hostile-or-Not, MaxAllowedRange, RepeatMin, RepeatMax Expires when a unit moves within distance (MaxAllowedRange) of a creature. If (Param1) is zero it will expire only when unit is hostile, friendly otherwise (Param1 = 1), depends generally on faction. Will repeat every (Param3) and (Param4). Does not expire when the creature is in combat. +11 EVENT_T_SPAWNED NONE Expires on initial spawn and on creature respawn (useful for setting ranged movement type). +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). +15 EVENT_T_FRIENDLY_IS_CC DispelType, Radius, RepeatMin, RepeatMax Expires when a friendly unit is crowd controlled within the given radius (Param2). Will repeat every (Param3) and (Param4). +16 EVENT_T_MISSING_BUFF SpellId, Radius, RepeatMin, RepeatMax Expires when a friendly unit is missing aura(s) given by a spell (Param1) within radius (Param2). Will repeat every (Param3) and (Param4). +17 EVENT_T_SUMMONED_UNIT CreatureId, RepeatMin, RepeatMax Expires after creature with entry = (Param1) is spawned (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3). +18 EVENT_T_TARGET_MANA ManaMax%, ManaMin%, RepeatMin, RepeatMax Expires when current target's Mana is between (Param1) and (Param2). Will repeat every (Param3) and (Param4). +21 EVENT_T_REACHED_HOME NONE Expires when a creature reaches it's home (spawn) location after evade. +22 EVENT_T_RECEIVE_EMOTE EmoteId, Condition, CondValue1, CondValue2 Expires when a creature receives an emote with emote text id (enum TextEmotes) in (Param1). Conditions can be defined (Param2) with optional values (Param3,Param4), see enum ConditionType. +23 EVENT_T_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a creature has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). +24 EVENT_T_TARGET_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a target unit has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). +25 EVENT_T_SUMMONED_JUST_DIE CreatureId, RepeatMin, RepeatMax Expires after creature with entry = (Param1) is die (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3). +26 EVENT_T_SUMMONED_JUST_DESPAWN CreatureId, RepeatMin, RepeatMax Expires before creature with entry = (Param1) is despawn (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3). ========================================= @@ -381,6 +383,27 @@ CONDITION_QUESTREWARDED (8) quest_id 0, if quest are rewarded CONDITION_QUESTTAKEN (9) quest_id 0, while quest active(incomplete) CONDITION_ACTIVE_EVENT (12) event_id 0, note this is id from dbc, also defined in Mangos source(enum HolidayIds) NOT id of game_event in database +--------------------------- +25 = EVENT_T_SUMMONED_JUST_DIE: +--------------------------- +Parameter 1: CreatureId - The CreatureID that the NPC is watching die to trigger this event +Parameter 2: RepeatMin - Minimum Time used to calculate Random Repeat Expire +Parameter 3: RepeatMax - Maximum Time used to calculate Random Repeat Expire + +BOTH - Expires after creature with entry(Param1) is die or for all spawns if param1 = 0. Will repeat every (Param2) and (Param3) . +This is commonly used for NPC's who will do something special once another NPC is die. Usually used is Complex Scripts or Special Events. + +--------------------------- +26 = EVENT_T_SUMMONED_JUST_DESPAWN: +--------------------------- +Parameter 1: CreatureId - The CreatureID that the NPC is watching despawn to trigger this event +Parameter 2: RepeatMin - Minimum Time used to calculate Random Repeat Expire +Parameter 3: RepeatMax - Maximum Time used to calculate Random Repeat Expire + +BOTH - Expires before creature with entry(Param1) is dwspawned or for all spawns if param1 = 0. Will repeat every (Param2) and (Param3) . +This is commonly used for NPC's who will do something special once another NPC is despawn. Usually used is Complex Scripts or Special Events. +NOTE: called before despawn happens, so summoned creature still in world at expire moment. + ========================================= Action Types ========================================= diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index 270018cf6..b3327583c 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -95,12 +95,16 @@ class MANGOS_DLL_SPEC CreatureAI // Called when the creature is killed virtual void JustDied(Unit *) {} + // Called when the creature summon is killed + virtual void SummonedCreatureJustDie(Creature* /*unit*/) {} + // Called when the creature kills a unit virtual void KilledUnit(Unit *) {} // Called when the creature summon successfully other creature virtual void JustSummoned(Creature* ) {} + // Called when the creature summon despawn virtual void SummonedCreatureDespawn(Creature* /*unit*/) {} // Called when hit by a spell diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 31adff401..afa5285d8 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -257,17 +257,19 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction break; } case EVENT_T_SUMMONED_UNIT: + case EVENT_T_SUMMONED_JUST_DIE: + case EVENT_T_SUMMONED_JUST_DESPAWN: { //Prevent event from occuring on no unit or non creatures if (!pActionInvoker || pActionInvoker->GetTypeId()!=TYPEID_UNIT) return false; //Creature id doesn't match up - if (((Creature*)pActionInvoker)->GetEntry() != event.summon_unit.creatureId) + if (((Creature*)pActionInvoker)->GetEntry() != event.summoned.creatureId) return false; //Repeat Timers - pHolder.UpdateRepeatTimer(m_creature,event.summon_unit.repeatMin,event.summon_unit.repeatMax); + pHolder.UpdateRepeatTimer(m_creature,event.summoned.repeatMin,event.summoned.repeatMax); break; } case EVENT_T_TARGET_MANA: @@ -911,6 +913,30 @@ void CreatureEventAI::JustSummoned(Creature* pUnit) } } +void CreatureEventAI::SummonedCreatureJustDie(Creature* pUnit) +{ + if (bEmptyList || !pUnit) + return; + + for (std::list::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) + { + if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DIE) + ProcessEvent(*i, pUnit); + } +} + +void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit) +{ + if (bEmptyList || !pUnit) + return; + + for (std::list::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) + { + if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DESPAWN) + ProcessEvent(*i, pUnit); + } +} + void CreatureEventAI::EnterCombat(Unit *enemy) { //Check for on combat start events diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 849f13b71..f39b12653 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -58,6 +58,8 @@ enum EventAI_Type EVENT_T_RECEIVE_EMOTE = 22, // EmoteId, Condition, CondValue1, CondValue2 EVENT_T_BUFFED = 23, // Param1 = SpellID, Param2 = Number of Time STacked, Param3/4 Repeat Min/Max EVENT_T_TARGET_BUFFED = 24, // Param1 = SpellID, Param2 = Number of Time STacked, Param3/4 Repeat Min/Max + EVENT_T_SUMMONED_JUST_DIE = 25, // CreatureId, RepeatMin, RepeatMax + EVENT_T_SUMMONED_JUST_DESPAWN = 26, // CreatureId, RepeatMin, RepeatMax EVENT_T_END, }; @@ -486,12 +488,14 @@ struct CreatureEventAI_Event uint32 repeatMax; } friendly_buff; // EVENT_T_SUMMONED_UNIT = 17 + //EVENT_T_SUMMONED_JUST_DIE = 25 + //EVENT_T_SUMMONED_JUST_DESPAWN = 26 struct { uint32 creatureId; uint32 repeatMin; uint32 repeatMax; - } summon_unit; + } summoned; // EVENT_T_QUEST_ACCEPT = 19 // EVENT_T_QUEST_COMPLETE = 20 struct @@ -582,6 +586,9 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI void UpdateAI(const uint32 diff); bool IsVisible(Unit *) const; void ReceiveEmote(Player* pPlayer, uint32 text_emote); + void SummonedCreatureJustDie(Creature* unit); + void SummonedCreatureDespawn(Creature* unit); + static int Permissible(const Creature *); bool ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pActionInvoker = NULL); diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index c968b6a8d..031e92258 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -404,9 +404,11 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() sLog.outErrorDb("CreatureEventAI: Creature %u are using event(%u) with param2 < param1 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); break; case EVENT_T_SUMMONED_UNIT: - if (!sCreatureStorage.LookupEntry(temp.summon_unit.creatureId)) - sLog.outErrorDb("CreatureEventAI: Creature %u are using event(%u) with not existed creature template id (%u) in param1, skipped.", temp.creature_id, i, temp.summon_unit.creatureId); - if (temp.summon_unit.repeatMax < temp.summon_unit.repeatMin) + case EVENT_T_SUMMONED_JUST_DIE: + case EVENT_T_SUMMONED_JUST_DESPAWN: + if (!sCreatureStorage.LookupEntry(temp.summoned.creatureId)) + sLog.outErrorDb("CreatureEventAI: Creature %u are using event(%u) with not existed creature template id (%u) in param1, skipped.", temp.creature_id, i, temp.summoned.creatureId); + if (temp.summoned.repeatMax < temp.summoned.repeatMin) sLog.outErrorDb("CreatureEventAI: Creature %u are using event(%u) with param2 < param1 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); break; case EVENT_T_QUEST_ACCEPT: diff --git a/src/game/PointMovementGenerator.cpp b/src/game/PointMovementGenerator.cpp index fd5925123..bcac405e3 100644 --- a/src/game/PointMovementGenerator.cpp +++ b/src/game/PointMovementGenerator.cpp @@ -98,13 +98,9 @@ void PointMovementGenerator::MovementInform(Creature &unit) { TemporarySummon* pSummon = (TemporarySummon*)(&unit); if (IS_CREATURE_GUID(pSummon->GetSummonerGUID())) - { - if (Unit* pSummoner = pSummon->GetSummoner()) - { - if (((Creature*)pSummoner)->AI()) - ((Creature*)pSummoner)->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id); - } - } + if(Creature* pSummoner = unit.GetMap()->GetCreature(pSummon->GetSummonerGUID())) + if (pSummoner->AI()) + pSummoner->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id); } } diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index a6e089180..09c066140 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -165,11 +165,10 @@ void TemporarySummon::UnSummon() { CombatStop(); - Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; - if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI()) - { - ((Creature*)sum)->AI()->SummonedCreatureDespawn(this); - } + if (IS_CREATURE_GUID(GetSummonerGUID())) + if(Creature* sum = GetMap()->GetCreature(GetSummonerGUID())) + if (sum->AI()) + sum->AI()->SummonedCreatureDespawn(this); AddObjectToRemoveList(); } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index a99b383ca..5784e7df2 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -35,6 +35,7 @@ #include "MapManager.h" #include "ObjectAccessor.h" #include "CreatureAI.h" +#include "TemporarySummon.h" #include "Formulas.h" #include "Pet.h" #include "Util.h" @@ -684,6 +685,16 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if (cVictim->AI()) cVictim->AI()->JustDied(this); + if (cVictim->isTemporarySummon()) + { + TemporarySummon* pSummon = (TemporarySummon*)cVictim; + if (IS_CREATURE_GUID(pSummon->GetSummonerGUID())) + if(Creature* pSummoner = cVictim->GetMap()->GetCreature(pSummon->GetSummonerGUID())) + if (pSummoner->AI()) + pSummoner->AI()->SummonedCreatureJustDie(cVictim); + } + + // Dungeon specific stuff, only applies to players killing creatures if(cVictim->GetInstanceId()) { diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 648199535..4b6110327 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 "9240" + #define REVISION_NR "9241" #endif // __REVISION_NR_H__