-- Combat stategha_combat = { }--INITgha_combat["Init"] = function(LuaAI)log("gha_combat Init")return false -- cant add this state from startup end-- ENTERgha_combat["Enter"] = function(LuaAI) log("gha_combat Enter") data = LuaAI:Data() unit = data["victim"] data["victim"] = nil data[GHA_COMBAT] = {} -- here will be gha_team_combat_state if unit == nil then LuaAI:ChangeState(gha_main) return end -- DEBUG STUFF log("Target guid = " .. unit:GetGUIDLow() ) if gha_checkforhelp(LuaAI,unit) then LuaAI:ChangeState( gha_team_combat ) return end gha_combat["AttackStart"](LuaAI,unit) LuaAI:SetUpdateInterval(100) LuaAI:SetDefaultUpdate(false) player = unit:CastToPlayer() if player ~= nil then i_creature:SetLootRecipient( player ) endend-- EXITgha_combat["Exit"] = function(LuaAI)log("gha_combat Exit")data = LuaAI:Data() data[GHA_COMBAT] = nil --TODO Stop attacking gha_combat["AttackStop"](LuaAI,nil) i_creature:CombatStop(true) i_creature:DeleteThreatList()end-- UPDATEgha_combat["Update"] = function(LuaAI) i_creature = LuaAI:GetCreature() local data = LuaAI:Data() if( not i_creature:SelectHostilTarget() ) or ( not i_creature:getVictim() ) then if data[GHA_COMBAT]["sent_evade_check"] then return end m_guid = i_creature:GetGUID() log("Sent GHA_COMBAT_EVADE_CHECK") DispatchMsg(7000,m_guid,m_guid,GHA_COMBAT_EVADE_CHECK,nil) data[GHA_COMBAT]["sent_evade_check"] = true return end if i_creature:getVictim() ~= nil then if ( gha_combat["needToStop"](LuaAI) ) then gha_combat["AttackStop"](LuaAI,nil) return; end if i_creature:IsWithinDist(i_creature:getVictim(), ATTACK_DIST) and i_creature:isAttackReady(BASE_ATTACK) then i_creature:AttackerStateUpdate(i_creature:getVictim(),BASE_ATTACK,false) i_creature:resetAttackTimer(BASE_ATTACK) end endend-- DEINITgha_combat["DeInit"] = function(LuaAI)log("gha_combat DeInit")gha_main["DeInit"](LuaAI)end-- MoveInLineOfSightgha_combat["MoveInLineOfSight"] = function(LuaAI,unit)log("gha_combat MoveInLineOfSight")end-- AttackStartgha_combat["AttackStart"] = function(LuaAI,unit)log("gha_combat AttackStart") if unit == nil then return end i_creature = LuaAI:GetCreature() local data = LuaAI:Data() if(unit:HasStealthAura()) then unit:RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH) end if i_creature:Attack(unit,false) then i_creature:AddThreat(unit, 0,0,nil) i_creature:resetAttackTimer(BASE_ATTACK) if gha_victim_is_within_combat_range(i_creature) then log(" i_creature:MutateTargeted(unit) ") i_creature:MutateTargeted(unit) end endend-- AttackStopgha_combat["AttackStop"] = function(LuaAI,unit)log("gha_combat AttackStop")-- WARNINGunit may be called with nil value ... so carefull i_creature = LuaAI:GetCreature() i_creature:AttackStop() if i_creature:GetMotionType() == TARGETED_MOTION_TYPE then i_creature:MovementClear(false) i_creature:MutateIdle() endend-- HandleMessagegha_combat["HandleMessage"] = function(LuaAI,sender,msg,extrainfo)log("gha_combat HandleMessage , msg= %d , mguidlow = %d" , msg ,LuaAI:GetCreature():GetGUIDLow() )i_creature = LuaAI:GetCreature() data = LuaAI:Data()if msg == GHA_COMBAT_EVADE_CHECK then data[GHA_COMBAT]["sent_evade_check"] = false if( not i_creature:SelectHostilTarget() ) or ( not i_creature:getVictim() ) then log("Evading from enemy ... ") i_creature:MovementClear(false) i_creature:MutateTargetedHome() LuaAI:ChangeState( gha_main ) else gha_combat["AttackStart"]( LuaAI,i_creature:getVictim() ) end return 0endreturn 0end-- DamageInflictgha_combat["DamageInflict"] = function(LuaAI,unit,amount_damage)log("gha_combat DamageInflict") if unit == nil then return end gha_combat["AttackStart"](LuaAI,unit)end-- IsVisiblegha_combat["IsVisible"] = function(LuaAI,unit)log("gha_combat IsVisible")-- In combat state ,we care only about our enemy .... possibly later will add trheat listreturn falseend-- needToStopgha_combat["needToStop"] = function(LuaAI)log("gha_combat needToStop")i_creature = LuaAI:GetCreature()-- checked in gha_victim_is_within_combat_range-- if ( not i_creature:isAlive() ) or ( i_creature:getVictim() == nil ) -- then-- return true-- end return not gha_victim_is_within_combat_range(i_creature)endm_AI["gha_combat"] = gha_combat