Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@SJuliez
Copy link
Member

@SJuliez SJuliez commented Jul 7, 2024

This modernizes some very old code of TargetRoll and TargetRollModifier. TargetRollModifier is now immutable for which I had to adapt two places in Compute. Also updates the test for TargetRoll.

@codecov
Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 29.33%. Comparing base (e7fd8fc) to head (fbca48a).
Report is 14 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5696      +/-   ##
============================================
- Coverage     29.34%   29.33%   -0.01%     
+ Complexity    13868    13867       -1     
============================================
  Files          2466     2467       +1     
  Lines        263322   263338      +16     
  Branches      47174    47166       -8     
============================================
- Hits          77264    77251      -13     
- Misses       182170   182202      +32     
+ Partials       3888     3885       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +2528 to +2546
toHit.addModifier(3 / dedicatedGunnerMod, "attacker used UMUs");
} else if (entity instanceof LandAirMech && movement == EntityMovementType.MOVE_VTOL_WALK) {
toHit.addModifier(3, "attacker cruised");
toHit.addModifier(3 / dedicatedGunnerMod, "attacker cruised");
} else if (entity instanceof LandAirMech && movement == EntityMovementType.MOVE_VTOL_RUN) {
toHit.addModifier(4, "attacker flanked");
toHit.addModifier(4 / dedicatedGunnerMod, "attacker flanked");
} else if ((movement == EntityMovementType.MOVE_WALK) || (movement == EntityMovementType.MOVE_VTOL_WALK)
|| (movement == EntityMovementType.MOVE_CAREFUL_STAND)) {
toHit.addModifier(1, "attacker walked");
toHit.addModifier(1 / dedicatedGunnerMod, "attacker walked");
} else if ((movement == EntityMovementType.MOVE_RUN) || (movement == EntityMovementType.MOVE_VTOL_RUN)) {
toHit.addModifier(2, "attacker ran");
toHit.addModifier(2 / dedicatedGunnerMod, "attacker ran");
} else if (movement == EntityMovementType.MOVE_SKID) {
toHit.addModifier(3, "attacker ran and skidded");
toHit.addModifier(3 / dedicatedGunnerMod, "attacker ran and skidded");
} else if (movement == EntityMovementType.MOVE_JUMP) {
if (entity.hasAbility(OptionsConstants.PILOT_JUMPING_JACK)) {
toHit.addModifier(1, "attacker jumped");
toHit.addModifier(1 / dedicatedGunnerMod, "attacker jumped");
} else if (entity.hasAbility(OptionsConstants.PILOT_HOPPING_JACK)) {
toHit.addModifier(2, "attacker jumped");
toHit.addModifier(2 / dedicatedGunnerMod, "attacker jumped");
} else {
toHit.addModifier(3, "attacker jumped");
toHit.addModifier(3 / dedicatedGunnerMod, "attacker jumped");
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we can get non-integer results here, which I believe Java will round down.

  1. is that expected behavior?
  2. do we check anywhere that this code produces the expected results for every combination?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. I think so as it was like that before
  2. No. Currently there are no combinations, this method only returns a single modifier. I did not check the rules as - see 1. :)

Comment on lines +86 to +92
return switch (total) {
case IMPOSSIBLE -> "Impossible";
case AUTOMATIC_FAIL -> "Automatic Failure";
case AUTOMATIC_SUCCESS -> "Automatic Success";
case CHECK_FALSE -> "Did not need to roll";
default -> Integer.toString(total);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

So fresh and so clean!

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah :) although strictly speaking this should be localized...

Comment on lines 244 to 245
return modifier.getValue() == AUTOMATIC_FAIL || modifier.getValue() == AUTOMATIC_SUCCESS
|| modifier.getValue() == IMPOSSIBLE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can also be accomplished fairly quickly and cleanly with:

return Set.of(AUTOMATIC_FAIL, AUTOMATIC_SUCCESS, IMPOSSIBLE).contains(modifier.getValue());

Copy link
Collaborator

@Sleet01 Sleet01 left a comment

Choose a reason for hiding this comment

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

A couple of questions/comments but overall looks good.

Copy link
Collaborator

@Sleet01 Sleet01 left a comment

Choose a reason for hiding this comment

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

LGTM!

@IllianiBird IllianiBird merged commit bb26cc3 into MegaMek:master Jul 7, 2024
@SJuliez SJuliez deleted the TargetRoll-modernize-and-test branch August 1, 2024 11:09
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.

3 participants