[8233] Implement new EventAI action ACTION_T_SET_INVINCEABILITY_HP_LEVEL. Author: VladimirMangos

Action set min. health value that can be set for creature in result damage apply.
    It can be used in duel like events with creatures to prevent killing creature and other
    cases when creature must avoid damage at some health level while it used.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-07-30 10:53:16 +08:00
parent dd94fb12d6
commit 3926cb174b
4 changed files with 53 additions and 5 deletions

View File

@@ -137,6 +137,7 @@ Each event type has its own specific interpretation of it's params, like every e
39 ACTION_T_CALL_FOR_HELP Radius Call any friendly out-of-combat creatures in a radius (Param1) to attack current creature's target.
40 ACTION_T_SET_SHEATH Sheath Sets sheath state for a creature (0 = no weapon, 1 = melee weapon, 2 = ranged weapon).
41 ACTION_T_FORCE_DESPAWN No Params Despawns the creature
42 ACTION_T_SET_INVINCEABILITY_HP_LEVEL hp_level, is_percent Set min. health level for creature that can be set at damage as flat value or percent from max health
* = Use -1 where the param is expected to do nothing. Random constant is generated for each event, so if you have a random yell and a random sound, they will be linked up with each other (ie. param2 with param2).
@@ -737,6 +738,14 @@ This possible setup by set ar event AI start (single used EVENT_T_TIMER_OOC set
Despawns the creature (in or out of combat)
No parameters
-------------------------
42 ACTION_T_SET_INVINCEABILITY_HP_LEVEL
-------------------------
Parameter 1: min. health level for creature that can be set at damage, 0 used as absent min. health value for apply damage.
Parameter 2: format of paramater 1 value
0 paramater 1 used as flat value
1 paramater 1 used as percent (0..100) from creature max health
=========================================
Target Types
=========================================

View File

@@ -96,6 +96,8 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
AttackDistance = 0.0f;
AttackAngle = 0.0f;
InvinceabilityHpLevel = 0;
//Handle Spawned Events
if (!bEmptyList)
{
@@ -792,6 +794,14 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
m_creature->ForcedDespawn();
break;
}
case ACTION_T_SET_INVINCEABILITY_HP_LEVEL:
{
if(action.invinceability_hp_level.is_percent)
InvinceabilityHpLevel = m_creature->GetMaxHealth()*100/action.invinceability_hp_level.hp_level;
else
InvinceabilityHpLevel = action.invinceability_hp_level.hp_level;
break;
}
}
}
@@ -1338,6 +1348,17 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
}
}
void CreatureEventAI::DamageTaken( Unit* done_by, uint32& damage )
{
if(InvinceabilityHpLevel > 0 && m_creature->GetHealth() < InvinceabilityHpLevel+damage)
{
if(m_creature->GetHealth() <= InvinceabilityHpLevel)
damage = 0;
else
damage = m_creature->GetHealth() - InvinceabilityHpLevel;
}
}
bool CreatureEventAI::SpawnedEventConditionsCheck(CreatureEventAI_Event const& event)
{
if(event.event_type != EVENT_T_SPAWNED)

View File

@@ -113,6 +113,7 @@ enum EventAI_ActionType
ACTION_T_FORCE_DESPAWN = 41, // No Params
ACTION_T_END = 105,
ACTION_T_SET_INVINCEABILITY_HP_LEVEL= 42, // MinHpValue, format(0-flat,1-percent from max health)
};
enum Target
@@ -379,6 +380,11 @@ struct CreatureEventAI_Action
{
uint32 sheath;
} set_sheath;
struct
{
uint32 hp_level;
uint32 is_percent;
} invinceability_hp_level;
// RAW
struct
{
@@ -581,6 +587,7 @@ class TRINITY_DLL_SPEC CreatureEventAI : public CreatureAI
void AttackStart(Unit *who);
void MoveInLineOfSight(Unit *who);
void SpellHit(Unit* pUnit, const SpellEntry* pSpell);
void DamageTaken(Unit* done_by, uint32& damage);
void UpdateAI(const uint32 diff);
void ReceiveEmote(Player* pPlayer, uint32 text_emote);
static int Permissible(const Creature *);
@@ -608,10 +615,11 @@ class TRINITY_DLL_SPEC CreatureEventAI : public CreatureAI
bool bEmptyList;
//Variables used by Events themselves
uint8 Phase; //Current phase, max 32 phases
bool CombatMovementEnabled; //If we allow targeted movment gen (movement twoards top threat)
bool MeleeEnabled; //If we allow melee auto attack
float AttackDistance; //Distance to attack from
float AttackAngle; //Angle of attack
uint8 Phase; // Current phase, max 32 phases
bool CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
bool MeleeEnabled; // If we allow melee auto attack
float AttackDistance; // Distance to attack from
float AttackAngle; // Angle of attack
uint32 InvinceabilityHpLevel; // Minimal health level allowed at damage apply
};
#endif

View File

@@ -661,6 +661,16 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
action.set_sheath.sheath = SHEATH_STATE_UNARMED;
}
break;
case ACTION_T_SET_INVINCEABILITY_HP_LEVEL:
if(action.invinceability_hp_level.is_percent)
{
if(action.invinceability_hp_level.hp_level > 100)
{
sLog.outErrorDb("CreatureEventAI: Event %u Action %u uses wrong percent value %u.", i, j+1, action.invinceability_hp_level.hp_level);
action.invinceability_hp_level.hp_level = 100;
}
}
break;
case ACTION_T_EVADE: //No Params
case ACTION_T_FLEE_FOR_ASSIST: //No Params
case ACTION_T_DIE: //No Params