コード例 #1
0
        private void ProcessActions(List <ICombatAction> actions, IActionPlan plan)
        {
            if (actions.Count > 0)
            {
                var nextAction = actions[0];
                var poiFactory = new PointOfInterestFactory(BattleViewState.Dimensions);
                var poi        = nextAction.GetPointofInterest(poiFactory);

                Action panListener = null;
                panListener = new Action(() => {
                    Action listener = null;
                    listener        = new Action(() => {
                        ProcessActions(actions.Skip(1).ToList(), plan);
                        ActionCompleteSignal.RemoveListener(listener);
                    });
                    ActionCompleteSignal.AddListener(listener);
                    AnimateActionSignal.Dispatch(nextAction);

                    CameraPanCompleteSignal.RemoveListener(panListener);
                });
                CameraPanCompleteSignal.AddListener(panListener);
                PanToPointOfInterestSignal.Dispatch(poi);
            }
            else if (plan.HasActionsRemaining())
            {
                ProcessActions(plan.NextActionStep(BattleViewState.Battle), plan);
            }
            else
            {
                Release();
                EnemyTurnCompleteSignal.Dispatch();
            }
        }
コード例 #2
0
        public override void OnRegister()
        {
            View.MapClicked.AddListener(OnMapClicked);
            View.MapHovered.AddListener(OnMapHovered);
            View.MapRightClicked.AddListener(OnRightClick);
            AnimateActionSignal.AddListener(AnimateAction);

            if (!Game.Maps.ContainsKey(View.MapId))
            {
                throw new Exception("Could not find map by id " + View.MapId);
            }

            var mapConfig = Game.Maps[View.MapId];
            var map       = new Map(mapConfig.Width, mapConfig.Height);

            foreach (var tile in mapConfig.ObstructionLocations)
            {
                map.AddObstruction(tile);
            }

            var combatantReferences = View.GetCombatants();
            var combatantDb         = new CombatantDatabase(combatantReferences, SaveGameService.CurrentSave);

            foreach (var combatant in combatantDb.GetAllCombatants())
            {
                map.AddCombatant(combatant);
            }

            View.CombatantDatabase = combatantDb;
            View.Map = map;

            GatherSignal.AddOnce(() => {
                var config = new MapConfiguration(View.GetDimensions(), View.Map, combatantDb, View.ChapterNumber, View.MapId);
                InitializeMapSignal.Dispatch(config);
            });
        }
コード例 #3
0
        public override void Execute()
        {
            var state = BattleViewModel.State;

            if (state == BattleUIState.Uninitialized ||
                state == BattleUIState.PhaseChanging ||
                state == BattleUIState.Preparations ||
                state == BattleUIState.Surveying)
            {
                return;
            }

            var combatant = BattleViewModel.Map.GetAtPosition(Position);

            if (state == BattleUIState.SelectingUnit)
            {
                if (combatant != null && combatant.Army == ArmyType.Friendly)
                {
                    var actions = AvailableActions.GetAvailableActionTypes(combatant);
                    if (actions.Count <= 0)
                    {
                        return;
                    }
                    // Mark the unit at Position as selected, change the battle state.
                    BattleViewModel.SelectedCombatant = combatant;
                    BattleViewModel.State             = BattleUIState.SelectingAction;
                    BattleViewModel.AvailableActions  = actions;

                    var dimensions    = BattleViewModel.Dimensions;
                    var worldPosition = dimensions.GetWorldPositionForGridPosition(combatant.Position);
                    UnitSelectedSignal.Dispatch(worldPosition);
                }
            }
            else if (state == BattleUIState.SelectingMoveLocation)
            {
                var map  = BattleViewModel.Map;
                var path = BattleViewModel.CurrentMovementPath;
                if (path != null)
                {
                    // Don't allow movement to the terminal points of a path if they are blocked.
                    var terminus = path.Terminus;
                    if (!map.IsBlocked(terminus))
                    {
                        var positions = path.Positions.GetRange(1, path.Positions.Count - 1);

                        var action = new MoveAction(map, path.Combatant, positions.Last(), positions);
                        AnimateActionSignal.Dispatch(action);
                        BattleViewModel.State = BattleUIState.CombatantMoving;
                    }
                }
            }
            else if (state == BattleUIState.SelectingInteractTarget)
            {
                var map  = BattleViewModel.Map;
                var tile = map.GetEventTile(Position);

                // Only if the player clicks on a tile that is actually interactible by clicks
                if (tile != null && tile.InteractionMode == InteractionMode.Use)
                {
                    EventTileInteractedSignal.Dispatch(tile);
                }
            }
            else if (state == BattleUIState.SelectingAttackTarget)
            {
                if (combatant != null && combatant.Army == ArmyType.Enemy)
                {
                    // Forecast the fight against this unit
                    var attacker             = BattleViewModel.SelectedCombatant;
                    var battle               = BattleViewModel.Battle;
                    var selectedUnitPosition = attacker.Position;
                    var distanceToTarget     = MathUtils.ManhattanDistance(selectedUnitPosition, Position);
                    var map = BattleViewModel.Map;

                    SkillType skill;
                    if (BattleViewModel.SpecialAttack)
                    {
                        if (!attacker.SpecialSkill.HasValue)
                        {
                            throw new ArgumentException("Combatant " + attacker.Id + " has no special skill configured.");
                        }
                        skill = attacker.SpecialSkill.Value;
                    }
                    else
                    {
                        skill = battle.GetWeaponSkillForRange(attacker, distanceToTarget);
                    }

                    var skillDatabase = new SkillDatabase(map);
                    var forecaster    = new FightForecaster(map, skillDatabase);
                    var fight         = forecaster.Forecast(BattleViewModel.SelectedCombatant, combatant, skill);
                    FightForecastSignal.Dispatch(fight);
                    BattleViewModel.FightForecast = fight;
                    BattleViewModel.State         = BattleUIState.ForecastingCombat;
                }
            }
        }