(no commit message)
[asgard.git] / fighter.py
blob14da852576a9bfda278f8b9a7fd68c6d172afe13
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 ########################################################
19 from random import *
20 from equiption import *
21 from event import *
22 from status import *
23 from stat import *
24 class Fighter:
25 def __init__(self,name,jobType,plyble,tom,stats,equip,statuses):
26 """Constructor."""
27 self.__name = name
28 self.__jobType = jobType
29 self.__playable = plyble
30 self.__timeOfMove = tom
31 self.__stats = stats
32 self.__equiption = equip
33 self.__status = statuses
35 def getName(self):
36 """Get fighter's name."""
37 return self.__name
39 def setName(self, n):
40 """Change fighter's name."""
41 self.__name = n
43 def getJobType(self):
44 """Get Fighter's job type"""
45 return self.__jobType
47 def setJobType(self,jobType):
48 """ Set Fighter's job type"""
49 self.__jobType = jobType
51 def getTimeOfMove(self):
52 """Get fighter's time of move."""
53 return self.__timeOfMove
55 def setTimeOfMove(self, tMv):
56 """Change fighter's time of move."""
57 self.__timeOfMove = tMv
59 def getEquiption(self):
60 """Get equiption for fighter."""
61 return self.__equiption
63 def setEquiption(self, eq):
64 """Set equiption for fighter."""
65 self.__equiption = eq
67 def getPlayable(self):
68 """Is fighter playable?"""
69 return self.__playable
71 def setPlayable(self, plyble):
72 """Set fighter's playability."""
73 self.__playable = plyble
75 def getAttack(self):
76 """Compute value of attack."""
77 return self.getStat("str").getCurrent() + self.__equiption.computeAtkMod()
79 def getDefense(self):
80 """Compute value of defense."""
81 return self.__equiption.computeDefMod()
83 def getEvade(self):
84 """Compute value of evade."""
85 return self.getStat("agl").getCurrent() + self.__equiption.computeEvaMod()
88 def makeEvent(self, eparty, currentTime, cont, ):
89 """ Check if ready to make move.
91 If so, select random fighter from enemy party and return.
92 """
94 if not self.isAlive():
95 return None
97 if self.__timeOfMove != currentTime:
98 return None
100 # Generate per-turn status transactions
101 for s in self.__status:
102 s.genPerTurn(self)
104 t = []
106 # Playable fighters have battle menu
107 if self.getPlayable():
108 # Show battle menu and choose event from battle menu
109 command = cont.getCommand(eparty,self)
110 d = command[0]
111 t.append(command[1])
113 # Nonplayable fighters
114 elif currentTime >= self.__timeOfMove:
115 x = randint(0,eparty.sizeOfParty()-1)
116 while not eparty.getFighter(x).isAlive():
117 x = randint(0,eparty.sizeOfParty()-1)
119 d = eparty.getFighter(x)
121 x = randint(0,len(self.getEventTypes())-1)
122 t.append(cont.getBattle().getEventType(self.getEventTypes()[x]))
124 self.__timeOfMove += round((1/float(self.getStat("spd").getMax()))*100)
125 return Event(self,d,[],t)
127 def isAlive(self):
128 """If hp is greater than 0... return true"""
129 return (self.getStat("hp").getCurrent() > 0)
131 def getEventTypes(self):
132 """Return list of events available to fighter."""
133 if self.__jobType == "blackmage":
134 return ["attack","fire1","ice1","harm","poison","quit"]
135 elif self.__jobType == "swordsman":
136 return ["attack","cure1","sleep","quit"]
137 elif self.__name == "Roc":
138 return ["attack","ice1"]
139 elif self.__name == "Imp":
140 return ["attack"]
141 else:
142 return ["attack"]
144 def receiveExp(self,exp):
145 """Fighter receives experience for leveling up."""
146 # Add on exp
147 exp_s = self.getStat("exp")
148 exp_s.setCurrent(exp_s.getCurrent() + exp)
150 # Tax off exp from expTillNextLevel
151 exptnl_s = self.getStat("exptnl")
152 exptnl_s.setCurrent(exptnl_s.getCurrent() - exp)
154 # Level up?
155 while exptnl_s.getCurrent() <= 0:
156 # Increase level number
157 level_s = self.getStat("level")
158 level_s.setMax(level_s.getMax() + 1)
160 ## Increase stats...
162 # Increase hp?
163 x = randint(1,100)
164 hp = self.getStat("hp")
165 if x <= hp.getChance() * 100:
166 hp.setMax(hp.getMax() + hp.getPlus())
168 # Increase strength?
169 x = randint(1,100)
170 str = self.getStat("str")
171 if x <= str.getChance() * 100:
172 str.setMax(str.getMax() + str.getPlus())
173 str.setCurrent(str.getCurrent() + str.getPlus())
176 # Increase speed?
177 x = randint(1,100)
178 spd = self.getStat("spd")
179 if x <= spd.getChance() * 100:
180 spd.setMax(spd.getMax() + spd.getPlus())
181 spd.setCurrent(spd.getCurrent() + spd.getPlus())
183 # Increase dexterity?
184 x = randint(1,100)
185 dex = self.getStat("dex")
186 if x <= dex.getChance() * 100:
187 dex.setMax(dex.getMax() + dex.getPlus())
188 dex.setCurrent(dex.getCurrent() + dex.getPlus())
190 # Increase agility?
191 x = randint(1,100)
192 agl = self.getStat("agl")
193 if x <= agl.getChance() * 100:
194 agl.setMax(agl.getMax() + agl.getPlus())
195 agl.setCurrent(agl.getCurrent() + agl.getPlus())
197 # Increase wisdom?
198 x = randint(1,100)
199 wis = self.getStat("wis")
200 if x <= wis.getChance() * 100:
201 wis.setMax(wis.getMax() + wis.getPlus())
202 wis.setCurrent(wis.getCurrent() + wis.getPlus())
204 # Increase will?
205 x = randint(1,100)
206 wil = self.getStat("wil")
207 if x <= wil.getChance() * 100:
208 wil.setMax(wil.getMax() + wil.getPlus())
209 wil.setCurrent(wil.getCurrent() + wil.getPlus())
211 # Set new exp till next level maximum
212 exptnl_s.setMax(int(exptnl_s.getMax() * exptnl.getGrowthRate()))
214 # Carry over any experience that didn't go towards getting the last level
215 exptnl_s.setCurrent(int(exptnl.getMax() + exptnl.getCurrent()))
217 def getElemModifier(self,elem):
218 return 0.25
220 def getStatModifier(self,stat):
221 return 0.25
223 def getStatus(self):
224 """Get status(es) of fighter."""
225 return self.__status
227 def setStatus(self,s):
228 """Set status(es) of fighter."""
229 self.__status = s
231 def addStatus(self,s):
232 """Add a status to status list for fighter."""
233 for i in self.__status:
234 if i == s:
235 found = True
236 break
238 if not found:
239 self.__status.append(s)
240 s.genEntrance()
241 else:
242 print 'ERROR: Status already in list!'
244 def removeStatus(self,s):
245 """Remove status s from status list for fighter."""
246 for i in self.__status:
247 if i == s:
248 found = True
249 break
251 if found == True:
252 self.__status.remove(s)
253 s.genExit(self)
254 else:
255 print 'ERROR: Status was not in list!'
257 def getStat(self,statName):
258 for stat in self.__stats:
259 if stat.getName() == statName:
260 return stat
261 print 'ERROR: No such Fighter stat.'
263 def getAllStats(self):
264 return self.__stats
266 def setAllStats(self,stats):
267 self.__stats = stats