comparison orpg/dieroller/wod.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children 449a8900f9ac
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 ## a vs die roller as used by WOD games
2 #!/usr/bin/env python
3 # Copyright (C) 2000-2001 The OpenRPG Project
4 #
5 # openrpg-dev@lists.sourceforge.net
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # --
21 #
22 # File: wod.py
23 # Author: OpenRPG Dev Team
24 # Maintainer:
25 # Version:
26 # $Id: wod.py,v 1.14 2007/05/09 19:57:00 digitalxero Exp $
27 #
28 # Description: WOD die roller
29 #
30 # Targetthr is the Threshhold target
31 # for compatibility with Mage die rolls.
32 # Threshhold addition by robert t childers
33 from die import *
34
35 __version__ = "$Id: wod.py,v 1.14 2007/05/09 19:57:00 digitalxero Exp $"
36
37
38 class wod(std):
39 def __init__(self,source=[],target=0,targetthr=0):
40 std.__init__(self,source)
41 self.target = target
42 self.targetthr = targetthr
43
44 def vs(self,target):
45 self.target = target
46 return self
47
48 def thr(self,targetthr):
49 self.targetthr = targetthr
50 return self
51
52 def sum(self):
53 rolls = []
54 s = 0
55 s1 = self.targetthr
56 botch = 0
57 for a in self.data:
58 rolls.extend(a.gethistory())
59 for r in rolls:
60 if r >= self.target or r == 10:
61 s += 1
62 if s1 >0:
63 s1 -= 1
64 s -= 1
65 else:
66 botch = 1
67 elif r == 1:
68 s -= 1
69 if botch == 1 and s < 0:
70 s = 0
71 return s
72
73 def __str__(self):
74 if len(self.data) > 0:
75 myStr = "[" + str(self.data[0])
76 for a in self.data[1:]:
77 myStr += ","
78 myStr += str(a)
79 if self.sum() < 0:
80 myStr += "] vs " +str(self.target)+" result of a botch"
81 elif self.sum() == 0:
82 myStr += "] vs " +str(self.target)+" result of a failure"
83 else:
84 myStr += "] vs " +str(self.target)+" result of (" + str(self.sum()) + ")"
85
86
87 return myStr