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
):
32 return self
.__typeName
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":
66 numHits
= self
.__computeHM
(exct
.getStat("dex").getCurrent())
69 # hpChange is target's current hp
70 hpChange
= t
.getStat("hp").getCurrent()
73 hpChange
= numHits
* (t
.getDefense() - exct
.getAttack())
74 transList
.append(Transaction(t
,"hp",int(hpChange
),None))
75 elif self
.__typeName
== "BLACK":
77 transList
.append(Transaction(exct
,"mp",-1 * self
.__mpCost
,None))
79 for e
in self
.__elementals
:
80 # Compute base-error damage
81 be
= self
.__computeBaseError
(e
[1],e
[2])
82 # Compute <damage per target> = <base-error damage>/len(targets)
83 dmgPer
= be
/len(targets
)
84 # Compute net damage according to executor's will
85 netDmg
= dmgPer
* math
.log10(exct
.getStat("wil").getCurrent() + 2)
86 # elemental mod(float) for target?
87 mod
= t
.getElemModifier(e
[0])
88 # Compute hpChange for target
89 hpChange
= netDmg
* (1.0 - mod
)
90 transList
.append(Transaction(t
,"hp",int(hpChange
),None))
92 for s
in self
.__afflictions
:
94 if self
.__eventOccurs
(t
.getStatusModifier(s
)):
95 transList
.append(Transaction(t
,None,0,s
))
98 elif self
.__typeName
== "WHITE":
100 transList
.append(Transaction(exct
,"mp",-1 * self
.__mpCost
,None))
102 for e
in self
.__elementals
:
103 # Compute base-error damage
104 be
= self
.__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 wisdom
108 netDmg
= dmgPer
* math
.log10(exct
.getStat("wis").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))
114 for s
in self
.__afflictions
:
115 if self
.__eventOccurs
(t
.getStatusModifier(s
)):
116 transList
.append(Transaction(t
,None,0,s
))
119 def __computeBaseError(self
, base
, err
):
121 beg
= min(base
- n
,base
+ n
)
122 end
= max(base
- n
,base
+ n
)
123 return random
.randint(beg
,end
)
125 def __computeHM(self
, cdex
):
126 """Hit/Miss? If Hit, how many?"""
127 if (cdex
>= 1) and (cdex
<= 100):
128 x
= random
.randint(1,100)
129 if x
<= cdex
: return 1
131 elif (cdex
>= 101) and (cdex
<= 200):
132 x
= random
.randint(1,200)
134 if (x
>= 1) and (x
<= 100):
136 elif x
>= 101: return 2
138 elif (cdex
>= 201) and (cdex
<= 254):
139 x
= random
.randint(1,254)
141 if (x
>= 1) and (x
<= 100):
143 elif (x
>= 101) and (x
<= 200):
145 elif x
>= 201: return 3
148 x
= random
.randint(1,2)
150 elif x
== 2: return 5
152 def __eventOccurs(self
, percent
):
153 a
= random
.randint(1,100)