annotate orpg/dieroller/base.py @ 238:b44dad398833 beta

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