Esempio n. 1
0
        // WARNING: The Game must not be changing during this,
        // ie. it is not thread-safe unless the game is inactive
        public Game CloneState()
        {
            var  entities = new EntityController(Entities);
            Game game     = entities.FindGame();

            // Set references to the new player proxies (no additional cloning)
            game.Player1 = entities.FindPlayer(1);
            game.Player2 = entities.FindPlayer(2);
            if (game.CurrentPlayer != null)
            {
                game.CurrentPlayer = (CurrentPlayer.Id == game.Player1.Id ? game.Player1 : game.Player2);
            }
            // Generate zones owned by game
            for (int i = 0; i < 2; i++)
            {
                game.Players[i].Deck = new Deck(game, Players[i].Deck.HeroClass, game.Players[i]);
            }
            // Clone queue, stack and events
            game.ActionQueue = ((ActionQueue)ActionQueue.Clone());
            game.ActionQueue.Attach(game);
            // Clone triggers
            game.ActiveTriggers      = ((TriggerManager)ActiveTriggers.Clone());
            game.ActiveTriggers.Game = game;
            // Clone environment
            game.Environment = (Environment)Environment.Clone();
            // Link PowerHistory
            if (PowerHistory != null)
            {
                game.PowerHistory = new PowerHistory(game, this);
            }
#if _GAME_DEBUG
            DebugLog.WriteLine("Cloned game " + GameId + " => " + game.GameId);
#endif
            return(game);
        }