public static async Task<bool> EquipHarvestTool(Actor harvestable)
{
var harvestType = harvestable.RequiredTradeskill;
// Only these 3 need specific harvesting types.
if (harvestType != Tradeskill.Mining && harvestType != Tradeskill.RelicHunter && harvestType != Tradeskill.Survivalist)
return true;
// Check if we already have the required tool equipped.
var currentlyEquipped = GameManager.Inventory.Equipped.Items.FirstOrDefault(i => i.EquipSlot == ItemSlot.WeaponTool);
if (currentlyEquipped != null && currentlyEquipped.Info.Tradeskill == harvestable.RequiredTradeskill)
{
// The item is already equipped. TODO: Should we check for upgrades to the harvestable tool?
return true;
}
// Do we have any tools that can actually be used?
var tools = GameManager.Inventory.Bags.Items.Where(i => i.EquipSlot == ItemSlot.WeaponTool && i.Info.Tradeskill == harvestType).ToList();
if (tools.Count == 0)
return false;
// Shortcut the ordering logic if we only have 1.
// This may cause issues with trying to equip a higher level tool than we can actually use, but that's on the user.
if (tools.Count == 1)
{
return tools[0].Equip() == GenericError.Ok;
}
// Order by their tradeskill tier requirement (highest first, since we want to use the "best" available tool)
tools = tools.OrderByDescending(i => i.Info.GetTradeskillTierRequirement()).ToList();
// Equip the "best" tool we can use for our current tradeskill tier.
// Grab the current tier of the tradeskill. Note: The FirstOrDefault will return an empty structure if we don't have a tradeskill requested.
// This means IsActive == false. So USE that. (Also check "Tier" for sanity)
var currentTier = GameManager.CurrentTradeskills.FirstOrDefault(ts => ts.Tradeskill == harvestType);
if (currentTier.IsActive && currentTier.Tier > 0)
{
// Check the tools list for the first tool we can actually use (just by it's tier... TODO: check tool level requirement)
var bestTool = tools.FirstOrDefault(tool => tool.Info.GetTradeskillTierRequirement() <= currentTier.Tier);
return bestTool?.Equip() == GenericError.Ok;
}
return false;
}