Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if items level requirement is met. #14

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WorkshopOptimizerPlugin/Optimizer/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class Item
public When When => whenOverrides[staticData.Id];
public Categories[] Categories => staticData.Categories;
public Materials[] Materials => staticData.Materials;
public int MinLevel => staticData.MinLevel;

// Dynamic Data
public Popularity Popularity => dynamicData.Popularity;
Expand Down Expand Up @@ -66,7 +67,7 @@ public List<SupplyDemandPattern> FindPatterns(int cycle)
{
return (null, patterns.Count > 0);
}

return (patterns[0], true);
}

Expand Down
15 changes: 7 additions & 8 deletions WorkshopOptimizerPlugin/Optimizer/Optimizer.cs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to expand the if below into two cases (Gaherables vs the rest), or else change it so that the function is something more like !IsMaterialLocked(material)

Then change to:
if ((options.Strictness & option) == 0 && (InventoryProvider.GetItemCount(material.Material) < material.Count || !IslandProvider.IsMaterialUnlocked(material.Material)))

(and have IsMaterialUnlocked return true for non-gatherables).

It I read it correctly, today it only excludes the item if it's locked and below count. (and always excluded non-gatherable items).

Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ private List<ItemSet> generateCombinationsRecursive(List<Item> items, int hours)
{
newItem
};
foreach (var itemset in generateCombinationsRecursive(newItems, newHours))
{
result.Add(itemset);
}
result.AddRange(generateCombinationsRecursive(newItems, newHours));
}
return result;
}
Expand All @@ -155,6 +152,7 @@ private bool checkItem(Item item)
{
static bool IsSet(Strictness a, Strictness b) => (a & b) != 0;

if (item.MinLevel > IslandProvider.GetIslandRank()) { return false; }
if (item.When == When.Never) { return false; }
if (!checkMaterials(item)) { return false; }
if (item.When is When.Always or When.Required) { return true; }
Expand All @@ -165,7 +163,8 @@ private bool checkItem(Item item)
if ((patterns.Count > 1) &&
(!IsSet(options.Strictness, Strictness.AllowMultiCycle) ||
(IsSet(options.Strictness, Strictness.UseMultiCycleLimit) &&
(item.Value > options.MultiCycleLimit)))) {
(item.Value > options.MultiCycleLimit))))
{
return false;
}

Expand All @@ -190,10 +189,10 @@ private bool checkMaterials(Item item)
{
if ((options.Strictness & (Strictness.AllowMissingCommonMaterials | Strictness.AllowMissingRareMaterials)) == (Strictness.AllowMissingCommonMaterials | Strictness.AllowMissingRareMaterials)) return true;

foreach(var material in item.Materials)
foreach (var material in item.Materials)
{
var option = (material.Material.Source == MaterialSource.Gatherable)? Strictness.AllowMissingCommonMaterials : Strictness.AllowMissingRareMaterials;
if ((options.Strictness & option) == 0 && InventoryProvider.GetItemCount(material.Material) <= 0)
var option = (material.Material.Source == MaterialSource.Gatherable) ? Strictness.AllowMissingCommonMaterials : Strictness.AllowMissingRareMaterials;
if ((options.Strictness & option) == 0 && InventoryProvider.GetItemCount(material.Material) < material.Count)
{
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions WorkshopOptimizerPlugin/Utils/IslandProvider.cs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just of curiosity for the intent. If they meet the minium level, and they can craft the tool, why exclude them? Can they just go craft the tool and then gather the items? (i.e.; shouldn't we suggest the best possible items they can get?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know if maybe any tool needs (time) gated materials. Just checked the wiki and it's not the case. So as soon as a level is reached the tools should be craftable. I guess with this information I can remove the whole IsGatherable and purely rely on the items MinLevel and just assume it unlocks the required tools with the workshop items.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FFXIVClientStructs.FFXIV.Client.Game.MJI;

namespace WorkshopOptimizerPlugin.Utils;

internal class IslandProvider
{
public static unsafe int GetIslandRank()
{
return MJIManager.Instance()->IslandState.CurrentRank;
}
}