public override bool Live(Universe.Map map) { StopAnyMovement(); if (closest != null) { if ((body.position - closest).Length > navigator.MaximumDistance || !map.ClearSight(body.position, closest)) { Move(map); } else { if ((body.position - closest).Length > (navigator.MaximumDistance + navigator.MinimumDistance) / 2 || (body.position - closest).Length < navigator.MaximumDistance) { Move(map); } Attack(); } } closest = null; return(base.Live(map)); }
void Move(Universe.Map map) { if (!navigator.Navigating) { if (path == null || (path.Count == 0 && (body.position - closest).Length > navigator.MinimumDistance) || (path.Count > 0 && !map.ClearSight(body.position, path.First.Value)) || (navigator.Target - closest).Length > 100) { navigator.StartNavigation(body.position, closest, map); path = navigator.Navigate(50); } } else { path = navigator.Navigate(50); } if (path != null && path.Count > 0) { while (path.Count > 1) { if (map.ClearSight(path.First.Next.Value, body.position)) { path.RemoveFirst(); } else { break; } } Vector target = path.First.Value; Vector movement = target - body.position; if (movement.y < -2) { agentActions.KeyDown(Constants.North); } if (movement.y > 2) { agentActions.KeyDown(Constants.South); } if (movement.x < -2) { agentActions.KeyDown(Constants.West); } if (movement.x > 2) { agentActions.KeyDown(Constants.East); } if ((body.position - target).Length < 5) { path.RemoveFirst(); } else { agentActions.lookDirection = agentActions.MovementDirection; } } }