Mercurial > traipse_dev
annotate orpg/dieroller/die.py @ 163:565ab3d84430 alpha
Traipse Alpha 'OpenRPG' {091202-00}
Traipse is a distribution of OpenRPG that is designed to be easy to
setup and go. Traipse also makes it easy for developers to work on code
without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy'
and adds fixes to the code. 'Ornery-Orc's main goal is to offer more
advanced features and enhance the productivity of the user.
Update Summary (Keeping up with Beta)
New Features:
Added Bookmarks
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from
FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
New TrueDebug Class in orpg_log (See documentation for usage)
Portable Mercurial
Tip of the Day added, from Core and community
New Reference Syntax added for custom PC sheets
New Child Reference for gametree
New Gametree Recursion method, mapping, context sensitivity, and
effeciency..
New Features node with bonus nodes and Node Referencing help added
Added 7th Sea die roller method; ie [7k3] =
[7d10.takeHighest(3).open(10)]
New 'Mythos' System die roller added
Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)].
Includes support for Mythos roller.
Fixes:
Fix to Text based Server
Fix to Remote Admin Commands
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Fix to Map from gametree not showing to all clients
Fix to gametree about menus
Fix to Password Manager check on startup
Fix to PC Sheets from tool nodes. They now use the tabber_panel
Fixed Whiteboard ID to prevent random line or text deleting.
Modified ID's to prevent non updated clients from ruining the fix.
default_manifest.xml renamed to default_upmana.xml
Fix to Update Manager; cleaner clode for saved repositories
Fixes made to Settings Panel and no reactive settings when Ok is
pressed.
author | sirebral |
---|---|
date | Wed, 02 Dec 2009 21:20:44 -0600 |
parents | bf799efe7a8a |
children |
rev | line source |
---|---|
155 | 1 #!/usr/bin/env python |
2 # Copyright (C) 2000-2001 The OpenRPG Project | |
3 # | |
4 # openrpg-dev@lists.sourceforge.net | |
5 # | |
6 # This program is free software; you can redistribute it and/or modify | |
7 # it under the terms of the GNU General Public License as published by | |
8 # the Free Software Foundation; either version 2 of the License, or | |
9 # (at your option) any later version. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 # -- | |
20 # | |
21 # File: die.py | |
22 # Author: Andrew Bennett | |
23 # Maintainer: | |
24 # Version: | |
25 # $Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $ | |
26 # | |
27 # Description: This class is used to make working with dice easier | |
28 # | |
29 | |
30 __version__ = "$Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $" | |
31 | |
32 | |
33 import random | |
34 import UserList | |
35 import copy | |
36 #import string | |
37 | |
38 class die_base(UserList.UserList): | |
39 | |
40 def __init__(self,source = []): | |
41 if isinstance(source, (int, float, basestring)): | |
42 s = [] | |
43 s.append(di(source)) | |
163 | 44 else: s = source |
155 | 45 UserList.UserList.__init__(self,s) |
46 | |
47 def sum(self): | |
48 s = 0 | |
49 for a in self.data: | |
50 s += int(a) | |
51 return s | |
52 | |
53 def __lshift__(self,other): | |
163 | 54 if type(other) == type(3) or type(other) == type(3.0): o = other |
55 elif hasattr(other,"sum"): o = other.sum() | |
56 else: return None | |
155 | 57 result = [] |
58 for die in self: | |
163 | 59 if die < o: result.append(die) |
155 | 60 return self.__class__(result) |
61 | |
62 def __rshift__(self,other): | |
163 | 63 if type(other) == type(3) or type(other) == type(3.0): o = other |
64 elif hasattr(other,"sum"): o = other.sum() | |
65 else: return None | |
155 | 66 result = [] |
67 for die in self: | |
163 | 68 if die > o: result.append(die) |
155 | 69 return self.__class__(result) |
70 | |
71 def __rlshift__(self,other): | |
72 return self.__rshift__(other) | |
73 | |
74 def __rrshift__(self,other): | |
75 return self.__lshift__(other) | |
76 | |
77 def __str__(self): | |
78 if len(self.data) > 0: | |
79 myStr = "[" + str(self.data[0]) | |
80 for a in self.data[1:]: | |
81 myStr += "," | |
82 myStr += str(a) | |
83 myStr += "] = (" + str(self.sum()) + ")" | |
163 | 84 else: myStr = "[] = (0)" |
155 | 85 return myStr |
86 | |
87 def __lt__(self,other): | |
163 | 88 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() < other) |
89 elif hasattr(other,"sum"): return (self.sum() < other.sum()) | |
90 else: return UserList.UserList.__lt__(self,other) | |
155 | 91 |
92 def __le__(self,other): | |
163 | 93 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() <= other) |
94 elif hasattr(other,"sum"): return (self.sum() <= other.sum()) | |
95 else: return UserList.UserList.__le__(self,other) | |
155 | 96 |
97 def __eq__(self,other): | |
163 | 98 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() == other) |
99 elif hasattr(other,"sum"): return (self.sum() == other.sum()) | |
100 else: return UserList.UserList.__eq__(self,other) | |
155 | 101 |
102 def __ne__(self,other): | |
163 | 103 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() != other) |
104 elif hasattr(other,"sum"):return (self.sum() != other.sum()) | |
105 else: return UserList.UserList.__ne__(self,other) | |
155 | 106 |
107 def __gt__(self,other): | |
163 | 108 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() > other) |
109 elif hasattr(other,"sum"): return (self.sum() > other.sum()) | |
110 else: return UserList.UserList.__gt__(self,other) | |
155 | 111 |
112 def __ge__(self,other): | |
163 | 113 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() >= other) |
114 elif hasattr(other,"sum"): return (self.sum() >= other.sum()) | |
115 else: return UserList.UserList.__ge__(self,other) | |
155 | 116 |
117 def __cmp__(self,other): | |
118 # this function included for backwards compatibility | |
119 # As of 2.1, lists implement the "rich comparison" | |
120 # methods overloaded above. | |
163 | 121 if type(other) == type(3) or type(other) == type(3.0): return cmp(self.sum(), other) |
122 elif hasattr(other,"sum"): return cmp(self.sum(), other.sum()) | |
123 else: return UserList.UserList.__cmp__(self,other) | |
155 | 124 |
125 def __rcmp__(self,other): | |
126 return self.__cmp__(other) | |
127 | |
128 def __add__(self,other): | |
129 mycopy = copy.deepcopy(self) | |
163 | 130 if type(other) == type(3) or type(other) == type(3.0): other = [static_di(other)] |
131 elif type(other) == type("test"): return self | |
155 | 132 mycopy.extend(other) |
133 return mycopy | |
134 | |
135 def __iadd__(self,other): | |
136 return self.__add__(other) | |
137 | |
138 def __radd__(self,other): | |
139 mycopy = copy.deepcopy(self) | |
140 if type(other) == type(3) or type(other) == type(3.0): | |
141 new_die = di(0) | |
142 new_die.set_value(other) | |
143 other = new_die | |
144 mycopy.insert(0,other) | |
145 return mycopy | |
146 | |
147 def __int__(self): | |
148 return self.sum() | |
149 | |
150 def __sub__(self,other): | |
151 mycopy = copy.deepcopy(self) | |
152 if type(other) == type(3) or type(other) == type(3.0): | |
153 neg_die = static_di(-other) | |
154 other = [neg_die] | |
163 | 155 else: other = -other |
155 | 156 mycopy.extend(other) |
157 return mycopy | |
158 | |
159 def __rsub__(self,other): | |
160 mycopy = -copy.deepcopy(self) | |
161 if type(other) == type(3) or type(other) == type(3.0): | |
162 new_die = di(0) | |
163 new_die.set_value(other) | |
164 other = new_die | |
165 mycopy.insert(0,other) | |
166 return mycopy | |
167 | |
168 def __isub__(self,other): | |
169 return self.__sub__(other) | |
170 | |
171 def __mul__(self,other): | |
163 | 172 if type(other) == type(3) or type(other) == type(3.0): return self.sum() * other |
173 elif hasattr(other,"sum"): return other.sum() * self.sum() | |
174 else: return UserList.UserList.__mul__(self,other) | |
155 | 175 |
176 | |
177 def __rmul__(self,other): | |
178 return self.__mul__(other) | |
179 | |
180 | |
181 def __div__(self,other): | |
163 | 182 if type(other) == type(3) or type(other) == type(3.0): return float(self.sum()) / other |
183 elif hasattr(other,"sum"): return float(self.sum()) / other.sum() | |
184 else: return UserList.UserList.__div__(self,other) | |
155 | 185 |
186 | |
187 def __rdiv__(self,other): | |
163 | 188 if type(other) == type(3) or type(other) == type(3.0): return other / float(self.sum()) |
189 elif hasattr(other,"sum"): return other.sum() / float(self.sum()) | |
190 else: return UserList.UserList.__rdiv__(self,other) | |
155 | 191 |
192 | |
193 def __mod__(self,other): | |
194 if type(other) == type(3) or type(other) == type(3.0): | |
195 return self.sum()%other | |
196 elif hasattr(other,"sum"): | |
197 return self.sum() % other.sum() | |
198 else: | |
199 return UserList.UserList.__mod__(self,other) | |
200 | |
201 | |
202 def __rmod__(self,other): | |
203 if type(other) == type(3) or type(other) == type(3.0): | |
204 return other % self.sum() | |
205 elif hasattr(other,"sum"): | |
206 return other.sum() % self.sum() | |
207 else: | |
208 return UserList.UserList.__rmod__(self,other) | |
209 | |
210 | |
211 def __neg__(self): | |
212 for i in range(len(self.data)): | |
213 self.data[i] = -self.data[i] | |
214 return self | |
215 | |
216 | |
217 def __pos__(self): | |
218 for i in range(len(self.data)): | |
219 self.data[i] = +self.data[i] | |
220 return self | |
221 | |
222 | |
223 def __abs__(self): | |
224 for i in range(len(self.data)): | |
225 self.data[i] = abs(self.data[i]) | |
226 return self | |
227 #return abs(self.sum()) | |
228 | |
229 | |
230 def __pow__(self,other): | |
231 if type(other) == type(3) or type(other) == type(3.0): | |
232 return self.sum() ** other | |
233 elif hasattr(other,"sum"): | |
234 return self.sum() ** other.sum() | |
235 else: | |
236 return UserList.UserList.__pow__(self,other) | |
237 | |
238 | |
239 | |
240 def __rpow__(self,other): | |
241 # We're overloading exponentiation of ints to create "other" number of dice | |
242 | |
243 if other >= 1: | |
244 result = self.__class__(self[0].sides) | |
245 for t in range(other-1): | |
246 result+=self.__class__(self[0].sides) | |
247 else: | |
248 result = None | |
249 | |
250 return result | |
251 | |
252 ### di class to handle actual dice | |
253 | |
254 class di: | |
255 | |
256 def __init__(self,sides,min=1): | |
257 self.sides = sides | |
258 self.history = None | |
259 self.value = None | |
260 self.target = None | |
261 self.roll(min) | |
262 | |
263 | |
264 def __str__(self): | |
265 if len(self.history) > 1: | |
266 return str(self.history) | |
267 else: | |
268 return str(self.value) | |
269 | |
270 | |
271 def __neg__(self): | |
272 self.value = -self.value | |
273 for i in range(len(self.history)): | |
274 self.history[i] = -self.history[i] | |
275 return self | |
276 | |
277 | |
278 def __pos__(self): | |
279 self.value = +self.value | |
280 for i in range(len(self.history)): | |
281 self.history[i] = +self.history[i] | |
282 return self | |
283 | |
284 | |
285 def __abs__(self): | |
286 self.value = abs(self.value) | |
287 for i in range(len(self.history)): | |
288 self.history[i] = abs(self.history[i]) | |
289 return self | |
290 | |
291 | |
292 def __repr__(self): | |
293 if len(self.history) > 1: | |
294 return str(self.history) | |
295 else: | |
296 return str(self.value) | |
297 | |
298 | |
299 def __int__(self): | |
300 return self.value | |
301 | |
302 | |
303 | |
304 def __lt__(self,other): | |
305 if type(other) == type(3) or type(other) == type(3.0): | |
306 return self.value < other | |
307 elif hasattr(other,"value"): | |
308 return self.value < other.value | |
309 else: | |
310 return self < other | |
311 | |
312 | |
313 def __le__(self,other): | |
314 if type(other) == type(3) or type(other) == type(3.0): | |
315 return self.value <= other | |
316 elif hasattr(other,"value"): | |
317 return self.value <= other.value | |
318 else: | |
319 return self <= other | |
320 | |
321 | |
322 def __eq__(self,other): | |
323 if type(other) == type(3) or type(other) == type(3.0): | |
324 return self.value == other | |
325 elif hasattr(other,"value"): | |
326 return self.value == other.value | |
327 else: | |
328 return self == other | |
329 | |
330 | |
331 def __ne__(self,other): | |
332 if type(other) == type(3) or type(other) == type(3.0): | |
333 return self.value != other | |
334 elif hasattr(other,"value"): | |
335 return self.value != other.value | |
336 else: | |
337 return self != other | |
338 | |
339 | |
340 def __gt__(self,other): | |
341 if type(other) == type(3) or type(other) == type(3.0): | |
342 return self.value > other | |
343 elif hasattr(other,"value"): | |
344 return self.value > other.value | |
345 else: | |
346 return self > other | |
347 | |
348 | |
349 def __ge__(self,other): | |
350 if type(other) == type(3) or type(other) == type(3.0): | |
351 return self.value >= other | |
352 elif hasattr(other,"value"): | |
353 return self.value >= other.value | |
354 else: | |
355 return self >= other | |
356 | |
357 | |
358 def __cmp__(self,other): | |
359 # this function included for backwards compatibility | |
360 # As of 2.1, lists implement the "rich comparison" | |
361 # methods overloaded above. | |
362 if type(other) == type(3) or type(other) == type(3.0): | |
363 return cmp(self.value, other) | |
364 elif hasattr(other,"value"): | |
365 return cmp(self.value, other.value) | |
366 else: | |
367 return cmp(self,other) | |
368 | |
369 | |
370 def roll(self,min=1): | |
371 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': | |
372 self.value = random.randint(-1, 1) | |
373 else: | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
374 #self.value = random.randint(min, self.sides) |
155 | 375 self.value = int(random.uniform(min, self.sides+1)) |
376 self.history = [] | |
377 self.history.append(self.value) | |
378 | |
379 | |
380 def extraroll(self): | |
381 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': | |
382 result = random.randint(-1, 1) | |
383 else: | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
384 #result = random.randint(1, self.sides) |
155 | 385 result = int(random.uniform(1,self.sides+1)) |
386 | |
387 self.value += result | |
388 self.history.append(result) | |
389 | |
390 | |
391 def lastroll(self): | |
392 return self.history[len(self.history)-1] | |
393 | |
394 | |
395 def set_value(self,value): | |
396 self.value = value | |
397 self.history = [] | |
398 self.history.append(self.value) | |
399 | |
400 | |
401 def modify(self,mod): | |
402 self.value += mod | |
403 self.history.append(mod) | |
404 | |
405 | |
406 def gethistory(self): | |
407 return self.history[:] | |
408 | |
409 class static_di(di): | |
410 | |
411 def __init__(self,value): | |
412 di.__init__(self,value,value) | |
413 self.set_value(value) | |
414 | |
415 | |
416 class std(die_base): | |
417 | |
418 def __init__(self,source=[]): | |
419 die_base.__init__(self,source) | |
420 | |
421 # Examples of adding member functions through inheritance. | |
422 | |
423 | |
424 def ascending(self): | |
425 result = self[:] | |
426 result.sort() | |
427 return result | |
428 | |
429 | |
430 def descending(self): | |
431 result = self[:] | |
432 result.sort() | |
433 result.reverse() | |
434 return result | |
435 | |
436 | |
437 def takeHighest(self,num_dice): | |
438 return self.descending()[:num_dice] | |
439 | |
440 | |
441 def takeLowest(self,num_dice): | |
442 return self.ascending()[:num_dice] | |
443 | |
444 | |
445 def extra(self,num): | |
446 for i in range(len(self.data)): | |
447 if self.data[i].lastroll() >= num: | |
448 self.data[i].extraroll() | |
449 return self | |
450 | |
451 | |
452 def open(self,num): | |
453 if num <= 1: | |
454 self | |
455 done = 1 | |
456 for i in range(len(self.data)): | |
457 if self.data[i].lastroll() >= num: | |
458 self.data[i].extraroll() | |
459 done = 0 | |
460 if done: | |
461 return self | |
462 else: | |
463 return self.open(num) | |
464 | |
465 | |
466 def minroll(self,min): | |
467 for i in range(len(self.data)): | |
468 if self.data[i].lastroll() < min: | |
469 self.data[i].roll(min) | |
470 return self | |
471 | |
472 | |
473 def each(self,mod): | |
474 mod = int(mod) | |
475 for i in range(len(self.data)): | |
476 self.data[i].modify(mod) | |
477 return self | |
478 | |
479 | |
480 | |
481 def vs(self, target): | |
482 for dn in self.data: | |
483 dn.target = target | |
484 return self | |
485 | |
486 | |
487 ## If we are testing against a saving throw, we check for | |
488 ## greater than or equal to against the target value and | |
489 ## we only return the number of successful saves. A negative | |
490 ## value will never be generated. | |
491 | |
492 def sum(self): | |
493 retValue = 0 | |
494 for dn in self.data: | |
495 setValue = reduce( lambda x, y : int(x)+int(y), dn.history ) | |
496 if dn.target: | |
497 if setValue >= dn.target: | |
498 retValue += 1 | |
499 | |
500 else: | |
501 retValue += setValue | |
502 | |
503 return retValue |