1
2 """ This module implements the GameAction class """
3 from dice import Dice
4 from base import Base
5
6
8 """
9 Every GameActor has, at any given time, a list of possible actions
10 from which they can choose. Some of these possibilities may be
11 intrinsic in the actor, while others are made possible by GameObjects
12 (e.g. a weapon), by other actors (e.g. interaction) or a GameContext
13 (e.g. searching a room).
14
15 A GameAction is an action possibility that has been associated with
16 a GameActor. It has attributes that describe and quantify its effects.
17 When the GameAction's C{act()} method is called, it computes probabilities
18 and strengths (based on attributes of the actor and enabling artifact)
19 and calls the target's C{accept_action()} handler, which will determine
20 and return the results.
21
22 @ivar attributes: (dict) of <name,value> pairs
23 @ivar source: (GameObject) that delivers this action
24 @ivar verb: (string) simple or sub-classed name(s)
25
26 verbs may be simple or sub-classed (with subtypes):
27 - SEARCH
28 - VERBAL.INTIMMIDATE
29 - ATTACK.STAB
30
31 attributes to be set by client after instantiation:
32 - ATTACK verbs are expected to have ACCURACY (to-hit percentage) and
33 DAMAGE (dice formula) attributes.
34 - non-ATTACK verbs are expected to have POWER (to-hit percentage) and
35 STACKS (dice formulat for instances to attempt/deliver) attributes.
36
37 A verb can also be a plus-separated concatenation of simple and/or
38 sub-classed verbs. If a passed verb contains multiple (plus-separated)
39 terms, the ACCURACY, DAMAGE, POWER, and STACKS attributes are each assumed
40 to be comma-separated lists with the same number of terms.
41
42 Example:
43 - verb="ATTACK.STAB+ATTACK.POISON"
44 - ACCURACY=60,40
45 - DAMAGE=D6,3D4
46
47 If there are multiple verbs but only a single value, that single value
48 should be used for each verb.
49 """
51 """
52 create a new C{GameAction}
53 @param source: (GameObject) instrument for the action
54 @param verb: (string) the name of the action(s)
55 """
56
57
59 """
60 return a string representation of our verb and its attributes
61 """
62
63 - def act(self, initiator, target, context):
64 """
65 Initiate an action against a target
66
67 If the verb is a concatenation (list of simple/sub-classed verbs),
68 split it and process each action separately (stopping if one of
69 them fails).
70
71 This (base-class) C{act()} method knows how to process (a list of)
72 simple or sub-typed verbs that are simply a matter of looking up
73 initiator bonus values, adding them up, and calling the target's
74 C{accept_action()} handler, passing:
75 - the C{GameAction} (with all of its attributes)
76 - the initiating C{GameActor}
77 - the C{GameContext} in which this is taking place
78
79 When the target is called, the C{GameAction} attributes will
80 include (for ATTACK verbs):
81 - C{TO_HIT}: 100 + sum of action's and actor's C{ACCURACY}
82 - C{DAMAGE}: sum of rolls against actions's and actor's C{DAMAGE}
83 for non-attack verbs:
84 - C{TO_HIT}: 100 + the action's and initiator's C{POWER}
85 - C{STACKS}: sum of rolls against actions's & initiator's C{STACKS}
86
87 Actions that require more complex processing (before
88 calling the target) must be implemented (by additional
89 code in a sub-class that extends this method (at least
90 for the verbs in question)
91
92 @param initiator: (GameActor) initiating the action
93 @param target: (GameObject) target of the action
94 @param context: (GameContext) in which this is happening
95 @return: (string) description of the results (returned from the target)
96
97 """
98
99
100
101
102
103
104
106 """
107 read specified attribute, lex its (comma-separated) values into a list
108
109 @param name: (string) name of attribute to be looked up and split
110 @param size: (int) length of desired list
111 @return: (list of strings)
112 - if no value is found, a list of Nones will be returned
113 - if there is only single value, it will be replicated the
114 specified number of times
115 """
116
118 """
119 helper to compute accuracy of this attack, based on the supplied
120 base ACCURACY plus any initiator ACCURACY(.subtype) bonus(es).
121
122 @param verb: (string) attack verb
123 @param base: (int) accuracy (from the action)
124 @param initiator: (GameActor) who is initiating the attack
125 @return: (int) probability of hitting
126 """
127
128
129
130
131 - def __damage(self, verb, base, initiator):
132 """
133 helper to compute the damage of this attack, based on the supplied
134 base DAMAGE plus any initiator DAMAGE(.subtype) bonus(es).
135
136 @param verb: (string) attack verb
137 @param base: (string) dice formula for base damage
138 @param initiator: (GameActor) who is initiating the attack
139 @return: (int) total damage
140 """
141
142
143
144
145 - def __power(self, verb, base, initiator):
146 """
147 helper to compute the power of this action, based on the supplied
148 base POWER plus any initiator POWER.verb/POWER.verb.subtype bonuses
149
150 @param verb: (string) action verb
151 @param base: (int) base power (from action)
152 @param initiator: (GameActor) who is sending the condition
153 @return: (int) total probability of hitting
154 """
155
156
157
158
159
160 - def __stacks(self, verb, base, initiator):
161 """
162 helper to compute the stacks of this action, based on the supplied
163 base STACKS plus any initiator STACKS.verb/STACKS.verb.subtype bonuses
164
165 @param verb: (string) action verb
166 @param base: (string) dice formula for base stacks
167 @param initiator: (GameActor) who is sending the condition
168 @return: (int) total number of stacks
169 """
170
171
172
173
174