annotate orpg/dieroller/base.py @ 214:4dc11df853bf alpha

Traipse Alpha 'OpenRPG' {100429-0} 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 (Patch-2) New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start New to Mini Lin node, change title in design mode Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Fix to InterParse and logger requiring traceback Fix to Update Manager Status Bar Fix to failed image and erroneous pop up Fix to Mini Lib node that was preventing use Fix to plugins that parce dice but did not call InterParse Fix to nodes for name changing by double click
author sirebral
date Thu, 29 Apr 2010 23:33:53 -0500
parents b633f4c64aae
children 24769389a7ba
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):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
79 if len(self.data) > 0:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
80 myStr = "[" + str(self.data[0])
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
81 for a in self.data[1:]:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
82 myStr += ","
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
83 myStr += str(a)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
84 myStr += "] = (" + str(self.sum()) + ")"
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
85 else: myStr = "[] = (0)"
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
86 return myStr
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
87
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
88 def __lt__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
89 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
90 return (self.sum() < other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
91 elif hasattr(other,"sum"): return (self.sum() < other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
92 else: return UserList.UserList.__lt__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
93
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
94 def __le__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
95 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
96 return (self.sum() <= other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
97 elif hasattr(other,"sum"): return (self.sum() <= other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
98 else: return UserList.UserList.__le__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
99
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
100 def __eq__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
101 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
102 return (self.sum() == other)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
103 elif hasattr(other,"sum"): return (self.sum() == other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
104 else: return UserList.UserList.__eq__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
105
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
106 def __ne__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
107 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
108 elif hasattr(other,"sum"): return (self.sum() != other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
109 else: return UserList.UserList.__ne__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
110
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
111 def __gt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
112 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
113 elif hasattr(other,"sum"): return (self.sum() > other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
114 else: return UserList.UserList.__gt__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
115
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
116 def __ge__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
117 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
118 elif hasattr(other,"sum"): return (self.sum() >= other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
119 else: return UserList.UserList.__ge__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
120
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
121 def __cmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
122 # this function included for backwards compatibility
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
123 # As of 2.1, lists implement the "rich comparison"
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
124 # methods overloaded above.
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
125 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
126 elif hasattr(other,"sum"): return cmp(self.sum(), other.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
127 else: return UserList.UserList.__cmp__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
128
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
129 def __rcmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
130 return self.__cmp__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
131
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
132 def __add__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
133 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
134 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
135 other = [static_di(other)]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
136 elif type(other) == type("test"): return self
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
137 mycopy.extend(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
138 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
139
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
140 def __iadd__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
141 return self.__add__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
142
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
143 def __radd__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
144 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
145 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
146 new_die = di(0)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
147 new_die.set_value(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
148 other = new_die
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
149 mycopy.insert(0,other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
150 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
151
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
152 def __int__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
153 return self.sum()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
154
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
155 def __sub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
156 mycopy = copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
157 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
158 neg_die = static_di(-other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
159 other = [neg_die]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
160 else: other = -other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
161 mycopy.extend(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
162 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
163
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
164 def __rsub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
165 mycopy = -copy.deepcopy(self)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
166 if type(other) == type(3) or type(other) == type(3.0):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
167 new_die = di(0)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
168 new_die.set_value(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
169 other = new_die
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
170 mycopy.insert(0,other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
171 return mycopy
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
172
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
173 def __isub__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
174 return self.__sub__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
175
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
176 def __mul__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
177 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
178 elif hasattr(other,"sum"): return other.sum() * self.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
179 else: return UserList.UserList.__mul__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
180
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
181 def __rmul__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
182 return self.__mul__(other)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
183
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
184 def __div__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
185 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
186 elif hasattr(other,"sum"): return float(self.sum()) / other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
187 else: return UserList.UserList.__div__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
188
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
189 def __rdiv__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
190 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
191 elif hasattr(other,"sum"): return other.sum() / float(self.sum())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
192 else: return UserList.UserList.__rdiv__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
193
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
194 def __mod__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
195 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
196 elif hasattr(other,"sum"): return self.sum() % other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
197 else: return UserList.UserList.__mod__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
198
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
199 def __rmod__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
200 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
201 elif hasattr(other,"sum"): return other.sum() % self.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
202 else: return UserList.UserList.__rmod__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
203
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
204 def __neg__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
205 for i in range(len(self.data)): self.data[i] = -self.data[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
206 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
207
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
208 def __pos__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
209 for i in range(len(self.data)): self.data[i] = +self.data[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
210 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
211
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
212 def __abs__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
213 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
214 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
215
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
216 def __pow__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
217 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
218 elif hasattr(other,"sum"): return self.sum() ** other.sum()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
219 else: return UserList.UserList.__pow__(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
220
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
221 def __rpow__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
222 # We're overloading exponentiation of ints to create "other" number of dice
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
223 if other >= 1:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
224 result = self.__class__(self[0].sides)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
225 for t in range(other-1): result+=self.__class__(self[0].sides)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
226 else: result = None
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
227 return result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
228
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
229 ### di class to handle actual dice
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
230
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
231 class di:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
232 def __init__(self, sides, min=1):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
233 self.sides = sides
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
234 self.history = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
235 self.value = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
236 self.target = None
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
237 self.roll(min)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
238
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
239 def __str__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
240 if len(self.history) > 1: return str(self.history)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
241 else: return str(self.value)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
242
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
243 def __neg__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
244 self.value = -self.value
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
245 for i in range(len(self.history)): self.history[i] = -self.history[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
246 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
247
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
248 def __pos__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
249 self.value = +self.value
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
250 for i in range(len(self.history)): self.history[i] = +self.history[i]
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
251 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
252
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
253 def __abs__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
254 self.value = abs(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
255 for i in range(len(self.history)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
256 self.history[i] = abs(self.history[i])
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
257 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
258
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
259 def __repr__(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
260 if len(self.history) > 1: return str(self.history)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
261 else: return str(self.value)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
262
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
263 def __int__(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
264 return self.value
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
265
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
266 def __lt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
267 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
268 elif hasattr(other,"value"): return self.value < other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
269 else: return self < other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
270
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
271 def __le__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
272 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
273 elif hasattr(other,"value"): return self.value <= other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
274 else: return self <= other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
275
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
276 def __eq__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
277 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
278 elif hasattr(other,"value"): return self.value == other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
279 else: return self == other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
280
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
281 def __ne__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
282 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
283 elif hasattr(other,"value"): return self.value != other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
284 else: return self != other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
285
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
286 def __gt__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
287 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
288 elif hasattr(other,"value"): return self.value > other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
289 else: return self > other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
290
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
291 def __ge__(self,other):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
292 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
293 elif hasattr(other,"value"): return self.value >= other.value
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
294 else: return self >= other
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
295
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
296 def __cmp__(self,other):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
297 # this function included for backwards compatibility
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 177
diff changeset
298 # As of 2.1, lists implement the "rich comparison"
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 177
diff changeset
299 # methods overloaded above.
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
300 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
301 elif hasattr(other,"value"): return cmp(self.value, other.value)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
302 else: return cmp(self,other)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
303
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
304 def roll(self,min=1):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
305 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
306 else: self.value = int(random.uniform(min, self.sides+1))
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
307 self.history = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
308 self.history.append(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
309
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
310 def extraroll(self):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
311 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
312 else: result = int(random.uniform(1,self.sides+1))
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
313 self.value += result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
314 self.history.append(result)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
315
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
316 def lastroll(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
317 return self.history[len(self.history)-1]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
318
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
319 def set_value(self,value):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
320 self.value = value
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
321 self.history = []
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
322 self.history.append(self.value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
323
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
324 def modify(self,mod):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
325 self.value += mod
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
326 self.history.append(mod)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
327
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
328 def gethistory(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
329 return self.history[:]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
330
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
331 class static_di(di):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
332 def __init__(self,value):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
333 di.__init__(self,value,value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
334 self.set_value(value)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
335
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
336 class DieRollers(object):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
337 _rollers = {}
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
338 def __new__(cls):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
339 it = cls.__dict__.get("__it__")
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 180
diff changeset
340 if it is not None: return it
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
341 cls.__it__ = it = object.__new__(cls)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
342 return it
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
343
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
344 def keys(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
345 return self._rollers.keys()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
346
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
347 def register(self, roller):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
348 if not self._rollers.has_key(roller.name):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
349 self._rollers[roller.name] = roller
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
350
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
351 def __getitem__(self, roller_name):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
352 return self._rollers.get(roller_name, None)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
353
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
354 def __setitem__(self, *args):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
355 raise AttributeError
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
356
177
60dde67c4ed6 Traipse Alpha 'OpenRPG' {100114-00}
sirebral
parents: 167
diff changeset
357 die_rollers = DieRollers()