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 ########################################################
21 from transaction
import *
22 from utilities
import *
25 def __init__(self
, eTree
):
26 """ Construct an Eventtype object from an eventtype XML tree. """
28 # These are in every Eventtype!
29 self
.__name
= eTree
.xpathEval("//name")[0].content
30 self
.__typeName
= eTree
.xpathEval("//type")[0].content
31 self
.__mpCost
= int(eTree
.xpathEval("//mpCost")[0].content
)
32 self
.__targetSelection
= (eTree
.xpathEval("//targetSelection")[0].content
== "True")
33 self
.__affectsDeath
= (eTree
.xpathEval("//affectsDeath")[0].content
== "True")
34 self
.__exitBattle
= (eTree
.xpathEval("//exitBattle")[0].content
== "True")
36 # Retrieving any status afflictions
37 self
.__afflictions
= []
38 aTree
= eTree
.xpathEval("//status")
40 self
.__afflictions
.append((a
.content
,a
.prop("remove")=="True"))
42 # Retrieving any elementals
43 self
.__elementals
= []
44 elemTree
= eTree
.xpathEval("//element")
46 n
= elem
.xpathEval("//name")[0].content
47 b
= int(elem
.prop("base"))
48 err
= float(elem
.prop("error"))
49 self
.__elementals
.append((n
,b
,err
))
51 def getTypeName(self
):
52 return self
.__typeName
54 def setTypeName(self
, tn
):
60 def setName(self
, name
):
63 def getAfflictions(self
):
64 return self
.__afflictions
66 def setAfflictions(self
, aff
):
67 self
.__afflictions
= aff
69 def getElementals(self
):
70 return self
.__elementals
72 def setElementals(self
, elem
):
73 self
.__elementals
= elem
78 def setMpCost(self
, mpC
):
81 def getAffectsDeath(self
):
82 return self
.__affectsDeath
84 def setAffectsDeath(self
,affectsDeath
):
85 self
.__affectsDeath
= affectsDeath
87 def getExitBattle(self
):
88 return self
.__exitBattle
90 def setExitBattle(self
, exitBattle
):
91 self
.__exitBattle
= exitBattle
93 def getTargetSelection(self
):
94 return self
.__targetSelection
96 def setTargetSelection(self
,targetSelection
):
97 self
.__targetSelection
= targetSelection
99 def detTransactions(self
, exct
, targets
):
101 if self
.__typeName
== "ATTACK":
104 if t
.isAlive() or self
.__affectsDeath
:
107 numHits
= computeHM(exct
.getStat("dex").getCurrent(),t
.getStat("agl").getCurrent())
110 # hpChange is target's current hp
111 hpChange
= t
.getStat("hp").getCurrent()
114 hpChange
= numHits
* (t
.getDefense() - exct
.getAttack())
116 for s
in t
.getStatus():
117 if s
.getName() == "sleep":
118 t
.removeStatus(s
.getName())
119 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
121 elif self
.__typeName
== "BLACK":
123 transList
.append(TransactionStatistic(exct
,"mp",-1 * self
.__mpCost
))
125 if t
.isAlive() or self
.__affectsDeath
:
126 for e
in self
.__elementals
:
127 # Compute base-error damage
128 be
= computeBaseError(e
[1],e
[2])
129 # Compute <damage per target> = <base-error damage>/len(targets)
130 dmgPer
= be
/len(targets
)
131 # Compute net damage according to executor's will
132 netDmg
= dmgPer
* math
.log10(exct
.getStat("wil").getCurrent() + 2)
133 # elemental mod(float) for target?
134 mod
= t
.getElemModifier(e
[0])
135 # Compute hpChange for target
136 hpChange
= netDmg
* (1.0 - mod
)
137 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
139 for s
in self
.__afflictions
:
140 if eventOccurs(t
.getStatusModifier(s
)):
141 transList
.append(TransactionStatus(t
,s
[0],not s
[1]))
144 elif self
.__typeName
== "WHITE":
146 transList
.append(TransactionStatistic(exct
,"mp",-1 * self
.__mpCost
))
148 if t
.isAlive() or self
.__affectsDeath
:
149 for e
in self
.__elementals
:
150 # Compute base-error damage
151 be
= computeBaseError(e
[1],e
[2])
152 # Compute <damage per target> = <base-error damage>/len(targets)
153 dmgPer
= be
/len(targets
)
154 # Compute net damage according to executor's wisdom
155 netDmg
= dmgPer
* math
.log10(exct
.getStat("wis").getCurrent() + 2)
156 # elemental mod(float) for target?
157 mod
= t
.getElemModifier(e
[0])
158 # Compute hpChange for target
159 hpChange
= netDmg
* (1.0 - mod
)
160 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
161 for s
in self
.__afflictions
:
162 if eventOccurs(t
.getStatusModifier(s
)):
163 transList
.append(TransactionStatus(t
,s
[0],not s
[1]))
165 elif self
.__typeName
== "DEFEND":
166 transList
.append(TransactionStatus(targets
[0],"dfdup",True))
167 elif self
.__typeName
== "RUN":