/// <summary> /// Remove an item from the player inventory /// </summary> /// <param name="id">Id of the item to remove</param> public Constants RemoveItemFromInventory(int id) { //Verification que l'item existe dans la liste complete & dans l'inventaire if (!ExistingItemsList.Exists(i => i.Id == id) || !Inventory.Exists(i => i.Id == id)) { return(Constants.NotFound); } //S'il n'y en as qu'un on le supprime if (Inventory.Find(i => i.Id == id).Quantity == 1) { Inventory.RemoveAll(i => i.Id == id); } //Sinon on le diminue de un else { Inventory.Find(i => i.Id == id).Quantity -= 1; } return(Constants.Removed); }
/// <summary> /// Add an item to the player inventory /// </summary> /// <param name="id">Id of the item to add</param> public Constants AddItemToInventory(int id) { //Verification que l'item existe dans la liste complete if (!ExistingItemsList.Exists(i => i.Id == id)) { return(Constants.NotFound); } //Si on en as pas encore, on l'ajoute if (!Inventory.Exists(i => i.Id == id)) { var item = ExistingItemsList.Find(i => i.Id == id); Inventory.Add(item); } //s'il existe on incremente la quantite else { Inventory.Find(i => i.Id == id).Quantity += 1; } return(Constants.Added); }