예제 #1
0
        internal void ProcessPlayerAction()
        {
            foreach (var playerAction in _playerActions)
            {
                _isProcessingTask = true;
                _randomController.RandomHappened = false;
                if (playerAction.ActionType == ActionType.PLAYCARD && playerAction.Player == 2)
                {
                    STCEntities.IPlayable toBePlayed = STCEntities.Entity.FromCard(_game.Player2, STC.Cards.FromAssetId(playerAction.Source.Card.DbfIf));
                    _game.Player2.HandZone.Replace(_game.Player2.HandZone[0], toBePlayed);
                    _entityIdMapping.Add(playerAction.Source.Id, toBePlayed.Id);
                }
                List <PlayerTask> allOptions      = playerAction.Player == 1 ? _game.Player1.Options(true) : _game.Player2.Options(true);
                List <PlayerTask> filteredOptions = new List <PlayerTask>();
                allOptions.ForEach(option =>
                {
                    try
                    {
                        switch (playerAction.ActionType)
                        {
                        case ActionType.HEROPOWER:
                            if (option is HeroPowerTask)
                            {
                                filteredOptions.Add(option);
                            }
                            break;

                        case ActionType.PLAYCARD:
                            if (option is PlayCardTask)
                            {
                                if (option.Source.Id == _entityIdMapping[playerAction.Source.Id])
                                {
                                    filteredOptions.Add(option);
                                }
                            }
                            break;

                        case ActionType.MINIONATTACK:
                            if (option is MinionAttackTask)
                            {
                                if (option.Source.Id == _entityIdMapping[playerAction.AttackInfo.Attacker.Id])
                                {
                                    filteredOptions.Add(option);
                                }
                            }
                            if (option is HeroAttackTask)
                            {
                                if (option.Controller.HeroId == _entityIdMapping[playerAction.AttackInfo.Attacker.Id])
                                {
                                    filteredOptions.Add(option);
                                }
                            }
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                });

                if (filteredOptions.Count > 0)
                {
                    if (filteredOptions.Count == 1)
                    {
                        _game.Process(filteredOptions[0]);
                        _game.MainCleanUp();
                    }
                    else
                    {
                        STC.Game nextGame = null;
                        List <List <string> > errorsList = new List <List <string> >();
                        foreach (PlayerTask task in filteredOptions)
                        {
                            STC.Game clonedGame = _game.Clone(false, false, _randomController.Clone());
                            clonedGame.Process(task);
                            clonedGame.MainCleanUp();
                            var errors = Converter.AreGamesInSync(clonedGame, Core.Game);
                            if (errors.Count == 0)
                            {
                                nextGame = clonedGame;
                                break;
                            }
                            else
                            {
                                errorsList.Add(errors);
                            }
                        }
                        if (nextGame == null)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                        _game             = nextGame;
                        _randomController = (RandomController)nextGame.RandomController;
                    }
                    Converter.SyncEntityIds(ref _entityIdMapping, _game, Core.Game);
                    _game.Step = Step.MAIN_ACTION;
                    _randomController.Reset();
                    if (_randomController.RandomHappened)
                    {
                        launchAgent();
                    }
                }
                else
                {
                    System.Diagnostics.Debugger.Break();
                    var foo = playerAction.Player == 1 ? _game.Player1.Options(true) : _game.Player2.Options(true);
                }
            }
            _isProcessingTask = false;
            _randomController.RandomHappened = false;
            _playerActions = new List <PlayerAction>();
        }
예제 #2
0
        public void NextStepEvent(Game game, Step step)
        {
            _game.Log(LogLevel.DEBUG, BlockType.TRIGGER, "Event", $"NextStepEvent - {step}");
            switch (step)
            {
            case Step.BEGIN_FIRST:
                game.Step = step;
                game.BeginFirst();
                break;

            case Step.BEGIN_SHUFFLE:
                game.Step = step;
                game.BeginShuffle();
                break;

            case Step.BEGIN_DRAW:
                game.Step = step;
                game.BeginDraw();
                break;

            case Step.BEGIN_MULLIGAN:
                game.Step = step;
                game.BeginMulligan();
                break;

            case Step.MAIN_BEGIN:
                game.Step = step;
                game.MainBegin();
                break;

            case Step.MAIN_DRAW:
                game.Step = step;
                game.MainDraw();
                break;

            case Step.MAIN_READY:
                game.Step = step;
                game.MainReady();
                break;

            case Step.MAIN_RESOURCE:
                game.Step = step;
                game.MainRessources();
                break;

            case Step.MAIN_START:
                game.Step = step;
                game.MainStart();
                break;

            case Step.MAIN_START_TRIGGERS:
                game.Step = step;
                game.MainStartTriggers();
                break;

            case Step.MAIN_ACTION:
                game.Step = step;
                break;

            case Step.MAIN_COMBAT:
                break;

            case Step.MAIN_CLEANUP:
                game.Step = step;
                game.MainCleanUp();
                break;

            case Step.MAIN_END:
                game.Step = step;
                game.MainEnd();
                break;

            case Step.MAIN_NEXT:
                game.Step = step;
                game.MainNext();
                break;

            case Step.FINAL_WRAPUP:
                game.FinalWrapUp();
                break;

            case Step.FINAL_GAMEOVER:
                game.FinalGameOver();
                break;

            case Step.INVALID:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(step), step, null);
            }
        }