(no commit message)
[asgard.git] / eventtype.py
blob66a2f528b7ad0750077357568b1bcb32a87393ad
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.__name
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?
67 # if hit
68 hpChange = t.getDefense() - exct.getAttack()
69 transList.append(Transaction(t,"hp",int(hpChange),None))
70 elif self.__typeName == "BLACK":
71 # mpCost transaction
72 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
73 for t in targets:
74 for e in self.__elementals:
75 # Compute base-error damage
76 be = self.__computeBaseError(e[1],e[2])
77 # Compute <damage per target> = <base-error damage>/len(targets)
78 dmgPer = be/len(targets)
79 # Compute net damage according to executor's will
80 netDmg = dmgPer * math.log10(exct.getStat("wil").getCurrent() + 2)
81 # elemental mod(float) for target?
82 mod = t.getElemModifier(e[0])
83 # Compute hpChange for target
84 hpChange = netDmg * (1.0 - mod)
85 transList.append(Transaction(t,"hp",int(hpChange),None))
87 for s in self.__afflictions:
88 if self.__eventOccurs(t.getStatusModifier(s)):
89 transList.append(Transaction(t,None,0,s))
92 elif self.__typeName == "WHITE":
93 # mpCost transaction
94 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
95 for t in targets:
96 for e in self.__elementals:
97 # Compute base-error damage
98 be = self.__computeBaseError(e[1],e[2])
99 # Compute <damage per target> = <base-error damage>/len(targets)
100 dmgPer = be/len(targets)
101 # Compute net damage according to executor's wisdom
102 netDmg = dmgPer * math.log10(exct.getStat("wis").getCurrent() + 2)
103 # elemental mod(float) for target?
104 mod = t.getElemModifier(e[0])
105 # Compute hpChange for target
106 hpChange = netDmg * (1.0 - mod)
107 transList.append(Transaction(t,"hp",int(hpChange),None))
108 for s in self.__afflictions:
109 if self.__eventOccurs(t.getStatusModifier(s)):
110 transList.append(Transaction(t,None,0,s))
111 return transList
113 def __computeBaseError(self, base, err):
114 n = int(base * err)
115 beg = min(base - n,base + n)
116 end = max(base - n,base + n)
117 return random.randint(beg,end)
119 def __eventOccurs(self, percent):
120 a = random.randint(1,100)
121 b = 100 * percent
122 return (a < b)