enemy pointers are now actually enemy clones. (3 rocs = 3 entirely separate rocs)
[asgard.git] / eventtype.py
blob34e8d5a8f69a8c0023ca75a3dac008831f50b339
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 *
22 from utilities 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 __init__(self, eTree):
32 """ Construct an Eventtype object from an eventtype XML tree. """
34 # These are in every Eventtype!
35 self.__name = eTree.xpathEval("//name")[0].content
36 self.__typeName = eTree.xpathEval("//type")[0].content
37 self.__mpCost = int(eTree.xpathEval("//mpCost")[0].content)
39 # Retrieving any status afflictions
40 self.__afflictions = []
41 aTree = eTree.xpathEval("//status")
42 for a in aTree:
43 self.__afflictions.append(a)
45 # Retrieving any elementals
46 self.__elementals = []
47 elemTree = eTree.xpathEval("//element")
48 for elem in elemTree:
49 n = elem.xpathEval("//name")[0].content
50 b = int(elem.prop("base"))
51 err = float(elem.prop("error"))
52 self.__elementals.append((n,b,err))
54 def getTypeName(self):
55 return self.__typeName
57 def setTypeName(self, tn):
58 self.__typeName = tn
60 def getName(self):
61 return self.__name
63 def setName(self, name):
64 self.__name = name
66 def getAfflictions(self):
67 return self.__afflictions
69 def setAfflictions(self, aff):
70 self.__afflictions = aff
72 def getElementals(self):
73 return self.__elementals
75 def setElementals(self, elem):
76 self.__elementals = elem
78 def getMpCost(self):
79 return self.__mpCost
81 def setMpCost(self, mpC):
82 self.__mpCost = mpC
84 def detTransactions(self, exct, targets):
85 transList = []
86 if self.__typeName == "ATTACK":
87 for t in targets:
88 # Hit/Miss?
89 numHits = computeHM(exct.getStat("dex").getCurrent(),t.getStat("agl").getCurrent())
90 # Auto-Kill!
91 if numHits == 5:
92 # hpChange is target's current hp
93 hpChange = t.getStat("hp").getCurrent()
94 # Non-lethal damage
95 else:
96 hpChange = numHits * (t.getDefense() - exct.getAttack())
97 transList.append(Transaction(t,"hp",int(hpChange),None))
98 elif self.__typeName == "BLACK":
99 # mpCost transaction
100 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
101 for t in targets:
102 for e in self.__elementals:
103 # Compute base-error damage
104 be = computeBaseError(e[1],e[2])
105 # Compute <damage per target> = <base-error damage>/len(targets)
106 dmgPer = be/len(targets)
107 # Compute net damage according to executor's will
108 netDmg = dmgPer * math.log10(exct.getStat("wil").getCurrent() + 2)
109 # elemental mod(float) for target?
110 mod = t.getElemModifier(e[0])
111 # Compute hpChange for target
112 hpChange = netDmg * (1.0 - mod)
113 transList.append(Transaction(t,"hp",int(hpChange),None))
115 for s in self.__afflictions:
116 if self.__eventOccurs(t.getStatusModifier(s)):
117 transList.append(Transaction(t,None,0,s))
120 elif self.__typeName == "WHITE":
121 # mpCost transaction
122 transList.append(Transaction(exct,"mp",-1 * self.__mpCost,None))
123 for t in targets:
124 for e in self.__elementals:
125 # Compute base-error damage
126 be = computeBaseError(e[1],e[2])
127 # Compute <damage per target> = <base-error damage>/len(targets)
128 dmgPer = be/len(targets)
129 # Compute net damage according to executor's wisdom
130 netDmg = dmgPer * math.log10(exct.getStat("wis").getCurrent() + 2)
131 # elemental mod(float) for target?
132 mod = t.getElemModifier(e[0])
133 # Compute hpChange for target
134 hpChange = netDmg * (1.0 - mod)
135 transList.append(Transaction(t,"hp",int(hpChange),None))
136 for s in self.__afflictions:
137 if self.__eventOccurs(t.getStatusModifier(s)):
138 transList.append(Transaction(t,None,0,s))
139 return transList