Class TargetRoll

java.lang.Object
megamek.common.rolls.TargetRoll
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AttackToHitData, ManeuverToHitData, PilotingRollData, RecoveringNerveActionToHitData, SBFDetectionModifiers, SBFToHitData, ToHitData

public class TargetRoll extends Object implements Serializable
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 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_FALSE
      The 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

      public TargetRoll(int value, String desc)
      Creates a new TargetRoll with a base value and desc
    • TargetRoll

      public TargetRoll(int value, String desc, boolean cumulative)
      Creates a new TargetRoll with a base value and desc, which is possibly not cumulative
    • TargetRoll

      public TargetRoll(TargetRollModifier baseValue)
  • Method Details

    • getValue

      public int getValue()
      Returns:
      The sum of all modifiers. When a finalizer is present, the value equals that finalizer.
    • getValueAsString

      public String getValueAsString()
      Returns:
      The total value of all modifiers as a text.
    • getModifiers

      public List<TargetRollModifier> getModifiers()
      Returns:
      All modifiers of this TargetRoll. The list is a copy and may be modified.
    • getDesc

      public String 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

      public String toString()
      Overrides:
      toString in class Object
    • getPlainDesc

      public String getPlainDesc()
      Returns the first description found
    • getCumulativePlainDesc

      public String getCumulativePlainDesc()
      Returns:
      the description of the first cumulative TargetRollModifier
    • getLastPlainDesc

      public String getLastPlainDesc()
      Returns the last description found
    • addModifier

      public void addModifier(int value, String desc)
      Adds a new cumulative modifier of the given value and description.
      Parameters:
      value - The modifier value, e.g. +2 or -1
      desc - A short description of the modifier
    • doNothing

      public void doNothing()
      Does not do anything, necessary because Java does not have a "noop" function.
    • addModifier

      public void addModifier(int value, String desc, boolean cumulative)
      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 -1
      desc - A short description of the modifier
      cumulative - True when this modifier is cumulative
    • addModifier

      public void addModifier(TargetRollModifier modifier)
      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

      public TargetRollModifier removeModifier(String fragment)
      Attempts to remove and return (if needed) the first mod that matches the provided string
      Parameters:
      fragment - of mod description to match
    • removeModifiers

      public List<TargetRollModifier> removeModifiers(List<String> fragments)
      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

      public void append(TargetRoll other)
      Append another TargetRoll to the end of this one
    • append

      public void append(TargetRoll other, boolean appendNonCumulative)
      Append another TargetRoll to the end of this one, possibly discarding non-cumulative modifier in the other one.
      Parameters:
      other - the TargetRoll to append
      appendNonCumulative - 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.