comparison orpg/dieroller/rollers/earthdawn.py @ 36:d02e9197c066 ornery-orc

Traipse 'OpenRPG' {101220-00} 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 (Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log New Earthdawn Dieroller New IronClaw roller, sheet, and image New ShapeShifter PC Sheet Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner Update to Dieroller. Cleaner, more effecient expression system Update to Hidden Die plugin, allows for non standard dice rolls Update to location.py, allows for more portable references when starting Traipse Update to the Features node Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to Server, removing wxPython dependencies where not needed Fix to metaservers.xml file not being created Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug Fix to Gametree for XSLT Sheets Fix to Gametree for locating gametree files Fix to Send to Chat from Gametree Fix to Gametree, renaming and remapping operates correctly Fix to aliaslib, prevents error caused when SafeHTML is sent None
author sirebral
date Sun, 19 Dec 2010 22:44:36 -0600
parents
children
comparison
equal deleted inserted replaced
35:ee890f424e16 36:d02e9197c066
1 ## A die roller as used by Earthdawn RPG
2 # Copyright (C) 2000-2010 The OpenRPG Project
3 #
4 # owner@madmathlabs.com
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # --
20 #
21 # File: earthdawn.py
22 # Author: Prof. Ebral, TaS (Traipse)
23 # Maintainer:
24 # Version:
25 # $Id: earthdawn.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
26 #
27 # Description: Earthdawn Die Roller
28 # Comissioned by Jacob H.
29 #
30
31
32 from std import std
33 import random
34 from orpg.dieroller.base import *
35
36 class earthdawn(std):
37 name = "earthdawn"
38 regExpression = "[a-zA-Z]+([0-9]+/[0-9]+|[0-9]+)"
39
40 def __init__(self, source=[]):
41 std.__init__(self, source)
42 self.successLevels = self.buildLevels()
43
44 def non_stdDie(self, match):
45 s = match.group(0)
46 if s[:4] == 'step' or s[:1] == 's':
47 dice = s.lower().split('step')
48 rollType = 'Step'
49 if len(dice) == 1: dice = s.lower().split('s')
50 try: step, vs = dice[1].split('/')
51 except: step, vs = dice[1], 0
52 stepRoll = self.stepAlgorithm(step)
53 elif s[:5] == 'karma' or s[:1] == 'k':
54 dice = s.lower().split('karma')
55 rollType = 'Karma'
56 if len(dice) == 1: dice = s.lower().split('k')
57 step, vs = dice[1], 0
58 stepRoll = self.stepAlgorithm(step)
59 elif s[:4] == 'test' or s[:1] == 't':
60 dice = s.lower().split('test')
61 rollType = 'Test'
62 if len(dice) == 1: dice = s.lower().split('t')
63 try: step, vs = dice[1].split('/')
64 except: return
65 return self.successTest(step, vs)
66 return self.finalize(step, stepRoll, vs, rollType)
67
68 def rollDice(self, dice, facets):
69 rolls = []
70 for x in range(0, dice):
71 roll = self.roll(facets)
72 while roll >= facets:
73 rolls.append(roll)
74 roll = self.roll(facets)
75 rolls.append(roll)
76 return rolls
77
78 def roll(self, facets):
79 return int(random.uniform(1, facets+1))
80
81 def stepAlgorithm(self, stepRoll):
82 if stepRoll == 0: return 0
83 oneTothree = {'1': -3, '2': -2, '3': -1}
84 if oneTothree.has_key(stepRoll):
85 dieList = self.rollDice(1, 6)
86 dieList[0] += oneTothree[stepRoll]
87 return dieList
88 stepRoll = int(stepRoll)-3; self.dieList = []
89 for step in xrange(0, stepRoll): self.stepIncrease()
90 d6s = 0; d8s = 0; d10s = 0; d12s = 0
91 dieList = []
92 for die in self.dieList:
93 if die == 6: d6s += 1
94 if die == 8: d8s += 1
95 if die == 10: d10s += 1
96 if die == 12: d12s += 1
97 if d6s!= 0: d6s = self.rollDice(d6s, 6); dieList += d6s
98 if d8s!= 0: d8s = self.rollDice(d8s, 8); dieList += d8s
99 if d10s!= 0: d10s = self.rollDice(d10s, 10); dieList += d10s
100 if d12s!= 0: d12s = self.rollDice(d12s, 12); dieList += d12s
101 return dieList
102
103 def stepIncrease(self):
104 lowDie = 12
105 if len(self.dieList) == 0: self.dieList.append(6); return
106 for splitDie in self.dieList:
107 if splitDie < lowDie: lowDie = splitDie
108 if lowDie == 12: self.dieList[self.dieList.index(lowDie)] = 6; self.dieList.append(6); return
109 else: self.dieList[self.dieList.index(lowDie)] += 2; return
110
111 def successLevel(self, level, vs):
112 index = 0
113 successLevels = self.successLevels[int(vs)]
114 for success in successLevels:
115 if level > success: index = successLevels.index(success)+1
116 elif level == success: index = successLevels.index(success)
117 if index == 0: return 'Pathetic'
118 if index == 1: return 'Poor'
119 if index == 2: return 'Average'
120 if index == 3: return 'Good'
121 if index == 4: return 'Excellent'
122 if index >= 5: return 'Extraordinary'
123
124 def successTest(self, stepTotal, vs):
125 myStr = '<b>Success Test: </b> ' +stepTotal+ ' vs. ' +vs
126 successLevel = self.successLevel(int(stepTotal), int(vs))
127 myStr += '= ' +successLevel
128 return myStr
129
130 def finalize(self, step, stepRoll, vs, rollType):
131 myStr = '<b>' +rollType+' Roll: </b>' +step
132 if vs != 0: myStr += ' vs. ' +vs
133 myStr += ' => ' +str(stepRoll)+ ' (Total: '
134 stepTotal = 0
135 for step in stepRoll: stepTotal += step
136 myStr += str(stepTotal)
137 if vs != 0:
138 myStr += ' vs. ' +str(vs)
139 successLevel = self.successLevel(stepTotal, vs)
140 myStr += ') ' +successLevel
141 else: myStr += ')'
142 return myStr
143
144 def buildLevels(self):
145 successLevels = {
146 2: [0, 1, 4, 6, 8, 9], 3: [0, 2, 5, 7, 9, 10], 4: [0, 3, 6, 9, 11, 12],
147 5: [1, 4, 7, 10, 13, 14], 6: [1, 5, 8, 12, 16, 17], 7: [2, 6, 10, 14, 18, 19],
148 8: [3, 7, 12, 15, 19, 20], 9: [4, 8, 14, 17, 21, 22], 10: [5, 9, 15, 19, 22, 23],
149 11: [5, 10, 16, 20, 24, 25], 12: [6, 11, 17, 22, 26, 27], 13: [6, 12, 19, 24, 28, 29],
150 14: [7, 13, 20, 25, 30, 31], 15: [8, 14, 22, 26, 30, 31], 16: [9, 15, 23, 27, 32, 33],
151 17: [10, 16, 24, 29, 33, 34], 18: [11, 17, 25, 30, 35, 36], 19: [11, 18, 27, 32, 36, 37],
152 20: [12, 19, 28, 33, 38, 39], 21: [13, 20, 29, 35, 40, 41], 22: [14, 21, 30, 36, 41, 42],
153 23: [15, 22, 32, 37, 42, 43], 24: [15, 23, 33, 38, 43, 44], 25: [16, 24, 34, 40, 45, 46],
154 26: [17, 25, 35, 41, 46, 47], 27: [18, 26, 36, 42, 48, 49], 28: [18, 27, 38, 44, 49, 50],
155 29: [20, 28, 39, 45, 50, 51], 30: [20, 29, 40, 46, 52, 53], 31: [21, 30, 41, 47, 53, 54],
156 32: [22, 31, 42, 48, 54, 55], 33: [23, 32, 44, 50, 56, 57], 34: [23, 33, 45, 51, 57, 58],
157 35: [24, 34, 46, 52, 59, 60], 36: [25, 35, 47, 53, 59, 60], 37: [26, 36, 48, 55, 61, 62],
158 38: [27, 37, 50, 56, 62, 63], 39: [28, 38, 51, 57, 63, 64], 40: [29, 39, 52, 58, 65, 66],
159 41: [28, 40, 52, 60, 70, 71], 42: [29, 41, 53, 61, 71, 72], 43: [30, 42, 54, 63, 72, 73],
160 44: [31, 43, 55, 64, 74, 75], 45: [31, 44, 57, 66, 76, 77]
161 }
162 return successLevels
163
164 die_rollers.register(earthdawn)
165