Exemplo n.º 1
0
 private void SetDirection(Direction direction)
 {
     currentDirection = direction;
     // Clear area
     foreach (Tile oldTile in area.AllTiles())
     {
         oldTile.ResetDisplay();
     }
     area.Clear();
     // Set area
     if (direction == Direction.NONE)
     {
         return;
     }
     (int x, int y) = wide ? launcher.on.GetNeighborCoords(direction.Opposite()) : (launcher.on.x, launcher.on.y);
     foreach (Tile newTile in BoardUtils.AllTiles(t => {
         if (BoardUtils.DirectionTo(x, y, t) != direction)
         {
             return(false);
         }
         float distance = BoardUtils.DistanceBetween(launcher.on, constraint, t);
         return(minRange <= distance && distance <= maxRange);
     }))
     {
         var flow = new TileFlow(newTile, direction);
         area.Add(flow);
         flow.UpdateDisplay(2, Tile.TileColor.VALID);
     }
 }
Exemplo n.º 2
0
 public SkillArea SkillAreaIfTarget(Direction direction)
 {
     (int x, int y) = launcher.on.GetNeighborCoords(direction.Opposite());
     return(new SkillArea(BoardUtils.AllTiles(t => {
         if (BoardUtils.DirectionTo(x, y, t) != direction)
         {
             return false;
         }
         float distance = BoardUtils.DistanceBetween(launcher.on, constraint, t);
         return minRange <= distance && distance <= maxRange;
     }).Select(t => new TileFlow(t, direction))));
 }
Exemplo n.º 3
0
        public async void Launch()
        {
            enabled = false;
            await skill.Apply(launcher, area.Done());

            if (skill.condition.passTurn)
            {
                Global.battleUI.EndTurn();
            }
            else
            {
                Global.battleUI.SwitchState(BattleUI.BattleState.SKILL);
            }
            BoardUtils.AllTiles(t => {
                t.ResetDisplay();
                return(false);
            });
        }
Exemplo n.º 4
0
    public async void Play()
    {
        await Task.Delay(1000);

        Skill walking = actor.GetMoveSkills().FirstOrDefault();

        if (walking != null && walking.area is Snake snake)
        {
            var reachableTiles = BoardUtils.AllReachableTiles(piece.on, maxLength: snake.maxRange, valid: CanStepOn);
            // TODO: Think
            var pair = reachableTiles.ToList().Random();
            if (pair.Key != piece.on)
            {
                SkillArea a = new SkillArea();
                a.AddRange(pair.Value);
                await SkillHandler.WALK.Apply(piece, a);
            }
        }

        var       skills        = actor.GetCoreSkills();
        float     bestHeuristic = 0;
        Skill     bestSkill     = null;
        SkillArea bestArea      = null;

        foreach (Skill skill in skills)
        {
            if (!skill.condition.IsValid())
            {
                continue;
            }
            // Try Cone
            skill.area.launcher = piece;
            if (skill.area is Cone cone)
            {
                foreach (Direction dir in DirectionUtils.DIRECTIONS)
                {
                    SkillArea area      = cone.SkillAreaIfTarget(dir);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
            // Try Target
            else if (skill.area is Target target)
            {
                foreach (Tile tile in BoardUtils.AllTiles(t => target.CanSelect(t)))
                {
                    SkillArea area      = target.SkillAreaIfTarget(tile);
                    float     heuristic = skill.effect.Heuristic(skill.element, piece, area);
                    if (heuristic > bestHeuristic)
                    {
                        bestHeuristic = heuristic;
                        bestArea      = area;
                        bestSkill     = skill;
                    }
                }
            }
        }
        if (bestSkill != null)
        {
            await bestSkill.Apply(piece, bestArea);
        }
        Global.battle.NextTurn();
    }