1
2 """ This module implements the (foundation) GameObject Class """
3 import sys
4 from random import randint
5 from base import Base
6 from gameaction import GameAction
7
8
10 """
11 This is the base class for all artifacts, actors, and contexts.
12 The abilities of this base class are:
13 - own a list of objects (which can be added and retrieved)
14 - return a list of GameActions that it enables
15 - accept and process non-ATTACK GameActions
16
17 @ivar objects: list of owned/contained GameObjects
18
19 objects can be I{hidden} in which case they might not be returned
20 """
21 - def __init__(self, name="actor", descr=None):
22 """
23 create a new GameObject
24 @param name: display name of this object
25 @param descr: for players description of this object
26 """
27
29 """
30 return the given name of this object
31 """
32
34 """
35 return a list of GameObjects contained in/owned by this GameObject
36
37 if an object is hidden (has a positive RESISTANCE.SEARCH) it may not
38 be visible unless
39 - it has been successfully found (SEARCH > 0)
40 - caller specifies that hidden objects should be returned
41
42 @param hidden: return only hidden objects
43 @return: list of discoverd GameOjects
44 """
45
46
47
48
50 """
51 return a named object from my inventory
52
53 @param name: (string) of the desired object
54 @return: first matching object (or None)
55 """
56
58 """
59 add another object to my C{objects} list (if not already there)
60 """
61
63 """
64 called by C{GameAction.act()} to receive GameAction, determine effects
65
66 NOTE: this base class cannot process ATTACK actions.
67 Those are processed by the C{GameActor} sub-class.
68 This base class can only process actions which (if successful),
69 increment the property who's name matches the action verb.
70
71 @param action: GameAction being performed
72 @param actor: GameActor initiating the action
73 @param context: GameContext in which action is occuring
74
75 NOTE: this base class makes no use of the C{actor} or C{context}
76 parameters, but they might be useful to a subc-class that could
77 process actions before passing them down to us.
78
79 @return: <(boolean) success, (string) description of the effect>
80 """
81
82
83
84
85
86
87
88
89
90
91
92
94 """
95 return list of C{GameAction}s this object enables
96
97 verbs come from our (comma-separated-verbs) ACTIONS attribute
98 for each C{GameAction}, ACCURACY, DAMAGE, POWER, STACKS are the sum of
99 - our base ACCURACY, DAMAGE, POWER, STACKS
100 - our ACCURACY.verb, DAMAGE.verb, POWER.verb, STACKS.verb,
101
102 @param actor: GameActor initiating the action
103 @param context: GameContext in which the action is taken
104
105 NOTE: this base class makes no use of the C{actor} and C{context}
106 parameters, but a sub-class might want to determine whether or not
107 B{this actor} could perform this action in B{this context}.
108
109 @return: list of possible GameActions
110 """
111
112
113
114
115
116
117
118
119
120
121
122
123
124 - def load(self, filename):
125 """
126 read object definitions from a file
127 - blank lines and lines beginning w/# are ignored
128 - NAME string ... is the name of an object
129 - DESCRIPTION string ... is the description of that object
130 - ACTIONS string ... is the list of supported verbs
131 - OBJECT ... introduces definition of an object in our inventory
132 - anything else is an atribute and value (strings should be quoted)
133
134 NOTE: The object being defined can contain other objects.
135 (e.g. guard has a sword, box contains a scroll)
136 But contained objects cannot, themselves, contain other objects.
137
138 @param filename: name of file to be read
139 """
140
141
142
143
144
146 """
147 helper function to lex a name and (potentially quoted) value from a line
148 - treat (single or double) quoted strings as a single token
149 - if second token is an integer, return it as such, else a string
150
151 @param line: string to be lexed
152 @return: (name, value) ... or (None, None) for blank/comment lines
153 """
154
155
156
157
158
159
160
161