Module gameaction :: Class GameAction
[hide private]
[frames] | no frames]

Class GameAction

source code


Every GameActor has, at any given time, a list of possible actions from which they can choose. Some of these possibilities may be intrinsic in the actor, while others are made possible by GameObjects (e.g. a weapon), by other actors (e.g. interaction) or a GameContext (e.g. searching a room).

A GameAction is an action possibility that has been associated with a GameActor. It has attributes that describe and quantify its effects. When the GameAction's act() method is called, it computes probabilities and strengths (based on attributes of the actor and enabling artifact) and calls the target's accept_action() handler, which will determine and return the results.

Instance Methods [hide private]
 
__init__(self, source, verb)
create a new GameAction
source code
 
__str__(self)
return a string representation of our verb and its attributes
source code
 
act(self, initiator, target, context)
Initiate an action against a target
source code
 
__get_list(self, name, size)
read specified attribute, lex its (comma-separated) values into a list
source code
 
__accuracy(self, verb, base, initiator)
helper to compute accuracy of this attack, based on the supplied base ACCURACY plus any initiator ACCURACY(.subtype) bonus(es).
source code
 
__damage(self, verb, base, initiator)
helper to compute the damage of this attack, based on the supplied base DAMAGE plus any initiator DAMAGE(.subtype) bonus(es).
source code
 
__power(self, verb, base, initiator)
helper to compute the power of this action, based on the supplied base POWER plus any initiator POWER.verb/POWER.verb.subtype bonuses
source code
 
__stacks(self, verb, base, initiator)
helper to compute the stacks of this action, based on the supplied base STACKS plus any initiator STACKS.verb/STACKS.verb.subtype bonuses
source code

Inherited from base.Base: get, set

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Instance Variables [hide private]
  attributes
(dict) of <name,value> pairs
  source
(GameObject) that delivers this action
  verb
(string) simple or sub-classed name(s)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source, verb)
(Constructor)

source code 

create a new GameAction

Parameters:
  • source - (GameObject) instrument for the action
  • verb - (string) the name of the action(s)
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

return a string representation of our verb and its attributes

Overrides: object.__str__

act(self, initiator, target, context)

source code 

Initiate an action against a target

If the verb is a concatenation (list of simple/sub-classed verbs), split it and process each action separately (stopping if one of them fails).

This (base-class) act() method knows how to process (a list of) simple or sub-typed verbs that are simply a matter of looking up initiator bonus values, adding them up, and calling the target's accept_action() handler, passing:

  • the GameAction (with all of its attributes)
  • the initiating GameActor
  • the GameContext in which this is taking place

When the target is called, the GameAction attributes will include (for ATTACK verbs):

  • TO_HIT: 100 + sum of action's and actor's ACCURACY
  • DAMAGE: sum of rolls against actions's and actor's DAMAGE

for non-attack verbs:

  • TO_HIT: 100 + the action's and initiator's POWER
  • STACKS: sum of rolls against actions's & initiator's STACKS

Actions that require more complex processing (before calling the target) must be implemented (by additional code in a sub-class that extends this method (at least for the verbs in question)

Parameters:
  • initiator - (GameActor) initiating the action
  • target - (GameObject) target of the action
  • context - (GameContext) in which this is happening
Returns:
(string) description of the results (returned from the target)

__get_list(self, name, size)

source code 

read specified attribute, lex its (comma-separated) values into a list

Parameters:
  • name - (string) name of attribute to be looked up and split
  • size - (int) length of desired list
Returns:
(list of strings)
  • if no value is found, a list of Nones will be returned
  • if there is only single value, it will be replicated the specified number of times

__accuracy(self, verb, base, initiator)

source code 

helper to compute accuracy of this attack, based on the supplied base ACCURACY plus any initiator ACCURACY(.subtype) bonus(es).

Parameters:
  • verb - (string) attack verb
  • base - (int) accuracy (from the action)
  • initiator - (GameActor) who is initiating the attack
Returns:
(int) probability of hitting

__damage(self, verb, base, initiator)

source code 

helper to compute the damage of this attack, based on the supplied base DAMAGE plus any initiator DAMAGE(.subtype) bonus(es).

Parameters:
  • verb - (string) attack verb
  • base - (string) dice formula for base damage
  • initiator - (GameActor) who is initiating the attack
Returns:
(int) total damage

__power(self, verb, base, initiator)

source code 

helper to compute the power of this action, based on the supplied base POWER plus any initiator POWER.verb/POWER.verb.subtype bonuses

Parameters:
  • verb - (string) action verb
  • base - (int) base power (from action)
  • initiator - (GameActor) who is sending the condition
Returns:
(int) total probability of hitting

__stacks(self, verb, base, initiator)

source code 

helper to compute the stacks of this action, based on the supplied base STACKS plus any initiator STACKS.verb/STACKS.verb.subtype bonuses

Parameters:
  • verb - (string) action verb
  • base - (string) dice formula for base stacks
  • initiator - (GameActor) who is sending the condition
Returns:
(int) total number of stacks

Instance Variable Details [hide private]

verb

(string) simple or sub-classed name(s)

verbs may be simple or sub-classed (with subtypes):

  • SEARCH
  • VERBAL.INTIMMIDATE
  • ATTACK.STAB

attributes to be set by client after instantiation:

  • ATTACK verbs are expected to have ACCURACY (to-hit percentage) and DAMAGE (dice formula) attributes.
  • non-ATTACK verbs are expected to have POWER (to-hit percentage) and STACKS (dice formulat for instances to attempt/deliver) attributes.

A verb can also be a plus-separated concatenation of simple and/or sub-classed verbs. If a passed verb contains multiple (plus-separated) terms, the ACCURACY, DAMAGE, POWER, and STACKS attributes are each assumed to be comma-separated lists with the same number of terms.

Example:

  • verb="ATTACK.STAB+ATTACK.POISON"
  • ACCURACY=60,40
  • DAMAGE=D6,3D4

If there are multiple verbs but only a single value, that single value should be used for each verb.