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

#6063: Fix targeting choice with iNarcs #6115

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions megamek/src/megamek/client/ui/swing/TargetChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.client.ui.swing.tooltip.UnitToolTip;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.actions.BrushOffAttackAction;
import megamek.common.actions.WeaponAttackAction;
import megamek.common.annotations.Nullable;

Expand Down Expand Up @@ -90,15 +91,25 @@ protected String infoText(Targetable target) {
String result = "";

if (firingEntity != null) {
ToHitData thd = WeaponAttackAction.toHit(clientGUI.getClient().getGame(), firingEntity.getId(), target);
thd.setLocation(target.getPosition());
thd.setRange(firingEntity.getPosition().distance(target.getPosition()));
ToHitData thd;
if (target instanceof INarcPod) {
// must not call getPosition() on INarcPods! Check both arms if necessary
thd = BrushOffAttackAction.toHit(clientGUI.getClient().getGame(),
firingEntity.getId(), target, BrushOffAttackAction.RIGHT);
if (thd.getValue() == TargetRoll.IMPOSSIBLE) {
thd = BrushOffAttackAction.toHit(clientGUI.getClient().getGame(),
firingEntity.getId(), target, BrushOffAttackAction.LEFT);
}
} else {
thd = WeaponAttackAction.toHit(clientGUI.getClient().getGame(), firingEntity.getId(), target);
thd.setLocation(target.getPosition());
thd.setRange(firingEntity.getPosition().distance(target.getPosition()));
}
if (thd.needsRoll()) {
int mod = thd.getValue();
result += "<br>Target To Hit Mod: <b>" + (mod < 0 ? "" : "+") + mod + "</b>";
} else {
result += "<br><b>" + thd.getValueAsString() + " To Hit</b>: " + thd.getDesc();

}
}

Expand Down
5 changes: 4 additions & 1 deletion megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,10 @@ public static ToHitData toHit(Game game, int attackerId, Targetable target) {
int aElev = ae.getElevation();
int tElev = target.getElevation();
int targEl;
if (te == null) {
if (target instanceof INarcPod) {
// brush off attached INarcs on oneself; use left arm as a placeholder here as no choice has been made
return BrushOffAttackAction.toHit(game, attackerId, target, BrushOffAttackAction.LEFT);
} else if (te == null) {
targEl = game.getBoard().getHex(target.getPosition()).floor();
} else {
targEl = te.relHeight();
Expand Down