annotate orpg/dieroller/base.py @ 239:56c1f2729413 beta

Traipse Beta 'OpenRPG' {100811-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 New Earthdawn Dieroller 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. Update to Dieroller. Cleaner, more effecient expression system. 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 Fix to Gametree for locating gametree files
author sirebral
date Wed, 11 Aug 2010 13:52:30 -0500
parents 13054be69834
children
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
239
56c1f2729413 Traipse Beta 'OpenRPG' {100811-00}
sirebral
parents: 212
diff changeset
129
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
130 def __rcmp__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
131 return self.__cmp__(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
132
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
133 def __add__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
134 mycopy = copy.deepcopy(self)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
135 if type(other) == type(3) or type(other) == type(3.0):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
136 other = [static_di(other)]
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
137 elif type(other) == type("test"): return self
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
138 mycopy.extend(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
139 return mycopy
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
140
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
141 def __iadd__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
142 return self.__add__(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
143
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
144 def __radd__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
145 mycopy = copy.deepcopy(self)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
146 if type(other) == type(3) or type(other) == type(3.0):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
147 new_die = di(0)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
148 new_die.set_value(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
149 other = new_die
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
150 mycopy.insert(0,other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
151 return mycopy
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
152
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
153 def __int__(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
154 return self.sum()
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
155
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
156 def __sub__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
157 mycopy = copy.deepcopy(self)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
158 if type(other) == type(3) or type(other) == type(3.0):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
159 neg_die = static_di(-other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
160 other = [neg_die]
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
161 else: other = -other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
162 mycopy.extend(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
163 return mycopy
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
164
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
165 def __rsub__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
166 mycopy = -copy.deepcopy(self)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
167 if type(other) == type(3) or type(other) == type(3.0):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
168 new_die = di(0)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
169 new_die.set_value(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
170 other = new_die
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
171 mycopy.insert(0,other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
172 return mycopy
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
173
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
174 def __isub__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
175 return self.__sub__(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
176
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
177 def __mul__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
178 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
179 elif hasattr(other,"sum"): return other.sum() * self.sum()
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
180 else: return UserList.UserList.__mul__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
181
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
182 def __rmul__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
183 return self.__mul__(other)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
184
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
185 def __div__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
186 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
187 elif hasattr(other,"sum"): return float(self.sum()) / other.sum()
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
188 else: return UserList.UserList.__div__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
189
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
190 def __rdiv__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
191 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
192 elif hasattr(other,"sum"): return other.sum() / float(self.sum())
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
193 else: return UserList.UserList.__rdiv__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
194
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
195 def __mod__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
196 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
197 elif hasattr(other,"sum"): return self.sum() % other.sum()
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
198 else: return UserList.UserList.__mod__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
199
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
200 def __rmod__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
201 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
202 elif hasattr(other,"sum"): return other.sum() % self.sum()
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
203 else: return UserList.UserList.__rmod__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
204
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
205 def __neg__(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
206 for i in range(len(self.data)): self.data[i] = -self.data[i]
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
207 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
208
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
209 def __pos__(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
210 for i in range(len(self.data)): self.data[i] = +self.data[i]
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
211 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
212
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
213 def __abs__(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
214 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
215 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
216
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
217 def __pow__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
218 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
219 elif hasattr(other,"sum"): return self.sum() ** other.sum()
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
220 else: return UserList.UserList.__pow__(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
221
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
222 def __rpow__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
223 # We're overloading exponentiation of ints to create "other" number of dice
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
224 if other >= 1:
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
225 result = self.__class__(self[0].sides)
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
226 for t in range(other-1): result+=self.__class__(self[0].sides)
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
227 else: result = None
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
228 return result
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
229
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
230 ### di class to handle actual dice
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
231
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
232 class di:
239
56c1f2729413 Traipse Beta 'OpenRPG' {100811-00}
sirebral
parents: 212
diff changeset
233 def __init__(self,sides,min=1):
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
234 self.sides = sides
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
235 self.history = None
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
236 self.value = None
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
237 self.target = None
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
238 self.roll(min)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
239
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
240 def __str__(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
241 if len(self.history) > 1: return str(self.history)
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
242 else: return str(self.value)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
243
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
244 def __neg__(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
245 self.value = -self.value
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
246 for i in range(len(self.history)): self.history[i] = -self.history[i]
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
247 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
248
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
249 def __pos__(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
250 self.value = +self.value
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
251 for i in range(len(self.history)): self.history[i] = +self.history[i]
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
252 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
253
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
254 def __abs__(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
255 self.value = abs(self.value)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
256 for i in range(len(self.history)):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
257 self.history[i] = abs(self.history[i])
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
258 return self
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
259
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
260 def __repr__(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
261 if len(self.history) > 1: return str(self.history)
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
262 else: return str(self.value)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
263
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
264 def __int__(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
265 return self.value
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
266
239
56c1f2729413 Traipse Beta 'OpenRPG' {100811-00}
sirebral
parents: 212
diff changeset
267
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
268 def __lt__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
269 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
270 elif hasattr(other,"value"): return self.value < other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
271 else: return self < other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
272
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
273 def __le__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
274 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
275 elif hasattr(other,"value"): return self.value <= other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
276 else: return self <= other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
277
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
278 def __eq__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
279 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
280 elif hasattr(other,"value"): return self.value == other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
281 else: return self == other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
282
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
283 def __ne__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
284 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
285 elif hasattr(other,"value"): return self.value != other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
286 else: return self != other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
287
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
288 def __gt__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
289 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
290 elif hasattr(other,"value"): return self.value > other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
291 else: return self > other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
292
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
293 def __ge__(self,other):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
294 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
295 elif hasattr(other,"value"): return self.value >= other.value
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
296 else: return self >= other
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
297
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
298 def __cmp__(self,other):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
299 # this function included for backwards compatibility
183
0d9b746b5751 Traipse Beta 'OpenRPG' {100115-00}
sirebral
parents: 171
diff changeset
300 # As of 2.1, lists implement the "rich comparison"
0d9b746b5751 Traipse Beta 'OpenRPG' {100115-00}
sirebral
parents: 171
diff changeset
301 # methods overloaded above.
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
302 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
303 elif hasattr(other,"value"): return cmp(self.value, other.value)
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
304 else: return cmp(self,other)
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
305
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
306 def roll(self,min=1):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
307 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
308 else: self.value = int(random.uniform(min, self.sides+1))
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
309 self.history = []
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
310 self.history.append(self.value)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
311
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
312 def extraroll(self):
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
313 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
314 else: result = int(random.uniform(1,self.sides+1))
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
315 self.value += result
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
316 self.history.append(result)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
317
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
318 def lastroll(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
319 return self.history[len(self.history)-1]
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
320
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
321 def set_value(self,value):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
322 self.value = value
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
323 self.history = []
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
324 self.history.append(self.value)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
325
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
326 def modify(self,mod):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
327 self.value += mod
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
328 self.history.append(mod)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
329
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
330 def gethistory(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
331 return self.history[:]
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
332
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
333 class static_di(di):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
334 def __init__(self,value):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
335 di.__init__(self,value,value)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
336 self.set_value(value)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
337
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
338 class DieRollers(object):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
339 _rollers = {}
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
340 def __new__(cls):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
341 it = cls.__dict__.get("__it__")
184
dcae32e219f1 Traipse Beta 'OpenRPG' {100117-00}
sirebral
parents: 183
diff changeset
342 if it is not None: return it
171
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
343 cls.__it__ = it = object.__new__(cls)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
344 return it
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
345
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
346 def keys(self):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
347 return self._rollers.keys()
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
348
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
349 def register(self, roller):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
350 if not self._rollers.has_key(roller.name):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
351 self._rollers[roller.name] = roller
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
352
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
353 def __getitem__(self, roller_name):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
354 return self._rollers.get(roller_name, None)
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
355
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
356 def __setitem__(self, *args):
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
357 raise AttributeError
ff48c2741fe7 Traipse Beta 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
358
183
0d9b746b5751 Traipse Beta 'OpenRPG' {100115-00}
sirebral
parents: 171
diff changeset
359 die_rollers = DieRollers()