public override ICommand GetAction() { if (Game.Map.PlayerMap[Loc.X, Loc.Y] <= 2) { // in attack range // TODO: better decision of when to use large attacks Loc dir = Utils.Distance.GetNearestDirection(Game.Player.Loc, Loc); IAction action = _attacks[_current]; IEnumerable <Loc> targets = action.Area.GetTilesInRange(this, Loc + dir); ICommand command = new DelayActionCommand(this, action, targets); if (++_current >= _attacks.Count) { _current = 0; } return(command); } else if (Game.Map.PlayerMap[Loc.X, Loc.Y] < Parameters.Awareness) { // in range, chase // TODO: don't chase if not alerted LocCost nextMove = Game.Map.MoveTowardsTarget(Loc, Game.Map.PlayerMap); return(new MoveCommand(this, nextMove.Loc)); } else { // out of range, sleep return(new WaitCommand(this)); } }
public IEnumerable <LocCost> GetPathToPlayer(Loc pos) { System.Diagnostics.Debug.Assert(Field.IsValid(pos)); int nearest = PlayerMap[pos.X, pos.Y]; int prev = nearest; while (nearest > 0) { LocCost nextMove = MoveTowardsTarget(pos, PlayerMap); nearest = nextMove.Cost; if (Math.Abs(nearest - prev) < 0.001f || Math.Abs(nearest) < 0.01f) { yield break; } else { prev = nearest; yield return(nextMove); } } }
public Option <ICommand> HandleKeyInput(int key) { bool breaking = false; foreach (Loc pos in Game.Map.Discovered) { Game.Map.GetExit(pos).MatchSome(exit => { Game.MessageHandler.AddMessage($"You see an exit to {exit.Destination}"); Game.StateHandler.PopState(); breaking = true; }); if (breaking) { return(Option.None <ICommand>()); } Game.Map.GetStack(pos).MatchSome(stack => { Game.MessageHandler.AddMessage($"You see {stack}"); Game.StateHandler.PopState(); breaking = true; }); if (breaking) { return(Option.None <ICommand>()); } } breaking = false; foreach (Tile tile in Game.Map.Field.Where(t => t.IsVisible)) { Game.Map.GetActor(new Loc(tile.X, tile.Y)) .Filter(actor => !(actor is Player)) .MatchSome(actor => { Game.MessageHandler.AddMessage($"You see a {actor.Name}"); Game.StateHandler.PopState(); breaking = true; }); if (breaking) { return(Option.None <ICommand>()); } } LocCost move = Game.Map.MoveTowardsTarget( Game.Player.Loc, Game.Map.AutoexploreMap); if (move.Loc == Game.Player.Loc) { // If the best move is to stay still, we must have explored everything reachable // already, so we can end autoexplore. Game.MessageHandler.AddMessage($"Fully explored {Game.World.CurrentLevel}"); Game.StateHandler.PopState(); return(Option.None <ICommand>()); } else { return(Option.Some <ICommand>(new MoveCommand(Game.Player, move.Loc))); } }