// public void verify(){ // loginControllerScript.ShowSuccessfulLogin(); // } /// <summary> /// Function which is used to create a starting account in the database with default information and items /// </summary> /// <param name="verified"></param> /// <param name="username"></param> /// <param name="email"></param> private void PostToDatabase(bool verified = false, string username = null, string email = null) { UserData userData = new UserData(); Debug.Log("1"); if (verified) { userData.email = email; userData.localId = localId; userData.userName = username; userData.level = 1; userData.experience = 0; userData.maxExperience = 100; userData.hp = 100; userData.coin = 0; userData.verified = true; } Debug.Log("2"); //verify(); RestClient.Put(databaseURL + "/" + localId + ".json?auth=" + idToken, userData); Item item = new Item("Bronze Daggger", "Damage", 1, username); EquippedItems equippedItem = new EquippedItems(); equippedItem.weapon = item; InventoryDBHandler.PutEquippedItem(username, equippedItem); }
/// <summary> /// Triggers when user select which item to equip from the list of items in inventory. /// </summary> /// <param name="itemClicked">The button object that was clicked by the user.</param> public void onInBagItemClick(Button itemClicked) { bool toAppendItem = true; Item previousEquippedItem = this.equippedItems.weapon; Item item; // search for the item that is being clicked foreach (string key in this.inBagList.Keys) { item = this.inBagList[key]; if (item.name.Equals(itemClicked.name)) { // check if clicked item to be equipped is a weapon as can only equip weaponm not potions if (item.property.Equals(Item.WEAPON)) { Debug.Log("Equipping item..."); // update the newly equipped weapon to the UI this.equippedWeapon.GetComponent <Text>().text = item.name; // set Model of EquippedItems to the newly equipped item equippedItems.weapon = item; // remove item from the inventory since quantity of it becomes 0 after adding it to the item list // if (item.quantity - 1 == 0) // this.inBagList.Remove(key); // // reduce quantity of that equipped item from the inventory // else item.quantity -= 1; // found the item so don't need to continue to search break; } else { // can exit loop because only can equip weapons, not any of the potions. return; } } } // just incase there isn't anything if (previousEquippedItem != null) { // search item in inventory that contains the same item as the previously equipped item so can increase its quantity in the inventory foreach (string key in this.inBagList.Keys) { item = this.inBagList[key]; // check if found the inventory item to increase the quantity if (item.name.Equals(previousEquippedItem.name)) { // increment item's quantity by 1 since adding previous equipped item back into the inventory ++item.quantity; // since increased the quantity, no need to append the item to the inventory list toAppendItem = false; // can return since no more task break; } } // check if need to append item into the inventory list if (toAppendItem) { // append previous equipped item since inventory doesn't have that item this.inBagList.Add(userData.getName() + previousEquippedItem.name, previousEquippedItem); } } // update the UI in the list of items in the inventory this.populateInBagItems(); InventoryDBHandler.PutEquippedItem(userData.getName(), this.equippedItems); InventoryDBHandler.PutInventory(this.inBagList); }