Skip to content

fix(SentinelModule): improve target clearing logic during attack cool…#291

Merged
dm94 merged 2 commits intomasterfrom
fix/sentinel-clear-logic
Apr 25, 2026
Merged

fix(SentinelModule): improve target clearing logic during attack cool…#291
dm94 merged 2 commits intomasterfrom
fix/sentinel-clear-logic

Conversation

@dm94
Copy link
Copy Markdown
Owner

@dm94 dm94 commented Apr 21, 2026

…down

Ensure old targets are only retained when the sentinel is actively attacking them. Clear attack targets consistently when no valid target exists or the cooldown period ends without a valid old target. This prevents stale target references and ensures proper attack state reset.

Summary by Sourcery

Improve sentinel attack state handling by only retaining old targets while they are actively being attacked and consistently clearing attack targets when no valid target exists or cooldown expires without a valid target.

Bug Fixes:

  • Prevent stale sentinel target references by clearing attack targets when cooldown elapses without a valid active target or when no new valid target is found.

Enhancements:

  • Introduce helper methods to determine when to keep an old target and to centralize attack target clearing logic for more consistent sentinel behavior.

…down

Ensure old targets are only retained when the sentinel is actively attacking them. Clear attack targets consistently when no valid target exists or the cooldown period ends without a valid old target. This prevents stale target references and ensures proper attack state reset.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 21, 2026

Reviewer's Guide

Refines the SentinelModule attack state handling so that old targets are only kept while the sentinel is actually attacking them, and consistently clears attack-related state when no valid target exists or cooldown elapses without a valid target, preventing stale target references.

Sequence diagram for updated isAttacking target handling

sequenceDiagram
    participant SentinelModule
    participant Sentinel
    participant Attacker
    participant ShipAttacker

    SentinelModule->>SentinelModule: isAttacking()
    alt randomWaitTime_in_future
        SentinelModule->>SentinelModule: shouldKeepOldTarget()
        alt shouldKeepOldTarget returns true
            SentinelModule-->>SentinelModule: return true
        else shouldKeepOldTarget returns false
            SentinelModule->>SentinelModule: clearAttackTargets()
            SentinelModule-->>SentinelModule: return false
        end
    else randomWaitTime_expired
        SentinelModule->>SentinelModule: compute_target()
        alt target_is_null
            SentinelModule->>SentinelModule: clearAttackTargets()
            SentinelModule-->>SentinelModule: return false
        else target_is_not_null
            SentinelModule->>SentinelModule: changeTarget(target)
            SentinelModule->>SentinelModule: oldTarget = target
            SentinelModule-->>SentinelModule: return true
        end
    end

    rect rgb(230,230,230)
        SentinelModule->>Sentinel: getTarget()
        Sentinel-->>SentinelModule: sentinelTarget
        SentinelModule-->>SentinelModule: compare sentinelTarget.id with oldTarget.id
    end

    rect rgb(230,230,230)
        SentinelModule->>Attacker: setTarget(null)
        SentinelModule->>ShipAttacker: resetDefenseData()
    end
Loading

Class diagram for updated SentinelModule attack state management

classDiagram
    class SentinelModule {
        - long randomWaitTime
        - Entity oldTarget
        - boolean isNpc
        - Sentinel sentinel
        - Attacker attacker
        - ShipAttacker shipAttacker
        - SentinelConfig sConfig

        + boolean isAttacking()
        - boolean shouldKeepOldTarget()
        - void clearAttackTargets()
        - void changeTarget(Entity target)
    }

    class Entity {
        + int getId()
        + boolean isValid()
    }

    class Sentinel {
        + Entity getTarget()
    }

    class Attacker {
        + void setTarget(Entity target)
    }

    class ShipAttacker {
        + void resetDefenseData()
    }

    class SentinelConfig {
        + HumanizerConfig humanizer
    }

    class HumanizerConfig {
        + boolean addRandomTime
    }

    SentinelModule --> Entity : uses
    SentinelModule --> Sentinel : controls
    SentinelModule --> Attacker : clears_target
    SentinelModule --> ShipAttacker : resets_defense
    SentinelModule --> SentinelConfig : reads_settings
    SentinelConfig --> HumanizerConfig : contains
    Sentinel ..> Entity : returns
Loading

File-Level Changes

Change Details Files
Refactor attack state evaluation to keep or clear old targets based on sentinel’s current target and to centralize attack-target clearing logic.
  • Adjust isAttacking() to consult a new helper for deciding whether to retain the old target during the random cooldown window, otherwise clearing all attack targets.
  • Ensure isAttacking() clears attack-related state and returns false whenever a new target cannot be acquired.
  • Introduce shouldKeepOldTarget() to validate the old target and confirm it matches the sentinel’s current in-game target before reusing it.
  • Introduce clearAttackTargets() to centralize resetting of oldTarget, NPC flag, attacker target, and ship defense data.
src/main/java/com/deeme/modules/SentinelModule.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dm94 dm94 merged commit ec4dbce into master Apr 25, 2026
5 checks passed
@dm94 dm94 deleted the fix/sentinel-clear-logic branch April 25, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant