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.
- There is currently no way to indicate that an attack as any sort of ‘to hit bonus’. This will be included in the next revision
- The generateDamage method will return a tuple of integers, not one integer. Currently it is possible for a sword that does 1d6 of damage with 1d4 of fire damage, but if this sword is used against a combatant with a defense with fire invulnerability all of the damage will be lost, instead of just the 1d4 of fire damage that should be stopped.
- If you call myAttack = Attack(‘this’, buttockprodding=‘mightily’) Attack will raise an error, but not an Exception Class object. I’ll add this in the next revision
- Another limitation on the Attack class (and the way Damage Managers work right now) is that one attack can only have one effect. This is usually fine, but some people will probably want a sword that poisons enemies while zapping them with electricity. Think of most of the cool weapons from Diablo 2, they can do lots of stuff. In short, the Attack.Effect will become a list instead of a single string.