public bool ExecuteOrder(Order order) { order.Executed = false; if (order.PlatformOrder) { switch (order) { case MoveOrder moveOrder: Shooter.StopShooting(); Shooter.SearchForTarget = false; ResetExplicitTarget(); order.Executed = Walker.GoTo(moveOrder.Target); break; case AttackOrder attackOrder: Shooter.StopShooting(); if (Unit.Player.IsEnemy(attackOrder.Target.Player) && (SetExplicitTarget(attackOrder.Target) != null)) { order.Executed = Shooter.ShootAt(explicitTarget) || Walker.GoTo(Level.Map.PathFinding.GetClosestNode(explicitTarget.CurrentPosition)); } if (order.Executed) { Shooter.SearchForTarget = false; } break; } } return(order.Executed); }
public override void OnUpdate(float timeStep) { if (dying) { if (animationController.IsAtEnd("Assets/Units/Chicken/Models/Dying.ani")) { Unit.RemoveFromLevel(); } return; } if (explicitTarget != null) { shootTestTimer -= timeStep; if (shootTestTimer < 0) { shootTestTimer = timeBetweenTests; if (Shooter.CanShootAt(explicitTarget)) { Walker.Stop(); Shooter.ShootAt(explicitTarget); } else if (explicitTarget.Moving && targetMoved) { targetMoved = false; Walker.GoTo(Level.Map.PathFinding.GetClosestNode(explicitTarget.CurrentPosition)); } } } if (Shooter.Target != null && Walker.State != WorldWalkerState.Started) { var targetPos = Shooter.Target.CurrentPosition; var diff = Unit.Position - targetPos; Unit.FaceTowards(Unit.Position + diff); } }