(no commit message)
[asgard.git] / fighter.py
blob0ee2b556c5a48ee2c0b1147e3ccac4859c3d5161
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,stats,equip,statuses):
26 """Constructor."""
27 self.__name = name
28 self.__jobType = jobType
29 self.__playable = plyble
30 self.__stats = stats
31 self.__equiption = equip
32 self.__status = statuses
34 def getName(self):
35 """Get fighter's name."""
36 return self.__name
38 def setName(self, n):
39 """Change fighter's name."""
40 self.__name = n
42 def getJobType(self):
43 """Get Fighter's job type"""
44 return self.__jobType
46 def setJobType(self,jobType):
47 """ Set Fighter's job type"""
48 self.__jobType = jobType
50 def getEquiption(self):
51 """Get equiption for fighter."""
52 return self.__equiption
54 def setEquiption(self, eq):
55 """Set equiption for fighter."""
56 self.__equiption = eq
58 def getPlayable(self):
59 """Is fighter playable?"""
60 return self.__playable
62 def setPlayable(self, plyble):
63 """Set fighter's playability."""
64 self.__playable = plyble
66 def getAttack(self):
67 """Compute value of attack."""
68 return self.getStat("str").getCurrent() + self.__equiption.computeAtkMod()
70 def getDefense(self):
71 """Compute value of defense."""
72 return self.__equiption.computeDefMod()
74 def getEvade(self):
75 """Compute value of evade."""
76 return self.getStat("agl").getCurrent() + self.__equiption.computeEvaMod()
79 def makeEvent(self, eparty, currentTime, cont):
80 """ Check if ready to make move.
82 If so, select random fighter from enemy party and return.
83 """
85 if not self.isAlive():
86 return None
88 if self.getStat("tom").getCurrent() != currentTime:
89 return None
91 # Generate per-turn status transactions
92 for s in self.__status:
93 s.genPerTurn()
95 d = []
97 # Playable fighters have battle menu
98 if self.getPlayable():
99 # Show battle menu and choose event from battle menu
100 command = cont.getCommand(eparty,self)
101 d.append(command[0])
102 t = command[1]
104 # Nonplayable fighters
105 elif currentTime >= self.getStat("tom").getCurrent():
106 x = randint(0,eparty.sizeOfParty()-1)
107 while not eparty.getFighter(x).isAlive():
108 x = randint(0,eparty.sizeOfParty()-1)
110 d.append(eparty.getFighter(x))
112 x = randint(0,len(self.getEventTypes())-1)
113 t = cont.getBattle().getEventType(self.getEventTypes()[x])
115 self.getStat("tom").setCurrent(self.getStat("tom").getMax() + round((1/float(self.getStat("spd").getMax()))*100))
116 return Event(self,d,[],t)
118 def isAlive(self):
119 """If hp is greater than 0... return true"""
120 return (self.getStat("hp").getCurrent() > 0)
122 def getEventTypes(self):
123 """Return list of events available to fighter."""
124 if self.__jobType == "blackmage":
125 return ["attack","fire1","ice1","harm","poison","quit"]
126 elif self.__jobType == "swordsman":
127 return ["attack","cure1","quit"]
128 elif self.__name == "Roc":
129 return ["attack","ice1"]
130 elif self.__name == "Imp":
131 return ["attack"]
132 else:
133 return ["attack"]
135 def receiveExp(self,exp):
136 """Fighter receives experience for leveling up."""
137 # Add on exp
138 exp_s = self.getStat("exp")
139 exp_s.setCurrent(exp_s.getCurrent() + exp)
141 # Tax off exp from expTillNextLevel
142 exptnl_s = self.getStat("exptnl")
143 exptnl_s.setCurrent(exptnl_s.getCurrent() - exp)
145 # Level up?
146 while exptnl_s.getCurrent() <= 0:
147 # Increase level number
148 level_s = self.getStat("level")
149 level_s.setMax(level_s.getMax() + 1)
151 ## Increase stats...
153 # Increase hp?
154 x = randint(1,100)
155 hp = self.getStat("hp")
156 if x <= hp.getChance() * 100:
157 hp.setMax(hp.getMax() + hp.getPlus())
159 # Increase strength?
160 x = randint(1,100)
161 str = self.getStat("str")
162 if x <= str.getChance() * 100:
163 str.setMax(str.getMax() + str.getPlus())
164 str.setCurrent(str.getCurrent() + str.getPlus())
167 # Increase speed?
168 x = randint(1,100)
169 spd = self.getStat("spd")
170 if x <= spd.getChance() * 100:
171 spd.setMax(spd.getMax() + spd.getPlus())
172 spd.setCurrent(spd.getCurrent() + spd.getPlus())
174 # Increase dexterity?
175 x = randint(1,100)
176 dex = self.getStat("dex")
177 if x <= dex.getChance() * 100:
178 dex.setMax(dex.getMax() + dex.getPlus())
179 dex.setCurrent(dex.getCurrent() + dex.getPlus())
181 # Increase agility?
182 x = randint(1,100)
183 agl = self.getStat("agl")
184 if x <= agl.getChance() * 100:
185 agl.setMax(agl.getMax() + agl.getPlus())
186 agl.setCurrent(agl.getCurrent() + agl.getPlus())
188 # Increase wisdom?
189 x = randint(1,100)
190 wis = self.getStat("wis")
191 if x <= wis.getChance() * 100:
192 wis.setMax(wis.getMax() + wis.getPlus())
193 wis.setCurrent(wis.getCurrent() + wis.getPlus())
195 # Increase will?
196 x = randint(1,100)
197 wil = self.getStat("wil")
198 if x <= wil.getChance() * 100:
199 wil.setMax(wil.getMax() + wil.getPlus())
200 wil.setCurrent(wil.getCurrent() + wil.getPlus())
202 # Set new exp till next level maximum
203 exptnl_s.setMax(int(exptnl_s.getMax() * exptnl.getGrowthRate()))
205 # Carry over any experience that didn't go towards getting the last level
206 exptnl_s.setCurrent(int(exptnl.getMax() + exptnl.getCurrent()))
208 def getElemModifier(self,elem):
209 return 0.25
211 def getStatusModifier(self,stat):
212 return 1
214 def getStatus(self):
215 """Get status(es) of fighter."""
216 return self.__status
218 def setStatus(self,s):
219 """Set status(es) of fighter."""
220 self.__status = s
222 def addStatus(self,s):
223 """Add a status to status list for fighter."""
224 found = False
225 for i in self.__status:
226 if i == s:
227 found = True
228 break
230 if not found:
231 self.__status.append(s)
232 s.genEntrance()
233 else:
234 print 'ERROR: Status already in list!'
236 def removeStatus(self,s):
237 """Remove status s from status list for fighter."""
238 for i in self.__status:
239 if i == s:
240 found = True
241 break
243 if found == True:
244 self.__status.remove(s)
245 s.genExit(self)
246 else:
247 print 'ERROR: Status was not in list!'
249 def getStat(self,statName):
250 for stat in self.__stats:
251 if stat.getName() == statName:
252 return stat
253 print 'ERROR: No such Fighter stat.'
255 def getAllStats(self):
256 return self.__stats
258 def setAllStats(self,stats):
259 self.__stats = stats