public void OnSocketPlayerStatus(SocketIOEvent ev) { PlayerStatusData data = PlayerStatusData.FromJSONObject(ev.data); if (data.hp != null) { player.hp = (int)data.hp; } if (data.currentHp != null) { player.currentHp = (int)data.currentHp; if (data.currentHp <= 0) { encounter.EndEncounter(true); } } if (data.gold != null) { player.gold = (int)data.gold; } //set player location; if (data.x != 0 && data.y != 0) { Vector2Int playerWorldPosition = new Vector2Int((int)data.x, (int)data.y); player.SetWorldPosition(playerWorldPosition); map.Initialize(playerWorldPosition); SendMapRequest(playerWorldPosition); } }
void BuyBuff(ShopBuff item) { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); if (!item.HasReachedItemMax().Invoke()) { PlayErrorSound(); alertMessageManager.SetAlertMessage(itemMaxReachedMsg); return; } if (PlayerHasEnoughFundsToBuy(item.buffPrice)) { playerScore -= item.buffPrice; item.BuyItem().Invoke(); playerData.DecreaseScore(item.buffPrice); PlayerStatusService.SavePlayerStatus(playerData); LoadPlayerData(); item.DeselectObject(); selectedObjectManager.RemoveSelectedObject(); PlayBuySound(); } else { PlayErrorSound(); alertMessageManager.SetAlertMessage(notEnoughMoneyMsg); } }
private void onStatusChanged(PlayerStatusData playerStatusData, string questMascotName) { DataEntityHandle entityByComponent = dataEntityCollection.GetEntityByComponent(playerStatusData); if (dataEntityCollection.TryGetComponent <SessionIdData>(entityByComponent, out var sessionId)) { if (mascotNameToIconMap.TryGetValue(questMascotName, out var value)) { setStatusIcon(sessionId.SessionId, value); return; } SpriteContentKey questStatusIconContentKey = getQuestStatusIconContentKey(questMascotName); if (questStatusIconContentKey != null && !string.IsNullOrEmpty(questStatusIconContentKey.Key)) { Content.LoadAsync(delegate(string path, Sprite mascotIcon) { onMascotIconLoaded(questMascotName, mascotIcon, sessionId.SessionId); }, questStatusIconContentKey); } else { Log.LogError(this, "Mascot icon content key was null or empty"); } } else { Log.LogError(this, "Could not find a session id for this player status data"); } }
public void LoadOwnedShips(bool displayPriceTag) { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); GameObject[] ships = GetAllShipsFromPrefabList(); GameObject[] filteredList = ships.Where(x => playerData.GetOwnedShipsIDs().Contains(x.GetComponent <Ship>().shipId)).ToArray(); PlotShipsIntoCarousel(filteredList, displayPriceTag); }
public void DefineShip() { PlayerStatusData playerdata = PlayerStatusService.LoadPlayerStatus(); playerdata.SetSelectedShipId(selectedShip.GetId()); PlayerStatusService.SavePlayerStatus(playerdata); GameObject.Find("SceneManager").GetComponent <ScenesManager>().LoadNewGame(); }
void GenerateData() { statusData = Resources.Load("sex") as TextAsset; playerStatusData = JsonUtility.FromJson <PlayerStatusData>(statusData.ToString()); Debug.Log(playerStatusData.playerLevel); Debug.Log(playerStatusData.playerName); Debug.Log(playerStatusData.playerMaxHealth); Debug.Log(playerStatusData.playerCurrentHealth); }
public static void SavePlayerStatus(PlayerStatusData playerStatusData = null) { var appDataReader = new ApplicationDataReader <PlayerStatusData>(); if (playerStatusData == null) { playerStatusData = appDataReader.LoadData(playerDataFilePath); } appDataReader.SaveDataAsync(playerStatusData, playerDataFilePath); }
private bool onComponentRemoved(DataEntityEvents.ComponentRemovedEvent evt) { PlayerStatusData playerStatusData = evt.Component as PlayerStatusData; if (playerStatusData != null && dataEntityCollection.TryGetComponent <SessionIdData>(evt.Handle, out var component)) { hideStatusIcon(component.SessionId); } return(false); }
protected virtual object ReadPlayerStatus(byte playerIndex) { PlayerStatusData data = new PlayerStatusData(); data.playerIndex = (byte)((playerIndex & 0x0F) - 1); data.health = ReadByte(); data.mana = ReadByte(); data.status = ReadByte(); return(data); }
void DisableOwnedShips() { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); foreach (var shipInstance in shipsInstance) { //if player has already bought this ship, disable its button if (playerData.GetOwnedShipsIDs().Contains(shipInstance.GetComponent <Ship>().shipId)) { DisableShipButtonClick(shipInstance); } } }
protected GameObject LoadShipPrefab() { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); int selectedShipId = playerData.GetSelectedShipId(); if (selectedShipId == 0) { selectedShipId = 1; } return(Resources.Load <GameObject>("Prefabs/Ships/" + selectedShipId)); }
private void Start() { PlayerLifeManager playerLifeManager = GetComponent <PlayerLifeManager>(); PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); playerData.SwapStoredShields(); amountShields = playerData.GetShieldBuff(); int initialAmountShields = amountShields; PlayerStatusService.SavePlayerStatus(playerData); UpdateShieldText(); }
public void HideNotOwnedShips() { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); List <int> ownedShipsIDs = playerData.GetOwnedShipsIDs(); foreach (var shipInstance in shipsInstance) { //if player doesn't have a ship, remove it from the interface if (!ownedShipsIDs.Contains(shipInstance.GetComponent <Ship>().shipId)) { shipInstance.SetActive(false); } } }
static PlayerStatusData CreateInitialPlayerStatus(ApplicationDataReader <PlayerStatusData> appDataReader) { PlayerStatusData playerData = new PlayerStatusData(0, 1, 1); //player always owns the first ship by default playerData.GetOwnedShipsIDs().Add(1); playerData.IncreaseDashUpgrade(); appDataReader.SaveDataAsync(playerData, playerDataFilePath); SavePlayerStatus(playerData); return(playerData); }
void DisableOwnedShips(Ship[] instantiatedShips) { //player data in ShipCarousel instance has not been loaded yet, so we'll have to do it manually PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); foreach (var shipInstance in instantiatedShips) { //if player has already bought this ship, disable its button if (playerData.GetOwnedShipsIDs().Contains(shipInstance.GetId())) { shipInstance.DisableCharacterButton(); } } }
void LoadPlayerData() { PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); playerScore = playerData.GetScore(); scoreAmountTxt.text = playerScore.ToString(); SetTokensText(playerData.GetJackpotTokens()); SetLivesAmountText(playerData.GetLifeBuff(), playerData.GetLifeUpgrade()); SetShieldsAmountText(playerData.GetShieldBuff(), playerData.GetShieldUpgrade()); SetStoredLifesText(playerData.GetStoreLifePrizes()); SetStoredShieldsText(playerData.GetStoredShieldPrizes()); SetDashUpgradesText(playerData.GetDashUpgrade(), playerData.GetMaxDashUpgrade()); }
private void Awake() { mascotNameToIconMap = new Dictionary <string, Sprite>(); dataEntityCollection = Service.Get <CPDataEntityCollection>(); DataEntityHandle[] entitiesByType = dataEntityCollection.GetEntitiesByType <PlayerStatusData>(); if (entitiesByType.Length > 0) { for (int i = 0; i < entitiesByType.Length; i++) { PlayerStatusData component = dataEntityCollection.GetComponent <PlayerStatusData>(entitiesByType[i]); onPlayerStatusDataAdded(new DataEntityEvents.ComponentAddedEvent <PlayerStatusData>(entitiesByType[i], component)); } } dataEntityCollection.EventDispatcher.AddListener <DataEntityEvents.ComponentAddedEvent <PlayerStatusData> >(onPlayerStatusDataAdded); dataEntityCollection.EventDispatcher.AddListener <DataEntityEvents.ComponentRemovedEvent>(onComponentRemoved); PlayerNameController.OnPlayerNameAdded += onPlayerTagAdded; }
public static PlayerStatusData LoadPlayerStatus() { var appDataReader = new ApplicationDataReader <PlayerStatusData>(); if (!HasPlayerDataFile()) { PlayerStatusData playerData = CreateInitialPlayerStatus(appDataReader); _playerDataInstance = playerData; return(_playerDataInstance); } if (_playerDataInstance == null) { _playerDataInstance = appDataReader.LoadData(playerDataFilePath); } return(_playerDataInstance); }
private void LoadData() { Func <string, string> LoadDataToJson = ( string statusDataName ) => { string jsonData = null; Addressables.LoadAssetAsync <string>(statusDataName).Completed += json => { jsonData = json.Result; }; return(jsonData); }; weaponStatusData_ = JsonUtility.FromJson <WeaponStatusData>(LoadDataToJson("WeaponStatusData")); armorStatusData_ = JsonUtility.FromJson <ArmorStatusData>(LoadDataToJson("ArmorStatusData")); playerStatusData_ = JsonUtility.FromJson <PlayerStatusData>(LoadDataToJson("PlayerStatusData")); }
private void Start() { playerSpritesManager = GetComponent <PlayerSpritesManager>(); PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); maxLifes = playerData.GetLifeUpgrade(); playerData.SwapStoredLivesToBuff(); lives += playerData.GetLifeBuff(); UpdateLifeText(); canBeHit = true; PlayerStatusService.SavePlayerStatus(playerData); hitAudioSource.clip.LoadAudioData(); }
private void Start() { playerData = PlayerStatusService.LoadPlayerStatus(); priceTag.text = string.Format("{0}", shipPrice); ui_shipDescription = GameObject.Find("SelectedItemDescription").GetComponent <Text>(); var selectedObjectManager = GameObject.Find("SelectedObjectManager").GetComponent <SelectedObjectManager>(); shipButton = this.transform.Find("ShipButton"); var cmp = shipButton.gameObject.GetComponentInChildren <Image>(); cmp.sprite = shipImage; //set listener when clicking to select object shipButton.GetComponent <Button>().onClick.AddListener(() => selectedObjectManager.SetSelectedObject(this)); originalColor = shipButton.GetComponent <Image>().color; }
static void SaveData(string appDataPath, PlayerStatusData playerStatusData = null) { BinaryFormatter bf = new BinaryFormatter(); //Load currentScore with previously saved score FileStream fileStream = File.Open(appDataPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); if (playerStatusData == null) { bf.Serialize(fileStream, _playerDataInstance); } else { _playerDataInstance = playerStatusData; bf.Serialize(fileStream, playerStatusData); } fileStream.Close(); }
public void DecreaseLife() { if (canBeHit) { hitAudioSource.Play(); lives--; PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); //Game Over if (lives <= 0) { SetDummyDeadPlayer(); gameOverManager.TakeScreenShot(); //Stop the score count scoreCounterManager.enabled = false; //Save player stats playerData.SetLifeBuff(0); int finalScore = scoreCounterManager.FinishAndGetFinalScore(); playerData.IncreaseScore(finalScore); PlayerStatusService.SavePlayerStatus(playerData); gameOverManager.SetGameOver(finalScore); DisablePlayer(); UpdateLifeText(); } else { //buffs means extra lives, so we reduce one from total amount of lives the player has playerData.SetLifeBuff(lives - 1); PlayerStatusService.SavePlayerStatus(playerData); UpdateLifeText(); //Make player invulnerable for few seconds SetPlayerInvulnerable(); } } }
private void Start() { notEnoughTokensMsg = "Not enough tokens!"; spritesForResult = new List <Sprite>(); playerData = PlayerStatusService.LoadPlayerStatus(); tokenAmountTxt.text = playerData.GetJackpotTokens().ToString(); imageQueue = new Queue <Image>(); var _spritesForResult = Resources.LoadAll <Sprite>("Sprites/Jackpot/RollingImages"); foreach (var item in _spritesForResult) { spritesForResult.Add(item); } maxValue = (short)(spritesForResult.Count - 1); LoadTextsLanguage(); }
void BuyShip(IShopItem selectedShip) { //Player has enough money? if (!PlayerHasEnoughFundsToBuy(selectedShip.GetPrice())) { PlayErrorSound(); alertMessageManager.SetAlertMessage(notEnoughMoneyMsg); return; } PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); //Player already bought this ship? if (!((IShopCharacterSkin)selectedShip).AlreadyHasShip().Invoke()) { playerScore -= selectedShip.GetPrice(); scoreAmountTxt.text = playerScore.ToString(); selectedShip.BuyItem().Invoke(); PlayerStatusService.SavePlayerStatus(playerData); ((IShopCharacterSkin)selectedShip).DisableCharacterButton(); //Clear data //remove from selectedobjectmanager selectedObjectManager.RemoveSelectedObject(); selectedShip = null; PlayBuySound(); } else { PlayErrorSound(); alertMessageManager.SetAlertMessage(subAlreadyBoughtMsg); } }
void GetShieldPrize(bool bestPrize, PlayerStatusData playerData, int prizeNum) { resultMsgTxt.text = shieldItem; if (bestPrize) { resultMsgTxt.text = string.Format("+3 {0}", shieldItem); for (int i = 0; i < 3; i++) { if (playerData.CanIncreaseShieldBuff()) { playerData.IncreaseShieldBuff(1); } else { resultMsgTxt.text = string.Format("+3 {0}", stockedShieldMsg); playerData.IncreaseShielStock(1); } } } else { if (playerData.CanIncreaseShieldBuff()) { playerData.IncreaseShieldBuff(1); } else { resultMsgTxt.text = string.Format("+1 {0}", stockedShieldMsg); playerData.IncreaseShielStock(1); } } resultPanelPrizeImg.sprite = spritesForResult[prizeNum]; }
bool GetPrizeObject(int prizeNum, bool bestPrize) { bool hasPrize = false; PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus(); switch (prizeNum) { case 1: //Life Buff GetLifePrize(bestPrize, playerData, prizeNum); hasPrize = true; break; case 2: //Extra Credits XXX resultPanelPrizeImg.sprite = spritesForResult[prizeNum]; if (bestPrize) { resultMsgTxt.text = string.Format("+300 {0}", creditsItem); playerData.IncreaseScore(300); } else { resultMsgTxt.text = string.Format("+50 {0}", creditsItem); playerData.IncreaseScore(50); } hasPrize = true; break; case 3: //Dash Upgrade if (bestPrize && playerData.CanUpgradeDash()) { playerData.IncreaseDashUpgrade(); resultMsgTxt.text = dashUpgradeItem; resultPanelPrizeImg.sprite = spritesForResult[prizeNum]; hasPrize = true; } else { resultMsgTxt.text = twoPointsDashWarningJackPot; } break; case 4: //New Skin if (bestPrize) { resultMsgTxt.text = skinItem; resultPanelPrizeImg.sprite = skinPrize; playerData.GetOwnedShipsIDs().Add(skinPrizeId); hasPrize = true; } else { resultMsgTxt.text = twoPointsSkinsWarningJackPot; } break; } PlayerStatusService.SavePlayerStatus(playerData); return(hasPrize); }
protected virtual object ReadPlayerStatus(byte playerIndex) { PlayerStatusData data = new PlayerStatusData(); data.playerIndex = (byte)((playerIndex&0x0F) - 1); data.health = ReadByte(); data.mana = ReadByte(); data.status = ReadByte(); return data; }