Skip to content

Commit

Permalink
Core: RequirementFactory: Added 'SoftTargetDead' and 'SoftTarget'
Browse files Browse the repository at this point in the history
Fix: Core: LootGoal: Prevent possible endless wait for LootStatus to be reset.

Revert: Core: ConsumeCorpseGoal: Allow to loot early even while the player is in combat, but theres not immediate danger from CombatLog(DamagaTaken,DamageDone)

Core: ClassConfigurationBaseActions: Approach and AutoAttack has a predefined Requirement to prevent colliding with Soft Targeting feature if its enabled...

Core: ClassConfiguration: Added a way to inhert BaseAction Requirements to Goal
  • Loading branch information
Xian55 committed Dec 19, 2024
1 parent c21bd58 commit b255d90
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
5 changes: 2 additions & 3 deletions Core/ClassConfig/ClassConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ private static void SetBaseActions(

user.Key = baseAction.Key;

//if (!string.IsNullOrEmpty(@default.Requirement))
// user.Requirement += " " + @default.Requirement;
//user.Requirements.AddRange(@default.Requirements);
if (!string.IsNullOrEmpty(baseAction.Requirement))
user.Requirement += " " + baseAction.Requirement;

if (user.BeforeCastDelay == @default.BeforeCastDelay)
user.BeforeCastDelay = baseAction.BeforeCastDelay;
Expand Down
6 changes: 4 additions & 2 deletions Core/ClassConfig/ClassConfigurationBaseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public sealed partial class ClassConfiguration
Key = "I", // Interact.Key
Name = nameof(Approach),
PressDuration = 10,
BaseAction = true
BaseAction = true,
Requirement = "!SoftTargetDead"
};

public KeyAction AutoAttack { get; } = new()
{
Key = "I", // Interact.Key
Name = nameof(AutoAttack),
BaseAction = true
BaseAction = true,
Requirement = "!AutoAttacking && !SoftTargetDead"
};

public KeyAction TargetLastTarget { get; } = new()
Expand Down
5 changes: 2 additions & 3 deletions Core/Goals/ConsumeCorpseGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public ConsumeCorpseGoal(ILogger<ConsumeCorpseGoal> logger,
{
AddPrecondition(GoapKey.consumablecorpsenearby, true);
}
AddPrecondition(GoapKey.pulled, false);
AddPrecondition(GoapKey.dangercombat, false);
AddPrecondition(GoapKey.incombat, false);
AddPrecondition(GoapKey.damagedone, false);
AddPrecondition(GoapKey.damagetaken, false);

AddPrecondition(GoapKey.producedcorpse, true);
AddPrecondition(GoapKey.consumecorpse, false);
Expand Down
28 changes: 18 additions & 10 deletions Core/Goals/LootGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ public LootGoal(ILogger<LootGoal> logger,

this.token = cts.Token;
AddPrecondition(GoapKey.pulled, false);
AddPrecondition(GoapKey.incombat, false);
AddPrecondition(GoapKey.dangercombat, false);
AddPrecondition(GoapKey.shouldloot, true);
AddEffect(GoapKey.shouldloot, false);
}

public override void OnEnter()
{
WaitForLootReset();
float elapsedMs = WaitForLootReset();
if (elapsedMs < 0)
{
LogLootStatusDidNotChangedInTime(logger, elapsedMs);
return;
}

if (combatLog.DamageTakenCount() == 0)
{
Expand All @@ -103,9 +107,9 @@ public override void OnEnter()
ClearTargetIfNeeded();
}

private void WaitForLootReset()
private float WaitForLootReset()
{
wait.WhileWithTimeout(LootReset, MAX_TIME_TO_RESET_LOOT);
return wait.Until(MAX_TIME_TO_RESET_LOOT, LootStatusIsCorpse);
}

private void WaitForLosingTarget()
Expand Down Expand Up @@ -151,10 +155,8 @@ private bool TryLoot()
return true;
}
}
if (!input.KeyboardOnly) {
return LootMouse();
}
return false;

return !input.KeyboardOnly && LootMouse();
}

private void HandleSuccessfulLoot()
Expand Down Expand Up @@ -400,8 +402,8 @@ private bool MoveToTargetAndReached()
return bits.Target() && playerReader.MinRangeZero();
}

private bool LootReset() =>
(LootStatus)playerReader.LootEvent.Value != LootStatus.CORPSE;
private bool LootStatusIsCorpse() =>
(LootStatus)playerReader.LootEvent.Value == LootStatus.CORPSE;

#region Logging

Expand Down Expand Up @@ -457,5 +459,11 @@ private void LogWarning(string text)
Message = "Keyboard loot failed! Has target ? {hasTarget}")]
static partial void LogKeyboardLootFailed(ILogger logger, bool hasTarget);

[LoggerMessage(
EventId = 0137,
Level = LogLevel.Error,
Message = "LootGoal failed to start due LootStatus did not changed within the expected time window {elapsedMs}ms")]
static partial void LogLootStatusDidNotChangedInTime(ILogger logger, float elapsedMs);

#endregion
}
9 changes: 0 additions & 9 deletions Core/GoalsComponent/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,4 @@ public void While(Func<bool> condition)
Update();
}
}

public void WhileWithTimeout(Func<bool> condition, int timeoutMs) {
DateTime start = DateTime.UtcNow;
float elapsedMs;
while ((elapsedMs = (float)(DateTime.UtcNow - start).TotalMilliseconds) < timeoutMs && condition())
{
Update();
}
}
}
4 changes: 4 additions & 0 deletions Core/Requirement/RequirementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public RequirementFactory(IServiceProvider sp, ClassConfiguration classConfig)
{ "TargetsPet", playerReader.TargetsPet },
{ "TargetsNone", playerReader.TargetsNone },

// Soft Target
{ "SoftTarget", bits.SoftInteract },
{ "SoftTargetDead", bits.SoftInteract_Dead },

{ AddVisible, npcNameFinder._PotentialAddsExist },
{ "InCombat", bits.Combat },

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,8 @@ Allow requirements about what buffs/debuffs you have or the target has or in gen
| `"TargetsMe"` | The target currently targets the player |
| `"TargetsPet"` | The target currently targets the player's pet |
| `"TargetsNone"` | The target currently has not target |
| `"SoftTarget"` | The player has an available soft target |
| `"SoftTargetDead"` | The player has an available soft target which is dead |
| `"AddVisible"` | Around the target there are possible additional NPCs |
| `"InCombat"` | Player in combat. |
| `"TargetCastingSpell"` | Target casts any spell |
Expand Down

0 comments on commit b255d90

Please sign in to comment.