public static string Stringify(this Player player) { string cards = player.Cards.Stringify(); string futureCards = player.FutureCards.Stringify(); string animals = player.Animals.Stringify(); string goods = player.Goods.Stringify(); string projectArea = player.ProjectArea.Stringify(); string bonusActionCards = player.BonusActionCards.Stringify(); string completedProjects = player.CompletedProjects.Stringify(); string receivedBonuses = player.ReceivedBonuses.Stringify(); var sp = new SerializedPlayer(cards, futureCards, animals, goods, projectArea, bonusActionCards, completedProjects, receivedBonuses, player.NickName, player.Score, player.WorkersCount, player.SilverCount, player.SilverActionDoneThisTurn); return(JsonUtility.ToJson(sp)); }
public void SerializedPlayerAnswer(Messenger messenger, string key, SerializedPlayerAnswer answer) { var sp = new SerializedPlayer(); sp.data = answer.bytes; Player.FindPlayerByName(answer.player).SerializedPlayer(sp); }
public static Player DeSerialize(SerializedPlayer serializedPlayer) { string playername = serializedPlayer.Playername; Board board = new Board(serializedPlayer.col, serializedPlayer.row, 0); int counter = 0; for (int i = 0; i < board.GameBoard.GetLength(0); i++) { for (int j = 0; j < board.GameBoard.GetLength(1); j++) { int id = serializedPlayer.boardConfiguration[counter]; Card card = new Card(id, ResourceLoader.icons[id], i, j); if (serializedPlayer.cardState[counter] == 0) { card.IsDone = false; } else { card.IsDone = true; } board.GameBoard[i, j] = card; counter++; } } Player p = new Player(playername, board); p.Moves = serializedPlayer.moves; p.TimeSeconds = serializedPlayer.TimeSeconds; return(p); }
public void LoadSavedState(SerializedPlayer[] state) { for (int i = 0; i < playerList.Count; i++) { SerializedPlayer playerState = state[i]; Player currentPlayer = getPlayerFromId(playerState.id); CharacterAttributes current = currentPlayer.attributes; current.Level = playerState.level; current.Experience = playerState.experience; current.StatPoints = playerState.statPoints; current.Strength = playerState.strength; current.Intelligence = playerState.intelligence; current.Stamina = playerState.stamina; currentPlayer.abilities.UpdateUnlockedAbilities(current); currentPlayer.resources.currentHealth = playerState.health; currentPlayer.resources.currentEnergy = playerState.energy; for (int j = 0; j < playerState.abilities.Length; j++) { currentPlayer.abilities.SetNewAbility(playerState.abilities[j], j); } currentPlayer.abilities.SetBasic(playerState.basic); if (playerState.isInControl) { activePlayer = currentPlayer; currentPlayer.strategy.isplayerControlled = true; playerResources = activePlayer.GetComponent <PlayerResources>(); // cameraScript = Camera.main.GetComponent<OffsetCamera>(); cameraScript.activePlayerCharacter = activePlayer.gameObject; } } }
public SerializedPlayer[] currentState() { SerializedPlayer[] players = new SerializedPlayer[playerList.Count]; for (int i = 0; i < playerList.Count; i++) { CharacterAttributes current = playerList[i].attributes; SerializedPlayer player = new SerializedPlayer(); player.level = current.Level; player.experience = current.Experience; player.strength = current.Strength; player.intelligence = current.Intelligence; player.stamina = current.Stamina; player.isInControl = playerList[i].Equals(activePlayer); player.id = playerList[i].id; player.statPoints = current.StatPoints; players[i] = player; player.health = playerList[i].resources.currentHealth; player.energy = playerList[i].resources.currentEnergy; int[] abilities = new int[4]; for (int j = 0; j < playerList[i].abilities.abilityArray.Length; j++) { IAbility ability = playerList[i].abilities.abilityArray[j]; abilities[j] = ability.id; } player.abilities = abilities; player.basic = playerList[i].abilities.Basic.id; } return(players); }
//Biggest spaghetti ever public static void WriteToFile(Player player) { SerializedPlayer sp = new SerializedPlayer(player); if (!PlayerPrefs.HasKey("Data")) { string json = JsonUtility.ToJson(sp); PlayerPrefs.SetString("Data", json); PlayerPrefs.Save(); } else { string jsons = PlayerPrefs.GetString("Data"); List <SerializedPlayer> list = new List <SerializedPlayer>(); string[] strings = jsons.Split(SEPARTOR); foreach (var item in strings) { list.Add(JsonUtility.FromJson <SerializedPlayer>(item)); } foreach (var item in list) { if (item.Playername.Equals(player.Playername) && !item.hasEndedGame) { list.Insert(list.IndexOf(item), sp); list.Remove(item); StringBuilder s = new StringBuilder(); SerializedPlayer[] sl = list.ToArray <SerializedPlayer>(); for (int i = 0; i < sl.Length; i++) { string temp = JsonUtility.ToJson(sl[i]); if (i != sl.Length - 1) { s.Append(temp + SEPARTOR); } else { s.Append(temp); } } PlayerPrefs.SetString("Data", s.ToString()); PlayerPrefs.Save(); return; } } string json = JsonUtility.ToJson(sp); string joined = jsons + SEPARTOR + json; PlayerPrefs.SetString("Data", joined); PlayerPrefs.Save(); } }
public GameResponse(GameState state, IKickermatPlayer player) { State = state; if (player == null) { Player = null; } else { Player = new SerializedPlayer( player.GetType().FullName, player.Name, player.Description, player.Authors, player.Emoji); } }
//Created a new SavedState and saves it under autosave. Loads level 1 public void LoadNewGame() { SavedState newGame = new SavedState(); //newGame.name = "autosave"; newGame.level = 1; newGame.checkPoint = 0; newGame.saveSlot = 6; newGame.date = System.DateTime.Now.ToString(); SerializedPlayer[] players = new SerializedPlayer[4]; for (int i = 0; i < 4; i++) { SerializedPlayer playerStart = new SerializedPlayer(); playerStart.level = 1; playerStart.experience = 0; playerStart.statPoints = 2; playerStart.stamina = 0; playerStart.strength = 0; playerStart.intelligence = 0; playerStart.id = i + 1; playerStart.health = PlayerResources.maxHealth; playerStart.energy = PlayerResources.maxEnergy; playerStart.abilities = new int[4]; playerStart.basic = 1; players[i] = playerStart; if (i == 0) { playerStart.isInControl = true; } } newGame.players = players; bool[] objectives = new bool[6] { false, false, false, false, false, false }; newGame.objectives = objectives; levelToLoad = 1; SaveLoad.Save(newGame, 6); LoadLevel(); }
public void SerializedPlayer(SerializedPlayer rpc) { if (isLocal) { return; } if (rpc.data.Length <= 1) { return; } Deserialize(rpc.data); //Deserialize only set the field _weapon, not the property weapon. so, we should call this property manually. weapon = weapon; //Weapon Sync; Sync s = new Sync(RPCType.Others, "", "weapon"); s.signallerID = networkID; s.sender = userName; Sync(s); //same as weapon accessory = accessory; s = new Sync(RPCType.Others, "", "accessory"); s.signallerID = networkID; s.sender = userName; Sync(s); //itemStack Sync s = new Sync(RPCType.Others, "", "itemStacks"); s.signallerID = networkID; s.sender = userName; Sync(s); //money Sync s = new Sync(RPCType.Others, "", "money"); s.signallerID = networkID; s.sender = userName; Sync(s); }
/// <summary> /// Gets the game save info from the currently loaded scene. /// </summary> /// <returns>The game save info.</returns> public static GameSaveInfo GetGameSaveInfoFromCurrent() { GameObject levelInfoObj = GameObject.FindGameObjectWithTag("LevelGameInfoObj"); if (levelInfoObj == null) { return(null); } LevelGameInfoObjContent lgiObj = levelInfoObj.GetComponent <LevelGameInfoObjContent>(); string currentLevelUID = lgiObj.LevelSceneName; //List<Entity> sceneEntities = GameObject.FindGameObjectsWithTag("Entity").Where(go => go.GetComponent<Entity>() != null).Select(go => go.GetComponent<Entity>()).ToList(); Player scenePlayer = GameObject.FindGameObjectsWithTag("Player").Where(go => go.GetComponent <Player>() != null).Select(go => go.GetComponent <Player>()).FirstOrDefault(); if (scenePlayer == null) { Debug.LogError("GetSaveInfo(): Did not find a player object."); return(null); } SerializedPlayer scenePlayerSer = SerializedPlayer.NewFromPlayer(scenePlayer); return(new GameSaveInfo(currentLevelUID, scenePlayerSer)); }
public static Player ReadFromFile(string playername) { if (PlayerPrefs.HasKey("Data")) { List <SerializedPlayer> list = new List <SerializedPlayer>(); string jsons = PlayerPrefs.GetString("Data"); string[] strings = jsons.Split(SEPARTOR); foreach (var item in strings) { list.Add(JsonUtility.FromJson <SerializedPlayer>(item)); } foreach (var item in list) { if (item.Playername.Equals(playername) && !item.hasEndedGame) { return(SerializedPlayer.DeSerialize(item)); } } } return(new Player(playername, new Board(Game.COL, Game.ROW))); }
/// <summary> /// Create a serializable representation of this class.</summary> public void DeSerialize(SerializedPlayer serializedPlayer) { transform.position = new Vector3(serializedPlayer._position[0], serializedPlayer._position[1], serializedPlayer._position[2]); Stats._name = serializedPlayer._name; Stats._experience = serializedPlayer._experience; Stats._bodyBase = serializedPlayer._bodyBase; Stats._mindBase = serializedPlayer._mindBase; Stats._soulBase = serializedPlayer._soulBase; Stats._currentLife = serializedPlayer._currentLife; Stats._availableAttributePoints = serializedPlayer._availableAttributePoints; Stats._movementSpeed = serializedPlayer._movementSpeed; Stats._alertnessRangeBase = serializedPlayer._alertnessRangeBase; Stats._sightAngleBase = serializedPlayer._sightAngleBase; Stats._attackRangeBase = serializedPlayer._attackRangeBase; // Equipped Weapon Stats.EquippedWeapon = (Weapon)ItemDatabase.GetItemById(serializedPlayer._equippedWeapon); // Equipped Items foreach(int id in serializedPlayer._equippedItems) { Stats._equippedItems.Add(ItemDatabase.GetItemById(id)); } // Inventory for (int i = 0; i < serializedPlayer._items.Count; i++) { var item = ItemDatabase.GetItemById(serializedPlayer._items[i]); _inventory.AddItem(item, serializedPlayer._quantities[i]); } // Skills foreach (int id in serializedPlayer._learnedSkills) { Skill skill = SkillDatabase.GetSkillById(id); Stats._learnedSkills.Add(skill); } // foreach (int id in serializedPlayer._activeSkills) // { // Skill skill = SkillDatabase.GetSkillById(id); // Stats._activeSkills.Add(skill); // Stats.AddSkill(skill); // } // foreach (int id in serializedPlayer._passiveSkills) // { // Skill skill = SkillDatabase.GetSkillById(id); // Stats._passiveSkills.Add(skill); // Stats.AddSkill(skill); // } Stats._currentLife = Stats.MaxLife; Stats._currentMagic = Stats.MaxMagic; }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="currentLevelUID">The current level uid.</param> /// <param name="player">The serialized current player.</param> public GameSaveInfo(string currentLevelUID, SerializedPlayer player) { this.CurrentLevelUID = currentLevelUID; this.Player = player; }
public void SerializedPlayer(SerializedPlayer rpc) { if (isLocal) return; if (rpc.data.Length <= 1) return; Deserialize(rpc.data); //Deserialize only set the field _weapon, not the property weapon. so, we should call this property manually. weapon = weapon; //Weapon Sync; Sync s = new Sync(RPCType.Others | RPCType.Buffered, "", "weapon"); s.signallerID = networkID; s.sender = userName; Sync(s); //same as weapon accessory = accessory; s = new Sync(RPCType.Others | RPCType.Buffered, "", "accessory"); s.signallerID = networkID; s.sender = userName; Sync(s); //itemStack Sync s = new Sync(RPCType.Others | RPCType.Buffered, "", "itemStacks"); s.signallerID = networkID; s.sender = userName; Sync(s); //itemStack Sync s = new Sync(RPCType.Others | RPCType.Buffered, "", "gotQuest"); s.signallerID = networkID; s.sender = userName; Sync(s); //money Sync s = new Sync(RPCType.Others | RPCType.Buffered, "", "money"); s.signallerID = networkID; s.sender = userName; Sync(s); }