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 ########################################################
22 """ Model: Transaction Class """
25 """ The Fighter that the transaction is being executed on. Can be the same as executor. """
27 def __init__(self
,target
):
28 """ Base Transaction. """
38 def setStatus(self
,status
):
44 def setTarget(self
,target
):
47 class TransactionStatistic(Transaction
):
48 """ Model: TransactionStatistic Class """
51 """ The stat name. i.e. "hp", "mp", "level". """
54 """ How much the stat is changed. """
56 def __init__(self
,target
,stat
,change
):
57 """ Construct a Transaction for modifying Statistics. """
59 Transaction
.__init
__(self
,target
)
61 self
.__change
= change
64 """ Perform transaction in target. Called by Event.execute().
65 (Note: If change = 0 and status != "", generate the Status object and it's
66 Transactions based off the target's Statistics. If add is set to True, add the
67 status, if add is set to False, remove it. (if this is a Status Transaction))
70 # If a Stat is supposed to be modified
71 if self
.__stat
!= None:
72 alive_before_transaction
= self
.target
.isAlive()
74 # Retrieve that Stat from the target
75 stat_to_change
= self
.target
.getStat(self
.__stat
)
77 # change the value of that stat by the amount in "change"
78 stat_to_change
.setCurrent(stat_to_change
.getCurrent() + self
.__change
)
80 if self
.target
.getStat("hp").getCurrent() <= 0 and alive_before_transaction
:
81 deathT
= TransactionStatus(self
.target
,"death",True)
83 elif self
.target
.getStat("hp").getCurrent() > self
.target
.getStat("hp").getMax():
84 self
.target
.getStat("hp").setCurrent(self
.target
.getStat("hp").getMax())
89 def setStat(self
,stat
):
95 def setChange(self
,change
):
96 self
.__change
= change
98 class TransactionStatus(Transaction
):
99 """ Model: TransactionStatus Class """
102 """ The status this transaction inflicts. """
104 def __init__(self
,target
,status
,add
):
105 """ Construct a Transaction for adding or removing a Status. If
106 add is true, it adds the Status. """
108 Transaction
.__init
__(self
,target
)
109 self
.__status
= status
113 """ Perform transaction in target. Called by Event.execute().
114 (Note: If change = 0 and status != "", generate the Status object and it's
115 Transactions based off the target's Statistics. If add is set to True, add the
116 status, if add is set to False, remove it. (if this is a Status Transaction))
123 tlistPerTurnOnMove
= []
126 self
.target
.removeStatus(self
.__status
)
129 if self
.__status
== "poison":
130 # remove 5% of hp per turn; this is lame and should be more dynamic
131 trans
= TransactionStatistic(self
.target
,"hp",int(-1 * self
.target
.getStat("hp").getMax()*.05))
132 tlistPerTurnOnMove
.append(trans
)
133 elif self
.__status
== "aglup":
134 trans
= TransactionStatistic(self
.target
,"agl",10)
135 tlistEntrance
.append(trans
)
136 trans
= TransactionStatistic(self
.target
,"agl",-10)
137 tlistExit
.append(trans
)
138 elif self
.__status
== "sleep":
139 tlistEntrance
.append(TransactionStatistic(self
.target
,"canMove",-1))
140 tlistExit
.append(TransactionStatistic(self
.target
,"canMove",1))
141 elif self
.__status
== "death":
142 tlistEntrance
.append(TransactionStatistic(self
.target
,"canMove",-1))
143 tlistEntrance
.append(TransactionStatistic(self
.target
,"hp",self
.target
.getStat("hp").getCurrent()*-1))
144 tlistExit
.append(TransactionStatistic(self
.target
,"canMove",1))
145 tlistExit
.append(TransactionStatistic(self
.target
,"hp",int(self
.target
.getStat("hp").getMax() * .25)))
146 elif self
.__status
== "paralysis":
147 tlistEntrance
.append(TransactionStatistic(self
.target
,"canMove",-1))
148 tlistExit
.append(TransactionStatistic(self
.target
,"canMove",1))
149 elif self
.__status
== "madness":
150 ai
= self
.target
.getStat("ai").getCurrent()
152 tlistEntrance
.append(TransactionStatistic(self
.target
,"ai",2))
153 tlistExit
.append(TransactionStatistic(self
.target
,"ai",-2))
155 tlistEntrance
.append(TransactionStatistic(self
.target
,"ai",1))
156 tlistExit
.append(TransactionStatistic(self
.target
,"ai",-1))
158 # create the status object and add it to the target
159 self
.target
.addStatus(Status(self
.__status
,tlistEntrance
,tlistPerTurn
,tlistPerIter
,tlistExit
,tlistPerTurnOnMove
))
165 def setStatus(self
,status
):
166 self
.__status
= status
171 def setAdd(self
, add
):