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
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
1 #!/usr/bin/env python
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
2 # Copyright (C) 2000-2001 The OpenRPG Project
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
3 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
4 # openrpg-dev@lists.sourceforge.net
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
5 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
6 # This program is free software; you can redistribute it and/or modify
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
7 # it under the terms of the GNU General Public License as published by
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
9 # (at your option) any later version.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
10 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
11 # This program is distributed in the hope that it will be useful,
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
14 # GNU General Public License for more details.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
15 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
16 # You should have received a copy of the GNU General Public License
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
17 # along with this program; if not, write to the Free Software
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
19 # --
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
20 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
21 # File: die.py
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
22 # Author: Andrew Bennett
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
23 # Maintainer:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
24 # Version:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
25 # $Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
26 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
27 # Description: This class is used to make working with dice easier
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
28 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
29
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
30 __version__ = "$Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
31
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
32
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
33 import random
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
34 import UserList
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
35 import copy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
36 #import string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
37
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
38 class die_base(UserList.UserList):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
39
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
40 def __init__(self,source = []):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
41 if isinstance(source, (int, float, basestring)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
42 s = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
43 s.append(di(source))
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
44 else: s = source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
45 UserList.UserList.__init__(self,s)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
46
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
47 def sum(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
48 s = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
49 for a in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
50 s += int(a)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
51 return s
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
52
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
53 def __lshift__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
54 if type(other) == type(3) or type(other) == type(3.0): o = other
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
55 elif hasattr(other,"sum"): o = other.sum()
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
56 else: return None
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
57 result = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
58 for die in self:
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
59 if die < o: result.append(die)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
60 return self.__class__(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
61
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
62 def __rshift__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
63 if type(other) == type(3) or type(other) == type(3.0): o = other
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
64 elif hasattr(other,"sum"): o = other.sum()
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
65 else: return None
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
66 result = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
67 for die in self:
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
68 if die > o: result.append(die)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
69 return self.__class__(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
70
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
71 def __rlshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
72 return self.__rshift__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
73
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
74 def __rrshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
75 return self.__lshift__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
76
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
77 def __str__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
78 if len(self.data) > 0:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
79 myStr = "[" + str(self.data[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
80 for a in self.data[1:]:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
81 myStr += ","
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
82 myStr += str(a)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
83 myStr += "] = (" + str(self.sum()) + ")"
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
84 else: myStr = "[] = (0)"
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
85 return myStr
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
86
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
87 def __lt__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
88 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() < other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
89 elif hasattr(other,"sum"): return (self.sum() < other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
90 else: return UserList.UserList.__lt__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
91
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
92 def __le__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
93 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() <= other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
94 elif hasattr(other,"sum"): return (self.sum() <= other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
95 else: return UserList.UserList.__le__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
96
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
97 def __eq__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
98 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() == other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
99 elif hasattr(other,"sum"): return (self.sum() == other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
100 else: return UserList.UserList.__eq__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
101
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
102 def __ne__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
103 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() != other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
104 elif hasattr(other,"sum"):return (self.sum() != other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
105 else: return UserList.UserList.__ne__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
106
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
107 def __gt__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
108 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() > other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
109 elif hasattr(other,"sum"): return (self.sum() > other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
110 else: return UserList.UserList.__gt__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
111
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
112 def __ge__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
113 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() >= other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
114 elif hasattr(other,"sum"): return (self.sum() >= other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
115 else: return UserList.UserList.__ge__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
116
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
117 def __cmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
118 # this function included for backwards compatibility
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
119 # As of 2.1, lists implement the "rich comparison"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
120 # methods overloaded above.
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
121 if type(other) == type(3) or type(other) == type(3.0): return cmp(self.sum(), other)
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
122 elif hasattr(other,"sum"): return cmp(self.sum(), other.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
123 else: return UserList.UserList.__cmp__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
124
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
125 def __rcmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
126 return self.__cmp__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
127
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
128 def __add__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
129 mycopy = copy.deepcopy(self)
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
130 if type(other) == type(3) or type(other) == type(3.0): other = [static_di(other)]
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
131 elif type(other) == type("test"): return self
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
132 mycopy.extend(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
133 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
134
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
135 def __iadd__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
136 return self.__add__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
137
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
138 def __radd__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
139 mycopy = copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
140 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
141 new_die = di(0)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
142 new_die.set_value(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
143 other = new_die
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
144 mycopy.insert(0,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
145 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
146
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
147 def __int__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
148 return self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
149
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
150 def __sub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
151 mycopy = copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
152 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
153 neg_die = static_di(-other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
154 other = [neg_die]
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
155 else: other = -other
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
156 mycopy.extend(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
157 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
158
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
159 def __rsub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
160 mycopy = -copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
161 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
162 new_die = di(0)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
163 new_die.set_value(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
164 other = new_die
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
165 mycopy.insert(0,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
166 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
167
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
168 def __isub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
169 return self.__sub__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
170
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
171 def __mul__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
172 if type(other) == type(3) or type(other) == type(3.0): return self.sum() * other
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
173 elif hasattr(other,"sum"): return other.sum() * self.sum()
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
174 else: return UserList.UserList.__mul__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
175
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
176
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
177 def __rmul__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
178 return self.__mul__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
179
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
180
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
181 def __div__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
182 if type(other) == type(3) or type(other) == type(3.0): return float(self.sum()) / other
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
183 elif hasattr(other,"sum"): return float(self.sum()) / other.sum()
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
184 else: return UserList.UserList.__div__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
185
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
186
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
187 def __rdiv__(self,other):
163
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
188 if type(other) == type(3) or type(other) == type(3.0): return other / float(self.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
189 elif hasattr(other,"sum"): return other.sum() / float(self.sum())
565ab3d84430 Traipse Alpha 'OpenRPG' {091202-00}
sirebral
parents: 155
diff changeset
190 else: return UserList.UserList.__rdiv__(self,other)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
191
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
192
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
193 def __mod__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
194 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
195 return self.sum()%other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
196 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
197 return self.sum() % other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
198 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
199 return UserList.UserList.__mod__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
200
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
201
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
202 def __rmod__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
203 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
204 return other % self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
205 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
206 return other.sum() % self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
207 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
208 return UserList.UserList.__rmod__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
209
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
210
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
211 def __neg__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
212 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
213 self.data[i] = -self.data[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
214 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
215
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
216
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
217 def __pos__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
218 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
219 self.data[i] = +self.data[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
220 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
221
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
222
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
223 def __abs__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
224 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
225 self.data[i] = abs(self.data[i])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
226 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
227 #return abs(self.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
228
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
229
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
230 def __pow__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
231 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
232 return self.sum() ** other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
233 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
234 return self.sum() ** other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
235 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
236 return UserList.UserList.__pow__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
237
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
238
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
239
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
240 def __rpow__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
241 # We're overloading exponentiation of ints to create "other" number of dice
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
242
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
243 if other >= 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
244 result = self.__class__(self[0].sides)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
245 for t in range(other-1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
246 result+=self.__class__(self[0].sides)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
247 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
248 result = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
249
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
250 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
251
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
252 ### di class to handle actual dice
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
253
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
254 class di:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
255
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
256 def __init__(self,sides,min=1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
257 self.sides = sides
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
258 self.history = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
259 self.value = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
260 self.target = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
261 self.roll(min)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
262
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
263
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
264 def __str__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
265 if len(self.history) > 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
266 return str(self.history)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
267 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
268 return str(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
269
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
270
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
271 def __neg__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
272 self.value = -self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
273 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
274 self.history[i] = -self.history[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
275 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
276
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
277
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
278 def __pos__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
279 self.value = +self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
280 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
281 self.history[i] = +self.history[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
282 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
283
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
284
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
285 def __abs__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
286 self.value = abs(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
287 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
288 self.history[i] = abs(self.history[i])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
289 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
290
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
291
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
292 def __repr__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
293 if len(self.history) > 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
294 return str(self.history)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
295 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
296 return str(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
297
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
298
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
299 def __int__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
300 return self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
301
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
302
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
303
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
304 def __lt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
305 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
306 return self.value < other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
307 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
308 return self.value < other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
309 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
310 return self < other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
311
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
312
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
313 def __le__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
314 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
315 return self.value <= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
316 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
317 return self.value <= other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
318 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
319 return self <= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
320
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
321
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
322 def __eq__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
323 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
324 return self.value == other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
325 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
326 return self.value == other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
327 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
328 return self == other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
329
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
330
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
331 def __ne__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
332 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
333 return self.value != other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
334 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
335 return self.value != other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
336 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
337 return self != other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
338
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
339
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
340 def __gt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
341 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
342 return self.value > other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
343 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
344 return self.value > other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
345 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
346 return self > other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
347
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
348
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
349 def __ge__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
350 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
351 return self.value >= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
352 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
353 return self.value >= other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
354 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
355 return self >= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
356
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
357
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
358 def __cmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
359 # this function included for backwards compatibility
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
360 # As of 2.1, lists implement the "rich comparison"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
361 # methods overloaded above.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
362 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
363 return cmp(self.value, other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
364 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
365 return cmp(self.value, other.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
366 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
367 return cmp(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
368
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
369
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
370 def roll(self,min=1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
371 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
372 self.value = random.randint(-1, 1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
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
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
375 self.value = int(random.uniform(min, self.sides+1))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
376 self.history = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
377 self.history.append(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
378
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
379
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
380 def extraroll(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
381 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
382 result = random.randint(-1, 1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
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
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
385 result = int(random.uniform(1,self.sides+1))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
386
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
387 self.value += result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
388 self.history.append(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
389
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
390
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
391 def lastroll(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
392 return self.history[len(self.history)-1]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
393
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
394
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
395 def set_value(self,value):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
396 self.value = value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
397 self.history = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
398 self.history.append(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
399
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
401 def modify(self,mod):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
402 self.value += mod
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
403 self.history.append(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
404
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
405
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
406 def gethistory(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
407 return self.history[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
408
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
409 class static_di(di):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
410
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
411 def __init__(self,value):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
412 di.__init__(self,value,value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
413 self.set_value(value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
414
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
415
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
416 class std(die_base):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
417
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
418 def __init__(self,source=[]):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
419 die_base.__init__(self,source)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
420
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
421 # Examples of adding member functions through inheritance.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
422
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
423
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
424 def ascending(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
425 result = self[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
426 result.sort()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
427 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
428
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
429
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
430 def descending(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
431 result = self[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
432 result.sort()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
433 result.reverse()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
434 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
435
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
436
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
437 def takeHighest(self,num_dice):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
438 return self.descending()[:num_dice]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
439
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
440
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
441 def takeLowest(self,num_dice):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
442 return self.ascending()[:num_dice]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
443
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
444
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
445 def extra(self,num):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
446 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
447 if self.data[i].lastroll() >= num:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
448 self.data[i].extraroll()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
449 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
450
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
451
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
452 def open(self,num):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
453 if num <= 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
454 self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
455 done = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
456 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
457 if self.data[i].lastroll() >= num:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
458 self.data[i].extraroll()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
459 done = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
460 if done:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
461 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
462 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
463 return self.open(num)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
464
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
465
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
466 def minroll(self,min):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
467 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
468 if self.data[i].lastroll() < min:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
469 self.data[i].roll(min)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
470 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
471
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
472
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
473 def each(self,mod):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
474 mod = int(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
475 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
476 self.data[i].modify(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
477 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
478
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
479
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
480
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
481 def vs(self, target):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
482 for dn in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
483 dn.target = target
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
484 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
485
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
486
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
487 ## If we are testing against a saving throw, we check for
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
488 ## greater than or equal to against the target value and
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
489 ## we only return the number of successful saves. A negative
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
490 ## value will never be generated.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
491
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
492 def sum(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
493 retValue = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
494 for dn in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
495 setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
496 if dn.target:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
497 if setValue >= dn.target:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
498 retValue += 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
499
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
500 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
501 retValue += setValue
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
502
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
503 return retValue