public void UseItem() { Action <string> afterPickItem = (string item) => { Debug.Log("Using " + item); InventoryCategory obj; PF_PlayerData.characterInvByCategory.TryGetValue(item, out obj); if (obj != null) { var first = obj.inventory.FirstOrDefault(); if (first != null) { var attributes = PlayFab.Json.JsonWrapper.DeserializeObject <Dictionary <string, string> >(obj.catalogRef.CustomData); if (attributes.ContainsKey("modifies") && attributes.ContainsKey("modifyPercent") && attributes.ContainsKey("target")) { if (string.Equals(attributes["target"], "self")) { // item effect applies to the player string mod = attributes["modifies"]; float modPercent = float.Parse(attributes["modifyPercent"]); switch (mod) { case "HP": this.pendingValue = Mathf.CeilToInt((float)this.LifeBar.maxValue * modPercent); Debug.Log(string.Format("Player Heals {0}", this.pendingValue)); PF_PlayerData.activeCharacter.PlayerVitals.Health += this.pendingValue; RequestShake(defaultShakeTime, PF_GamePlay.ShakeEffects.IncreaseHealth); break; } gameplayController.DecrementPlayerCDs(); PF_GamePlay.ConsumeItem(first.ItemInstanceId); PF_GamePlay.QuestProgress.ItemsUsed++; } } } } }; DialogCanvasController.RequestInventoryPrompt(afterPickItem, DialogCanvasController.InventoryFilters.UsableInCombat, false, FloatingInventoryController.InventoryMode.Character); }
private void UseCombatItem(string item) { var JsonUtil = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); Debug.Log("Using " + item); InventoryCategory obj; if (!PF_PlayerData.inventoryByCategory.TryGetValue(item, out obj) || obj.count == 0) { return; } var attributes = JsonUtil.DeserializeObject <Dictionary <string, string> >(obj.catalogRef.CustomData); if (!attributes.ContainsKey("modifies") || !attributes.ContainsKey("modifyPercent") || !attributes.ContainsKey("target") || !string.Equals(attributes["target"], "self")) { return; } // item effect applies to the player var mod = attributes["modifies"]; var modPercent = float.Parse(attributes["modifyPercent"]); switch (mod) { case "HP": pendingValue = Mathf.CeilToInt(LifeBar.maxValue * modPercent); PF_PlayerData.activeCharacter.PlayerVitals.Health += pendingValue; RequestShake(defaultShakeTime, PF_GamePlay.ShakeEffects.IncreaseHealth); break; } gameplayController.DecrementPlayerCDs(); PF_GamePlay.ConsumeItem(obj.inventory[0].ItemInstanceId); PF_GamePlay.QuestProgress.ItemsUsed++; }