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"
|
|
41
|
|
42 def __init__(self,source=[],target=0,targetthr=0):
|
|
43 std.__init__(self,source)
|
|
44 self.target = target
|
|
45 self.targetthr = targetthr
|
|
46
|
|
47 def vs(self,target):
|
|
48 self.target = target
|
|
49 return self
|
|
50
|
|
51 def thr(self,targetthr):
|
|
52 self.targetthr = targetthr
|
|
53 return self
|
|
54
|
|
55 def sum(self):
|
|
56 rolls = []
|
|
57 s = 0
|
|
58 s1 = self.targetthr
|
|
59 botch = 0
|
|
60 for a in self.data:
|
|
61 rolls.extend(a.gethistory())
|
|
62 for r in rolls:
|
|
63 if r >= self.target or r == 10:
|
|
64 s += 1
|
|
65 if s1 >0:
|
|
66 s1 -= 1
|
|
67 s -= 1
|
183
|
68 else: botch = 1
|
|
69 elif r == 1: s -= 1
|
|
70 if botch == 1 and s < 0: s = 0
|
171
|
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)
|
183
|
79 if self.sum() < 0: myStr += "] vs " +str(self.target)+" result of a botch"
|
|
80 elif self.sum() == 0: myStr += "] vs " +str(self.target)+" result of a failure"
|
|
81 else: myStr += "] vs " +str(self.target)+" result of (" + str(self.sum()) + ")"
|
171
|
82 return myStr
|
|
83
|
183
|
84 def non_stdDie(self, s):
|
|
85 num_sides = s.split('v')
|
|
86 if len(num_sides) > 1:
|
|
87 num_sides; num = num_sides[0]; sides = num_sides[1]
|
|
88 sides = '10'; target = num_sides[1]
|
|
89 ret = ['(', num.strip(), "**die_rollers['wod'](",
|
|
90 sides.strip(), ')).vs(', target, ')']
|
|
91 s = ''.join(ret); return str(eval(s))
|
|
92
|
|
93 die_rollers.register(wod)
|