Update collectable logic for items above your level/low collectability increase

This commit is contained in:
Liza 2024-08-18 00:41:58 +02:00
parent a11dd11424
commit 8a011bb1f4
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
@ -25,7 +26,10 @@ internal sealed class DoGatherCollectable(
private bool _revisitTriggered; private bool _revisitTriggered;
private Queue<EAction>? _actionQueue; private Queue<EAction>? _actionQueue;
public ITask With(GatheringController.GatheringRequest currentRequest, GatheringNode currentNode, bool revisitRequired) private bool? _expectedScrutiny;
public ITask With(GatheringController.GatheringRequest currentRequest, GatheringNode currentNode,
bool revisitRequired)
{ {
_currentRequest = currentRequest; _currentRequest = currentRequest;
_currentNode = currentNode; _currentNode = currentNode;
@ -71,10 +75,27 @@ internal sealed class DoGatherCollectable(
if (nodeCondition == null) if (nodeCondition == null)
return ETaskResult.TaskComplete; return ETaskResult.TaskComplete;
if (_expectedScrutiny != null)
{
if (nodeCondition.ScrutinyActive != _expectedScrutiny)
return ETaskResult.StillRunning;
// continue on next frame
_expectedScrutiny = null;
return ETaskResult.StillRunning;
}
if (_actionQueue != null && _actionQueue.TryPeek(out EAction nextAction)) if (_actionQueue != null && _actionQueue.TryPeek(out EAction nextAction))
{ {
if (gameFunctions.UseAction(nextAction)) if (gameFunctions.UseAction(nextAction))
{ {
_expectedScrutiny = nextAction switch
{
EAction.ScrutinyMiner or EAction.ScrutinyBotanist => true,
EAction.ScourMiner or EAction.ScourBotanist or EAction.MeticulousMiner
or EAction.MeticulousBotanist => false,
_ => null
};
logger.LogInformation("Used action {Action} on node", nextAction); logger.LogInformation("Used action {Action} on node", nextAction);
_actionQueue.Dequeue(); _actionQueue.Dequeue();
} }
@ -108,7 +129,7 @@ internal sealed class DoGatherCollectable(
MaxCollectability: atkValues[14].UInt, MaxCollectability: atkValues[14].UInt,
CurrentIntegrity: atkValues[62].UInt, CurrentIntegrity: atkValues[62].UInt,
MaxIntegrity: atkValues[63].UInt, MaxIntegrity: atkValues[63].UInt,
ScrutinyActive: atkValues[80].Bool, ScrutinyActive: atkValues[54].Bool,
CollectabilityFromScour: atkValues[48].UInt, CollectabilityFromScour: atkValues[48].UInt,
CollectabilityFromMeticulous: atkValues[51].UInt CollectabilityFromMeticulous: atkValues[51].UInt
); );
@ -120,17 +141,25 @@ internal sealed class DoGatherCollectable(
private Queue<EAction> GetNextActions(NodeCondition nodeCondition) private Queue<EAction> GetNextActions(NodeCondition nodeCondition)
{ {
uint gp = clientState.LocalPlayer!.CurrentGp; uint gp = clientState.LocalPlayer!.CurrentGp;
logger.LogTrace(
"Getting next actions (with {GP} GP, {MeticulousCollectability}~ meticulous, {ScourCollectability}~ scour)",
gp, nodeCondition.CollectabilityFromMeticulous, nodeCondition.CollectabilityFromScour);
Queue<EAction> actions = new(); Queue<EAction> actions = new();
uint neededCollectability = nodeCondition.CollectabilityToGoal(_currentRequest.Collectability); uint neededCollectability = nodeCondition.CollectabilityToGoal(_currentRequest.Collectability);
if (neededCollectability <= nodeCondition.CollectabilityFromMeticulous) if (neededCollectability <= nodeCondition.CollectabilityFromMeticulous)
{ {
logger.LogTrace("Can get all needed {NeededCollectability} from {Collectability}~ meticulous",
neededCollectability, nodeCondition.CollectabilityFromMeticulous);
actions.Enqueue(PickAction(EAction.MeticulousMiner, EAction.MeticulousBotanist)); actions.Enqueue(PickAction(EAction.MeticulousMiner, EAction.MeticulousBotanist));
return actions; return actions;
} }
if (neededCollectability <= nodeCondition.CollectabilityFromScour) if (neededCollectability <= nodeCondition.CollectabilityFromScour)
{ {
logger.LogTrace("Can get all needed {NeededCollectability} from {Collectability}~ scour",
neededCollectability, nodeCondition.CollectabilityFromScour);
actions.Enqueue(PickAction(EAction.ScourMiner, EAction.ScourBotanist)); actions.Enqueue(PickAction(EAction.ScourMiner, EAction.ScourBotanist));
return actions; return actions;
} }
@ -138,17 +167,23 @@ internal sealed class DoGatherCollectable(
// neither action directly solves our problem // neither action directly solves our problem
if (!nodeCondition.ScrutinyActive && gp >= 200) if (!nodeCondition.ScrutinyActive && gp >= 200)
{ {
logger.LogTrace("Still missing {NeededCollectability} collectability, scrutiny inactive",
neededCollectability);
actions.Enqueue(PickAction(EAction.ScrutinyMiner, EAction.ScrutinyBotanist)); actions.Enqueue(PickAction(EAction.ScrutinyMiner, EAction.ScrutinyBotanist));
return actions; return actions;
} }
if (nodeCondition.ScrutinyActive) if (nodeCondition.ScrutinyActive)
{ {
logger.LogTrace("Scrutiny active, need {NeededCollectability} and we expect {Collectability}~ meticulous",
neededCollectability, nodeCondition.CollectabilityFromMeticulous);
actions.Enqueue(PickAction(EAction.MeticulousMiner, EAction.MeticulousBotanist)); actions.Enqueue(PickAction(EAction.MeticulousMiner, EAction.MeticulousBotanist));
return actions; return actions;
} }
else else
{ {
logger.LogTrace("Scrutiny active, need {NeededCollectability} and we expect {Collectability}~ scour",
neededCollectability, nodeCondition.CollectabilityFromScour);
actions.Enqueue(PickAction(EAction.ScourMiner, EAction.ScourBotanist)); actions.Enqueue(PickAction(EAction.ScourMiner, EAction.ScourBotanist));
return actions; return actions;
} }
@ -168,7 +203,7 @@ internal sealed class DoGatherCollectable(
} }
public override string ToString() => public override string ToString() =>
$"DoGatherCollectable({SeIconChar.Collectible.ToIconString()} {_currentRequest.Collectability}){(_revisitRequired ? " if revist" : "")}"; $"DoGatherCollectable({SeIconChar.Collectible.ToIconString()}/{_expectedScrutiny} {_currentRequest.Collectability}){(_revisitRequired ? " if revist" : "")}";
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Local")] [SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Local")]
private sealed record NodeCondition( private sealed record NodeCondition(