-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from Stuff-Mods/refresh
MIsc. fixes
- Loading branch information
Showing
12 changed files
with
175 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using HunterPie.Core; | ||
using MHWItemBoxTracker.Utils; | ||
using MHWItemBoxTracker.Views; | ||
|
||
namespace MHWItemBoxTracker.Service { | ||
public class EventService { | ||
private Game Context; | ||
InventoryView GUI; | ||
InventoryService Inventory; | ||
public EventService(Game Context, InventoryView GUI, InventoryService Inventory) { | ||
this.Context = Context; | ||
this.GUI = GUI; | ||
this.Inventory = Inventory; | ||
} | ||
|
||
public void Subscribe() { | ||
var player = Context.Player; | ||
player.OnVillageEnter += Refresh; | ||
player.OnVillageLeave += Refresh; | ||
player.ItemBox.OnItemBoxUpdate += Refresh; | ||
player.Inventory.OnInventoryUpdate += Refresh; | ||
player.OnCharacterLogin += ShowWidget; | ||
player.OnCharacterLogout += HideWidget; | ||
// TODO: subscribe to save event? | ||
} | ||
|
||
public void Unsubscribe() { | ||
var player = Context.Player; | ||
player.OnVillageEnter -= Refresh; | ||
player.OnVillageLeave -= Refresh; | ||
player.ItemBox.OnItemBoxUpdate -= Refresh; | ||
player.Inventory.OnInventoryUpdate -= Refresh; | ||
player.OnCharacterLogin -= ShowWidget; | ||
player.OnCharacterLogout -= HideWidget; | ||
} | ||
|
||
public void Refresh(object source, EventArgs e) { | ||
Dispatcher.Dispatch(Inventory.Refresh); | ||
} | ||
public void ShowWidget(object source, EventArgs e) { | ||
Dispatcher.Dispatch(() => GUI.ShouldShow = true); | ||
} | ||
public void HideWidget(object source, EventArgs e) { | ||
Dispatcher.Dispatch(() => GUI.ShouldShow = false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using HunterPie.Core; | ||
using HunterPie.Core.Craft; | ||
using HunterPie.Core.Definitions; | ||
|
||
namespace MHWItemBoxTracker.Service { | ||
public class HunterPieService { | ||
private Game Context; | ||
public bool InHarvestZone { | ||
get => Context.Player.InHarvestZone; | ||
} | ||
public HunterPieService(Game Context) { | ||
this.Context = Context; | ||
} | ||
|
||
public Dictionary<int, int> FindItemsInBox(HashSet<int> ids) { | ||
return Context.Player.ItemBox?.FindItemsInBox(ids) ?? new(); | ||
} | ||
|
||
public Dictionary<int, int> FindItemsInPouch(HashSet<int> ids) { | ||
return Context.Player.Inventory?.FindItemsAndAmmos(ids)?.ToDictionary(i => i.ItemId, i => i.Amount) ?? new(); | ||
} | ||
|
||
public HashSet<int> GetMaterialsForRecipes(List<Recipe> recipes) { | ||
return recipes | ||
.SelectMany(r => r.MaterialsNeeded) | ||
.Select(m => m.ItemId) | ||
.ToHashSet(); | ||
} | ||
|
||
public int FindCraftableInBox(List<Recipe> recipeList) { | ||
return FindCraftable(recipeList, ids => SearchBox(ids)); | ||
} | ||
|
||
public int FindCraftableInPouch(List<Recipe> recipeList) { | ||
return FindCraftable(recipeList, ids => SearchPouch(ids)); | ||
} | ||
public Dictionary<int, List<Recipe>> FindRecipes(HashSet<int> ids) { | ||
return ids.ToDictionary(id => id, id => Recipes.FindRecipes(id) ?? new()); | ||
} | ||
|
||
private int FindCraftable(List<Recipe> recipeList, Func<HashSet<int>, sItem[]> FindItems) { | ||
var recipes = recipeList ?? new(); | ||
var ids = GetMaterialsForRecipes(recipes); | ||
var materials = FindItems(ids) ?? new sItem[0]; | ||
return recipes.Select(r => r.Calculate(materials)).Sum(); | ||
} | ||
|
||
private sItem[] SearchBox(HashSet<int> ids) { | ||
return (Context.Player.ItemBox?.FindItemsInBox(ids) ?? new()) | ||
.Select( | ||
i => new sItem() { | ||
ItemId = i.Key, | ||
Amount = i.Value, | ||
}) | ||
.ToArray(); | ||
} | ||
private sItem[] SearchPouch(HashSet<int> ids) { | ||
return Context.Player.Inventory?.FindItemsAndAmmos(ids); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters