-
Notifications
You must be signed in to change notification settings - Fork 12
How to Use Items
All _gc
references in these examples are instances of a IGameController
More about crafting and inventory engine here
Let's say you have an item (InventoryItemBase of some sort) selected in your inventory UI, and user pressed USE.
You need to call the Inventory Controller:
var usageResult = _gc.Inventory.TryUse(item, checkOnly: false);
usageResult
contains ItemUseResult instance. You can check what happened with this item: Result (UsageResult enum) property.
- If Result is UsedSingle, then Count property of the item was decremented. See how WaterVesselItem and FoodItem are being used
- If Result is UsedAll, then item was removed from the inventory. See how WaterVesselItem and FoodItem are being used
- If Result is InsufficientResources, then nothing is happened because, for example, water flask is empty.
- If Result is Unapplicable, then you are trying to use item that cannot be used itself (for example, an empty syringe)
If checkOnly is true, then TryUse will not do anything with items, and will only simulate the usage.
How items marked with IInventoryInfiniteItem are treated
These items (for example, needle and thread) are not affected by TryUse, and always will return UsedSingle.
Any item that derives from WaterVesselItemBase is expected to be Count of 1
, because it contains N doses of liquid inside, and can be empty.
To fill your water vessel with water, call
flaskWithWater.FillUp(WorldTime.Value);
Every FillUp call causes the whole thing to become not safe (IsSafe=false)
To disinfect the water inside, call Disinfect
flaskWithWater.Disinfect(WorldTime.Value);
To boil (which also disinfects) the water inside, call Boil
flaskWithWater.Boil(WorldTime.Value);
You can always access last filling up, disinfecting and boiling times with LastFillTime, LastDisinfectTime and LastBoilTime properties.
TryUse will return InsufficientResources if DosesLeft is 0
.
When TryUse returns UsedSingle, then Count has not changed, but DosesLeft is now decremented.
When TryUse returns UsedAll, then Count has not changed, item remains in the inventory, but DosesLeft is now 0
.
Any item that derives from FoodItemBase is expected to be Count of 1
, because it is a container for the fresh and spoiled pieces.
To put new fresh piece of food into the item, call
var countOfPieces = 3;
foodItem.AddGatheringInfo(_gc.WorldTime.Value, countOfPieces);
This will add 3
pieces to the fresh group.\
To put new spoiled piece of food into the item, you need to call method above but passing time that is less than current game time minus MinutesUntilSpoiled minutes.
var countOfPieces = 2;
foodItem.AddGatheringInfo(_gc.WorldTime.Value.AddHours(-10), countOfPieces);
This will add 2
pieces to the spoiled group.
To get fresh food item of a particular type from the inventory, call
var freshMeat = _gc.Inventory.GetByName("Meat");
... where meat is the Name of your food item. You'll get the new instance of requested food item with Count=count of fresh pieces.
To get spoiled food item, call
var spoiledMeat = _gc.Inventory.GetByName($"Meat{FoodItemBase.SpoiledPostfix}");
You'll get the new instance of requested food item with Count=count of spoiled pieces.
Detailed info see here.
If you TryUse fresh item
Piece from a fresh group is taken, and fresh group pieces count inside this inventory item decremented.
For example, if we have Meat with 3 fresh pieces and 4 spoiled pieces, we will end up with the Meat item with 2 fresh pieces and 4 spoiled.
If fresh pieces count became 0
, UsedAll will be returned. Otherwise UsedSingle will be returned.
If fresh pieces count is 0
, then TryUse will try to use one piece from the spoiled group.
If you TryUse spoiled item
Piece from a spoiled group is taken, and spoiled group pieces count inside this inventory item decremented.
For example, if we have Meat with 3 fresh pieces and 4 spoiled pieces, we will end up with the Meat item with 3 fresh pieces and 3 spoiled.
If spoiled pieces count became 0
, UsedAll will be returned. Otherwise UsedSingle will be returned.
If spoiled pieces count is 0
, then InsufficientResources will be returned, even if this item has something in his fresh group.
If TryUse call with FoodlItemBase resulted in both spoiled and fresh groups to become 0
, TryUse will remove this item from the inventory.