Class Monster

Direct Known Subclasses:
Character

public class Monster extends Object
Monster (hostile or benign creature).
Since:
2014-05-20
  • Field Details

    • BASE_HIT_DIE

      private static final int BASE_HIT_DIE
      Sides on standard hit dice.
      See Also:
    • MAX_MELEERS

      private static final int MAX_MELEERS
      Maximum enemies who can melee us at once. As per 1E DMG p. 69 (assumes same-size attackers)
      See Also:
    • UNDEFINED_EHD

      public static final int UNDEFINED_EHD
      Sentinel value for undefined EHD in database.
      See Also:
    • FIGHT_SWALLOWED

      private static final boolean FIGHT_SWALLOWED
      Is fighting while swallowed in another monster allowed?
      See Also:
    • race

      String race
    • sourceBook

      String sourceBook
    • type

      char type
    • environment

      char environment
    • numberAppearing

      Dice numberAppearing
    • armorClass

      int armorClass
    • moveInches

      int moveInches
    • hitDice

      Dice hitDice
    • inLairPct

      int inLairPct
    • treasureType

      char treasureType
    • attack

      Attack attack
    • alignment

      Alignment alignment
    • hitDiceDecimal

      float hitDiceDecimal
    • equivalentHitDice

      int equivalentHitDice
    • hitPoints

      int hitPoints
    • maxHitPoints

      int maxHitPoints
    • dragonAge

      int dragonAge
    • breathCharges

      int breathCharges
    • killTally

      int killTally
    • timesMeleed

      int timesMeleed
    • host

      Monster host
    • master

      Monster master
    • puppet

      Monster puppet
    • specialsString

      String specialsString
    • specialList

      Set<SpecialType> specialList
    • conditionList

      Set<SpecialType> conditionList
    • specialValues

    • spellMemory

      SpellMemory spellMemory
  • Constructor Details

    • Monster

      public Monster(String race, int AC, int MV, int hitDice, int damageDice)
      Very basic constructor (for testing).
    • Monster

      public Monster(String race, int AC, int MV, Dice hitDice, Attack attack)
      Fairly basic constructor (for testing).
    • Monster

      public Monster(String[] s)
      Creates a prototype monster from text file specification. Some values are left undefined by this method: E.g., dragon random ages (and hp), spells memorized. For those, see the spawn() function.
      Parameters:
      s - specification string array.
    • Monster

      public Monster(Monster src)
      Constructor (copy).
  • Method Details

    • getRace

      public String getRace()
    • getSourceBook

      public String getSourceBook()
    • getNumberAppearing

      public Dice getNumberAppearing()
    • getArmorClass

      public int getArmorClass()
    • getHitPoints

      public int getHitPoints()
    • getMaxHitPoints

      public int getMaxHitPoints()
    • getInLairPct

      public int getInLairPct()
    • getHitDice

      public Dice getHitDice()
    • getHitDiceNum

      public int getHitDiceNum()
    • getLevel

      public int getLevel()
    • getTreasureType

      public char getTreasureType()
    • getAttack

      public Attack getAttack()
    • getAlignment

      public Alignment getAlignment()
    • getType

      public char getType()
    • getEquivalentHitDice

      public int getEquivalentHitDice()
    • getEnvironment

      public char getEnvironment()
    • getKillTally

      public int getKillTally()
    • getTimesMeleed

      public int getTimesMeleed()
    • getAC

      public int getAC()
    • getHD

      public int getHD()
    • getHP

      public int getHP()
    • getMV

      public int getMV()
    • getEHD

      public int getEHD()
    • setAlignment

      public void setAlignment(Alignment align)
    • clearTimesMeleed

      public void clearTimesMeleed()
    • incTimesMeleed

      public void incTimesMeleed()
    • getArmor

      public Armor getArmor()
    • getShield

      public Armor getShield()
    • getWeapon

      public Weapon getWeapon()
    • drawBestWeapon

      public void drawBestWeapon(Monster m)
    • boostMagicItemsOneLevel

      public void boostMagicItemsOneLevel()
    • zeroAbilityDamage

      public void zeroAbilityDamage()
    • addXP

      public void addXP(int xp)
    • loseEquipment

      protected void loseEquipment(Equipment e)
    • takeAbilityDamage

      protected void takeAbilityDamage(Ability a, int n)
    • hasNullAbilityScore

      protected boolean hasNullAbilityScore()
    • hasFeat

      protected boolean hasFeat(Feat feat)
    • getSweepRate

      protected int getSweepRate()
    • parseHitDice

      private Dice parseHitDice(String s)
      Parse hit dice record from short descriptor.
    • getHDString

      private String getHDString()
      Make short hit dice descriptor from record.
    • parseAttackRoutine

      private Attack parseAttackRoutine(String atkRate, String damageDesc)
      Parse attack routine from rate and damage.
    • setSpecialAbilities

      private void setSpecialAbilities()
      Parse special ability list from descriptor string.
    • addImpliedSpecials

      private void addImpliedSpecials()
      Add some special qualifiers based on name or type.
    • parseEHD

      private int parseEHD(String s)
      Parse the EHD value (possibly undefined).
    • spawn

      public Monster spawn()
      Spawn a new monster of this type, with different hit points.
    • rollHitPoints

      private void rollHitPoints()
      Roll hit points from hit dice.
    • takeDamage

      private void takeDamage(int damage)
      Take damage (minimum 0 hp).
    • horsDeCombat

      public boolean horsDeCombat()
      Check if the monster is out of the fight.
    • setPerfectHealth

      public void setPerfectHealth()
      Set to perfect health.
    • boundHitPoints

      protected void boundHitPoints()
      Bound current hit points.
    • isOpenToMelee

      public boolean isOpenToMelee()
      Check if we are subject to more melee attacks.
    • takeTurn

      public void takeTurn(Party friends, Party enemies)
      Take our turn against an enemy party.
    • checkSpecialsInMelee

      private boolean checkSpecialsInMelee(Party friends, Party enemies)
      Check for special ability use in melee.
      Returns:
      true if our turn is consumed (no melee attacks)
    • checkHandicaps

      private boolean checkHandicaps(Party friends)
      Check for handicap conditions.
      Returns:
      true if we are unable to take a normal action
    • useSweepAttacks

      private boolean useSweepAttacks(Party enemies)
      Check if we should be making sweep attacks.
    • getAttackRate

      private int getAttackRate(boolean isSweeping)
      Get the current attack rate.
    • singleAttack

      private void singleAttack(Attack attack, Monster target, boolean last)
      Make one attack on another creature.
    • canAttack

      protected boolean canAttack(Monster target)
      Can we feasibly attack this target in melee? This needs to be deterministic (no random rolls), because it's checked by the FightManager to stop a fight.
    • getMagicHitLevel

      protected int getMagicHitLevel()
      Find what level of magic-to-hit we can strike. This is overridden in a subclass.
    • hitModifier

      private int hitModifier(Monster target)
      Return hit modifier against a target.
      Returns:
      Modifier to hit.
    • checkChopResistance

      private int checkChopResistance(Monster target, int damage)
      Check for chop resistance on target.
      Returns:
      Adjusted damage.
    • checkSpecialOnHit

      private void checkSpecialOnHit(Monster target, int totalRoll, boolean isLastAttack)
      Check for special ability triggers when we hit.
    • makeSpecialAttack

      public void makeSpecialAttack(Party friends, Party enemy)
      Make one special attack on an enemy party. Pre-melee, ranged-attack specials go here. Mostly uses just one ability (first one in monster list).
    • addSpecial

      protected void addSpecial(SpecialType type)
      Add a special ability (no parameter).
    • addSpecial

      protected void addSpecial(SpecialType type, int param)
      Add a special ability.
    • hasSpecial

      private boolean hasSpecial(SpecialType type)
      Check if this monster has a given type of special ability.
    • getSpecialParam

      private int getSpecialParam(SpecialType type)
      Get the parameter for a given special ability.
    • addCondition

      private void addCondition(SpecialType type)
      Add a condition suffered from a special ability.
    • removeCondition

      private void removeCondition(SpecialType type)
      Remove a condition of a given special type.
    • hasCondition

      public boolean hasCondition(SpecialType type)
      Check if we suffer from a given condition.
    • hasDisablingCondition

      private boolean hasDisablingCondition()
      Check if we suffer from a disabling condition.
    • isImmuneToCondition

      public boolean isImmuneToCondition(SpecialType condition)
      Check if we are immune to a given condition.
    • catchCondition

      public void catchCondition(SpecialType condition, int casterLevel, int saveMod)
      Take a given condition unless we resist.
    • throwCondition

      private void throwCondition(Monster target, SpecialType condition, int saveMod)
      Try to force a condition on one enemy monster.
    • throwCondition

      private void throwCondition(Monster target, SpecialType condition)
      Try to force a condition on one enemy monster (no save modifier).
    • throwConditionArea

      private void throwConditionArea(Party enemy, int number, SpecialType condition)
      Try to force a condition on multiple enemy party numbers.
    • catchEnergy

      public void catchEnergy(EnergyType energy, int damage, SavingThrows.Type saveType, int casterLevel)
      Take energy damage; save for half.
    • takeEnergyDamage

      private void takeEnergyDamage(EnergyType energy, int damage)
      Take a given amount of energy damage.
    • isImmuneToEnergy

      public boolean isImmuneToEnergy(EnergyType energy)
      Is this monster immune to this energy type?
    • isResistantToEnergy

      private boolean isResistantToEnergy(EnergyType energy)
      Is this monster resistant to this energy type?
    • isVulnerableToEnergy

      private boolean isVulnerableToEnergy(EnergyType energy)
      Is this monster extra-vulnerable to this energy type?
    • throwEnergy

      private void throwEnergy(Monster target, int damage, EnergyType energy, SavingThrows.Type saveType)
      Try to force energy damage to one enemy monster.
    • throwEnergyArea

      private void throwEnergyArea(Party enemy, int number, int damage, EnergyType energy, SavingThrows.Type saveType)
      Try to force energy damage to multiple enemy party numbers.
    • catchLevelDrain

      private void catchLevelDrain(int levelLoss, int casterLevel)
      Take level energy drain unless we resist.
    • throwLevelDrain

      private void throwLevelDrain(Monster target, int levelLoss)
      Try to force level energy drain to one enemy monster.
    • isImmuneToMagic

      public boolean isImmuneToMagic()
      Check if we are immune to all magic.
    • checkResistMagic

      private boolean checkResistMagic(int casterLevel)
      Check if we specially resist a magic spell.
      Returns:
      true if we resist or have immunity to a spell.
    • getBreathWeapon

      private SpecialType getBreathWeapon()
      Get our breath weapon (if any).
    • getGazeWeapon

      private SpecialType getGazeWeapon()
      Get our gaze weapon (if any).
    • getSummonsAbility

      private SpecialType getSummonsAbility()
      Get our summons ability (if any).
    • getAttachmentAbility

      private SpecialType getAttachmentAbility()
      Get our attachment ability (if any).
    • checkAttachment

      private boolean checkAttachment()
      Check if we're attached to some host. If so, do special violence instead of a normal attack.
      Returns:
      true if interrupted from making a normal attack
    • doBloodDrain

      private void doBloodDrain()
      Drain blood from host.
    • doConstriction

      private void doConstriction()
      Constrict host for damage. This ability is used by serpent/tentacle-type monsters. Automatic initiation on any hit.
    • doRending

      private void doRending()
      Rend our host. This ability is used by animals like bears and cats. Requires high total hit score to initiate (25+) (book is nat 18+, converted here for convenience)
    • doSmothering

      private void doSmothering()
      Smother our host. This ability is used by Shambling Mounds and Lurkers Above. Requires high total hit score to initiate (25+) Then, damage and auto-death in a few rounds.
    • checkRegeneration

      private void checkRegeneration()
      Regenerate hit points if appropriate.
    • checkBreathWeapon

      private boolean checkBreathWeapon(Party enemy)
      Check for a breath weapon attack. Estimates max number hit for given area.
      Returns:
      Did we make a breath attack?
    • getMaxVictimsInCone

      private int getMaxVictimsInCone(int length)
      Compute maximum number of victims in a cone area. Following red dragon breath, cone width is one-third the length. We assume that number of targets is same as area. Hence: Targets = 1/2 * L * (1/3 * L) = L^2/6 (round up). See AreasOfEffect experiment images for confirmation.
    • getBreathVictims

      private int getBreathVictims(Party enemy, int maxVictimsByArea)
      Compute number of victims hit by breath weapon. After melee is engaged, we assume party is spread out, so at most we can hit half of enemy party (rounded up). Do not use this method for specials prior to melee.
    • mindBlastArea

      private void mindBlastArea(Party enemy, int number)
      Apply mind blast to enemy party numbers. Saving throws simplified; assume at long range.
    • checkSlowing

      private void checkSlowing(Party enemy)
      Cast slow on one of the enemy.
    • summonMinions

      public void summonMinions(Party party)
      Summon any minions to our party.
    • conjureElemental

      public void conjureElemental(Party party)
      Conjure an Elemental under our control.
    • catchDispel

      public void catchDispel(Party party)
      Catch a dispel magic effect.
    • checkConfusion

      private boolean checkConfusion(Party party)
      Check if we are confused on our turn to attack.
    • checkWebbing

      private boolean checkWebbing()
      Check if we are entangled in webs on our turn.
    • checkSwallowed

      private boolean checkSwallowed()
      Check if we are swallowed in another creature.
      Returns:
      true if we cannot fight
    • setHost

      private void setHost(Monster host)
      Attach ourselves to some creature (e.g., blood drain).
    • headCount

      private void headCount()
      Count current heads for many-headed types. Set one attack per full hit die.
    • loseLevel

      protected void loseLevel()
      Lose a level (e.g., energy drain). This is overridden in a subclass.
    • rollSave

      private boolean rollSave(SavingThrows.Type type)
      Roll a saving throw with no modifier.
    • rollSave

      protected boolean rollSave(SavingThrows.Type type, int modifier)
      Roll a saving throw with modifier. This is overridden in a subclass.
    • getSaveModsConstant

      private int getSaveModsConstant()
      Add up fixed save modifiers for this monster.
    • getSaveModsVsCondition

      private int getSaveModsVsCondition(SpecialType condition)
      Add up save modifiers vs. a given condition for this monster.
    • getSaveModsVsEnergy

      private int getSaveModsVsEnergy(EnergyType energy)
      Add up save modifiers vs. a given energy for this monster.
    • addToKillTally

      public void addToKillTally(int num)
      Add to kill tally.
    • getXPAward

      public int getXPAward()
      Get the XP award value for defeating this monster.
    • getTreasureValue

      public int getTreasureValue()
      Generate random treasure value by treasure type, for one monster, scaled by nominal number appearing. (Recommended for wilderness encounters only.)
    • hasUndefinedEHD

      public boolean hasUndefinedEHD()
      Return if this monster has an undefined EHD.
    • getMoveInches

      public int getMoveInches()
      Get current movement rate.
    • initBreathCharges

      public void initBreathCharges()
      Initialize breath weapon charges.
    • toString

      public String toString()
      Identify this monster as a stat-block string.
      Overrides:
      toString in class Object
    • shortString

      public String shortString()
      Short String representation of this monster.
    • getRacePlural

      private String getRacePlural()
      Get plural form for this monster's racial type.
    • exchangeEnd

      private String exchangeEnd(String s, int toCut, String newEnd)
      Cut end of string and replace with another.
    • getNameWithNum

      public String getNameWithNum(int number)
      Get singular or plural name with number tag.
    • getEHDString

      private String getEHDString()
      Identify EHD as a string.
    • parseFloat

      private float parseFloat(String s)
      Parse a floating-point string safely.
    • parseDragonAge

      private int parseDragonAge()
      Parse a dragon's age value from the name.
      Returns:
      the age bracket (1-6, or 0 if not given)
    • rollDragonAge

      private void rollDragonAge()
      Roll a dragon's age category, if not set already.
    • getDragonAge

      private int getDragonAge()
      Get a dragon's age category.
    • getAbilityScore

      public int getAbilityScore(Ability ability)
      Ability score defaults for a monster.
    • getAbilityBonus

      public int getAbilityBonus(Ability ability)
      Get an ability score bonus/modifier.
    • isPerson

      public boolean isPerson()
      Does this creature count as a person? (c.f., charm, hold spells)
    • hasSpells

      public boolean hasSpells()
      Does this monster know any spells?
    • hasCastableSpells

      private boolean hasCastableSpells()
      Does this monster have any castable spells?
    • getBestAttackSpell

      public Spell getBestAttackSpell(Party enemies, boolean areaEffect)
      Get the best castable attack spell. Search for viable spell that affects the most targets.
      Parameters:
      area - true if area-effect spell desired.
      Returns:
      the best spell in memory.
    • tryCastAttackSpell

      private boolean tryCastAttackSpell(Party friends, Party enemies, boolean area)
      Try to cast an attack spell at enemy group.
      Parameters:
      enemies - possible targets of attack spell.
      area - true if we want area-effect spell.
      Returns:
      true if we cast a spell.
    • checkCastSpellPreMelee

      private boolean checkCastSpellPreMelee(Party friends, Party enemies)
      Check casting an attack spell before melee. Look for area-effects first; then if none, try targeted.
      Returns:
      true if we cast a spell.
    • checkCastSpellInMelee

      private boolean checkCastSpellInMelee(Party friends, Party enemies)
      Check casting an attack spell in melee. Only targeted spells are allowed (not area-effects).
      Returns:
      true if we cast a spell.
    • wipeSpellFromMemory

      public boolean wipeSpellFromMemory(Spell s)
      Remove a spell from memory. Scan all classes to find a copy to remove.
    • checkManyEyesSalvo

      private boolean checkManyEyesSalvo(Party enemy)
      Are we a beholder casting eye-functions in melee?
    • doManyEyesSalvo

      private void doManyEyesSalvo(Party enemy)
      Beholder executes its many-eyes attacks. References available castable spells.
    • hasUndeadImmunity

      private boolean hasUndeadImmunity()
      Does this creature have undead-style immunities?
    • getSpellMemory

      public SpellMemory getSpellMemory()
      Get this monster's spell memory.
    • memorizeSpells

      private void memorizeSpells()
      Memorize spells for a monster that has them.
    • addFixedSpellsPerLevel

      private void addFixedSpellsPerLevel(int maxLevel, int numPerLevel)
      Add a fixed number of spells per level. The book idiom for early spell-casting monsters is to say, "use spells up to Nth level", and if detailed, indicate this means 2 spells per level (see Sup-I Titan, 1E MM Gold Dragon). We apply this standard by default.
    • addTwoSpellsPerLevel

      private void addTwoSpellsPerLevel(int maxLevel)
      Add the default two spells per level for monsters.
    • canEatEquipment

      private boolean canEatEquipment()
      Can this monster eat some kind of equipment?
    • canEatEquipment

      private boolean canEatEquipment(Equipment equip)
      Can this monster eat a given type of equipment?
    • eatEquipment

      private void eatEquipment(Monster target)
      Eat one piece of target equipment, if available.
    • catchEquipmentLoss

      private void catchEquipmentLoss(Equipment equip)
      A piece of this creature's equipment must save or be lost.
    • checkDrawNewWeapon

      private boolean checkDrawNewWeapon(Party enemies)
      Check if we need to draw a new weapon mid-fight.
      Returns:
      true if we drew a new weapon
    • isFlamingWeapon

      private boolean isFlamingWeapon(Equipment equip)
      Is this equipment a flaming weapon?
    • checkConcentration

      private boolean checkConcentration()
      Check if concentration spell costs our turn.
      Returns:
      true if we lose our turn
    • loseConcentration

      private void loseConcentration()
      Lose concentration when taking damage.
    • checkControl

      private boolean checkControl(Party friends, Party enemies)
      Check if our puppetry control has lapsed.
      Returns:
      true if we lose our turn
    • main

      public static void main(String[] args)
      Main test method.