changeset 522:cb99e2865f80

Add the d20 roller to the list of new rollers. Also comment out the old_std and old_d20. I will do the same on all rollers I convert them to ensure no depreciation messages
author digitalxero
date Mon, 22 Mar 2010 12:35:52 -0600
parents 71219011e19c
children 9045ef54e8e7
files orpg/dieroller/_base.py orpg/dieroller/rollers/d20.py orpg/dieroller/rollers/std.py
diffstat 3 files changed, 176 insertions(+), 134 deletions(-) [+]
line wrap: on
line diff
--- a/orpg/dieroller/_base.py	Fri Mar 19 18:47:25 2010 -0600
+++ b/orpg/dieroller/_base.py	Mon Mar 22 12:35:52 2010 -0600
@@ -216,6 +216,9 @@
 
     def register(self, roller):
         if not self._rollers.has_key(roller.name):
+            if not isinstance(roller, BaseRoller) and\
+               isinstance(roller(), BaseRoller):
+                roller = roller()
             self._rollers[roller.name] = roller
 
     def list(self):
--- a/orpg/dieroller/rollers/d20.py	Fri Mar 19 18:47:25 2010 -0600
+++ b/orpg/dieroller/rollers/d20.py	Mon Mar 22 12:35:52 2010 -0600
@@ -21,95 +21,134 @@
 
 # d20 stands for "d20 system" not 20 sided die :)
 
-from std import std
-from orpg.dieroller.base import *
+from orpg.dieroller._base import roller_manager
+from std import StandardRoller, std
 
-class d20(std):
+class D20Roller(StandardRoller):
     name = "d20"
 
-    def __init__(self,source=[]):
-        std.__init__(self,source)
+    def _sucess(self, roll, unmodified, dc):
+        return (int(roll) >= dc or unmodified == 20) and unmodified != 1
 
-# these methods return new die objects for specific options
+    def attack(self, ac, mod=0, critical=20):
+        roll = self.history.pop()
+        roll.modified = roll.modified or roll.result
+        r = roll.modified[0]
+        if mod:
+            self.extend_roll(roll, 0, mod)
+
+        if self._sucess(roll, r, ac):
+            if int(roll) >= critical:
+                self.extra = "Critical "
+
+            self.extra += "Hit!"
+        else:
+            self.extra = "Miss!"
 
-    def attack(self,AC,mod,critical):
-        return d20attack(self,AC,mod,critical)
+        self.history.append(roll)
+
+    def dc(self, dc, mod=0):
+        roll = self.history.pop()
+        roll.modified = roll.modified or roll.result
+        r = roll.modified[0]
+        if mod:
+            self.extend_roll(roll, 0, mod)
 
-    def dc(self,DC,mod):
-        return d20dc(self,DC,mod)
+        if self._sucess(roll, r, dc):
+            self.extra = "Success!"
+        else:
+            self.extra = "Failure!"
 
-die_rollers.register(d20)
+        self.history.append(roll)
+
+roller_manager.register(D20Roller)
+
+#class d20(std):
+    #name = "old_d20"
 
-class d20dc(std):
-    def __init__(self,source=[],DC=10,mod=0):
-        std.__init__(self,source)
-        self.DC = DC
-        self.mod = mod
-        self.append(static_di(mod))
+    #def __init__(self,source=[]):
+        #std.__init__(self,source)
+
+## these methods return new die objects for specific options
 
-    def is_success(self):
-        return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1)
+    #def attack(self,AC,mod,critical):
+        #return d20attack(self,AC,mod,critical)
+
+    #def dc(self,DC,mod):
+        #return d20dc(self,DC,mod)
+
+#roller_manager.register(d20)
 
-    def __str__(self):
-        myStr = "[" + str(self.data[0])
-        for a in self.data[1:]:
-            myStr += ","
-            myStr += str(a)
-        myStr += "] = (" + str(self.sum()) + ")"
+#class d20dc(std):
+    #def __init__(self,source=[],DC=10,mod=0):
+        #std.__init__(self,source)
+        #self.DC = DC
+        #self.mod = mod
+        #self.append(static_di(mod))
+
+    #def is_success(self):
+        #return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1)
 
-        myStr += " vs DC " + str(self.DC)
+    #def __str__(self):
+        #myStr = "[" + str(self.data[0])
+        #for a in self.data[1:]:
+            #myStr += ","
+            #myStr += str(a)
+        #myStr += "] = (" + str(self.sum()) + ")"
 
-        if self.is_success():
-            myStr += " Success!"
-        else:
-            myStr += " Failure!"
+        #myStr += " vs DC " + str(self.DC)
 
-        return myStr
+        #if self.is_success():
+            #myStr += " Success!"
+        #else:
+            #myStr += " Failure!"
+
+        #return myStr
 
 
-class d20attack(std):
-    def __init__(self,source=[],AC=10,mod=0,critical=20):
-        std.__init__(self,source)
-        self.mod = mod
-        self.critical = critical
-        self.AC = AC
-        self.append(static_di(mod))
-        self.critical_check()
+#class d20attack(std):
+    #def __init__(self,source=[],AC=10,mod=0,critical=20):
+        #std.__init__(self,source)
+        #self.mod = mod
+        #self.critical = critical
+        #self.AC = AC
+        #self.append(static_di(mod))
+        #self.critical_check()
 
-    def attack(AC=10,mod=0,critical=20):
-        self.mod = mod
-        self.critical = critical
-        self.AC = AC
+    #def attack(AC=10,mod=0,critical=20):
+        #self.mod = mod
+        #self.critical = critical
+        #self.AC = AC
 
-    def critical_check(self):
-        self.critical_result = 0
-        self.critical_roll = 0
-        if self.data[0] >= self.critical and self.is_hit():
-            self.critical_roll = die_base(20) + self.mod
-            if self.critical_roll.sum() >= self.AC:
-                self.critical_result = 1
+    #def critical_check(self):
+        #self.critical_result = 0
+        #self.critical_roll = 0
+        #if self.data[0] >= self.critical and self.is_hit():
+            #self.critical_roll = die_base(20) + self.mod
+            #if self.critical_roll.sum() >= self.AC:
+                #self.critical_result = 1
 
-    def is_critical(self):
-        return self.critical_result
+    #def is_critical(self):
+        #return self.critical_result
 
-    def is_hit(self):
-        return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1)
+    #def is_hit(self):
+        #return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1)
 
-    def __str__(self):
-        myStr = "[" + str(self.data[0])
-        for a in self.data[1:]:
-            myStr += ","
-            myStr += str(a)
-        myStr += "] = (" + str(self.sum()) + ")"
+    #def __str__(self):
+        #myStr = "[" + str(self.data[0])
+        #for a in self.data[1:]:
+            #myStr += ","
+            #myStr += str(a)
+        #myStr += "] = (" + str(self.sum()) + ")"
 
-        myStr += " vs AC " + str(self.AC)
+        #myStr += " vs AC " + str(self.AC)
 
-        if self.is_critical():
-            myStr += " Critical"
+        #if self.is_critical():
+            #myStr += " Critical"
 
-        if self.is_hit():
-            myStr += " Hit!"
-        else:
-            myStr += " Miss!"
+        #if self.is_hit():
+            #myStr += " Hit!"
+        #else:
+            #myStr += " Miss!"
 
-        return myStr
+        #return myStr
--- a/orpg/dieroller/rollers/std.py	Fri Mar 19 18:47:25 2010 -0600
+++ b/orpg/dieroller/rollers/std.py	Mon Mar 22 12:35:52 2010 -0600
@@ -109,87 +109,87 @@
             die = roll.modified[i]
             roll.modified[i] = 1 if die >= target else 0
 
-roller_manager.register(StandardRoller())
+roller_manager.register(StandardRoller)
 
-from orpg.dieroller.base import die_base
-class std(die_base):
-    name = "old_std"
+#from orpg.dieroller.base import die_base
+#class std(die_base):
+    #name = "old_std"
 
-    def __init__(self,source=[]):
-        die_base.__init__(self, source)
+    #def __init__(self,source=[]):
+        #die_base.__init__(self, source)
 
-    #  Examples of adding member functions through inheritance.
+    ##  Examples of adding member functions through inheritance.
 
-    def ascending(self):
-        result = self[:]
-        result.sort()
-        return result
+    #def ascending(self):
+        #result = self[:]
+        #result.sort()
+        #return result
 
-    def descending(self):
-        result = self[:]
-        result.sort()
-        result.reverse()
-        return result
+    #def descending(self):
+        #result = self[:]
+        #result.sort()
+        #result.reverse()
+        #return result
 
-    def takeHighest(self,num_dice):
-        return self.descending()[:num_dice]
+    #def takeHighest(self,num_dice):
+        #return self.descending()[:num_dice]
 
-    def takeLowest(self,num_dice):
-        return self.ascending()[:num_dice]
+    #def takeLowest(self,num_dice):
+        #return self.ascending()[:num_dice]
 
-    def extra(self,num):
-        for i in range(len(self.data)):
-            if self.data[i].lastroll() >= num:
-                self.data[i].extraroll()
-        return self
+    #def extra(self,num):
+        #for i in range(len(self.data)):
+            #if self.data[i].lastroll() >= num:
+                #self.data[i].extraroll()
+        #return self
 
-    def open(self,num):
-        if num <= 1:
-            self
-        done = 1
-        for i in range(len(self.data)):
-            if self.data[i].lastroll() >= num:
-                self.data[i].extraroll()
-                done = 0
-        if done:
-            return self
-        else:
-            return self.open(num)
+    #def open(self,num):
+        #if num <= 1:
+            #self
+        #done = 1
+        #for i in range(len(self.data)):
+            #if self.data[i].lastroll() >= num:
+                #self.data[i].extraroll()
+                #done = 0
+        #if done:
+            #return self
+        #else:
+            #return self.open(num)
 
-    def minroll(self,min):
-        for i in range(len(self.data)):
-            if self.data[i].lastroll() < min:
-                self.data[i].roll(min)
-        return self
+    #def minroll(self,min):
+        #for i in range(len(self.data)):
+            #if self.data[i].lastroll() < min:
+                #self.data[i].roll(min)
+        #return self
 
-    def each(self,mod):
-        mod = int(mod)
-        for i in range(len(self.data)):
-            self.data[i].modify(mod)
-        return self
+    #def each(self,mod):
+        #mod = int(mod)
+        #for i in range(len(self.data)):
+            #self.data[i].modify(mod)
+        #return self
 
 
-    def vs(self, target):
-        for dn in self.data:
-            dn.target = target
-        return self
+    #def vs(self, target):
+        #for dn in self.data:
+            #dn.target = target
+        #return self
 
 
-    ## If we are testing against a saving throw, we check for
-    ## greater than or equal to against the target value and
-    ## we only return the number of successful saves.  A negative
-    ## value will never be generated.
-    def sum(self):
-        retValue = 0
-        for dn in self.data:
-            setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
-            if dn.target:
-                if setValue >= dn.target:
-                    retValue += 1
+    ### If we are testing against a saving throw, we check for
+    ### greater than or equal to against the target value and
+    ### we only return the number of successful saves.  A negative
+    ### value will never be generated.
+    #def sum(self):
+        #retValue = 0
+        #for dn in self.data:
+            #setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
+            #if dn.target:
+                #if setValue >= dn.target:
+                    #retValue += 1
 
-            else:
-                retValue += setValue
+            #else:
+                #retValue += setValue
 
-        return retValue
+        #return retValue
 
-roller_manager.register(std)
\ No newline at end of file
+#roller_manager.register(std)
\ No newline at end of file