Skip to content

Commit

Permalink
Merge pull request #61 from Stuff-Mods/craftable
Browse files Browse the repository at this point in the history
merge: track craftable items
  • Loading branch information
DevilPepper authored May 16, 2021
2 parents 60bff47 + 384b7ec commit 117aa76
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Padding="0,0,10,0" />
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="75" />
<ColumnDefinition Width="125" />
</Grid.ColumnDefinitions>
</Grid>
<ContentControl Content="{Binding Path=., Converter={convert:InventoryToAmounts}}" />
Expand Down
30 changes: 27 additions & 3 deletions ItemBoxTracker/src/Plugin/Service/InventoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Threading;
using System.Threading.Tasks;
using HunterPie.Core;
using HunterPie.Core.Craft;
using HunterPie.Core.Definitions;
using MHWItemBoxTracker.Model;
using MHWItemBoxTracker.Utils;

Expand Down Expand Up @@ -69,12 +71,34 @@ public void Refresh() {
}
var ids = Data.Items.Select(i => i.Item.ItemId).ToHashSet();
var box = Context.Player.ItemBox?.FindItemsInBox(ids) ?? new();
var pouch = Context.Player.Inventory?.FindItemsAndAmmos(ids).ToDictionary(i => i.ItemId, i => i.Amount);
var pouch = Context.Player.Inventory?.FindItemsAndAmmos(ids)?.ToDictionary(i => i.ItemId, i => i.Amount) ?? new();
foreach (var item in Data.Items) {
box.TryGetValue(item.Item.ItemId, out int AmountInBox);
pouch.TryGetValue(item.Item.ItemId, out int AmountInPouch);
// TODO: Get this
int AmountCraftable = 0;

var recipes = Recipes.FindRecipes(item.Item.ItemId) ?? new();
var materials = recipes
.SelectMany(r => r.MaterialsNeeded)
.Select(m => m.ItemId)
.ToHashSet();

var pouchCraft = item.TrackPouch
? Context.Player.Inventory?.FindItemsAndAmmos(materials) ?? new sItem[0]
: new sItem[0];

var boxCraft = (item.TrackBox
? Context.Player.ItemBox?.FindItemsInBox(materials) ?? new()
: new())
.Select(
i => new sItem() {
ItemId = i.Key,
Amount = i.Value,
})
.ToArray();

int AmountCraftable = (item.TrackPouch ? recipes.Select(r => r.Calculate(pouchCraft)).Sum() : 0)
+ (item.TrackBox ? recipes.Select(r => r.Calculate(boxCraft)).Sum() : 0);

item.AmountInBox = item.TrackBox ? AmountInBox : 0;
item.AmountInPouch = item.TrackPouch ? AmountInPouch : 0;
item.AmountCraftable = item.TrackCraftable ? AmountCraftable : 0;
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ A plugin for hunter pie that lets players track the items they are farming.

Reducing cognitive overhead by allowing the player to stop looking at the box after every quest to find out that they still need 5 more tickets, 1 less than the last time they checked, and stop asking "how many did I need again?"

![Overlay](https://user-images.githubusercontent.com/5027713/118384904-3b74b600-b5d8-11eb-90d7-5b6794b67526.png)
![Overlay](https://user-images.githubusercontent.com/5027713/118386273-4df4ec80-b5e4-11eb-9a6b-7c1e4c2f9fa2.png)


> The numbers displayed are `pouch | box (+craftable) / wanted`
>
> Craftable items are counted from box items if **Track items in box** is enabled and from pouch if **Track items in pouch** is enabled. The number shown is their sum.
## Changelog

Expand Down

0 comments on commit 117aa76

Please sign in to comment.