private CombinationSpecialActionResult ProcessDisinfectWaterAction(ItemsCombination combination) { var cmbWater = combination.ItemsNeeded.FirstOrDefault(y => y.ItemType.IsSubclassOf(typeof(WaterVesselItemBase))); var cmbPellets = combination.ItemsNeeded.FirstOrDefault(y => y.ItemType.Name == typeof(DisinfectingPellets).Name); if (cmbWater == null || cmbPellets == null) { return(NoChanges()); } var invWater = (WaterVesselItemBase)_gc.Inventory.Items.FirstOrDefault(x => x.GetType().Name == cmbWater.ItemType.Name); var invPellets = (DisinfectingPellets)_gc.Inventory.Items.FirstOrDefault(x => x.GetType().Name == cmbPellets.ItemType.Name); if (invWater == null || invPellets == null) { return(NoChanges()); } if (invPellets.Count <= 0) { return(InsufficientResources()); } if (invWater.IsSafe) { return(NoChanges()); } invWater.Disinfect(_gc.WorldTime.Value); var wasteInfo = _gc.Inventory.WasteItem(invPellets, 1, checkOnly: false); return(Applied(wasteInfo)); }
public CombinationSpecialActionResult ProcessAction(ItemsCombination combination) { if (combination.SpecialAction == ItemsCombination.SpecialActions.DisinfectWater) { return(ProcessDisinfectWaterAction(combination)); } return(new CombinationSpecialActionResult { WasteInfo = null, IsAllowed = false, IsNoChanges = true }); }
private bool ProcessSpecialAction(ItemsCombination combination) { return(_combinationActionProcessor.ProcessAction(combination).IsAllowed); }
private InventoryCombinatoryResult CheckCombinationForResourcesAvailability(ItemsCombination combination) { if (combination != null) { // Special check for special actions if (combination.SpecialAction != ItemsCombination.SpecialActions.None) { var invItems = combination.ItemsNeeded.Select(item => Items.FirstOrDefault(x => x.GetType().Name == item.ItemType.Name)).ToList(); var result = combination.CheckForActionAvailability.Invoke(invItems); if (result.Result != InventoryCombinatoryResult.CombinatoryResult.Allowed) { return(result); } } // Validate combination via validation function if (combination.GetIsValidCombination != null) { var invItems = combination.ItemsNeeded.Select(item => Items.FirstOrDefault(x => x.GetType().Name == item.ItemType.Name)).ToList(); var validationResult = combination.GetIsValidCombination(invItems, _gc); if (validationResult.Result != InventoryCombinatoryResult.CombinatoryResult.Allowed) { return(validationResult); } } // Let's check if we have resources for this foreach (var item in combination.ItemsNeeded) { var invItem = Items.FirstOrDefault(x => x.GetType().Name == item.ItemType.Name); if (invItem != null) { var wasteInfo = WasteItem(invItem, item.Count, checkOnly: true); if (wasteInfo.Result == WasteCheckInfo.WasteResult.InsufficientResources) { return new InventoryCombinatoryResult { Result = InventoryCombinatoryResult.CombinatoryResult.InsufficientResources, ResultedItem = null, ResourcesWasteInfo = combination.ItemsNeeded } } ; } else { // We don't even have this item return(new InventoryCombinatoryResult { Result = InventoryCombinatoryResult.CombinatoryResult.InsufficientResources, ResultedItem = null, ResourcesWasteInfo = combination.ItemsNeeded }); } } } else { return(new InventoryCombinatoryResult { Result = InventoryCombinatoryResult.CombinatoryResult.CombinationDoesNotExist }); } return(new InventoryCombinatoryResult { Result = InventoryCombinatoryResult.CombinatoryResult.Allowed, ResourcesWasteInfo = combination.ItemsNeeded }); }