The Incomplete Works of Josh English

A Polymath in Pursuit of Publication

On this page: Introduction | Documentation | Attack Exceptions | Class Attributes | Instance Attributes | Class Methods | Using Attack | Subclassing the Attack Class | Future Plans

Introduction

The Attack class is the template for any attack you can come up with. Fighting (as in SlugFest 0 ), weapons, spells, special attacks like a dragon tail slap, a medusa paralyzing glare. Anything.

Before creating your own Attacks, it’s best to subclass the Attack class. The Attack class uses three enumerated lists as class attributes (meaning that they are defined for every instance of the class, and changing them in the instance changes them in every other instance of that class): DamageTypes, ElementTypes, and EffectTypes. Python does not have an enumerated type, but I found one on the internet that I adapted a bit and included as a support file for Combat . These enumerated types allow personalization of the items.

Documentation

Attack Exceptions

The following Exceptions are relevant to the Attack class:

BadRoll

This error indicates that a roll string was not acceptable to DieRoller

BadType

This error indicates that a damage type string was not in DamageTypes

BadEffect

This error indicates that an effect type string was not in EffectTypes

BadElement

This error indicates that an element type string was not in ElementTypes

Class Attributes

These are class attributes, meaning that they are defined for every instance of the class, and changing them in the instance changes them in every other instance of that class. It’s safest to declare these when subclassing the Attack class.

DamageTypes

The DamageTypes enumerated type represent physical types of damage. In D&D they are ‘Bludgeoning,' ‘Piercing,' and ‘Slashing,'. To simulate this you would also include ‘Spell’ as well.

ElementTypes

The ElementTypes enumerated type represent non-physical types of damage: Fire, Acid, Poison, Good, Evil, etc.

EffectTypes

The EffectTypes enumerated type represent abilities of an attack that alters the attributes of one of the combatants. Usually an effect code will add a temporary effect to a combatant or change something about that combatant. If Combatants have a level attribute, a vampiric attack may reduce this level, which may have other effects on the combatant.

Instance Attributes

The titles are the attributes. The parenthesis indicate shortcuts that can be used when creating instances of the Attack class.

BaseDamageRoll (bdr)

This string needs to be a Die Roll string. See the Die Roller page for details. This determines how much damabe the attack method does on it’s own. If not declared during initiation it defaults to ‘d1’ (in other words, does one point of damage).

BaseDamageType (bdt)

This is a string that must be in the class’ DamageTypes list or an error will be raised. If it this is not declared during initiation, the first item in the DamageTypes list will be used as the default value.

BaseElementType (bde)

This is a string that must be in the class’ ElementTypes list or an error will be raised. If it this is not declared during initiation, the first item in the ElementTypes list will be used as the default value.

SpecialDamageRoll (sdr)

This string needs to be a Die Roll string. See the Die Roller page for details. This defaults to ‘d0’ (in other words, doesn’t do any damage).

SpecialDamageType (sdt)

This is a string that has the same limitations as BaseDamageType .

SpecialElementType (sde)

This is a string that has the same limiations as BaseElementTypes .

Effect

This string is limited by the class’ EffectTypes list. The damage manager should check this effect code to see what happens. If it is not declared during initiation, the first item in the list is used as a default.

Class Methods

There is one public method that is used most often after initiation.

generateDamage()

This returns an actual number of points of damage. It uses Die Roller to roll the BaseDamageRoll and the SpecialDamageRoll and returns the sum. In the future this will return a tuple of both rolls.

The remaining seven methods are used during initiation, but can be called after an Attack instance is created:

SetBaseDamageRoll (Die Roll string)

SetBaseDamageType (Damage Type string)

SetBaseElement (Element Type string)

SetSpecialDamageRoll (Die Roll string)

SetSpecialDamageType (Damage Type string)

SetSpecialElement (Element Type string)

SetEffect (Effect type string)

Using Attack

Subclassing the Attack Class

The Attack class doesn’t have any interesting in the default DamageType , ElementType , or EffectTypes objects. Subclassing Attack is the safest way to do this:

class MyAttack(Combat.Attack):
	DamageTypes = Combat.enum('Crushing','Stabbing','Grappling','Slapping')
	EffectTypes = Combat.enum('hurt','stumble','kochance')
	ElementTypes = Combat.enum('normal','fire','acid','magic')
	
	def __init__(self,name,**kw):
		Combat.Attack.__init__(self,name,**kw)

Creating Instances

Now to create individual attacks:

NoAttack = SlugfestAttack('No attack',bdr='d0')
Slap = SlugfestAttack('Slap',bdr='d2',bdt='Slapping')

Note the shortcuts ‘bdr’ and ‘bdt’. These shortcuts mean less typing, which I think is a good thing.

Future Plans

There are a few things I want to add to future versions, which will mean recoding in lots of places.