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
.__affectsDeath
= (eTree
.xpathEval("//affectsDeath")[0].content
== "True")
34 # Retrieving any status afflictions
35 self
.__afflictions
= []
36 aTree
= eTree
.xpathEval("//status")
38 self
.__afflictions
.append((a
.content
,a
.prop("remove")=="True"))
40 # Retrieving any elementals
41 self
.__elementals
= []
42 elemTree
= eTree
.xpathEval("//element")
44 n
= elem
.xpathEval("//name")[0].content
45 b
= int(elem
.prop("base"))
46 err
= float(elem
.prop("error"))
47 self
.__elementals
.append((n
,b
,err
))
49 def getTypeName(self
):
50 return self
.__typeName
52 def setTypeName(self
, tn
):
58 def setName(self
, name
):
61 def getAfflictions(self
):
62 return self
.__afflictions
64 def setAfflictions(self
, aff
):
65 self
.__afflictions
= aff
67 def getElementals(self
):
68 return self
.__elementals
70 def setElementals(self
, elem
):
71 self
.__elementals
= elem
76 def setMpCost(self
, mpC
):
79 def getAffectsDeath(self
):
80 return self
.__affectsDeath
82 def setAffectsDeath(self
,affectsDeath
):
83 self
.__affectsDeath
= affectsDeath
85 def detTransactions(self
, exct
, targets
):
87 if self
.__typeName
== "ATTACK":
90 if t
.isAlive() or self
.__affectsDeath
:
93 numHits
= computeHM(exct
.getStat("dex").getCurrent(),t
.getStat("agl").getCurrent())
96 # hpChange is target's current hp
97 hpChange
= t
.getStat("hp").getCurrent()
100 hpChange
= numHits
* (t
.getDefense() - exct
.getAttack())
102 for s
in t
.getStatus():
105 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
107 elif self
.__typeName
== "BLACK":
109 transList
.append(TransactionStatistic(exct
,"mp",-1 * self
.__mpCost
))
111 if t
.isAlive() or self
.__affectsDeath
:
112 for e
in self
.__elementals
:
113 # Compute base-error damage
114 be
= computeBaseError(e
[1],e
[2])
115 # Compute <damage per target> = <base-error damage>/len(targets)
116 dmgPer
= be
/len(targets
)
117 # Compute net damage according to executor's will
118 netDmg
= dmgPer
* math
.log10(exct
.getStat("wil").getCurrent() + 2)
119 # elemental mod(float) for target?
120 mod
= t
.getElemModifier(e
[0])
121 # Compute hpChange for target
122 hpChange
= netDmg
* (1.0 - mod
)
123 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
125 for s
in self
.__afflictions
:
126 if eventOccurs(t
.getStatusModifier(s
)):
127 transList
.append(TransactionStatus(t
,s
[0],not s
[1]))
130 elif self
.__typeName
== "WHITE":
132 transList
.append(TransactionStatistic(exct
,"mp",-1 * self
.__mpCost
))
134 if t
.isAlive() or self
.__affectsDeath
:
135 for e
in self
.__elementals
:
136 # Compute base-error damage
137 be
= computeBaseError(e
[1],e
[2])
138 # Compute <damage per target> = <base-error damage>/len(targets)
139 dmgPer
= be
/len(targets
)
140 # Compute net damage according to executor's wisdom
141 netDmg
= dmgPer
* math
.log10(exct
.getStat("wis").getCurrent() + 2)
142 # elemental mod(float) for target?
143 mod
= t
.getElemModifier(e
[0])
144 # Compute hpChange for target
145 hpChange
= netDmg
* (1.0 - mod
)
146 transList
.append(TransactionStatistic(t
,"hp",int(hpChange
)))
147 for s
in self
.__afflictions
:
148 if eventOccurs(t
.getStatusModifier(s
)):
149 transList
.append(TransactionStatus(t
,s
[0],not s
[1]))