Class Monster
java.lang.Object
Monster
- Direct Known Subclasses:
Character
Monster (hostile or benign creature).
- Since:
- 2014-05-20
-
Field Summary
Modifier and TypeFieldDescription(package private) Alignment
(package private) int
(package private) Attack
private static final int
Sides on standard hit dice.(package private) int
(package private) Set<SpecialType>
(package private) int
(package private) char
(package private) int
private static final boolean
Is fighting while swallowed in another monster allowed?(package private) Dice
(package private) float
(package private) int
(package private) Monster
(package private) int
(package private) int
(package private) Monster
private static final int
Maximum enemies who can melee us at once.(package private) int
(package private) int
(package private) Dice
(package private) Monster
(package private) String
(package private) String
(package private) Set<SpecialType>
(package private) String
(package private) AbstractMap<SpecialType,
Integer> (package private) SpellMemory
(package private) int
(package private) char
(package private) char
static final int
Sentinel value for undefined EHD in database. -
Constructor Summary
ConstructorDescriptionCreates a prototype monster from text file specification.Very basic constructor (for testing).Fairly basic constructor (for testing).Constructor (copy). -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addCondition
(SpecialType type) Add a condition suffered from a special ability.private void
addFixedSpellsPerLevel
(int maxLevel, int numPerLevel) Add a fixed number of spells per level.private void
Add some special qualifiers based on name or type.protected void
addSpecial
(SpecialType type) Add a special ability (no parameter).protected void
addSpecial
(SpecialType type, int param) Add a special ability.void
addToKillTally
(int num) Add to kill tally.private void
addTwoSpellsPerLevel
(int maxLevel) Add the default two spells per level for monsters.void
addXP
(int xp) void
protected void
Bound current hit points.protected boolean
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.private boolean
Can this monster eat some kind of equipment?private boolean
canEatEquipment
(Equipment equip) Can this monster eat a given type of equipment?void
catchCondition
(SpecialType condition, int casterLevel, int saveMod) Take a given condition unless we resist.void
catchDispel
(Party party) Catch a dispel magic effect.void
catchEnergy
(EnergyType energy, int damage, SavingThrows.Type saveType, int casterLevel) Take energy damage; save for half.private void
catchEquipmentLoss
(Equipment equip) A piece of this creature's equipment must save or be lost.private void
catchLevelDrain
(int levelLoss, int casterLevel) Take level energy drain unless we resist.private boolean
Check if we're attached to some host.private boolean
checkBreathWeapon
(Party enemy) Check for a breath weapon attack.private boolean
checkCastSpellInMelee
(Party friends, Party enemies) Check casting an attack spell in melee.private boolean
checkCastSpellPreMelee
(Party friends, Party enemies) Check casting an attack spell before melee.private int
checkChopResistance
(Monster target, int damage) Check for chop resistance on target.private boolean
Check if concentration spell costs our turn.private boolean
checkConfusion
(Party party) Check if we are confused on our turn to attack.private boolean
checkControl
(Party friends, Party enemies) Check if our puppetry control has lapsed.private boolean
checkDrawNewWeapon
(Party enemies) Check if we need to draw a new weapon mid-fight.private boolean
checkHandicaps
(Party friends) Check for handicap conditions.private boolean
checkManyEyesSalvo
(Party enemy) Are we a beholder casting eye-functions in melee?private void
Regenerate hit points if appropriate.private boolean
checkResistMagic
(int casterLevel) Check if we specially resist a magic spell.private void
checkSlowing
(Party enemy) Cast slow on one of the enemy.private void
checkSpecialOnHit
(Monster target, int totalRoll, boolean isLastAttack) Check for special ability triggers when we hit.private boolean
checkSpecialsInMelee
(Party friends, Party enemies) Check for special ability use in melee.private boolean
Check if we are swallowed in another creature.private boolean
Check if we are entangled in webs on our turn.void
void
conjureElemental
(Party party) Conjure an Elemental under our control.private void
Drain blood from host.private void
Constrict host for damage.private void
doManyEyesSalvo
(Party enemy) Beholder executes its many-eyes attacks.private void
Rend our host.private void
Smother our host.void
private void
eatEquipment
(Monster target) Eat one piece of target equipment, if available.private String
exchangeEnd
(String s, int toCut, String newEnd) Cut end of string and replace with another.int
getAbilityBonus
(Ability ability) Get an ability score bonus/modifier.int
getAbilityScore
(Ability ability) Ability score defaults for a monster.int
getAC()
getArmor()
int
private SpecialType
Get our attachment ability (if any).private int
getAttackRate
(boolean isSweeping) Get the current attack rate.getBestAttackSpell
(Party enemies, boolean areaEffect) Get the best castable attack spell.private int
getBreathVictims
(Party enemy, int maxVictimsByArea) Compute number of victims hit by breath weapon.private SpecialType
Get our breath weapon (if any).private int
Get a dragon's age category.int
getEHD()
private String
Identify EHD as a string.char
int
private SpecialType
Get our gaze weapon (if any).int
getHD()
private String
Make short hit dice descriptor from record.int
int
int
getHP()
int
int
int
getLevel()
protected int
Find what level of magic-to-hit we can strike.int
private int
getMaxVictimsInCone
(int length) Compute maximum number of victims in a cone area.int
Get current movement rate.int
getMV()
getNameWithNum
(int number) Get singular or plural name with number tag.getRace()
private String
Get plural form for this monster's racial type.private int
Add up fixed save modifiers for this monster.private int
getSaveModsVsCondition
(SpecialType condition) Add up save modifiers vs.private int
getSaveModsVsEnergy
(EnergyType energy) Add up save modifiers vs.private int
getSpecialParam
(SpecialType type) Get the parameter for a given special ability.Get this monster's spell memory.private SpecialType
Get our summons ability (if any).protected int
int
char
int
Generate random treasure value by treasure type, for one monster, scaled by nominal number appearing.char
getType()
int
Get the XP award value for defeating this monster.private boolean
Does this monster have any castable spells?boolean
hasCondition
(SpecialType type) Check if we suffer from a given condition.private boolean
Check if we suffer from a disabling condition.protected boolean
protected boolean
private boolean
hasSpecial
(SpecialType type) Check if this monster has a given type of special ability.boolean
Does this monster know any spells?private boolean
Does this creature have undead-style immunities?boolean
Return if this monster has an undefined EHD.private void
Count current heads for many-headed types.private int
hitModifier
(Monster target) Return hit modifier against a target.boolean
Check if the monster is out of the fight.void
void
Initialize breath weapon charges.private boolean
isFlamingWeapon
(Equipment equip) Is this equipment a flaming weapon?boolean
isImmuneToCondition
(SpecialType condition) Check if we are immune to a given condition.boolean
isImmuneToEnergy
(EnergyType energy) Is this monster immune to this energy type?boolean
Check if we are immune to all magic.boolean
Check if we are subject to more melee attacks.boolean
isPerson()
Does this creature count as a person? (c.f., charm, hold spells)private boolean
isResistantToEnergy
(EnergyType energy) Is this monster resistant to this energy type?private boolean
isVulnerableToEnergy
(EnergyType energy) Is this monster extra-vulnerable to this energy type?private void
Lose concentration when taking damage.protected void
protected void
Lose a level (e.g., energy drain).static void
Main test method.void
makeSpecialAttack
(Party friends, Party enemy) Make one special attack on an enemy party.private void
Memorize spells for a monster that has them.private void
mindBlastArea
(Party enemy, int number) Apply mind blast to enemy party numbers.private Attack
parseAttackRoutine
(String atkRate, String damageDesc) Parse attack routine from rate and damage.private int
Parse a dragon's age value from the name.private int
Parse the EHD value (possibly undefined).private float
parseFloat
(String s) Parse a floating-point string safely.private Dice
Parse hit dice record from short descriptor.private void
removeCondition
(SpecialType type) Remove a condition of a given special type.private void
Roll a dragon's age category, if not set already.private void
Roll hit points from hit dice.private boolean
rollSave
(SavingThrows.Type type) Roll a saving throw with no modifier.protected boolean
rollSave
(SavingThrows.Type type, int modifier) Roll a saving throw with modifier.void
setAlignment
(Alignment align) private void
Attach ourselves to some creature (e.g., blood drain).void
Set to perfect health.private void
Parse special ability list from descriptor string.Short String representation of this monster.private void
singleAttack
(Attack attack, Monster target, boolean last) Make one attack on another creature.spawn()
Spawn a new monster of this type, with different hit points.void
summonMinions
(Party party) Summon any minions to our party.protected void
takeAbilityDamage
(Ability a, int n) private void
takeDamage
(int damage) Take damage (minimum 0 hp).private void
takeEnergyDamage
(EnergyType energy, int damage) Take a given amount of energy damage.void
Take our turn against an enemy party.private void
throwCondition
(Monster target, SpecialType condition) Try to force a condition on one enemy monster (no save modifier).private void
throwCondition
(Monster target, SpecialType condition, int saveMod) Try to force a condition on one enemy monster.private void
throwConditionArea
(Party enemy, int number, SpecialType condition) Try to force a condition on multiple enemy party numbers.private void
throwEnergy
(Monster target, int damage, EnergyType energy, SavingThrows.Type saveType) Try to force energy damage to one enemy monster.private void
throwEnergyArea
(Party enemy, int number, int damage, EnergyType energy, SavingThrows.Type saveType) Try to force energy damage to multiple enemy party numbers.private void
throwLevelDrain
(Monster target, int levelLoss) Try to force level energy drain to one enemy monster.toString()
Identify this monster as a stat-block string.private boolean
tryCastAttackSpell
(Party friends, Party enemies, boolean area) Try to cast an attack spell at enemy group.private boolean
useSweepAttacks
(Party enemies) Check if we should be making sweep attacks.boolean
Remove a spell from memory.void
-
Field Details
-
BASE_HIT_DIE
private static final int BASE_HIT_DIESides on standard hit dice.- See Also:
-
MAX_MELEERS
private static final int MAX_MELEERSMaximum 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_EHDSentinel value for undefined EHD in database.- See Also:
-
FIGHT_SWALLOWED
private static final boolean FIGHT_SWALLOWEDIs 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
AbstractMap<SpecialType,Integer> specialValues -
spellMemory
SpellMemory spellMemory
-
-
Constructor Details
-
Monster
Very basic constructor (for testing). -
Monster
Fairly basic constructor (for testing). -
Monster
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
Constructor (copy).
-
-
Method Details
-
getRace
-
getSourceBook
-
getNumberAppearing
-
getArmorClass
public int getArmorClass() -
getHitPoints
public int getHitPoints() -
getMaxHitPoints
public int getMaxHitPoints() -
getInLairPct
public int getInLairPct() -
getHitDice
-
getHitDiceNum
public int getHitDiceNum() -
getLevel
public int getLevel() -
getTreasureType
public char getTreasureType() -
getAttack
-
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
-
clearTimesMeleed
public void clearTimesMeleed() -
incTimesMeleed
public void incTimesMeleed() -
getArmor
-
getShield
-
getWeapon
-
drawBestWeapon
-
boostMagicItemsOneLevel
public void boostMagicItemsOneLevel() -
zeroAbilityDamage
public void zeroAbilityDamage() -
addXP
public void addXP(int xp) -
loseEquipment
-
takeAbilityDamage
-
hasNullAbilityScore
protected boolean hasNullAbilityScore() -
hasFeat
-
getSweepRate
protected int getSweepRate() -
parseHitDice
Parse hit dice record from short descriptor. -
getHDString
Make short hit dice descriptor from record. -
parseAttackRoutine
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
Parse the EHD value (possibly undefined). -
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
Take our turn against an enemy party. -
checkSpecialsInMelee
Check for special ability use in melee.- Returns:
- true if our turn is consumed (no melee attacks)
-
checkHandicaps
Check for handicap conditions.- Returns:
- true if we are unable to take a normal action
-
useSweepAttacks
Check if we should be making sweep attacks. -
getAttackRate
private int getAttackRate(boolean isSweeping) Get the current attack rate. -
singleAttack
Make one attack on another creature. -
canAttack
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
Return hit modifier against a target.- Returns:
- Modifier to hit.
-
checkChopResistance
Check for chop resistance on target.- Returns:
- Adjusted damage.
-
checkSpecialOnHit
Check for special ability triggers when we hit. -
makeSpecialAttack
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
Add a special ability (no parameter). -
addSpecial
Add a special ability. -
hasSpecial
Check if this monster has a given type of special ability. -
getSpecialParam
Get the parameter for a given special ability. -
addCondition
Add a condition suffered from a special ability. -
removeCondition
Remove a condition of a given special type. -
hasCondition
Check if we suffer from a given condition. -
hasDisablingCondition
private boolean hasDisablingCondition()Check if we suffer from a disabling condition. -
isImmuneToCondition
Check if we are immune to a given condition. -
catchCondition
Take a given condition unless we resist. -
throwCondition
Try to force a condition on one enemy monster. -
throwCondition
Try to force a condition on one enemy monster (no save modifier). -
throwConditionArea
Try to force a condition on multiple enemy party numbers. -
catchEnergy
Take energy damage; save for half. -
takeEnergyDamage
Take a given amount of energy damage. -
isImmuneToEnergy
Is this monster immune to this energy type? -
isResistantToEnergy
Is this monster resistant to this energy type? -
isVulnerableToEnergy
Is this monster extra-vulnerable to this energy type? -
throwEnergy
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
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
Get our breath weapon (if any). -
getGazeWeapon
Get our gaze weapon (if any). -
getSummonsAbility
Get our summons ability (if any). -
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
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
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
Apply mind blast to enemy party numbers. Saving throws simplified; assume at long range. -
checkSlowing
Cast slow on one of the enemy. -
summonMinions
Summon any minions to our party. -
conjureElemental
Conjure an Elemental under our control. -
catchDispel
Catch a dispel magic effect. -
checkConfusion
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
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
Roll a saving throw with no modifier. -
rollSave
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
Add up save modifiers vs. a given condition for this monster. -
getSaveModsVsEnergy
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
Identify this monster as a stat-block string. -
shortString
Short String representation of this monster. -
getRacePlural
Get plural form for this monster's racial type. -
exchangeEnd
Cut end of string and replace with another. -
getNameWithNum
Get singular or plural name with number tag. -
getEHDString
Identify EHD as a string. -
parseFloat
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
Ability score defaults for a monster. -
getAbilityBonus
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
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
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
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
Check casting an attack spell in melee. Only targeted spells are allowed (not area-effects).- Returns:
- true if we cast a spell.
-
wipeSpellFromMemory
Remove a spell from memory. Scan all classes to find a copy to remove. -
checkManyEyesSalvo
Are we a beholder casting eye-functions in melee? -
doManyEyesSalvo
Beholder executes its many-eyes attacks. References available castable spells. -
hasUndeadImmunity
private boolean hasUndeadImmunity()Does this creature have undead-style immunities? -
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
Can this monster eat a given type of equipment? -
eatEquipment
Eat one piece of target equipment, if available. -
catchEquipmentLoss
A piece of this creature's equipment must save or be lost. -
checkDrawNewWeapon
Check if we need to draw a new weapon mid-fight.- Returns:
- true if we drew a new weapon
-
isFlamingWeapon
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
Check if our puppetry control has lapsed.- Returns:
- true if we lose our turn
-
main
Main test method.
-