public HouseChestItem GetChestItem(HouseChest chest, ProductTypeEnum productType, int quality) { return(chest .HouseChestItems .Where(item => item.ProductID == (int)productType && item.Quality == quality) .FirstOrDefault()); }
public int GetUnusedSpace(HouseChest chest) { int capacity = chest.Capacity; int itemCount = chest.GetItemCount(); return(capacity - itemCount); }
public bool HasItem(HouseChest chest, ProductTypeEnum productType, int quality, int quantity = 1) { var item = GetChestItem(chest, productType, quality); if (item == null) { return(false); } return(item.Quantity >= quantity); }
public EquipmentViewModel(HouseChest houseChest) { ItemCapacity = houseChest.Capacity; ItemCount = houseChest.GetItemCount(); var items = houseChest.HouseChestItems .OrderBy(i => i.ProductID) .ThenBy(i => i.Quality) .ToList(); foreach (var item in items) { Items.Add(new EquipmentItemViewModel(item)); } }
public void RemoveItem(HouseChest chest, ProductTypeEnum productType, int quality, int quantity = 1) { var item = GetChestItem(chest, productType, quality); item.Quantity -= quantity; if (item.Quantity < 0) { throw new Exception($"Quantity in chest({chest.FurnitureID}) is less than 0!"); } if (item.Quantity == 0) { houseChestItemRepository.Remove(item); } ConditionalSaveChanges(houseChestItemRepository); }
public void GiveItem(HouseChest chest, ProductTypeEnum productType, int quality, int quantity = 1) { var item = GetChestItem(chest, productType, quality); if (item != null) { item.Quantity += quantity; } else { item = new HouseChestItem() { ChestID = chest.FurnitureID, ProductID = (int)productType, Quality = quality, Quantity = quantity }; houseChestItemRepository.Add(item); } ConditionalSaveChanges(houseChestItemRepository); }
public void TransferItemToChest(Entity currentEntity, EquipmentItem item, HouseChest chest, int quantity) { equipmentService.RemoveProductsFromEquipment((ProductTypeEnum)item.ProductID, quantity, item.Quality, item.Equipment); GiveItem(chest, (ProductTypeEnum)item.ProductID, item.Quality, quantity); }
public MethodResult CanTransferItemToChest(Entity currentEntity, EquipmentItem item, HouseChest chest, int quantity) { if (currentEntity.EquipmentID != item.EquipmentID) { return(new MethodResult("You cannot transfer items from your chest to someone else!")); } if (item == null) { return(new MethodResult("Item does not exist!")); } if (quantity <= 0) { return(new MethodResult("You must transfer at least 1 item!")); } ProductTypeEnum productType = (ProductTypeEnum)item.ProductID; if (item.Amount < quantity) { return(new MethodResult($"You do not have enough {productType.ToHumanReadable().FirstUpper()} in chest!")); } if (GetUnusedSpace(chest) < quantity) { return(new MethodResult("You do not have enough space in chest!")); } return(MethodResult.Success); }
public HouseChestObject(HouseFurniture furniture) : base(furniture) { Capacity = furniture.HouseChest.Capacity; ChestEntity = furniture.HouseChest; }
public static int GetItemCount(this HouseChest chest) { return(chest.HouseChestItems .Sum(item => item.ProductID == (int)ProductTypeEnum.UpgradePoints ? 0 : item.Quantity)); }
public HouseChestViewModel(House house, Entities.Equipment citizenEquipment, HouseChest chest, HouseRights houseRights) { Info = new HouseInfoViewModel(house, houseRights); CitizenEquipment = new EquipmentViewModel(citizenEquipment); ChestEquipment = new EquipmentViewModel(chest); }