public void OnTaskService(FixPoint delta_time) { PositionComponent position_cmp = ParentObject.GetComponent(PositionComponent.ID) as PositionComponent; LocomotorComponent locomotor_cmp = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent; SkillManagerComponent skill_cmp = ParentObject.GetComponent(SkillManagerComponent.ID) as SkillManagerComponent; Skill skill = skill_cmp.GetSkill(m_skill_index); if (skill == null) { StopTargeting(); return; } if (!skill.IsReady() && locomotor_cmp != null && locomotor_cmp.IsMoving) { FixPoint delay = skill.GetNextReadyTime(); if (delay == FixPoint.Zero) { delay = FixPoint.PrecisionFP; } ScheduleTargeting(delay); return; } bool move_required = false; FixPoint max_range = skill.GetDefinitionComponent().MaxRange; PositionComponent target_position_cmp = m_current_target.GetComponent(PositionComponent.ID) as PositionComponent; Vector3FP direction = target_position_cmp.CurrentPosition - position_cmp.CurrentPosition; if (max_range > 0) { FixPoint distance = direction.FastLength() - target_position_cmp.Radius - position_cmp.Radius; //ZZWTODO 多处距离计算 if (distance > max_range) { move_required = true; if (locomotor_cmp == null) { //ZZWTODO ScheduleTargeting(TARGETING_UPDATE_MAX_FREQUENCY); } else if (!locomotor_cmp.IsEnable()) { ScheduleTargeting(TARGETING_UPDATE_MIN_FREQUENCY); } else { FixPoint delay = (distance - max_range) / locomotor_cmp.MaxSpeed; if (delay > TARGETING_UPDATE_MAX_FREQUENCY) { delay = TARGETING_UPDATE_MAX_FREQUENCY; } else if (delay < TARGETING_UPDATE_MIN_FREQUENCY) { delay = TARGETING_UPDATE_MIN_FREQUENCY; } PathFindingComponent pathfinding_component = ParentObject.GetComponent(PathFindingComponent.ID) as PathFindingComponent; if (pathfinding_component != null) { if (pathfinding_component.FindPath(target_position_cmp.CurrentPosition)) { locomotor_cmp.GetMovementProvider().FinishMovementWhenTargetInRange(target_position_cmp, max_range); } } else { List <Vector3FP> path = new List <Vector3FP>(); path.Add(position_cmp.CurrentPosition); path.Add(target_position_cmp.CurrentPosition); locomotor_cmp.MoveAlongPath(path, false); locomotor_cmp.GetMovementProvider().FinishMovementWhenTargetInRange(target_position_cmp, max_range); } ScheduleTargeting(delay); } } } if (!move_required) { if (skill.CanActivate(false)) { position_cmp.SetFacing(direction); skill.GetDefinitionComponent().ExternalID = m_current_target.ID; skill.Activate(GetCurrentTime()); if (m_attack_once) { StopTargeting(); return; } FixPoint delay = skill.GetDefinitionComponent().CooldownTime + FixPoint.PrecisionFP; if (delay > TARGETING_UPDATE_MAX_FREQUENCY) { delay = TARGETING_UPDATE_MAX_FREQUENCY; } ScheduleTargeting(delay); } else { FixPoint delay = skill.GetNextReadyTime(); if (delay < TARGETING_UPDATE_MIN_FREQUENCY) { delay = TARGETING_UPDATE_MIN_FREQUENCY; } ScheduleTargeting(delay); } } }