annotate orpg/dieroller/die.py @ 155:bf799efe7a8a alpha

Traipse Alpha 'OpenRPG' {091125-02} 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 (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 12:32:34 -0600
parents 449a8900f9ac
children 565ab3d84430
rev   line source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
1 #!/usr/bin/env python
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
2 # Copyright (C) 2000-2001 The OpenRPG Project
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
3 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
4 # openrpg-dev@lists.sourceforge.net
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
5 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
6 # This program is free software; you can redistribute it and/or modify
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
7 # it under the terms of the GNU General Public License as published by
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
9 # (at your option) any later version.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
10 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
11 # This program is distributed in the hope that it will be useful,
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
14 # GNU General Public License for more details.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
15 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
16 # You should have received a copy of the GNU General Public License
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
17 # along with this program; if not, write to the Free Software
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
19 # --
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
20 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
21 # File: die.py
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
22 # Author: Andrew Bennett
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
23 # Maintainer:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
24 # Version:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
25 # $Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
26 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
27 # Description: This class is used to make working with dice easier
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
28 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
29
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
30 __version__ = "$Id: die.py,v 1.13 2007/03/13 17:53:42 digitalxero Exp $"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
31
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
32
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
33 import random
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
34 import UserList
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
35 import copy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
36 #import string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
37
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
38 class die_base(UserList.UserList):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
39
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
40
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
41 def __init__(self,source = []):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
42 if isinstance(source, (int, float, basestring)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
43 s = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
44 s.append(di(source))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
45 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
46 s = source
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
47 UserList.UserList.__init__(self,s)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
48
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
49
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
50
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
51 def sum(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
52 s = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
53 for a in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
54 s += int(a)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
55 return s
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
56
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
57
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
58 def __lshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
59 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
60 o = other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
61 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
62 o = other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
63 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
64 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
65
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
66 result = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
67 for die in self:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
68 if die < o:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
69 result.append(die)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
70 return self.__class__(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
71
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
72
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
73 def __rshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
74
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
75 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
76 o = other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
77 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
78 o = other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
79 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
80 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
81
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
82 result = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
83 for die in self:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
84 if die > o:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
85 result.append(die)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
86 return self.__class__(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
87
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
88
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
89 def __rlshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
90 return self.__rshift__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
91
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
92
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
93 def __rrshift__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
94 return self.__lshift__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
95
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
96
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
97
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
98 def __str__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
99 if len(self.data) > 0:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
100 myStr = "[" + str(self.data[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
101 for a in self.data[1:]:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
102 myStr += ","
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
103 myStr += str(a)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
104 myStr += "] = (" + str(self.sum()) + ")"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
105 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
106 myStr = "[] = (0)"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
107 return myStr
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
108
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
109
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
110 def __lt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
111 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
112 return (self.sum() < other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
113 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
114 return (self.sum() < other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
115 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
116 return UserList.UserList.__lt__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
117
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
118
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
119 def __le__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
120 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
121 return (self.sum() <= other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
122 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
123 return (self.sum() <= other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
124 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
125 return UserList.UserList.__le__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
126
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
127
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
128 def __eq__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
129 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
130 return (self.sum() == other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
131 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
132 return (self.sum() == other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
133 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
134 return UserList.UserList.__eq__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
135
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
136
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
137 def __ne__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
138 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
139 return (self.sum() != other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
140 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
141 return (self.sum() != other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
142 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
143 return UserList.UserList.__ne__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
144
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
145
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
146 def __gt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
147 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
148 return (self.sum() > other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
149 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
150 return (self.sum() > other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
151 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
152 return UserList.UserList.__gt__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
153
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
154
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
155 def __ge__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
156 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
157 return (self.sum() >= other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
158 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
159 return (self.sum() >= other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
160 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
161 return UserList.UserList.__ge__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
162
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
163
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
164 def __cmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
165 # this function included for backwards compatibility
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
166 # As of 2.1, lists implement the "rich comparison"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
167 # methods overloaded above.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
168 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
169 return cmp(self.sum(), other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
170 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
171 return cmp(self.sum(), other.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
172 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
173 return UserList.UserList.__cmp__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
174
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
175
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
176
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
177 def __rcmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
178 return self.__cmp__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
179
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
180
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
181 def __add__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
182 mycopy = copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
183 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
184 #if other < 0:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
185 # return self.__sub__(-other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
186 #other = [di(other,other)]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
187 other = [static_di(other)]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
188 #return self.sum() + other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
189
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
190 elif type(other) == type("test"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
191 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
192 mycopy.extend(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
193 #result = UserList.UserList.__add__(mycopy,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
194 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
195
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
196
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
197 def __iadd__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
198 return self.__add__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
199
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
200
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
201 def __radd__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
202 mycopy = copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
203 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
204 new_die = di(0)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
205 new_die.set_value(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
206 other = new_die
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
207 mycopy.insert(0,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
208 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
209
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
210
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
211 def __int__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
212 return self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
213
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
214
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
215 def __sub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
216 mycopy = copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
217 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
218 neg_die = static_di(-other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
219 #neg_die.set_value(-other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
220 other = [neg_die]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
221 #return self.sum() - other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
222 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
223 other = -other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
224 mycopy.extend(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
225 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
226
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
227
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
228 def __rsub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
229 mycopy = -copy.deepcopy(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
230 #print type(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
231 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
232 new_die = di(0)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
233 new_die.set_value(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
234 other = new_die
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
235 mycopy.insert(0,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
236 return mycopy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
237
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
238
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
239 def __isub__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
240 return self.__sub__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
241
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
242
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
243 def __mul__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
244 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
245 return self.sum() * other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
246 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
247 return other.sum() * self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
248 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
249 return UserList.UserList.__mul__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
250
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
251
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
252 def __rmul__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
253 return self.__mul__(other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
254
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
255
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
256 def __div__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
257 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
258 return float(self.sum()) / other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
259 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
260 return float(self.sum()) / other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
261 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
262 return UserList.UserList.__div__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
263
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
264
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
265 def __rdiv__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
266 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
267 return other / float(self.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
268 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
269 return other.sum() / float(self.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
270 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
271 return UserList.UserList.__rdiv__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
272
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
273
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
274 def __mod__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
275 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
276 return self.sum()%other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
277 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
278 return self.sum() % other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
279 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
280 return UserList.UserList.__mod__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
281
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
282
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
283 def __rmod__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
284 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
285 return other % self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
286 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
287 return other.sum() % self.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
288 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
289 return UserList.UserList.__rmod__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
290
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
291
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
292 def __neg__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
293 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
294 self.data[i] = -self.data[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
295 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
296
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
297
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
298 def __pos__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
299 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
300 self.data[i] = +self.data[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
301 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
302
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
303
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
304 def __abs__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
305 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
306 self.data[i] = abs(self.data[i])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
307 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
308 #return abs(self.sum())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
309
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
310
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
311 def __pow__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
312 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
313 return self.sum() ** other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
314 elif hasattr(other,"sum"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
315 return self.sum() ** other.sum()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
316 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
317 return UserList.UserList.__pow__(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
318
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
319
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
320
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
321 def __rpow__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
322 # We're overloading exponentiation of ints to create "other" number of dice
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
323
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
324 if other >= 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
325 result = self.__class__(self[0].sides)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
326 for t in range(other-1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
327 result+=self.__class__(self[0].sides)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
328 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
329 result = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
330
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
331 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
332
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
333 ### di class to handle actual dice
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
334
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
335 class di:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
336
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
337 def __init__(self,sides,min=1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
338 self.sides = sides
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
339 self.history = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
340 self.value = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
341 self.target = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
342 self.roll(min)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
343
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
344
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
345 def __str__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
346 if len(self.history) > 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
347 return str(self.history)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
348 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
349 return str(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
350
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
351
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
352 def __neg__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
353 self.value = -self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
354 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
355 self.history[i] = -self.history[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
356 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
357
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
358
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
359 def __pos__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
360 self.value = +self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
361 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
362 self.history[i] = +self.history[i]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
363 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
364
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
365
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
366 def __abs__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
367 self.value = abs(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
368 for i in range(len(self.history)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
369 self.history[i] = abs(self.history[i])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
370 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
371
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
372
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
373 def __repr__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
374 if len(self.history) > 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
375 return str(self.history)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
376 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
377 return str(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
378
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
379
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
380 def __int__(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
381 return self.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
382
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
383
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
384
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
385 def __lt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
386 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
387 return self.value < other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
388 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
389 return self.value < other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
390 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
391 return self < other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
392
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
393
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
394 def __le__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
395 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
396 return self.value <= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
397 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
398 return self.value <= other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
399 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
400 return self <= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
401
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
402
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
403 def __eq__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
404 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
405 return self.value == other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
406 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
407 return self.value == other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
408 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
409 return self == other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
410
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
411
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
412 def __ne__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
413 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
414 return self.value != other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
415 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
416 return self.value != other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
417 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
418 return self != other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
419
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
420
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
421 def __gt__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
422 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
423 return self.value > other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
424 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
425 return self.value > other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
426 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
427 return self > other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
428
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
429
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
430 def __ge__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
431 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
432 return self.value >= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
433 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
434 return self.value >= other.value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
435 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
436 return self >= other
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
437
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
438
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
439 def __cmp__(self,other):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
440 # this function included for backwards compatibility
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
441 # As of 2.1, lists implement the "rich comparison"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
442 # methods overloaded above.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
443 if type(other) == type(3) or type(other) == type(3.0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
444 return cmp(self.value, other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
445 elif hasattr(other,"value"):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
446 return cmp(self.value, other.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
447 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
448 return cmp(self,other)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
449
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
450
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
451 def roll(self,min=1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
452 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
453 self.value = random.randint(-1, 1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
454 else:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
455 #self.value = random.randint(min, self.sides)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
456 self.value = int(random.uniform(min, self.sides+1))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
457 self.history = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
458 self.history.append(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
459
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
460
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
461 def extraroll(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
462 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
463 result = random.randint(-1, 1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
464 else:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
465 #result = random.randint(1, self.sides)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
466 result = int(random.uniform(1,self.sides+1))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
467
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
468 self.value += result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
469 self.history.append(result)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
470
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
471
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
472 def lastroll(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
473 return self.history[len(self.history)-1]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
474
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
475
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
476 def set_value(self,value):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
477 self.value = value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
478 self.history = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
479 self.history.append(self.value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
480
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
481
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
482 def modify(self,mod):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
483 self.value += mod
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
484 self.history.append(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
485
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
486
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
487 def gethistory(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
488 return self.history[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
489
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
490 class static_di(di):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
491
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
492 def __init__(self,value):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
493 di.__init__(self,value,value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
494 self.set_value(value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
495
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
496
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
497 class std(die_base):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
498
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
499 def __init__(self,source=[]):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
500 die_base.__init__(self,source)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
501
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
502 # Examples of adding member functions through inheritance.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
503
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
504
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
505 def ascending(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
506 result = self[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
507 result.sort()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
508 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
509
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
510
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
511 def descending(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
512 result = self[:]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
513 result.sort()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
514 result.reverse()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
515 return result
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
516
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
517
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
518 def takeHighest(self,num_dice):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
519 return self.descending()[:num_dice]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
520
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
521
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
522 def takeLowest(self,num_dice):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
523 return self.ascending()[:num_dice]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
524
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
525
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
526 def extra(self,num):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
527 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
528 if self.data[i].lastroll() >= num:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
529 self.data[i].extraroll()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
530 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
531
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
532
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
533 def open(self,num):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
534 if num <= 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
535 self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
536 done = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
537 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
538 if self.data[i].lastroll() >= num:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
539 self.data[i].extraroll()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
540 done = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
541 if done:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
542 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
543 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
544 return self.open(num)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
545
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
546
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
547 def minroll(self,min):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
548 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
549 if self.data[i].lastroll() < min:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
550 self.data[i].roll(min)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
551 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
552
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
553
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
554 def each(self,mod):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
555 mod = int(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
556 for i in range(len(self.data)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
557 self.data[i].modify(mod)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
558 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
559
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
560
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
561
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
562 def vs(self, target):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
563 for dn in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
564 dn.target = target
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
565 return self
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
566
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
567
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
568 ## If we are testing against a saving throw, we check for
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
569 ## greater than or equal to against the target value and
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
570 ## we only return the number of successful saves. A negative
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
571 ## value will never be generated.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
572
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
573 def sum(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
574 retValue = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
575 for dn in self.data:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
576 setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
577 if dn.target:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
578 if setValue >= dn.target:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
579 retValue += 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
580
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
581 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
582 retValue += setValue
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
583
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 71
diff changeset
584 return retValue