diff --git a/doc/EventAI.txt b/doc/EventAI.txt index 7434a7adf..c63fb9044 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -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 ========================================= diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index ca0384740..7d52d7c7b 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -93,6 +93,8 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c) AttackDistance = 0.0f; AttackAngle = 0.0f; + InvinceabilityHpLevel = 0; + //Handle Spawned Events if (!bEmptyList) { @@ -780,6 +782,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; + } } } @@ -1380,6 +1390,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) diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index ecdcaeb6f..8c1fbf624 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -106,6 +106,7 @@ enum EventAI_ActionType ACTION_T_CALL_FOR_HELP = 39, // Radius ACTION_T_SET_SHEATH = 40, // Sheath (0-passive,1-melee,2-ranged) ACTION_T_FORCE_DESPAWN = 41, // No Params + ACTION_T_SET_INVINCEABILITY_HP_LEVEL= 42, // MinHpValue, format(0-flat,1-percent from max health) ACTION_T_END, }; @@ -373,6 +374,11 @@ struct CreatureEventAI_Action { uint32 sheath; } set_sheath; + struct + { + uint32 hp_level; + uint32 is_percent; + } invinceability_hp_level; // RAW struct { @@ -575,6 +581,7 @@ class MANGOS_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); bool IsVisible(Unit *) const; void ReceiveEmote(Player* pPlayer, uint32 text_emote); @@ -604,10 +611,11 @@ class MANGOS_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 diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index b90f944ce..dfa017c0a 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -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 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index fe523912c..da3876f3a 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 "8232" + #define REVISION_NR "8233" #endif // __REVISION_NR_H__