removed protection elemental
[asgard.git] / eventtype.py
blobd34fb9666fb3f920d103dbd6d8585281ac4f98f8
1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
19 import math
20 import random
21 from transaction import *
23 class EventType:
24 def __init__(self, tn, name, afflictions, elementals, mpC):
25 self.__typeName = tn
26 self.__name = name
27 self.__afflictions = afflictions
28 self.__elementals = elementals
29 self.__mpCost = mpC
31 def getTypeName(self):
32 return self.__typeName
34 def setTypeName(self, tn):
35 self.__typeName = tn
37 def getName(self):
38 return self.__name
40 def setName(self, name):
41 self.__name = name
43 def getAfflictions(self):
44 return self.__afflictions
46 def setAfflictions(self, aff):
47 self.__afflictions = aff
49 def getElementals(self):
50 return self.__elementals
52 def setElementals(self, elem):
53 self.__elementals = elem
55 def getMpCost(self):
56 return self.__mpCost
58 def setMpCost(self, mpC):
59 self.__mpCost = mpC
61 def detTransactions(self, exct, targets):
62 transList = []
63 if self.__typeName == "ATTACK":
64 for t in targets:
65 # Hit/Miss?
66 numHits = self.__computeHM(exct.getStat("dex").getCurrent(),t.getStat("agl").getCurrent())
67 # Auto-Kill!
68 if numHits == 5:
69 # hpChange is target's current hp
70 hpChange = t.getStat("hp").getCurrent()
71 # Non-lethal damage
72 else:
73 hpChange = numHits * (t.getDefense() - exct.getAttack())
74 transList.append(Transaction(t,"hp",int(hpChange),None))
75 elif self.__typeName == "BLACK":
76 # mpCost transaction
77 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
78 for t in targets:
79 for e in self.__elementals:
80 # Compute base-error damage
81 be = self.__computeBaseError(e[1],e[2])
82 # Compute <damage per target> = <base-error damage>/len(targets)
83 dmgPer = be/len(targets)
84 # Compute net damage according to executor's will
85 netDmg = dmgPer * math.log10(exct.getStat("wil").getCurrent() + 2)
86 # elemental mod(float) for target?
87 mod = t.getElemModifier(e[0])
88 # Compute hpChange for target
89 hpChange = netDmg * (1.0 - mod)
90 transList.append(Transaction(t,"hp",int(hpChange),None))
92 for s in self.__afflictions:
93 if self.__eventOccurs(t.getStatusModifier(s)):
94 transList.append(Transaction(t,None,0,s))
97 elif self.__typeName == "WHITE":
98 # mpCost transaction
99 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
100 for t in targets:
101 for e in self.__elementals:
102 # Compute base-error damage
103 be = self.__computeBaseError(e[1],e[2])
104 # Compute <damage per target> = <base-error damage>/len(targets)
105 dmgPer = be/len(targets)
106 # Compute net damage according to executor's wisdom
107 netDmg = dmgPer * math.log10(exct.getStat("wis").getCurrent() + 2)
108 # elemental mod(float) for target?
109 mod = t.getElemModifier(e[0])
110 # Compute hpChange for target
111 hpChange = netDmg * (1.0 - mod)
112 transList.append(Transaction(t,"hp",int(hpChange),None))
113 for s in self.__afflictions:
114 if self.__eventOccurs(t.getStatusModifier(s)):
115 transList.append(Transaction(t,None,0,s))
116 return transList
118 def __computeBaseError(self, base, err):
119 n = int(base * err)
120 beg = min(base - n,base + n)
121 end = max(base - n,base + n)
122 return random.randint(beg,end)
124 def __computeHM(self, cdex, cagl):
125 """Hit/Miss? If Hit, how many?"""
126 # Compute Hit %
127 hitPC = (cdex - cagl) + 50
128 # Check that Hit % is in [0,100]
129 if hitPC < 0: hitPC = 0
130 if hitPC > 100: hitPC = 100
131 # Hit/Miss?
132 x = random.randint(1,100)
133 # MISS!
134 if x > hitPC: return 0
135 # HIT!
136 else:
137 if (cdex >= 1) and (cdex <= 100):
138 return 1
139 elif (cdex >= 101) and (cdex <= 200):
140 x = random.randint(1,200)
141 if (x >= 1) and (x <= 100):
142 return 1
143 elif x >= 101: return 2
144 elif (cdex >= 201) and (cdex <= 254):
145 x = random.randint(1,254)
146 if (x >= 1) and (x <= 100):
147 return 1
148 elif (x >= 101) and (x <= 200):
149 return 2
150 elif x >= 201: return 3
151 elif cdex == 255:
152 x = random.randint(1,2)
153 if x == 1: return 4
154 elif x == 2: return 5
156 def __eventOccurs(self, percent):
157 a = random.randint(1,100)
158 b = 100 * percent
159 return (a < b)