Ejemplo n.º 1
0
        public RandomController Clone()
        {
            RandomController clone = new RandomController(ref _entityIdMapping);

            clone.cardsToDraw     = new List <Hearthstone_Deck_Tracker.Hearthstone.Entities.Entity>(cardsToDraw);
            clone.cardsToPick     = new List <Hearthstone_Deck_Tracker.Hearthstone.Entities.Entity>(cardsToPick);
            clone.cardsToDiscover = new List <Hearthstone_Deck_Tracker.Hearthstone.Entities.Entity>(cardsToDiscover);
            return(clone);
        }
Ejemplo n.º 2
0
        internal void GameStart()
        {
            // Reset
            _messenger.Reset();
            _messenger.Show();
            _numberOfTurns    = 0;
            _isMulliganPhase  = true;
            _isMulliganDone   = false;
            _isNewTurn        = false;
            _isProcessingTask = false;
            _mulliganCards    = new List <SabberStoneCore.Model.Card>();
            _entityIdMapping  = new Dictionary <int, int>();
            _randomController = new RandomController(ref _entityIdMapping);
            _toBeKept         = new List <int>();
            _playerActions    = new List <PlayerAction>();

            _messenger.SetTitle("Game starts!");
            //System.Diagnostics.Debugger.Break();
        }
Ejemplo n.º 3
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>();
        }