コード例 #1
0
    private void Deserialize(SerializedGameState serializedGameState,
                             int expectedTotalPieceCount)
    {
        _gameState.rootPositionsForEachPiece.Clear();
        _gameState.rootsByBoardPosition.Clear();

        foreach (var root in serializedGameState.roots)
        {
            _gameState.rootsByBoardPosition.Add(root.boardPosition, root);
            foreach (var piece in root.connectedBoardPositions)
            {
                _gameState.rootPositionsForEachPiece[piece] = root.boardPosition;
            }
        }

        if (serializedGameState.totalPieceCount <= 0)                               // Dealing with legacy gamestate without total piece count
        {
            _gameState.totalPieceCount = expectedTotalPieceCount;
            CheckIfWon();
        }
        else
        {
            _gameState.totalPieceCount = serializedGameState.totalPieceCount;
            HasWon = serializedGameState.hasWon;
        }
    }
コード例 #2
0
        private byte[] createSerializedGamestate(GameState gameState, IEnumerable <GameVoxel> changedVoxels)
        {
            var s = new SerializedGameState();

            s.SetVoxels(changedVoxels, gameplayObjectsSerializer);
            s.Set(gameState, gameplayObjectsSerializer);
            return(SerializerHelper.Serialize(s));
        }
コード例 #3
0
 private void WriteStateToDirectory(SerializedGameState gameState, byte[] uiState, string currentSaveDir)
 {
     File.WriteAllBytes(Path.Join(currentSaveDir, MainStateFile), gameState.MainContent);
     File.WriteAllBytes(Path.Join(currentSaveDir, ActionSequencesSpellsFile), gameState.ActionSequenceSpells);
     File.WriteAllBytes(Path.Join(currentSaveDir, PartyConfigFile), gameState.PartyConfig);
     File.WriteAllBytes(Path.Join(currentSaveDir, MapFleeFile), gameState.FleeData);
     File.WriteAllBytes(Path.Join(currentSaveDir, UiStateFile), uiState);
 }
コード例 #4
0
    public static string Stringify(this GameState gameState)
    {
        string player1 = "";
        string player2 = "";
        string player3 = "";
        string player4 = "";

        if (gameState.Players.Count > 0)
        {
            player1 = gameState.Players[0].Stringify();
        }

        if (gameState.Players.Count > 1)
        {
            player2 = gameState.Players[1].Stringify();
        }

        if (gameState.Players.Count > 2)
        {
            player3 = gameState.Players[2].Stringify();
        }

        if (gameState.Players.Count > 3)
        {
            player4 = gameState.Players[3].Stringify();
        }

        string mainDeck = gameState.MainDeck.Stringify();
        string animals  = gameState.AnimalsDeck.Stringify();
        string goods    = gameState.GoodsDeck.Stringify();
        string projects = gameState.AvailableProjectCards.Stringify();
        string bonuses  = gameState.AvailableBonusCards.Stringify();

        var serializedGameState = new SerializedGameState(
            gameState.Id,
            player1,
            player2,
            player3,
            player4,
            mainDeck,
            animals,
            goods,
            projects,
            bonuses,
            gameState.CurrentRound,
            gameState.CurrentPlayerNickName,
            gameState.CurrentTurn,
            gameState.HowManyPlayers,
            gameState.IsFinished);


        string jsonString = JsonUtility.ToJson(serializedGameState)
                            .Replace("\\", "/")
                            .Replace("\"", "'");

        return(jsonString);
    }
コード例 #5
0
    public static GameState ParseToGameState(this string inputString)
    {
        var input = inputString.Replace("/", "\\").Replace("'", "\"");
        SerializedGameState sgs     = JsonUtility.FromJson <SerializedGameState>(input);
        List <Player>       players = new List <Player>();

        if (sgs.Player1 != "")
        {
            players.Add(sgs.Player1.ParseToPlayer());
        }

        if (sgs.Player2 != "")
        {
            players.Add(sgs.Player2.ParseToPlayer());
        }

        if (sgs.Player3 != "")
        {
            players.Add(sgs.Player3.ParseToPlayer());
        }

        if (sgs.Player4 != "")
        {
            players.Add(sgs.Player4.ParseToPlayer());
        }

        Deck mainDeck    = sgs.MainDeck.ParseToDeck();
        Deck animalsDeck = sgs.AnimalsDeck.ParseToDeck();
        Deck goodsDeck   = sgs.GoodsDeck.ParseToDeck();
        List <ProjectCard> availableProjectCards = sgs.AvailableProjectCards.ParseToProjectCardList();
        List <BonusCard>   availableBonusCards   = sgs.AvailableBonusCards.ParseToList <BonusCard>();

        return(new GameState(sgs.Id,
                             players,
                             mainDeck,
                             animalsDeck,
                             goodsDeck,
                             availableProjectCards,
                             availableBonusCards,
                             sgs.CurrentRound,
                             sgs.CurrentPlayerNickName,
                             sgs.CurrentTurn,
                             sgs.HowManyPlayers,
                             sgs.IsFinished));
    }
コード例 #6
0
    public void Save()
    {
        var serializedState = new SerializedGameState
        {
            roots           = new List <RootInfo>(_gameState.rootsByBoardPosition.Values),
            totalPieceCount = _gameState.totalPieceCount,
            hasWon          = HasWon
        };

        var asJson = JsonUtility.ToJson(serializedState);

        try
        {
            System.IO.File.WriteAllText(Paths.GetFullPathToGameState(), asJson);
        }
        catch (Exception e)
        {
            Debug.LogWarning(e.Message);
        }
    }
コード例 #7
0
 public void InitializeData(SerializedGameState msg)
 {
     this.set_GameID(msg.A);
     if (this.get_SelfAccountID() == null)
     {
         throw new InvalidOperationException(Constants.yM());
     }
     this.set_Options(new global::h.Y(msg.GameOptions));
     this.CardAnimationsInstantiator.Instantiate();
     this.MatchEffectsInstantiator.Instantiate();
     AccountID[] array = global::i.T.SortPlayerIDs(msg.PlayerAccounts, this.get_SelfAccountID());
     this.set_Player1AccountID(array[0]);
     this.set_Player2AccountID(array[1]);
     this.MatchEnd.AssignAccountIDs(this.get_Player1AccountID(), this.get_Player2AccountID());
     this.set_Entities(global::h.y.Create(this.get_Player1AccountID(), this.get_Player2AccountID(), msg.Entities, true, global::I.V.Find()));
     base.GetComponent <EntitiesProvider>().Initialize(this.get_Entities());
     this.set_Waiting(new global::J.h(new EntityID[]
     {
         this.get_Entities().player.get_Player().get_EntityID()
     }));
     this.get_Entities().opponent.get_Player().Add <global::J.M>(new global::J.M(this.get_Waiting()));
     Finder.FindOrThrow <PlaymatLaneScrolls>().Initialize(this.get_Entities().get_PlaymatLane1(), this.get_Entities().get_PlaymatLane2());
     this.checkForPresentedClones();
     this.set_ObserverModel(new global::C.h(this.get_Player1AccountID(), this.get_Player2AccountID()));
     this.set_DataInitialized(true);
     if (this.get_Entities().Playmat.GetOne <global::h.Z>().get_Phase() == Phases.StartGame)
     {
         string text = "";
         foreach (KeyValuePair <string, string> keyValuePair in msg.GameOptions)
         {
             text = string.Concat(new string[]
             {
                 text,
                 "[",
                 keyValuePair.Key,
                 "] = ",
                 keyValuePair.Value,
                 "; "
             });
         }
         string text2 = "";
         foreach (Colors colors in this.get_Entities().opponent.get_Player().GetAttribute <Colors[]>(global::g.D.Colors).get_Value())
         {
             if (text2 == "")
             {
                 text2 = colors.ToString();
             }
             else
             {
                 text2 = text2 + ", " + colors.ToString();
             }
         }
         AccountID value2 = this.get_Entities().Playmat.GetAttribute <AccountID>(global::g.D.activePlayer).get_Value();
         File.AppendAllText("sent.txt", string.Concat(new string[]
         {
             "=== Started Match; player = ",
             this.get_Entities().player.get_Player().GetOne <NameData>().get_Name(),
             "; opponent = ",
             this.get_Entities().opponent.get_Player().GetOne <NameData>().get_Name(),
             "; opponent_deck = ",
             text2,
             "; first player = ",
             (value2 == this.get_Player1AccountID()) ? "you" : "opponent",
             "; rank = ",
             global::f.Y.RankToNumber(Finder.FindOrThrow <RankProvider>().get_CurrentRank()),
             "; opponent_rank = ",
             global::f.Y.RankToNumber(this.get_Options().GetRank(this.get_Player2AccountID())),
             "; options = ",
             text,
             " ===\n"
         }));
     }
 }