예제 #1
0
        private void SetupAttackTargetState()
        {
            var map               = Model.Map;
            var battle            = Model.Battle;
            var origin            = Model.SelectedCombatant.Position;
            var range             = battle.GetMaxWeaponAttackRange(Model.SelectedCombatant);
            var attackableSquares = map.FindSurroundingPoints(origin, range);
            var highlights        = new MapHighlights(attackableSquares, HighlightLevel.PlayerAttack);

            HighlightSignal.Dispatch(highlights);
            HoverTileDisableSignal.Dispatch();
        }
예제 #2
0
        private void SetupInteractTargetState()
        {
            var origin             = Model.SelectedCombatant.Position;
            var interactiveSquares = Model.Map.GetEventTilesSurrounding(origin)
                                     .Where(tile => tile.InteractionMode == InteractionMode.Use)
                                     .Select(tile => tile.Location)
                                     .ToHashSet();
            var highlights = new MapHighlights(interactiveSquares, HighlightLevel.PlayerInteract);

            HighlightSignal.Dispatch(highlights);
            HoverTileDisableSignal.Dispatch();
        }
예제 #3
0
        private void SetupMoveLocationState()
        {
            var map       = Model.Map;
            var origin    = Model.SelectedCombatant.Position;
            var moveRange = Model.Battle.GetRemainingMoves(Model.SelectedCombatant);
            Predicate <KeyValuePair <Vector2, Tile> > movabilityPredicate = pair => {
                // If the tile is obstructed by props don't let them in.
                var tile = pair.Value;
                if (tile.Obstructed)
                {
                    return(false);
                }

                // If the occupant is friendly, and they are NOT at a terminal point, let them in.
                var location = pair.Key;
                var occupant = tile.Occupant;
                if (occupant != null && !occupant.Army.IsEnemyOf(Model.SelectedCombatant.Army))
                {
                    var distance = MathUtils.ManhattanDistance(origin, location);
                    if (distance == moveRange)
                    {
                        return(false);
                    }
                }

                return(true);
            };


            var squares = map.RangeQuery(origin, moveRange, movabilityPredicate)
                          .Select(square => map.FindPath(origin, square))

                          // If the length of the path to the square (minus the start point) is within range, let it in
                          .Where(path => path != null && path.Count() - 1 <= moveRange)

                          // Collect all points along the path to make sure we highlight squares that were not themselves
                          // standable (due to being obstructed by a path, but can be walked-through becuase of the
                          // friendly unit passthru rule.
                          .SelectMany(path => path.Skip(1).ToList())
                          .ToHashSet();


            var moveHighlights = new MapHighlights(squares, HighlightLevel.PlayerMove);

            HighlightSignal.Dispatch(moveHighlights);

            var attackableSquares = squares.SelectMany(square => { return(MathUtils.GetAdjacentPoints(square)); })
                                    .Distinct()
                                    .Where(square => {
                if (map.IsBlockedByEnvironment(square))
                {
                    return(false);
                }

                var occupant = map.GetAtPosition(square);
                return(occupant != null && occupant.Army.IsEnemyOf(Model.SelectedCombatant.Army));
            })
                                    .ToHashSet();

            var attackHighlights = new MapHighlights(attackableSquares, HighlightLevel.PlayerAttack);

            HighlightSignal.Dispatch(attackHighlights);
            HoverTileDisableSignal.Dispatch();
        }