private static void OnUserCharactersLoaded(string playFabId, string characterId, PfSharedControllerEx.Api eventSourceApi, bool requiresFullRefresh) { UserModel updatedUser; if (!PfSharedModelEx.serverUsers.TryGetValue(playFabId, out updatedUser)) return; updatedUser.serverCharacterModels.Clear(); for (int i = 0; i < updatedUser.characterIds.Count; i++) { var newCharInv = new PfInvServerChar(playFabId, updatedUser.characterIds[i], updatedUser.characterNames[i]); updatedUser.serverCharacterModels[updatedUser.characterIds[i]] = newCharInv; } }
public override void OnExampleGUI(ref int rowIndex) { bool isLoggedIn = PlayFabClientAPI.IsClientLoggedIn(); foreach (var userPair in PfSharedModelEx.serverUsers) { bool charsValid = isLoggedIn && userPair.Value.serverCharacterModels.Count > 0; int colIndex, temp; // User Owned Currency Button(isLoggedIn, rowIndex, 0, "Refresh User VC:", null, VirtualCurrencyExample_GetUserVc, userPair.Key); colIndex = 1; foreach (var vcKey in PfSharedModelEx.virutalCurrencyTypes) { userPair.Value.userVC.TryGetValue(vcKey, out temp); CounterField(isLoggedIn, rowIndex, colIndex++, vcKey + "=" + temp, VirtualCurrencyExample_AddUserVirtualCurrency, VirtualCurrencyExample_SubtractUserVirtualCurrency, userPair.Key, vcKey, 1); } rowIndex++; rowIndex++; foreach (var charPair in userPair.Value.serverCharacterModels) { PfInvServerChar eachCharacter = charPair.Value as PfInvServerChar; if (eachCharacter == null || eachCharacter.characterVC == null) { continue; } // User Owned Currency Button(charsValid, rowIndex, 0, "Refresh " + eachCharacter.characterName + " VC:", null, VirtualCurrencyExample_GetCharacterVc, userPair.Key, eachCharacter.characterId); colIndex = 1; foreach (var vcKey in PfSharedModelEx.virutalCurrencyTypes) { eachCharacter.characterVC.TryGetValue(vcKey, out temp); CounterField(charsValid, rowIndex, colIndex++, vcKey + "=" + temp, VirtualCurrencyExample_AddCharacterVirtualCurrency, VirtualCurrencyExample_SubtractCharacterVirtualCurrency, userPair.Key, eachCharacter.characterId, vcKey, 1); } rowIndex++; rowIndex++; } } }
private static void OnInventoryChanged(string playFabId, string characterId, PfSharedControllerEx.Api eventSourceApi, bool requiresFullRefresh) { if (!requiresFullRefresh && (eventSourceApi & PfSharedControllerEx.Api.Server) == PfSharedControllerEx.Api.Server) { return; // Don't need to handle this event } UserModel updatedUser; CharacterModel tempCharacter; if (!PfSharedModelEx.serverUsers.TryGetValue(playFabId, out updatedUser)) { return; } if (string.IsNullOrEmpty(characterId)) { // Reload the user inventory GetUserInventory(playFabId); } else { // Reload the character inventory if (!updatedUser.serverCharacterModels.TryGetValue(characterId, out tempCharacter)) { return; } PfInvServerChar eachCharacter = tempCharacter as PfInvServerChar; if (eachCharacter == null || eachCharacter.inventory == null) { return; } eachCharacter.GetInventory(); } }
public override void OnExampleGUI(ref int rowIndex) { bool isLoggedIn = PlayFabClientAPI.IsClientLoggedIn(); foreach (var userPair in PfSharedModelEx.serverUsers) { bool charsValid = isLoggedIn && userPair.Value.serverCharacterModels.Count > 0; int colIndex; Button(isLoggedIn, rowIndex, 0, "Refresh User Inv", null, InventoryExample_GetUserInventory, userPair.Key); TextField(isLoggedIn, rowIndex, 1, ref userPair.Value.userInvDisplay); rowIndex++; // Purchase Items TextField(isLoggedIn, rowIndex, 0, "Grant User Item:"); if (PfSharedModelEx.serverCatalog != null) { colIndex = 1; foreach (var catalogPair in PfSharedModelEx.serverCatalog) { Button(isLoggedIn, rowIndex, colIndex++, catalogPair.Value.DisplayName, null, InventoryExample_GrantUserItem, userPair.Key, catalogPair.Key); } } rowIndex++; // Move User Items to characters foreach (var charPair in userPair.Value.serverCharacterModels) { PfInvServerChar eachCharacter = charPair.Value as PfInvServerChar; if (eachCharacter == null || eachCharacter.inventory == null) { continue; } TextField(eachCharacter != null, rowIndex, 0, "Move to " + eachCharacter.characterName + ":"); for (int i = 0; i < userPair.Value.serverUserItems.Count; i++) { Button(eachCharacter != null, rowIndex, i + 1, userPair.Value.serverUserItems[i].DisplayName, eachCharacter, PfInvServerChar_MoveToCharFromUser, userPair.Value.serverUserItems[i].ItemInstanceId); } rowIndex++; } // Revoke User Items TextField(isLoggedIn, rowIndex, 0, "Revoke:"); if (userPair.Value.serverUserItems != null) { for (int i = 0; i < userPair.Value.serverUserItems.Count; i++) { Button(isLoggedIn, rowIndex, i + 1, userPair.Value.serverUserItems[i].DisplayName, null, InventoryExample_RevokeUserItem, userPair.Key, userPair.Value.serverUserItems[i].ItemInstanceId); } } rowIndex++; rowIndex++; foreach (var charPair in userPair.Value.serverCharacterModels) { PfInvServerChar eachCharacter = charPair.Value as PfInvServerChar; if (eachCharacter == null || eachCharacter.inventory == null) { continue; } Button(charsValid, rowIndex, 0, "Refresh " + eachCharacter.characterName + " Inv", eachCharacter.GetInventory); TextField(charsValid, rowIndex, 1, eachCharacter.inventoryDisplay); rowIndex++; // Grant Char Items TextField(charsValid, rowIndex, 0, "Grant " + eachCharacter.characterName + " Item:"); if (PfSharedModelEx.serverCatalog != null) { colIndex = 1; foreach (var catalogPair in PfSharedModelEx.serverCatalog) { Button(charsValid, rowIndex, colIndex++, catalogPair.Value.DisplayName, eachCharacter, PfInvServerChar_GrantCharacterItem, catalogPair.Key); } } rowIndex++; // Move Character Items to User TextField(charsValid, rowIndex, 0, "Move to User:"******"Revoke:"); for (int i = 0; i < eachCharacter.inventory.Count; i++) { Button(charsValid, rowIndex, i + 1, eachCharacter.inventory[i].DisplayName, eachCharacter, PfInvServerChar_RevokeItem, eachCharacter.inventory[i].ItemInstanceId); } rowIndex++; rowIndex++; } } }