-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
megamek/src/megamek/common/modifiers/SalvagQualityWeaponJamModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
megamek/src/megamek/common/modifiers/WeaponJamModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |