Stubbed out Drawable and MenuDrawable, added commenting for epydoc.
[asgard.git] / utilities.py
blob86bc4e053af49652cc0cd8ea273f043459dce16c
1 import random
3 def computeBaseError(base, err):
5 """ Computes a "net" damage by multiplying base and error from
6 elemental, subtracting and adding the base by that product (thus
7 creating a range of integers), and generating a random
8 number from that range. """
10 n = int(base * err)
11 beg = min(base - n,base + n)
12 end = max(base - n,base + n)
13 return random.randint(beg,end)
15 def computeHM(cdex, cagl):
16 """Computes whether or not the executor of an ATTACK hits or misses his
17 target by directly comparing the executor's current dexterity (cdex) to
18 his target's current agility (cagl). If he makes a hit, computes (and
19 returns) the number of hits based on various ranges of current
20 dexterity. """
22 # Compute Hit %
23 hitPC = (cdex - cagl) + 50
24 # Check that Hit % is in [0,100]
25 if hitPC < 0: hitPC = 0
26 if hitPC > 100: hitPC = 100
27 # Hit/Miss?
28 x = random.randint(1,100)
29 # MISS!
30 if x > hitPC: return 0
31 # HIT!
32 else:
33 if (cdex >= 1) and (cdex <= 100):
34 return 1
35 elif (cdex >= 101) and (cdex <= 200):
36 x = random.randint(1,200)
37 if (x >= 1) and (x <= 100):
38 return 1
39 elif x >= 101: return 2
40 elif (cdex >= 201) and (cdex <= 254):
41 x = random.randint(1,254)
42 if (x >= 1) and (x <= 100):
43 return 1
44 elif (x >= 101) and (x <= 200):
45 return 2
46 elif x >= 201: return 3
47 elif cdex == 255:
48 x = random.randint(1,2)
49 if x == 1: return 4
50 elif x == 2: return 5
52 def eventOccurs(percent):
53 a = random.randint(1,100)
54 b = 100 * percent
55 return (a < b)
57 def jobStatQuery(jTree,sname):
58 plus = 0
59 growthRate = 0.0
60 chance = 0.0
62 jStatQuery = jTree.xpathEval("//stat[@name='" + sname + "']")
64 if jStatQuery != []:
65 jStatElem = jStatQuery[0]
67 if jStatElem.prop("plus") != None:
68 plus = int(jStatElem.prop("plus"))
70 if jStatElem.prop("growthRate") != None:
71 growthRate = float(jStatElem.prop("growthRate"))
73 if jStatElem.prop("chance") != None:
74 chance = float(jStatElem.prop("chance"))
77 return (plus,chance,growthRate)