From 6751208eb2514ad401b3a979abb4a87c0a0637b5 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 29 Apr 2014 22:56:02 +0300 Subject: [PATCH] Eluna create workaround for SetReactState --- CreatureMethods.h | 30 +++++++++++------------------- HookMgr.cpp | 8 +++++++- LuaEngine.h | 2 -- LuaFunctions.cpp | 5 ++--- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/CreatureMethods.h b/CreatureMethods.h index 5eb6177..c365340 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -80,14 +80,15 @@ namespace LuaCreature return 1; } - int HasReactState(lua_State* L, Creature* creature) + int IsCombatAllowed(lua_State* L, Creature* creature) { - int32 state = sEluna->CHECKVAL(L, 2); - #ifdef MANGOS - sEluna->Push(L, creature->GetCharmInfo()->HasReactState((ReactStates)state)); + if (CreatureAI* ai = creature->AI()) + sEluna->Push(L, ai->IsCombatMovement()); + else + sEluna->Push(L, false); #else - sEluna->Push(L, creature->HasReactState((ReactStates)state)); + sEluna->Push(L, !creature->HasReactState(REACT_PASSIVE); #endif return 1; } @@ -270,16 +271,6 @@ namespace LuaCreature return 1; } - int GetReactState(lua_State* L, Creature* creature) - { -#ifdef MANGOS - sEluna->Push(L, creature->GetCharmInfo()->GetReactState()); -#else - sEluna->Push(L, creature->GetReactState()); -#endif - return 1; - } - int GetScriptName(lua_State* L, Creature* creature) { sEluna->Push(L, creature->GetScriptName()); @@ -480,14 +471,15 @@ namespace LuaCreature return 0; } - int SetReactState(lua_State* L, Creature* creature) + int SetAllowedCombat(lua_State* L, Creature* creature) { - int32 state = sEluna->CHECKVAL(L, 2); + bool allow = sEluna->CHECKVAL(L, 2); #ifdef MANGOS - creature->GetCharmInfo()->SetReactState((ReactStates)state); + if (CreatureAI* ai = creature->AI()) + ai->SetCombatMovement(allow); #else - creature->SetReactState((ReactStates)state); + creature->SetReactState(allow ? REACT_AGGRESSIVE : REACT_PASSIVE); #endif return 0; } diff --git a/HookMgr.cpp b/HookMgr.cpp index d644bfe..7251e0d 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -1656,7 +1656,13 @@ struct ElunaCreatureAI : ScriptedAI void UpdateAI(uint32 diff) OVERRIDE #endif { - ScriptedAI::UpdateAI(diff); +#ifdef MANGOS + if (IsCombatMovement()) + ScriptedAI::UpdateAI(diff); +#else + if (!me->HasReactState(REACT_PASSIVE)) + ScriptedAI::UpdateAI(diff); +#endif int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE); if (!bind) return; diff --git a/LuaEngine.h b/LuaEngine.h index 33a7d6b..92bb056 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -122,7 +122,6 @@ enum SelectAggroTarget #undef Opcodes #define Opcodes OpcodesList #endif -#define AllowCombat m_isCombatMovement #else #ifndef CATA typedef uint64 ObjectGuid; @@ -138,7 +137,6 @@ typedef ThreatContainer::StorageType ThreatList; #ifdef CATA #define NUM_MSG_TYPES NUM_OPCODE_HANDLERS #endif -#define AllowCombat _isCombatMovementAllowed #endif template diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index e98a961..4d954ff 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -702,7 +702,6 @@ ElunaRegister CreatureMethods[] = { "GetScriptId", &LuaCreature::GetScriptId }, // :GetScriptId() - Returns creature's script ID { "GetAIName", &LuaCreature::GetAIName }, // :GetAIName() - Returns creature's AI name { "GetScriptName", &LuaCreature::GetScriptName }, // :GetScriptName() - Returns creature's script name - { "GetReactState", &LuaCreature::GetReactState }, // :GetReactState() - Returns creature's react state { "GetAttackDistance", &LuaCreature::GetAttackDistance }, // :GetAttackDistance(unit) - Returns attack distance to unit { "GetAggroRange", &LuaCreature::GetAggroRange }, // :GetAggroRange(unit) - Returns aggro distance to unit { "GetDefaultMovementType", &LuaCreature::GetDefaultMovementType }, // :GetDefaultMovementType() - Returns default movement type @@ -721,7 +720,7 @@ ElunaRegister CreatureMethods[] = // Setters { "SetHover", &LuaCreature::SetHover }, // :SetHover([enable]) - Sets hover on or off // {"SetDisableGravity", &LuaCreature::SetDisableGravity}, // :SetDisableGravity([disable, packetOnly]) - Disables or enables gravity - { "SetReactState", &LuaCreature::SetReactState }, // :SetReactState(state) - Sets react state + { "SetAllowedCombat", &LuaCreature::SetAllowedCombat }, // :SetAllowedCombat(allow) - Allows the creature to attack or not { "SetNoCallAssistance", &LuaCreature::SetNoCallAssistance }, // :SetNoCallAssistance([noCall]) - Sets call assistance to false or true { "SetNoSearchAssistance", &LuaCreature::SetNoSearchAssistance }, // :SetNoSearchAssistance([noSearch]) - Sets assistance searhing to false or true { "SetDefaultMovementType", &LuaCreature::SetDefaultMovementType }, // :SetDefaultMovementType(type) - Sets default movement type @@ -745,7 +744,7 @@ ElunaRegister CreatureMethods[] = { "HasCategoryCooldown", &LuaCreature::HasCategoryCooldown }, // :HasCategoryCooldown(spellId) - Returns true if the creature has a cooldown for the spell's category { "CanWalk", &LuaCreature::CanWalk }, // :CanWalk() - Returns true if the creature can walk { "CanSwim", &LuaCreature::CanSwim }, // :CanSwim() - Returns true if the creature can swim - { "HasReactState", &LuaCreature::HasReactState }, // :HasReactState(state) - Returns true if the creature has react state + { "IsCombatAllowed", &LuaCreature::IsCombatAllowed }, // :IsCombatAllowed() - Returns true if the creature has combat allowed // {"CanStartAttack", &LuaCreature::CanStartAttack}, // :CanStartAttack(unit[, force]) - Returns true if the creature can attack the unit { "HasSearchedAssistance", &LuaCreature::HasSearchedAssistance }, // :HasSearchedAssistance() - Returns true if the creature has searched assistance { "CanAssistTo", &LuaCreature::CanAssistTo }, // :CanAssistTo(unit, enemy[, checkfaction]) - Returns true if the creature can assist unit with enemy