Package megamek.common.rolls
Class TargetRoll
java.lang.Object
megamek.common.rolls.TargetRoll
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AttackToHitData,ManeuverToHitData,PilotingRollData,RecoveringNerveActionToHitData,SBFDetectionModifiers,SBFToHitData,ToHitData
Keeps track of a target for a roll. Allows adding modifiers with descriptions, including appending the modifiers in
another TargetRoll. Intended for rolls like a to-hit roll or a piloting skill check.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intThe CHECK_FALSE value is returned when a function that normally would return a target roll number determines that the roll wasn't needed after all.static final int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, empty TargetRoll.TargetRoll(int value, String desc) Creates a new TargetRoll with a base value and descTargetRoll(int value, String desc, boolean cumulative) Creates a new TargetRoll with a base value and desc, which is possibly not cumulativeTargetRoll(TargetRollModifier baseValue) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModifier(int value, String desc) Adds a new cumulative modifier of the given value and description.voidaddModifier(int value, String desc, boolean cumulative) Adds a new modifier of the given value and description, which is or is not cumulative.voidaddModifier(TargetRollModifier modifier) Adds the given new modifier to this TargetRoll.voidappend(TargetRoll other) Append another TargetRoll to the end of this onevoidappend(TargetRoll other, boolean appendNonCumulative) Append another TargetRoll to the end of this one, possibly discarding non-cumulative modifier in the other one.booleanvoidDoes not do anything, necessary because Java does not have a "noop" function.getDesc()Returns a description of all applicable modifiersReturns the last description foundReturns the first description foundintgetValue()booleanbooleanbooleanbooleanvoidRemove all automatic failures or successes, but leave impossibles intactvoidremoveAutos(boolean removeImpossibles) Remove all automatic failures or successes, and possibly also remove impossibles.removeModifier(String fragment) Attempts to remove and return (if needed) the first mod that matches the provided stringvoidremoveModifier(TargetRollModifier modifier) Deprecated, for removal: This API element is subject to removal in a future version.removeModifiers(List<String> fragments) Attempts to remove and return (if needed) the first mod that matches each provided stringtoString()
-
Field Details
-
IMPOSSIBLE
public static final int IMPOSSIBLE- See Also:
-
AUTOMATIC_FAIL
public static final int AUTOMATIC_FAIL- See Also:
-
AUTOMATIC_SUCCESS
public static final int AUTOMATIC_SUCCESS- See Also:
-
CHECK_FALSE
public static final int CHECK_FALSEThe CHECK_FALSE value is returned when a function that normally would return a target roll number determines that the roll wasn't needed after all.- See Also:
-
-
Constructor Details
-
TargetRoll
public TargetRoll()Creates a new, empty TargetRoll. This is by itself not yet useful. -
TargetRoll
Creates a new TargetRoll with a base value and desc -
TargetRoll
Creates a new TargetRoll with a base value and desc, which is possibly not cumulative -
TargetRoll
-
-
Method Details
-
getValue
public int getValue()- Returns:
- The sum of all modifiers. When a finalizer is present, the value equals that finalizer.
-
getValueAsString
- Returns:
- The total value of all modifiers as a text.
-
getModifiers
- Returns:
- All modifiers of this TargetRoll. The list is a copy and may be modified.
-
getDesc
Returns a description of all applicable modifiers -
needsRoll
public boolean needsRoll()- Returns:
- False when this TargetRoll has any finalizers (automatic fail or success, impossible or no check required). True otherwise (even if the modifiers add up to very high or low values).
-
toString
-
getPlainDesc
Returns the first description found -
getCumulativePlainDesc
- Returns:
- the description of the first cumulative TargetRollModifier
-
getLastPlainDesc
Returns the last description found -
addModifier
Adds a new cumulative modifier of the given value and description.- Parameters:
value- The modifier value, e.g. +2 or -1desc- A short description of the modifier
-
doNothing
public void doNothing()Does not do anything, necessary because Java does not have a "noop" function. -
addModifier
Adds a new modifier of the given value and description, which is or is not cumulative.- Parameters:
value- The modifier value, e.g. +2 or -1desc- A short description of the modifiercumulative- True when this modifier is cumulative
-
addModifier
Adds the given new modifier to this TargetRoll.- Parameters:
modifier- The new modifier
-
removeModifier
@Deprecated(since="0.51.0", forRemoval=true) public void removeModifier(TargetRollModifier modifier) Deprecated, for removal: This API element is subject to removal in a future version.Base removal method -
removeModifier
Attempts to remove and return (if needed) the first mod that matches the provided string- Parameters:
fragment- of mod description to match
-
removeModifiers
Attempts to remove and return (if needed) the first mod that matches each provided string- Parameters:
fragments- List of strings / regexes to match- Returns:
- List of mods that are matched and removed
-
append
Append another TargetRoll to the end of this one -
append
Append another TargetRoll to the end of this one, possibly discarding non-cumulative modifier in the other one.- Parameters:
other- the TargetRoll to appendappendNonCumulative- True to append all modifiers, false to append only cumulative modifiers
-
removeAutos
public void removeAutos()Remove all automatic failures or successes, but leave impossibles intact -
removeAutos
public void removeAutos(boolean removeImpossibles) Remove all automatic failures or successes, and possibly also remove impossibles.- Parameters:
removeImpossibles- When true, IMPOSSIBLEEs are also removed
-
cannotSucceed
public boolean cannotSucceed()- Returns:
- True when this roll cannot succeed regardless of numbers, i.e. is impossible or automatically fails. Returns false otherwise, i.e. when the roll does not contain these finalizing conditions, even if the total roll modifier is above 12.
-
isAutomaticFail
public boolean isAutomaticFail()- Returns:
- True when this roll automatically fails. Returns false otherwise.
-
isAutomaticSuccess
public boolean isAutomaticSuccess()- Returns:
- True when this roll automatically succeeds. Returns false otherwise.
-
isImpossible
public boolean isImpossible()- Returns:
- True when this roll is impossible. Returns false otherwise.
-