private static void OnInventoryChanged(string playFabId, string characterId, PfSharedControllerEx.Api eventSourceApi, bool requiresFullRefresh) { if (!requiresFullRefresh && (eventSourceApi & PfSharedControllerEx.Api.Client) == PfSharedControllerEx.Api.Client) { return; // Don't need to handle this event } if (string.IsNullOrEmpty(characterId)) { // Reload the user inventory GetUserInventory(); } else { // Reload the character inventory CharacterModel tempCharacter; if (!PfSharedModelEx.globalClientUser.clientCharacterModels.TryGetValue(characterId, out tempCharacter)) { return; } PfInvClientChar eachCharacter = tempCharacter as PfInvClientChar; if (eachCharacter == null || eachCharacter.inventory == null) { return; } eachCharacter.GetInventory(); } }
private static void OnUserCharactersLoaded(string playFabId, string characterId, PfSharedControllerEx.Api eventSourceApi, bool requiresFullRefresh) { GetUserInventory(); PfSharedModelEx.globalClientUser.clientCharacterModels.Clear(); for (int i = 0; i < PfSharedModelEx.globalClientUser.characterIds.Count; i++) { var newInv = new PfInvClientChar(PfSharedModelEx.globalClientUser.playFabId, PfSharedModelEx.globalClientUser.characterIds[i], PfSharedModelEx.globalClientUser.characterNames[i]); PfSharedModelEx.globalClientUser.clientCharacterModels[PfSharedModelEx.globalClientUser.characterIds[i]] = newInv; } }
public void UnlockContainerCallback(UnlockContainerItemResult unlockResult) { // Merge the items we bought with the items we know we have CharacterModel tempModel; if (PfSharedModelEx.globalClientUser.clientCharacterModels.TryGetValue(characterId, out tempModel)) { PfInvClientChar characterModel = tempModel as PfInvClientChar; if (characterModel != null) { characterModel.inventory.AddRange(unlockResult.GrantedItems); } } // Get the unlocked item before we remove it (we need info from it later) var unlockedItem = PfSharedModelEx.globalClientUser.GetClientItem(characterId, unlockResult.UnlockedItemInstanceId); if (unlockedItem != null && unlockedItem.RemainingUses > 0) { unlockedItem.RemainingUses -= 1; if (unlockedItem.RemainingUses <= 0) { PfSharedModelEx.globalClientUser.RemoveItems(characterId, new HashSet <string>() { unlockResult.UnlockedItemInstanceId }); } } if (tempModel != null) { tempModel.UpdateInvDisplay(); } bool needsFullRefresh = (unlockedItem == null); // If we couldn't find our unlocked item, we're stuck and we need a full refresh PfSharedControllerEx.PostEventMessage(PfSharedControllerEx.EventType.OnInventoryChanged, PfSharedModelEx.globalClientUser.playFabId, characterId, PfSharedControllerEx.Api.Client, needsFullRefresh); PfSharedControllerEx.PostEventMessage(PfSharedControllerEx.EventType.OnVcChanged, PfSharedModelEx.globalClientUser.playFabId, characterId, PfSharedControllerEx.Api.Client, true); // unlockResult contains no information about potential currency we may have gained }
public void PurchaseItemCallback(PurchaseItemResult purchaseResult) { string characterId = ((PurchaseItemRequest)purchaseResult.Request).CharacterId; // Merge the items we bought with the items we know we have CharacterModel tempModel; if (PfSharedModelEx.globalClientUser.clientCharacterModels.TryGetValue(characterId, out tempModel)) { PfInvClientChar characterModel = tempModel as PfInvClientChar; if (characterModel != null) { characterModel.inventory.AddRange(purchaseResult.Items); } tempModel.UpdateInvDisplay(); } string vcKey = ((PurchaseItemRequest)purchaseResult.Request).VirtualCurrency; int cost = ((PurchaseItemRequest)purchaseResult.Request).Price; PfSharedModelEx.globalClientUser.ModifyVcBalance(characterId, vcKey, -cost); PfSharedControllerEx.PostEventMessage(PfSharedControllerEx.EventType.OnInventoryChanged, PfSharedModelEx.globalClientUser.playFabId, characterId, PfSharedControllerEx.Api.Client, false); PfSharedControllerEx.PostEventMessage(PfSharedControllerEx.EventType.OnVcChanged, PfSharedModelEx.globalClientUser.playFabId, characterId, PfSharedControllerEx.Api.Client | PfSharedControllerEx.Api.Server, false); }
public override void OnExampleGUI(ref int rowIndex) { bool isLoggedIn = PlayFabClientAPI.IsClientLoggedIn(); bool charsValid = isLoggedIn && PfSharedModelEx.globalClientUser.clientCharacterModels.Count > 0; int colIndex; Button(isLoggedIn, rowIndex, 0, "Refresh User Inv", null, InventoryExample_GetUserInventory); TextField(isLoggedIn, rowIndex, 1, ref PfSharedModelEx.globalClientUser.userInvDisplay); rowIndex++; // Purchase Items TextField(isLoggedIn, rowIndex, 0, "Purchase User Item:"); if (PfSharedModelEx.clientCatalog != null) { colIndex = 1; foreach (var catalogPair in PfSharedModelEx.clientCatalog) { Button(isLoggedIn, rowIndex, colIndex++, catalogPair.Value.DisplayName, null, InventoryExample_PurchaseUserItem, catalogPair.Key, (uint)1); } } rowIndex++; // Consume Appropriate User Items TextField(isLoggedIn, rowIndex, 0, "Consume:"); if (PfSharedModelEx.globalClientUser.clientUserItems != null) { colIndex = 1; for (int i = 0; i < PfSharedModelEx.globalClientUser.clientUserItems.Count; i++) { if (PfSharedModelEx.consumableItemIds.Contains(PfSharedModelEx.globalClientUser.clientUserItems[i].ItemId)) { Button(isLoggedIn, rowIndex, colIndex++, PfSharedModelEx.globalClientUser.clientUserItems[i].DisplayName, null, InventoryExample_ConsumeUserItem, PfSharedModelEx.globalClientUser.clientUserItems[i].ItemInstanceId); } } } rowIndex++; // Open Appropriate User Containers TextField(isLoggedIn, rowIndex, 0, "Open:"); if (PfSharedModelEx.globalClientUser.clientUserItems != null) { colIndex = 1; for (int i = 0; i < PfSharedModelEx.globalClientUser.clientUserItems.Count; i++) { if (PfSharedModelEx.containerItemIds.Contains(PfSharedModelEx.globalClientUser.clientUserItems[i].ItemId)) { Button(isLoggedIn, rowIndex, colIndex++, PfSharedModelEx.globalClientUser.clientUserItems[i].DisplayName, null, InventoryExample_UnlockUserContainer, PfSharedModelEx.globalClientUser.clientUserItems[i].ItemId); } } } rowIndex++; rowIndex++; foreach (var charPair in PfSharedModelEx.globalClientUser.clientCharacterModels) { CharacterModel tempCharacter; if (!PfSharedModelEx.globalClientUser.clientCharacterModels.TryGetValue(charPair.Value.characterId, out tempCharacter)) { continue; } PfInvClientChar eachCharacter = tempCharacter as PfInvClientChar; if (eachCharacter == null || eachCharacter.inventory == null) { continue; } Button(charsValid, rowIndex, 0, "Refresh " + charPair.Value.characterName + " Inv", eachCharacter.GetInventory); TextField(charsValid, rowIndex, 1, eachCharacter.inventoryDisplay); rowIndex++; // Grant Char Items TextField(charsValid, rowIndex, 0, "Purchase " + charPair.Value.characterName + " Item:"); if (PfSharedModelEx.clientCatalog != null) { colIndex = 1; foreach (var catalogPair in PfSharedModelEx.clientCatalog) { Button(charsValid, rowIndex, colIndex++, catalogPair.Value.DisplayName, eachCharacter, PfInvClientChar_PurchaseCharacterItem, catalogPair.Key); } } rowIndex++; // Consume Appropriate Character Items TextField(charsValid, rowIndex, 0, "Consume:"); colIndex = 1; for (int i = 0; i < eachCharacter.inventory.Count; i++) { if (PfSharedModelEx.consumableItemIds.Contains(eachCharacter.inventory[i].ItemId)) { Button(charsValid, rowIndex, colIndex++, eachCharacter.inventory[i].DisplayName, eachCharacter, PfInvClientChar_ConsumeItem, eachCharacter.inventory[i].ItemInstanceId); } } rowIndex++; // Open Appropriate Character Containers TextField(charsValid, rowIndex, 0, "Open:"); colIndex = 1; for (int i = 0; i < eachCharacter.inventory.Count; i++) { if (PfSharedModelEx.containerItemIds.Contains(eachCharacter.inventory[i].ItemId)) { Button(charsValid, rowIndex, colIndex++, eachCharacter.inventory[i].DisplayName, eachCharacter, PfInvClientChar_UnlockContainer, eachCharacter.inventory[i].ItemId); } } rowIndex++; rowIndex++; } }