local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_PhalanxSquareMoveMember = class("Decision_PhalanxSquareMoveMember", Base) --[[ 初始化 --]] function Decision_PhalanxSquareMoveMember:initialize(entity) --类型 self.Type = LuaConst.DecisionType.PhalanxSquareMoveMember --瞬时 self.IsOnce = false end function Decision_PhalanxSquareMoveMember:CalcOffsetByRotation(entity, decisionData, offset, dir) local dirRad = FP.V2.AngleToRight360(dir) dirRad:Mul(FP.Const.Deg2Rad) return FP.V2.RotateAroundOrigin(offset, dirRad) end function Decision_PhalanxSquareMoveMember:GetPhalanxPos(entity, decisionData) local groupComp = entity.components.group local index = groupComp.phalanxIndex local dir = groupComp.phalanxDir local center = groupComp.phalanxCenter local count = groupComp.phalanxMemberCount local strideColumn = groupComp.phalanxStrideColumn --列与列之间的间隔 local strideRow = groupComp.phalanxStrideRow --行与行之间的间隔 local rotateType = groupComp.rotateType local maxColumn = groupComp.maxColumn if index and dir and center and count then maxColumn = math.min(count, maxColumn) if maxColumn > 0 then local maxRow = math.ceil(count / groupComp.maxColumn) local column = (index - 1) % maxColumn + 1 local row = math.floor((index - 1) / maxColumn) + 1 --※这里的计算以右方向为0度角的方向,因为 fixedpoint 里的角度计算方法是以右方向为起始方向的( FP.V2.AngleToRight360 ) --队列排列方式:index从小到大,是从dir方向的左上(x、z最大的坐标)开始排 local startLeft = FP.newV1(0) --左边起始偏移, 是当dir指向x正方向时,row 1的x坐标 startLeft:Reset(maxRow):Sub(1):Div(2):Mul(strideRow) --(maxRow - 1) / 2 * strideRow local startTop = FP.newV1(0) --顶部起始偏移, 是当dir指向x正方向时, column 1 的z坐标 startTop:Reset(maxColumn):Sub(1):Div(2):Mul(strideColumn) --(maxColumn - 1) / 2 * strideColumn local xOffset = FP.newV1(row) xOffset:Sub(1):Mul(strideRow):Mul(-1):Add(startLeft) local zOffset = FP.newV1(column) zOffset:Sub(1):Mul(strideColumn):Mul(-1):Add(startTop) local offset = FP.newV2(xOffset, zOffset) if rotateType == LuaConst.EPhalanxRotateType.NORMAL_ROTATE then offset = self:CalcOffsetByRotation(entity, decisionData, offset, dir) end return center + offset end --else --正常情况,兵长没有设置行列信息,此时 do nothing 即可 end end function Decision_PhalanxSquareMoveMember:FindPathToPhalanxPos(entity, decisionData) local phalanxPos = self:GetPhalanxPos(entity, decisionData) if phalanxPos then -- local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) -- decisionRecordDic.phalanxPos = phalanxPos SystemManager.FindPath(entity, phalanxPos, true) end local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) decisionRecordDic.lastFindPathFrame = LogicUpdateManager._clientHandleFrame end --[[ 进入该Decision --]] function Decision_PhalanxSquareMoveMember:DecisionIn(entity, decisionData) Base.DecisionIn(self, entity, decisionData) self:FindPathToPhalanxPos(entity, decisionData) end function Decision_PhalanxSquareMoveMember:CanEnter(entity, decisionData, command) return entity.components.group.phalanxIndex ~= nil end --[[ 能否退出 退出条件:移动到固定目标点 --]] function Decision_PhalanxSquareMoveMember:CanExit(entity, decisionData, command) local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) if decisionRecordDic.phalanxPos then local pathComponent = entity.components.path local curPathPos = pathComponent.Path[pathComponent.CurPathPosIndex] return not curPathPos else return true end end function Decision_PhalanxSquareMoveMember:SetCommand(entity, decisionData, command) local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) if decisionRecordDic.lastFindPathFrame == nil or decisionRecordDic.lastFindPathFrame + decisionData.IntParam1 >= LogicUpdateManager._clientHandleFrame then self:FindPathToPhalanxPos(entity, decisionData, command) end return self:RunToPathPoint(entity, command,decisionData) end return Decision_PhalanxSquareMoveMember