源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 rivejä
1.5 KiB

NowOperateTargetMove = NowOperateTargetMove or BaseClass(NowOperateMove)
local NowOperateTargetMove = NowOperateTargetMove
function NowOperateTargetMove:__init(start_time, start_pos, end_pos, target, range,scene_obj)
NowOperateMove.__init(self, start_time, start_pos, end_pos,false,scene_obj)
self.target= target
self.range = range
self.scene_obj = scene_obj
--每隔一段时间重新检测路径
self.check_time_delta = 1
self.check_time = Status.NowTime
--print("NowOperateTargetMove:__init", self.check_time)
end
function NowOperateTargetMove:ExcuteImpl(elaspe_time)
local scene_obj = self.scene_obj or Scene.Instance:GetMainRole()
--每隔一段时间重新检测路径,所以可以停止当前路径
if Status.NowTime - self.check_time >= self.check_time_delta then
scene_obj:WaitForNextMove() --会有抖动
self.is_end = true
--print("NowOperateTargetMove:ExcuteImpl Stop Cur path 1", Status.NowTime, self.check_time)
return true
end
--如果与目标的距离达到范围内,也要停止当前路径
local x1, y1 = scene_obj:GetRealPos()
local x2, y2 = self.target:GetRealPos()
--local dir = co.Vector2(x2-x1, y2-y1)
-- local distance = dir:length()
local distance = GameMath.GetDistance(x1, y1, x2, y2, false)
--距离在可动作范围内
local d = (self.range > 5) and (self.range - 5) or self.range
if distance < d * d then
scene_obj:WaitForNextMove()
self.is_end = true
--print("NowOperateTargetMove:ExcuteImpl Stop Cur path 2", distance)
return true
end
return NowOperateMove.ExcuteImpl(self, elaspe_time)
end