[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
+21
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)
+13 -5
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
+10
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