171
|
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:
|
184
|
26 # $Id: wod.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
171
|
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
|
184
|
34 __version__ = "$Id: wod.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
171
|
35
|
|
36 from std import std
|
|
37 from orpg.dieroller.base import *
|
|
38
|
|
39 class wod(std):
|
|
40 name = "wod"
|
239
|
41 regExpression = "[\(0-9\*\-\+\)]+[a-zA-Z]+[0-9]+"
|
171
|
42
|
|
43 def __init__(self,source=[],target=0,targetthr=0):
|
|
44 std.__init__(self,source)
|
|
45 self.target = target
|
|
46 self.targetthr = targetthr
|
|
47
|
|
48 def vs(self,target):
|
|
49 self.target = target
|
|
50 return self
|
|
51
|
|
52 def thr(self,targetthr):
|
|
53 self.targetthr = targetthr
|
|
54 return self
|
|
55
|
|
56 def sum(self):
|
|
57 rolls = []
|
|
58 s = 0
|
|
59 s1 = self.targetthr
|
|
60 botch = 0
|
|
61 for a in self.data:
|
|
62 rolls.extend(a.gethistory())
|
|
63 for r in rolls:
|
|
64 if r >= self.target or r == 10:
|
|
65 s += 1
|
|
66 if s1 >0:
|
|
67 s1 -= 1
|
|
68 s -= 1
|
183
|
69 else: botch = 1
|
|
70 elif r == 1: s -= 1
|
|
71 if botch == 1 and s < 0: s = 0
|
171
|
72 return s
|
|
73
|
|
74 def __str__(self):
|
|
75 if len(self.data) > 0:
|
|
76 myStr = "[" + str(self.data[0])
|
|
77 for a in self.data[1:]:
|
|
78 myStr += ","
|
|
79 myStr += str(a)
|
183
|
80 if self.sum() < 0: myStr += "] vs " +str(self.target)+" result of a botch"
|
|
81 elif self.sum() == 0: myStr += "] vs " +str(self.target)+" result of a failure"
|
|
82 else: myStr += "] vs " +str(self.target)+" result of (" + str(self.sum()) + ")"
|
171
|
83 return myStr
|
|
84
|
239
|
85 def non_stdDie(self, match):
|
|
86 s = match.group(0)
|
183
|
87 num_sides = s.split('v')
|
|
88 if len(num_sides) > 1:
|
|
89 num_sides; num = num_sides[0]; sides = num_sides[1]
|
|
90 sides = '10'; target = num_sides[1]
|
|
91 ret = ['(', num.strip(), "**die_rollers['wod'](",
|
|
92 sides.strip(), ')).vs(', target, ')']
|
239
|
93 s = ''.join(ret); return s
|
183
|
94
|
|
95 die_rollers.register(wod)
|