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

Issue 6247:NPE with TacOps Energy Weapons when Changing Firing Mode #6251

Merged
9 changes: 4 additions & 5 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -6914,13 +6914,12 @@
return toReturn;
}

String damage = weapon.curMode().getName();
String damage = weapon.curMode().getName().toLowerCase();

// Vehicle flamers have damage and heat modes so lets make sure this is
// an actual dial down Damage.
if ((damage.trim().toLowerCase().indexOf("damage") == 0)
&& (damage.trim().length() > 6)) {
toReturn = Integer.parseInt(damage.substring(6).trim());
if ((damage.trim().length() > 6) && damage.contains("damage")) {
toReturn = Integer.parseInt(damage.substring(damage.indexOf("damage") + 6).trim());
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
}

return Math.min(wtype.getDamage(range), toReturn);
Expand Down Expand Up @@ -7252,7 +7251,7 @@
case TARGETING_COMPUTER:
if (!wtype.hasFlag(WeaponType.F_DIRECT_FIRE)
|| wtype.hasFlag(WeaponType.F_PULSE)
|| weapon.curMode().getName().equals("Pulse")
|| weapon.curMode().getName().startsWith("Pulse")
|| (wtype instanceof HAGWeapon)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/equipment/WeaponMounted.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ && getLinkedBy().getType().hasFlag(
heat++;
}
}
if (curMode().equals("Pulse")) {
if (curMode().getName().startsWith("Pulse")) {
heat += 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected boolean doChecks(Vector<Report> vPhaseReport) {

WeaponMounted laser = waa.getEntity(game).getWeapon(waa.getWeaponId());

if ((roll.getIntValue() == 2) && laser.curMode().equals("Pulse")) {
if ((roll.getIntValue() == 2) && laser.curMode().getName().startsWith("Pulse")) {
vPhaseReport.addAll(gameManager.explodeEquipment(laser.getEntity(), laser.getLocation(), laser.getLinkedBy()));
}
return false;
Expand Down
3 changes: 3 additions & 0 deletions megamek/src/megamek/common/weapons/lasers/EnergyWeapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ public void adaptToGameOptions(GameOptions gOp) {
for (; dmg >= 0; dmg--) {
addMode("Damage " + dmg);
}
removeMode("");
removeMode("Pulse");
} else {
int dmg = (damage == WeaponType.DAMAGE_VARIABLE) ? damageShort : damage;
for (; dmg >= 0; dmg--) {
removeMode("Damage " + dmg);
removeMode("Pulse Damage " + dmg);
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions megamek/src/megamek/common/weapons/lasers/LaserWeapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
*/
package megamek.common.weapons.lasers;

import megamek.common.AmmoType;
import megamek.common.Game;
import megamek.common.MiscType;
import megamek.common.Mounted;
import megamek.common.ToHitData;
import megamek.common.*;
import megamek.common.actions.WeaponAttackAction;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.MiscMounted;
Expand All @@ -29,6 +25,8 @@
import megamek.common.weapons.PulseLaserWeaponHandler;
import megamek.server.totalwarfare.TWGameManager;

import java.util.Collections;

/**
* @author Andrew Hunter
* @since Sep 2, 2004
Expand All @@ -49,8 +47,17 @@ public void adaptToGameOptions(GameOptions gOp) {
super.adaptToGameOptions(gOp);

if (!(this instanceof PulseLaserWeapon)) {
addMode("");
addMode("Pulse");
if (!hasModes()) {
addMode("");
addMode("Pulse");
}
else {
for (var mode : Collections.list(getModes())) {
if(!mode.getName().contains("Pulse") && !mode.getName().isEmpty()) {
addMode("Pulse " + mode.getName());
}
}
}
}
}

Expand All @@ -60,18 +67,21 @@ public int getModesCount(Mounted<?> mounted) {
if ((linkedBy instanceof MiscMounted)
&& !linkedBy.isInoperable()
&& ((MiscMounted) linkedBy).getType().hasFlag(MiscType.F_RISC_LASER_PULSE_MODULE)) {
return 2;
} else {
return 0;
return super.getModesCount();
} else if(this instanceof PulseLaserWeapon) {
return super.getModesCount();
}

//Only works if laser pulse module's "Pulse" modes are added last.
return (int) modes.stream().filter(mode -> !mode.getName().startsWith("Pulse")).count();
}

@Override
public int getToHitModifier(@Nullable Mounted<?> mounted) {
if ((mounted == null) || !(mounted.getLinkedBy() instanceof MiscMounted) || !mounted.getLinkedBy().getType().hasFlag(MiscType.F_RISC_LASER_PULSE_MODULE)) {
return super.getToHitModifier(mounted);
}
return mounted.curMode().getName().equals("Pulse") ? -2 : 0;
return mounted.curMode().getName().startsWith("Pulse") ? -2 : 0;
}

@Override
Expand Down
Loading