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 *
24 def __init__(self
, tn
, name
, afflictions
, elementals
, mpC
):
27 self
.__afflictions
= afflictions
28 self
.__elementals
= elementals
31 def getTypeName(self
):
34 def setTypeName(self
, tn
):
40 def setName(self
, 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
58 def setMpCost(self
, mpC
):
61 def detTransactions(self
, exct
, targets
):
63 if self
.__typeName
== "ATTACK":
68 hpChange
= t
.getDefense() - exct
.getAttack()
69 transList
.append(Transaction(t
,"hp",int(hpChange
),None))
70 elif self
.__typeName
== "BLACK":
72 transList
.append(Transaction(exct
,"mp",-1 * self
.__mpCost
,None))
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":
94 transList
.append(Transaction(exct
,"mp",-1 * self
.__mpCost
,None))
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
))
113 def __computeBaseError(self
, 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)