annotate orpg/dieroller/rollers/std.py @ 195:b633f4c64aae alpha

Traipse Alpha 'OpenRPG' {100219-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 (Patch-2) New Features: New Namespace method with two new syntaxes Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup
author sirebral
date Sat, 24 Apr 2010 08:37:20 -0500
parents 5c9a118476b2
children 24769389a7ba
rev   line source
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
1 from orpg.dieroller.base import die_base, die_rollers
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
2
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
3 class std(die_base):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
4 name = "std"
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
5
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
6 def __init__(self, source=[]):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
7 die_base.__init__(self, source)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
8
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
9 # Examples of adding member functions through inheritance.
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
10
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
11 def ascending(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
12 result = self[:]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
13 result.sort()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
14 return result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
15
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
16 def descending(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
17 result = self[:]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
18 result.sort()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
19 result.reverse()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
20 return result
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
21
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
22 def takeHighest(self, num_dice):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
23 return self.descending()[:num_dice]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
24
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
25 def takeLowest(self,num_dice):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
26 return self.ascending()[:num_dice]
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
27
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
28 def extra(self, num):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
29 for i in range(len(self.data)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
30 if self.data[i].lastroll() >= num:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
31 self.data[i].extraroll()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
32 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
33
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
34 def open(self, num):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
35 if num <= 1: self
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
36 done = 1
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
37 for i in range(len(self.data)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
38 if self.data[i].lastroll() >= num:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
39 self.data[i].extraroll()
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
40 done = 0
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
41 if done: return self
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
42 else: return self.open(num)
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
43
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
44 def minroll(self,min):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
45 for i in range(len(self.data)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
46 if self.data[i].lastroll() < min:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
47 self.data[i].roll(min)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
48 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
49
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
50 def each(self, mod):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
51 mod = int(mod)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
52 for i in range(len(self.data)):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
53 self.data[i].modify(mod)
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
54 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
55
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
56 def vs(self, target):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
57 for dn in self.data:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
58 dn.target = target
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
59 return self
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
60
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
61
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
62 ## If we are testing against a saving throw, we check for
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
63 ## greater than or equal to against the target value and
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
64 ## we only return the number of successful saves. A negative
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
65 ## value will never be generated.
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
66 def sum(self):
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
67 retValue = 0
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
68 for dn in self.data:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
69 setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
70 if dn.target:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
71 for dv in dn.history:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
72 if int(dv) >= dn.target: retValue += 1
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
73 else:
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
74 retValue += setValue
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
75 return retValue
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents:
diff changeset
76
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 167
diff changeset
77 die_rollers.register(std)