/// <summary> /// Intializes the value of stats. /// </summary> /// <param name="playerStatsData">Player stats data.</param> private void IntializeValueOfStats(PlayerStatsData playerStatsData) { this.Expirience = playerStatsData.Expirience; this.PlayerName = playerStatsData.PlayerName; this.Kills = playerStatsData.Kills; this.Deads = playerStatsData.Deads; }
/// <summary> /// Loads the list of saves and display it as a buttons on Select Player Panel. /// </summary> public void LoadListOfSaves() { // clear panel from all buttons( unupdated can exist) foreach (Button button in selectPlayerPanel.GetComponentsInChildren <Button>()) { string str = button.name; if (!str.Equals("Back To Start Game Button")) { DestroyObject(button.gameObject); } } // list of saves files in folder FileInfo[] listOfSavedFiles = PlayerStats.playerStats.GetListOfSavedFiles(); // Y position of button on the panel float posY = 300f; // looping throug all save files and creates buttons foreach (FileInfo file in listOfSavedFiles) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = file.OpenRead(); PlayerStatsData playerStatsData = null; try { // create object from file playerStatsData = (PlayerStatsData)bf.Deserialize(fs); if (playerStatsData != null) { // creating button GameObject buttonGO = Instantiate(loadPlayerButtonPR) as GameObject; // make panel a parent of new GameObject buttonGO.transform.SetParent(selectPlayerPanelRT); // positioning button buttonGO.transform.localPosition = new Vector3(20f, posY, 0); buttonGO.transform.localScale = new Vector3(1, 1, 1); // seting button label with player name buttonGO.GetComponentInChildren <Text> ().text = playerStatsData.PlayerName; // create references to the button (so far is a Game Object) Button button = buttonGO.GetComponent <Button> (); String fileName = file.Name; // add Action litenera to button button.onClick.AddListener(delegate { PlayerStats.playerStats.Load(fileName); PlayerStats.playerStats.Save(); ShowPanel(gameModePanel); }); } // very importent! // file need to be close(sharing error) fs.Close(); } catch (Exception ex) { Debug.LogError(file.Name + "File is corrupted"); Debug.LogError(ex.StackTrace); } // nex button get new position (45 lower) posY -= 45f; } }
public PlayerManager(List <Player> players, ServerConfig serverConfig) { allPlayersByName = players.ToDictionary(x => x.Name); currentPlayerId = (players.Count == 0) ? (ushort)0 : players.Max(x => x.Id); defaultPlayerStats = serverConfig.DefaultPlayerStats; this.serverConfig = serverConfig; }
public PlayerManager(List <Player> players, ServerConfig serverConfig) { allPlayersByName = new ThreadSafeDictionary <string, Player>(players.ToDictionary(x => x.Name), false); currentPlayerId = players.Count == 0 ? (ushort)0 : players.Max(x => x.Id); defaultPlayerStats = serverConfig.DefaultPlayerStats; this.serverConfig = serverConfig; }
protected void storeStats() { playerStatsCopy = new PlayerStatsData(); playerStatsCopy.calories = playerStats.calories; playerStatsCopy.health = playerStats.health; playerStatsCopy.lifes = playerStats.lifes; }
public static PlayerGameData CreateDataWithDefaultValues() { return(new PlayerGameData { Id = new Random().Next().ToString(), Stats = PlayerStatsData.CreateStatsWithDefaultValues(), InGamePurchases = InGamePurchasesData.CreatePurchasesWithDefaultValues() }); }
private void UpdateDisplay(int winnerID, PlayerStatsData psd) { statsText.text = string.Format( "{0}\n{1}\n{2}", psd.Fireballs, psd.Flaps, psd.Stomps); titleText.text = string.Format("Player {0} Wins", TextConstants.NUMBER_WORDS[winnerID]); }
private void SetPlayerStats(PlayerStatsData statsData) { if (statsData != null) { using (packetSender.Suppress <PlayerStats>()) { Player.main.oxygenMgr.AddOxygen(statsData.Oxygen); } } }
/// <summary> /// Validate and set player stats /// </summary> /// <param name="player"></param> /// <param name="data"></param> public void TrySetPlayerStats(Player player, PlayerStatsData data) { player.Name = data.PlayerName; player.ActiveHero = data.ActiveHero; Dictionary <string, UniqueBlock> uBlocks = BlockEffectsManager.UniqueBlocks; foreach (KeyValuePair <BlockTypes, UniqueBlockData> pair in data.UniqueBlockCollection.Level1Blocks) { if (pair.Value.Level != 1) { throw new NotSupportedException(); } if (player.UniqueBlockCollection.Collection.All(b => b.Name != pair.Value.Name)) { throw new NotSupportedException(); } player.UniqueBlockCollection.Level1Blocks[pair.Key] = uBlocks[pair.Value.Name]; } foreach (KeyValuePair <BlockTypes, UniqueBlockData> pair in data.UniqueBlockCollection.Level2Blocks) { if (pair.Value.Level != 2) { throw new NotSupportedException(); } if (player.UniqueBlockCollection.Collection.All(b => b.Name != pair.Value.Name)) { throw new NotSupportedException(); } player.UniqueBlockCollection.Level2Blocks[pair.Key] = uBlocks[pair.Value.Name]; } foreach (KeyValuePair <BlockTypes, UniqueBlockData> pair in data.UniqueBlockCollection.Level3Blocks) { if (pair.Value.Level != 3) { throw new NotSupportedException(); } if (player.UniqueBlockCollection.Collection.All(b => b.Name != pair.Value.Name)) { throw new NotSupportedException(); } player.UniqueBlockCollection.Level3Blocks[pair.Key] = uBlocks[pair.Value.Name]; } databaseManager.UpdatePlayer(player); databaseManager.UpdateCollection(player.UniqueBlockCollection); }
public PlayerGameData(IDataGetter dataGetter) { if (dataGetter == null) { throw new ArgumentNullException(nameof(dataGetter)); } Id = dataGetter.Id; Stats = new PlayerStatsData(dataGetter.Stats); InGamePurchases = new InGamePurchasesData(dataGetter.InGamePurchases); }
public InitialPlayerSync(string inventoryGuid, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, InitialPdaData pdaData, Vector3 playerSpawnData, PlayerStatsData playerStatsData) { InventoryGuid = inventoryGuid; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; PDAData = pdaData; PlayerSpawnData = playerSpawnData; PlayerStatsData = playerStatsData; }
// Save and load methods are called only by program (automaticly) // no need of user interaction public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + PlayerName + ".save", FileMode.OpenOrCreate); // create object to serilaize PlayerStatsData data = new PlayerStatsData(playerName, expirience, kills, deads); // serialize data and put it to file bf.Serialize(file, data); file.Close(); }
/// <summary> /// Load the specified fileName. /// </summary> /// <param name="fileName">File name.</param> public void Load(string fileName) { if (File.Exists(Application.persistentDataPath + "/" + fileName)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + fileName, FileMode.Open); PlayerStatsData data = (PlayerStatsData)bf.Deserialize(file); file.Close(); IntializeValueOfStats(data); } }
public PlayerManager(GameObject prefab, string name, int id, Material mat) { _prefab = prefab; _name = name; _id = id; _mat = mat; _state = new StateBools(); _state.Reset(); _stats = new PlayerStatsData(); _score = new PlayerScoreData(); Credits = 0; }
public InitialPlayerSync(string playerGuid, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, InitialPdaData pdaData, Vector3 playerSpawnData, Optional <string> playerSubRootGuid, PlayerStatsData playerStatsData, List <InitialRemotePlayerData> remotePlayerData) { PlayerGuid = playerGuid; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; PDAData = pdaData; PlayerSpawnData = playerSpawnData; PlayerSubRootGuid = playerSubRootGuid; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData; }
/// <summary> /// Loads the last save. From default persistent directory. /// Methods creates two object of type PlayerStatsData and compare lastSaveTime field. /// Object with the latest date is loaded to stats /// </summary> public void LoadLastSave() { PlayerStatsData currentData = null; PlayerStatsData tempData = null; listOfSavedFiles = GetListOfSavedFiles(); int compareResult; foreach (FileInfo file in listOfSavedFiles) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = file.OpenRead(); // If a file in directory not contents object of class TestObject then // deserialization of it will return Exeption, try { tempData = (PlayerStatsData)bf.Deserialize(fs); if (tempData != null) { if (currentData != null) { // compare which of data has latest lastSaveTime compareResult = currentData.LastSaveTime.CompareTo(tempData.LastSaveTime); if (compareResult <= 0) // currentData is later than tempData.LastSaveTime { currentData = tempData; } } else { currentData = tempData; } } } catch (Exception ex) { print(file.Name + " - File is corrupted"); print(ex.StackTrace); } fs.Close(); // if no current save then turn off the continue game button if (currentData != null) { IntializeValueOfStats(currentData); } else { Debug.Log("nie ma plikow do zaladowania"); //print ("nie ma plikow do zaladowania"); // MainMenuController.SetContinueGameButtonInteractable (false); } } }
public static PlayerStatsData LoadPlayerStats() { PlayerStatsData data = new PlayerStatsData(); if (File.Exists(Application.persistentDataPath + "/stats.hornes")) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = CreateFileStream("stats", FileMode.Open); data = bf.Deserialize(fs) as PlayerStatsData; fs.Close(); } return(data); }
public Player(ushort id, string name, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, List <EquippedItemData> equippedItems, List <EquippedItemData> modules) { Id = id; Name = name; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; this.equippedItems = equippedItems; this.modules = modules; }
/// <summary> /// Updates current stats with new /// </summary> /// <param name="data"></param> public void SetPlayerStats(PlayerStatsData data) { PlayerStats = new PlayerStats { PlayerName = data.PlayerName, ActiveHero = data.ActiveHero, Currency = data.Currency, Rating = data.Rating, Collection = data.UniqueBlockCollection.Collection.ToList(), Level1Blocks = data.UniqueBlockCollection.Level1Blocks, Level2Blocks = data.UniqueBlockCollection.Level2Blocks, Level3Blocks = data.UniqueBlockCollection.Level3Blocks, }; }
public static void SavePlayerStats(PlayerStats playerStats) { string path = Application.persistentDataPath + "/playerStats.knt"; BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Create); PlayerStatsData data = new PlayerStatsData(playerStats); formatter.Serialize(stream, data); stream.Close(); }
public void resetStats() { playerStatsCopy = new PlayerStatsData(); if (getPlayer() != null) { PlayerStats stats = getPlayerStats(); stats.calories = 0; stats.health = 0; stats.lifes = 0; } timeLeft = GameManager.instance.timeLimitMap; }
public InitialPlayerSync(NitroxId playerGameObjectId, bool firstTimeConnecting, IEnumerable <EscapePodModel> escapePodsData, NitroxId assignedEscapePodId, IEnumerable <EquippedItemData> equipment, IEnumerable <EquippedItemData> modules, IEnumerable <BasePiece> basePieces, IEnumerable <VehicleModel> vehicles, IEnumerable <ItemData> inventoryItems, IEnumerable <ItemData> storageSlotItems, IEnumerable <NitroxTechType> usedItems, IEnumerable <string> quickSlotsBinding, InitialPDAData pdaData, InitialStoryGoalData storyGoalData, HashSet <string> completedGoals, NitroxVector3 playerSpawnData, Optional <NitroxId> playerSubRootId, PlayerStatsData playerStatsData, IEnumerable <InitialRemotePlayerData> remotePlayerData, IEnumerable <Entity> globalRootEntities, IEnumerable <NitroxId> initialSimulationOwnerships, ServerGameMode gameMode, Perms perms) { EscapePodsData = escapePodsData.ToList(); AssignedEscapePodId = assignedEscapePodId; PlayerGameObjectId = playerGameObjectId; FirstTimeConnecting = firstTimeConnecting; EquippedItems = equipment.ToList(); Modules = modules.ToList(); BasePieces = basePieces.ToList(); Vehicles = vehicles.ToList(); InventoryItems = inventoryItems.ToList(); StorageSlotItems = storageSlotItems.ToList(); UsedItems = usedItems.ToList(); QuickSlotsBinding = quickSlotsBinding.ToList(); PDAData = pdaData; StoryGoalData = storyGoalData; CompletedGoals = completedGoals; PlayerSpawnData = playerSpawnData; PlayerSubRootId = playerSubRootId; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData.ToList(); GlobalRootEntities = globalRootEntities.ToList(); InitialSimulationOwnerships = initialSimulationOwnerships.ToList(); GameMode = gameMode; Permissions = perms; }
public InitialPlayerSync(string playerGuid, List <EscapePodModel> escapePodsData, string assignedEscapePodGuid, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, InitialPdaData pdaData, Vector3 playerSpawnData, Optional <string> playerSubRootGuid, PlayerStatsData playerStatsData, List <InitialRemotePlayerData> remotePlayerData, List <Entity> globalRootEntities) { EscapePodsData = escapePodsData; AssignedEscapePodGuid = assignedEscapePodGuid; PlayerGuid = playerGuid; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; PDAData = pdaData; PlayerSpawnData = playerSpawnData; PlayerSubRootGuid = playerSubRootGuid; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData; GlobalRootEntities = globalRootEntities; }
public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems); this.modules = new ThreadSafeCollection <EquippedItemData>(modules); }
public void LoadStats(PlayerStatsData data) { health = data.health; mana = data.mana; stamina = data.stamina; maxHealth = data.maxHealth; maxMana = data.maxMana; maxStamina = data.maxStamina; level = data.level; maxLevel = data.maxLevel; meleeDamage = data.meleeDamage; spellDamage = data.spellDamage; currentExperience = data.currentExperience; nextLevelExperience = data.nextLevelExperience; initialPosition = data.position; }
private void SetPlayerStats(PlayerStatsData statsData) { if (statsData != null) { Player.main.oxygenMgr.AddOxygen(statsData.Oxygen); Player.main.liveMixin.health = statsData.Health; Player.main.GetComponent <Survival>().food = statsData.Food; Player.main.GetComponent <Survival>().water = statsData.Water; Player.main.infectedMixin.SetInfectedAmount(statsData.InfectionAmount); //If InfectionAmount is at least 1f then the infection reveal should have happened already. //If InfectionAmount is below 1f then the reveal has not. if (statsData.InfectionAmount >= 1f) { Player.main.infectionRevealed = true; } } }
private void SetPlayerStats(PlayerStatsData statsData) { if (statsData != null) { using (packetSender.Suppress <PlayerStats>()) { Player.main.oxygenMgr.AddOxygen(statsData.Oxygen); Player.main.liveMixin.health = statsData.Health; Player.main.GetComponent <Survival>().food = statsData.Food; Player.main.GetComponent <Survival>().water = statsData.Water; Player.main.infectedMixin.SetInfectedAmount(statsData.InfectionAmount); if (statsData.InfectionAmount > 0f) { Player.main.infectionRevealed = true; } } } }
/// <summary> /// Player requests to get his info - collection, active hero.. /// </summary> /// <param name="clientID"></param> /// <param name="request"></param> public void ProcessGetPlayerStatsRequest(int clientID, GetPlayerStatsRequest request) { Player player = PlayersManager.GetPlayer(clientID); if (player == null) { Console.WriteLine($"Can't find player {clientID}"); return; } PlayerStatsData data = player.GetStatsData(); PlayerStatsResponse response = new PlayerStatsResponse { PlayerStats = data, }; Server.SendDataToClient(player.ClientID, (int)DataTypes.PlayerStatsResponse, response); }
public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, NitroxVector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; LastStoredPosition = null; LastStoredSubRootID = Optional.Empty; this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems); this.modules = new ThreadSafeCollection <EquippedItemData>(modules); visibleCells = new ThreadSafeCollection <AbsoluteEntityCell>(new HashSet <AbsoluteEntityCell>(), false); }
public InitialPlayerSync(string playerGuid, bool firstTimeConnecting, List <EscapePodModel> escapePodsData, string assignedEscapePodGuid, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, InitialPdaData pdaData, InitialStoryGoalData storyGoalData, Vector3 playerSpawnData, Optional <string> playerSubRootGuid, PlayerStatsData playerStatsData, List <InitialRemotePlayerData> remotePlayerData, List <Entity> globalRootEntities, string gameMode, Perms perms) { EscapePodsData = escapePodsData; AssignedEscapePodGuid = assignedEscapePodGuid; PlayerGuid = playerGuid; FirstTimeConnecting = firstTimeConnecting; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; PDAData = pdaData; StoryGoalData = storyGoalData; PlayerSpawnData = playerSpawnData; PlayerSubRootGuid = playerSubRootGuid; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData; GlobalRootEntities = globalRootEntities; GameMode = gameMode; Permissions = perms; }
public void LoadContent(PlayerStatsData initialStats) { this.characterID = initialStats.characterID; portraitTexture = GameClass.LoadTextureData(initialStats.portraitTextureFileName); this.level = initialStats.initialLevel; this.expToNext = level * 5; this.pointsToSpend = 0; hp = initialStats.initialHP; mp = initialStats.initialMP; atk = initialStats.initialATK; def = initialStats.initialDEF; mag_atk = initialStats.initialMAG_ATK; mag_def = initialStats.initialMAG_DEF; spd = initialStats.initialSPD; hpGrowth = initialStats.HPGrowth; mpGrowth = initialStats.MPGrowth; atkGrowth = initialStats.ATKGrowth; defGrowth = initialStats.DEFGrowth; mag_atkGrowth = initialStats.MAG_ATKGrowth; mag_defGrowth = initialStats.MAG_DEFGrowth; spdGrowth = initialStats.SPDGrowth; techniqueLevelData = initialStats.techniqueLevelData; }
public void LoadContent(PlayerStatsData growthStats, int level, int expToNext, int pointsToSpend, int HP, int MP, int ATK, int DEF, int MAG_ATK, int MAG_DEF, int SPD) { this.characterID = growthStats.characterID; portraitTexture = GameClass.LoadTextureData(growthStats.portraitTextureFileName); this.level = level; this.expToNext = expToNext; this.pointsToSpend = pointsToSpend; hp = HP; mp = MP; atk = ATK; def = DEF; mag_atk = MAG_ATK; mag_def = MAG_DEF; spd = SPD; hpGrowth = growthStats.HPGrowth; mpGrowth = growthStats.MPGrowth; atkGrowth = growthStats.ATKGrowth; defGrowth = growthStats.DEFGrowth; mag_atkGrowth = growthStats.MAG_ATKGrowth; mag_defGrowth = growthStats.MAG_DEFGrowth; spdGrowth = growthStats.SPDGrowth; techniqueLevelData = growthStats.techniqueLevelData; }