Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added the Extra movement conditions #211

Merged
merged 2 commits into from
Mar 1, 2025
Merged

Conversation

dm94
Copy link
Owner

@dm94 dm94 commented Feb 26, 2025

Summary by Sourcery

Adds new movement modes and condition-based movement logic. This allows the bot to use different movement strategies based on configurable conditions, enhancing its adaptability.

New Features:

  • Introduces configurable movement modes with condition checks, allowing the bot to adapt its movement style based on defined conditions.
  • Adds 'RANDOM', 'GROUPVSSAFETY', and 'GROUPVS' movement modes, expanding the bot's movement capabilities.
  • Implements a system to prioritize movement modes based on a list of conditions, providing more flexibility in adapting to different situations.

Copy link

sourcery-ai bot commented Feb 26, 2025

Reviewer's Guide by Sourcery

This pull request introduces new movement modes and condition-based movement logic. It allows the bot to use different movement strategies based on configurable conditions, enhancing its adaptability. The changes include the addition of 'RANDOM', 'GROUPVSSAFETY', and 'GROUPVS' movement modes, a system to prioritize movement modes based on a list of conditions, and integration of the new movement logic into existing modules.

Sequence diagram for ExtraMovementLogic move method

sequenceDiagram
    participant ExtraMovementLogic
    participant SafetyFinder
    participant MovementAPI
    participant GroupAPI
    participant HeroAPI

    ExtraMovementLogic->ExtraMovementLogic: getMovementMode()
    alt movementSelected == VSSAFETY or movementSelected == GROUPVSSAFETY
        ExtraMovementLogic->SafetyFinder: tick()
        alt tick() returns false
            SafetyFinder-->>ExtraMovementLogic: false
            ExtraMovementLogic->ExtraMovementLogic: break
        else tick() returns true
            SafetyFinder-->>ExtraMovementLogic: true
        end
    end
    alt movementSelected == GROUPVSSAFETY or movementSelected == GROUPVS
        ExtraMovementLogic->ExtraMovementLogic: getClosestMember()
        alt groupMember != null
            ExtraMovementLogic->GroupAPI: getMembers()
            GroupAPI-->>ExtraMovementLogic: GroupMember
            ExtraMovementLogic->GroupMember: getLocation()
            GroupMember-->>ExtraMovementLogic: Location
            ExtraMovementLogic->HeroAPI: getLocationInfo()
            HeroAPI-->>ExtraMovementLogic: LocationInfo
            ExtraMovementLogic->ExtraMovementLogic: groupMember.getLocation().distanceTo(hero)
            alt distance < DISTANCE_TO_USE_VS_MODE
                ExtraMovementLogic->ExtraMovementLogic: vsMove()
            else distance >= DISTANCE_TO_USE_VS_MODE
                ExtraMovementLogic->MovementAPI: moveTo(groupMember.getLocation())
            end
        else groupMember == null
            ExtraMovementLogic->ExtraMovementLogic: vsMove()
        end
    else movementSelected == RANDOM
        ExtraMovementLogic->MovementAPI: isMoving()
        ExtraMovementLogic->MovementAPI: isOutOfMap()
        alt !movement.isMoving() || movement.isOutOfMap()
            ExtraMovementLogic->MovementAPI: moveRandom()
        end
    else movementSelected == VS
        ExtraMovementLogic->ExtraMovementLogic: vsMove()
    else default
        ExtraMovementLogic->SafetyFinder: tick()
        alt tick() returns true
            SafetyFinder-->>ExtraMovementLogic: true
            ExtraMovementLogic->ExtraMovementLogic: vsMove()
        end
    end
Loading

File-Level Changes

Change Details Files
Introduced configurable movement modes with condition checks, allowing the bot to adapt its movement style based on defined conditions.
  • Added ExtraMovementLogic class to handle different movement modes based on conditions.
  • Created MovementConfig and MovementWithConditions classes for configuring movement modes and conditions.
  • Implemented MovementModeEnum to define available movement modes.
  • Added logic to prioritize movement modes based on a list of conditions.
  • Implemented tick method to execute the selected movement mode.
src/main/java/com/deeme/shared/movement/ExtraMovementLogic.java
src/main/java/com/deeme/shared/movement/MovementConfig.java
src/main/java/com/deeme/shared/movement/MovementWithConditions.java
src/main/java/com/deeme/shared/movement/MovementModeEnum.java
Expanded the bot's movement capabilities by adding 'RANDOM', 'GROUPVSSAFETY', and 'GROUPVS' movement modes.
  • Implemented RANDOM movement mode to move the bot randomly.
  • Implemented GROUPVSSAFETY movement mode to move towards a group member while considering safety.
  • Implemented GROUPVS movement mode to move towards a group member without considering safety.
  • Added a condition to switch to VS mode when close to a group member in GROUPVSSAFETY and GROUPVS modes.
src/main/java/com/deeme/shared/movement/ExtraMovementLogic.java
src/main/java/com/deeme/shared/movement/MovementModeEnum.java
Integrated the new movement logic into existing modules.
  • Added MovementConfig to DefenseConfig, PVPConfig, and SentinelConfig.
  • Instantiated and used ExtraMovementLogic in DefenseModule, PVPModule, and SentinelModule.
  • Added configuration options for the new movement modes in the plugin.json file.
src/main/java/com/deeme/behaviours/defense/DefenseConfig.java
src/main/java/com/deeme/behaviours/defense/DefenseModule.java
src/main/java/com/deeme/modules/PVPModule.java
src/main/java/com/deeme/modules/SentinelModule.java
src/main/java/com/deeme/modules/pvp/PVPConfig.java
src/main/java/com/deeme/types/config/SentinelConfig.java
src/main/resources/plugin.json

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@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.

We encountered an error and are unable to review this PR. We have been notified and are working to fix it.

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@dm94
Copy link
Owner Author

dm94 commented Feb 26, 2025

@sourcery-ai review

Copy link

@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 @dm94 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the condition checking logic into a separate utility class to improve readability and maintainability.
  • The DISTANCE_TO_USE_VS_MODE constant should be configurable.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 3 issues found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

Comment on lines +129 to +131
private Optional<Location> getDestination() {
Ship target = hero.getTargetAs(Ship.class);
if (target != null && target.isValid()) {
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential bug in getDestination condition check.

In the else branch, the condition is once again checking 'target' rather than the newly assigned 'other'. This appears to be a copy-paste mistake and may lead to incorrect behavior when hero.getTargetAs(Ship.class) is null but hero.getTarget() returns a valid entity.

Comment on lines +13 to +14
@Option("movement_config.condition")
public MovementWithConditions movementCondtion1 = new MovementWithConditions();
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): Typo in property naming: movementCondtion1.

The field name 'movementCondtion1' appears to contain a typo. Standardizing the naming to 'movementCondition1' (and similarly for condition 2-5) would improve readability and reduce potential confusion in the future.

Suggested implementation:

    public MovementWithConditions movementCondition1 = new MovementWithConditions();
    public MovementWithConditions movementCondition2 = new MovementWithConditions();
    public MovementWithConditions movementCondition3 = new MovementWithConditions();
    public MovementWithConditions movementCondition4 = new MovementWithConditions();

MovementModeEnum movementSelected = getMovementMode();

switch (movementSelected) {
case VSSAFETY:
Copy link

Choose a reason for hiding this comment

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

suggestion (review_instructions): Consider clarifying the fall-through in the VSSAFETY case for better readability.

If the fall-through from VSSAFETY to VS is intentional, adding a comment (e.g., // fallthrough) would improve code clarity.

Review instructions:

Path patterns: *.java

Instructions:
It is a plugin for the darkbot bot in java, check that the code is clean and efficient.

public MovementModeEnum defaultMovementMode = MovementModeEnum.VS;

@Option("movement_config.condition")
public MovementWithConditions movementCondtion1 = new MovementWithConditions();
Copy link

Choose a reason for hiding this comment

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

suggestion (review_instructions): Typo in variable name 'movementCondtion1' affecting code clarity.

Renaming 'movementCondtion1' to 'movementCondition1' (and similarly for the subsequent fields) would improve readability and maintainability.

Review instructions:

Path patterns: *.java

Instructions:
It is a plugin for the darkbot bot in java, check that the code is clean and efficient.

@dm94 dm94 merged commit 43e8dfe into master Mar 1, 2025
6 checks passed
@dm94 dm94 deleted the feat/extra-movement branch March 1, 2025 11:03
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