[7863] Implement for EVENT_T_SPAWNED map/zone/subzone only event conditions.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Alex 2009-05-21 05:24:25 +04:00 committed by VladimirMangos
parent 0f928164e0
commit bde5402b40
5 changed files with 65 additions and 9 deletions

View file

@ -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:

View file

@ -132,10 +132,8 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
if (!bEmptyList)
{
for (std::list<CreatureEventAIHolder>::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<CreatureEventAIHolder>::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;
}

View file

@ -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<Creature*>& _list, float range, uint32 spellid);
void DoFindFriendlyCC(std::list<Creature*>& _list, float range);

View file

@ -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)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7862"
#define REVISION_NR "7863"
#endif // __REVISION_NR_H__