fix(SentinelModule): improve target clearing logic during attack cool…#291
Merged
fix(SentinelModule): improve target clearing logic during attack cool…#291
Conversation
…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.
Contributor
Reviewer's GuideRefines 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 handlingsequenceDiagram
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
Class diagram for updated SentinelModule attack state managementclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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:
Enhancements: