local base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_Wander = class("Decision_Wander", base) local LuaConst=LuaConst local FP=FP --[[ 初始化 --]] function Decision_Wander:initialize(entity) --类型 self.Type = LuaConst.DecisionType.Wander --瞬时 self.IsOnce = false end --[[ 进入该Decision --]] function Decision_Wander:DecisionIn(entity, decisionData) entity.components.anim.NeedChangeWanderDir = true end --[[ 能否退出 完成条件:时间到 --]] function Decision_Wander:CanExit(entity, decisionData, command) local passFrame = LogicUpdateManager._clientHandleFrame - entity.components.aiBase.CurDecisionStartFrame local passTime = passFrame * LuaConst.TimeSpanMs if decisionData.IntParam2 >= 0 then return passTime > decisionData.IntParam2 * 1000 else --新增机制,如果是负数,就认为是毫秒(为了拓展精度,又不希望影响原来的数据) return passTime > -decisionData.IntParam2 end end --[[ 输出指令 --]] function Decision_Wander:SetCommand(entity, decisionData, command) command.DecisionID = decisionData.ID local target = entity.components.target.Target if target then command.RotateDir:Reset(target.components.move.LogicPos):Sub(entity.components.move.LogicPos) end entity.components.anim:SetCurAnimStartDir() -- 需要试试更新动作朝向 return command end function Decision_Wander:Handle(entity, decisionData, stateType, animName) local comp_Anim = entity.components.anim --if comp_Anim.IsCurAnimOver then if decisionData.IntParam1 == 1 then animName = "walk_front_loop" elseif decisionData.IntParam1 == 2 then animName = "walk_back_loop" elseif decisionData.IntParam1 == 3 then local random = LogicRandom.GetRangeValue(entity, 0, 100 ,1022) animName = FP.Greater(random,50) and "walk_left_loop" or "walk_right_loop" end --end local comp_AIBase = entity.components.aiBase if comp_AIBase.CurStateType == LuaConst.StateType.Wander and not comp_Anim.IsCurAnimOver then return LuaConst.StateType.None, nil else return LuaConst.StateType.Wander, animName end end return Decision_Wander