annotate orpg/dieroller/base.py @ 228:24769389a7ba alpha

Traipse Alpha 'OpenRPG' {100612-01} 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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 04:38:29 -0500
parents b633f4c64aae
children cc7629ab526d
rev   line source
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
1 #!/usr/bin/env python
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
2 # Copyright (C) 2000-2001 The OpenRPG Project
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
3 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
4 # openrpg-dev@lists.sourceforge.net
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
5 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
6 # This program is free software; you can redistribute it and/or modify
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
7 # it under the terms of the GNU General Public License as published by
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
9 # (at your option) any later version.
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
10 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
14 # GNU General Public License for more details.
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
15 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
17 # along with this program; if not, write to the Free Software
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
19 # --
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
20 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
21 # File: die.py
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
22 # Author: Andrew Bennett
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
23 # Maintainer:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
24 # Version:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
25 # $Id: die.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
26 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
27 # Description: This class is used to make working with dice easier
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
28 #
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
29
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
30 __version__ = "$Id: die.py,v Traipse 'Ornery-Orc' prof.ebral Exp Exp $"
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
31
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
32 import random
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
33 import UserList
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
34 import copy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
35
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
36 class die_base(UserList.UserList):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
37 name = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
38
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
39 def __init__(self,source = []):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
40 if isinstance(source, (int, float, basestring)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
41 s = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
42 s.append(di(source))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
43 else: s = source
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
44 UserList.UserList.__init__(self,s)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
45
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
46 def sum(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
47 s = 0
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
48 for a in self.data:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
49 s += int(a)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
50 return s
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
51
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
52 def __lshift__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
53 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
54 o = other
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
55 elif hasattr(other,"sum"):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
56 o = other.sum()
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
57 else: return None
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
58 result = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
59 for die in self:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
60 if die < o: result.append(die)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
61 return self.__class__(result)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
62
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
63 def __rshift__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
64 if type(other) == type(3) or type(other) == type(3.0): o = other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
65 elif hasattr(other,"sum"): o = other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
66 else: return None
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
67 result = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
68 for die in self:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
69 if die > o: result.append(die)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
70 return self.__class__(result)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
71
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
72 def __rlshift__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
73 return self.__rshift__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
74
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
75 def __rrshift__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
76 return self.__lshift__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
77
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
78 def __str__(self):
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 195
diff changeset
79 try: print "MY STRING", myStr
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 195
diff changeset
80 except: pass
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
81 if len(self.data) > 0:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
82 myStr = "[" + str(self.data[0])
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
83 for a in self.data[1:]:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
84 myStr += ","
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
85 myStr += str(a)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
86 myStr += "] = (" + str(self.sum()) + ")"
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
87 else: myStr = "[] = (0)"
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
88 return myStr
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
89
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
90 def __lt__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
91 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
92 return (self.sum() < other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
93 elif hasattr(other,"sum"): return (self.sum() < other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
94 else: return UserList.UserList.__lt__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
95
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
96 def __le__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
97 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
98 return (self.sum() <= other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
99 elif hasattr(other,"sum"): return (self.sum() <= other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
100 else: return UserList.UserList.__le__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
101
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
102 def __eq__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
103 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
104 return (self.sum() == other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
105 elif hasattr(other,"sum"): return (self.sum() == other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
106 else: return UserList.UserList.__eq__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
107
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
108 def __ne__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
109 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() != other)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
110 elif hasattr(other,"sum"): return (self.sum() != other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
111 else: return UserList.UserList.__ne__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
112
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
113 def __gt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
114 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() > other)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
115 elif hasattr(other,"sum"): return (self.sum() > other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
116 else: return UserList.UserList.__gt__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
117
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
118 def __ge__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
119 if type(other) == type(3) or type(other) == type(3.0): return (self.sum() >= other)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
120 elif hasattr(other,"sum"): return (self.sum() >= other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
121 else: return UserList.UserList.__ge__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
122
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
123 def __cmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
124 # this function included for backwards compatibility
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
125 # As of 2.1, lists implement the "rich comparison"
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
126 # methods overloaded above.
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
127 if type(other) == type(3) or type(other) == type(3.0): return cmp(self.sum(), other)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
128 elif hasattr(other,"sum"): return cmp(self.sum(), other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
129 else: return UserList.UserList.__cmp__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
130
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
131 def __rcmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
132 return self.__cmp__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
133
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
134 def __add__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
135 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
136 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
137 other = [static_di(other)]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
138 elif type(other) == type("test"): return self
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
139 mycopy.extend(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
140 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
141
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
142 def __iadd__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
143 return self.__add__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
144
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
145 def __radd__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
146 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
147 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
148 new_die = di(0)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
149 new_die.set_value(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
150 other = new_die
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
151 mycopy.insert(0,other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
152 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
153
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
154 def __int__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
155 return self.sum()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
156
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
157 def __sub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
158 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
159 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
160 neg_die = static_di(-other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
161 other = [neg_die]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
162 else: other = -other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
163 mycopy.extend(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
164 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
165
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
166 def __rsub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
167 mycopy = -copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
168 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
169 new_die = di(0)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
170 new_die.set_value(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
171 other = new_die
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
172 mycopy.insert(0,other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
173 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
174
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
175 def __isub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
176 return self.__sub__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
177
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
178 def __mul__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
179 if type(other) == type(3) or type(other) == type(3.0): return self.sum() * other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
180 elif hasattr(other,"sum"): return other.sum() * self.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
181 else: return UserList.UserList.__mul__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
182
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
183 def __rmul__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
184 return self.__mul__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
185
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
186 def __div__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
187 if type(other) == type(3) or type(other) == type(3.0): return float(self.sum()) / other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
188 elif hasattr(other,"sum"): return float(self.sum()) / other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
189 else: return UserList.UserList.__div__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
190
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
191 def __rdiv__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
192 if type(other) == type(3) or type(other) == type(3.0): return other / float(self.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
193 elif hasattr(other,"sum"): return other.sum() / float(self.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
194 else: return UserList.UserList.__rdiv__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
195
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
196 def __mod__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
197 if type(other) == type(3) or type(other) == type(3.0): return self.sum()%other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
198 elif hasattr(other,"sum"): return self.sum() % other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
199 else: return UserList.UserList.__mod__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
200
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
201 def __rmod__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
202 if type(other) == type(3) or type(other) == type(3.0): return other % self.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
203 elif hasattr(other,"sum"): return other.sum() % self.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
204 else: return UserList.UserList.__rmod__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
205
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
206 def __neg__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
207 for i in range(len(self.data)): self.data[i] = -self.data[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
208 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
209
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
210 def __pos__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
211 for i in range(len(self.data)): self.data[i] = +self.data[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
212 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
213
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
214 def __abs__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
215 for i in range(len(self.data)): self.data[i] = abs(self.data[i])
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
216 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
217
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
218 def __pow__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
219 if type(other) == type(3) or type(other) == type(3.0): return self.sum() ** other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
220 elif hasattr(other,"sum"): return self.sum() ** other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
221 else: return UserList.UserList.__pow__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
222
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
223 def __rpow__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
224 # We're overloading exponentiation of ints to create "other" number of dice
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
225 if other >= 1:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
226 result = self.__class__(self[0].sides)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
227 for t in range(other-1): result+=self.__class__(self[0].sides)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
228 else: result = None
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
229 return result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
230
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
231 ### di class to handle actual dice
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
232
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
233 class di:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
234 def __init__(self, sides, min=1):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
235 self.sides = sides
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
236 self.history = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
237 self.value = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
238 self.target = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
239 self.roll(min)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
240
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
241 def __str__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
242 if len(self.history) > 1: return str(self.history)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
243 else: return str(self.value)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
244
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
245 def __neg__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
246 self.value = -self.value
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
247 for i in range(len(self.history)): self.history[i] = -self.history[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
248 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
249
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
250 def __pos__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
251 self.value = +self.value
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
252 for i in range(len(self.history)): self.history[i] = +self.history[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
253 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
254
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
255 def __abs__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
256 self.value = abs(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
257 for i in range(len(self.history)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
258 self.history[i] = abs(self.history[i])
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
259 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
260
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
261 def __repr__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
262 if len(self.history) > 1: return str(self.history)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
263 else: return str(self.value)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
264
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
265 def __int__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
266 return self.value
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
267
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
268 def __lt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
269 if type(other) == type(3) or type(other) == type(3.0): return self.value < other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
270 elif hasattr(other,"value"): return self.value < other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
271 else: return self < other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
272
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
273 def __le__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
274 if type(other) == type(3) or type(other) == type(3.0): return self.value <= other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
275 elif hasattr(other,"value"): return self.value <= other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
276 else: return self <= other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
277
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
278 def __eq__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
279 if type(other) == type(3) or type(other) == type(3.0): return self.value == other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
280 elif hasattr(other,"value"): return self.value == other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
281 else: return self == other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
282
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
283 def __ne__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
284 if type(other) == type(3) or type(other) == type(3.0): return self.value != other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
285 elif hasattr(other,"value"): return self.value != other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
286 else: return self != other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
287
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
288 def __gt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
289 if type(other) == type(3) or type(other) == type(3.0): return self.value > other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
290 elif hasattr(other,"value"): return self.value > other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
291 else: return self > other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
292
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
293 def __ge__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
294 if type(other) == type(3) or type(other) == type(3.0): return self.value >= other
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
295 elif hasattr(other,"value"): return self.value >= other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
296 else: return self >= other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
297
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
298 def __cmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
299 # this function included for backwards compatibility
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 177
diff changeset
300 # As of 2.1, lists implement the "rich comparison"
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 177
diff changeset
301 # methods overloaded above.
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
302 if type(other) == type(3) or type(other) == type(3.0): return cmp(self.value, other)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
303 elif hasattr(other,"value"): return cmp(self.value, other.value)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
304 else: return cmp(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
305
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
306 def roll(self,min=1):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
307 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': self.value = random.randint(-1, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
308 else: self.value = int(random.uniform(min, self.sides+1))
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
309 self.history = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
310 self.history.append(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
311
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
312 def extraroll(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
313 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': result = random.randint(-1, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
314 else: result = int(random.uniform(1,self.sides+1))
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
315 self.value += result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
316 self.history.append(result)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
317
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
318 def lastroll(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
319 return self.history[len(self.history)-1]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
320
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
321 def set_value(self,value):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
322 self.value = value
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
323 self.history = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
324 self.history.append(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
325
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
326 def modify(self,mod):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
327 self.value += mod
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
328 self.history.append(mod)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
329
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
330 def gethistory(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
331 return self.history[:]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
332
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
333 class static_di(di):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
334 def __init__(self,value):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
335 di.__init__(self,value,value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
336 self.set_value(value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
337
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
338 class DieRollers(object):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
339 _rollers = {}
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
340 def __new__(cls):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
341 it = cls.__dict__.get("__it__")
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
342 if it is not None: return it
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
343 cls.__it__ = it = object.__new__(cls)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
344 return it
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
345
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
346 def keys(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
347 return self._rollers.keys()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
348
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
349 def register(self, roller):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
350 if not self._rollers.has_key(roller.name):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
351 self._rollers[roller.name] = roller
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
352
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
353 def __getitem__(self, roller_name):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
354 return self._rollers.get(roller_name, None)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
355
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
356 def __setitem__(self, *args):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
357 raise AttributeError
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
358
177
60dde67c4ed6 Traipse Alpha 'OpenRPG' {100114-00}
sirebral
parents: 167
diff changeset
359 die_rollers = DieRollers()