Skip to content

Commit

Permalink
add a jam modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Nov 27, 2024
1 parent 5f26b6d commit fd5b558
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
2 changes: 2 additions & 0 deletions megamek/src/megamek/common/MekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ private String modifierText(EquipmentModifier modifier) {
return damageModifier.formattedDamageModifier() + " damage";
} else if (modifier instanceof WeaponMisfireModifier) {
return "weapon may misfire";
} else if (modifier instanceof WeaponJamModifier) {
return "weapon may jam";
} else {
return "unknown";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.common.modifiers;

/**
* This class represents a modifier that is one of the options for weapons at salvage quality, CO p.215. It makes the weapon jam on a to hit
* roll of 2 or 3 and is applicable for missile and ballistic weapons.
*/
public class SalvagQualityWeaponJamModifier extends WeaponJamModifier {

/**
* Creates a weapon jam modifier for salvage quality missile and ballistic weapons, CO p.215. It makes the weapon jam on a to hit roll
* of 2 or 3.
*/
public SalvagQualityWeaponJamModifier() {
super(Reason.SALVAGE_QUALITY, 2, 3);
}
}
3 changes: 1 addition & 2 deletions megamek/src/megamek/common/modifiers/WeaponHeatModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
package megamek.common.modifiers;

/**
* This is an EquipmentModifier that changes the heat generation of a weapon (WeaponMounted). This can be a simple addition or subtraction,
* but also a more complicated method.
* This is an EquipmentModifier that changes the heat generation of a weapon (WeaponMounted).
*
* Note that multiple such heat modifiers can be applied to a weapon. Their effects stack by being applied one after the other.
*/
Expand Down
78 changes: 78 additions & 0 deletions megamek/src/megamek/common/modifiers/WeaponJamModifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.common.modifiers;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

/**
* This is an EquipmentModifier that jams a weapon (WeaponMounted) upon certain to hit roll results. Note that the modifier can be applied
* to any weapon, even energy weapons. Also, multiple such modifiers can be applied to a weapon; each of those is checked and the weapon
* is jammed if any modifier's roll results happen.
*/
public class WeaponJamModifier extends AbstractEquipmentModifier {

private final Set<Integer> jamRollResults = new HashSet<>();

/**
* Creates a weapon modifier that makes the weapon jam if the die roll matches a given test.
*
* A modifier that makes the weapon jam on to hit rolls of 7 or more can be created like this:
* <pre>{@code
* new WeaponJamModifier(roll -> roll >= 7);
* }</pre>
*
* @param misfireTest The test of the die roll result that returns true when a jam occurs
*/
public WeaponJamModifier(Predicate<Integer> misfireTest, Reason reason) {
super(reason);
for (int i = 2; i <= 12; i++) {
if (misfireTest.test(i)) {
jamRollResults.add(i);
}
}
}

/**
* Creates a weapon modifier that makes the weapon jam if the die roll matches any of the given numbers.
*
* @param jamRollResults A list of numbers (2...12) that make the weapon jam when rolled as a to-hit roll.
*/
public WeaponJamModifier(Reason reason, int... jamRollResults) {
super(reason);
Arrays.stream(jamRollResults).forEach(this.jamRollResults::add);
}

/**
* Creates a weapon modifier that makes the weapon jam if the die roll matches any of the given numbers.
*
* @param jamRollResults A list of numbers (2...12) that make the weapon jam when rolled as a to-hit roll.
*/
public WeaponJamModifier(Collection<Integer> jamRollResults, Reason reason) {
super(reason);
this.jamRollResults.addAll(jamRollResults);
}

public boolean isJammed(int toHitRollResult) {
return jamRollResults.contains(toHitRollResult);
}
}

0 comments on commit fd5b558

Please sign in to comment.