removed protection elemental
[asgard.git] / fighter.py
blobfad6ac1a32b6682e447411b2dbdfad5c2b8cb7bc
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 self.getStat("tom").setMax(self.getStat("tom").getCurrent())
117 return Event(self,d,[],t)
119 def isAlive(self):
120 """If hp is greater than 0... return true"""
121 return (self.getStat("hp").getCurrent() > 0)
123 def getEventTypes(self):
124 """Return list of events available to fighter."""
125 if self.__jobType == "blackmage":
126 return ["attack","fire1","ice1","cure1","fog","poison","quit"]
127 elif self.__jobType == "swordsman":
128 return ["attack","quit"]
129 elif self.__name == "Roc":
130 return ["attack","ice1"]
131 elif self.__name == "Imp":
132 return ["attack"]
133 else:
134 return ["attack"]
136 def receiveExp(self,exp):
137 """Fighter receives experience for leveling up."""
138 # Add on exp
139 exp_s = self.getStat("exp")
140 exp_s.setCurrent(exp_s.getCurrent() + exp)
142 # Tax off exp from expTillNextLevel
143 exptnl_s = self.getStat("exptnl")
144 exptnl_s.setCurrent(exptnl_s.getCurrent() - exp)
146 # Level up?
147 while exptnl_s.getCurrent() <= 0:
148 # Increase level number
149 level_s = self.getStat("level")
150 level_s.setCurrent(level_s.getCurrent() + 1)
152 ## Increase stats...
154 # Increase hp?
155 x = randint(1,100)
156 hp = self.getStat("hp")
157 if x <= hp.getChance() * 100:
158 hp.setMax(hp.getMax() + hp.getPlus())
160 # Increase strength?
161 x = randint(1,100)
162 str = self.getStat("str")
163 if x <= str.getChance() * 100:
164 str.setMax(str.getMax() + str.getPlus())
165 str.setCurrent(str.getMax())
168 # Increase speed?
169 x = randint(1,100)
170 spd = self.getStat("spd")
171 if x <= spd.getChance() * 100:
172 spd.setMax(spd.getMax() + spd.getPlus())
173 spd.setCurrent(spd.getMax())
175 # Increase dexterity?
176 x = randint(1,100)
177 dex = self.getStat("dex")
178 if x <= dex.getChance() * 100:
179 dex.setMax(dex.getMax() + dex.getPlus())
180 dex.setCurrent(dex.getMax())
182 # Increase agility?
183 x = randint(1,100)
184 agl = self.getStat("agl")
185 if x <= agl.getChance() * 100:
186 agl.setMax(agl.getMax() + agl.getPlus())
187 agl.setCurrent(agl.getMax())
189 # Increase wisdom?
190 x = randint(1,100)
191 wis = self.getStat("wis")
192 if x <= wis.getChance() * 100:
193 wis.setMax(wis.getMax() + wis.getPlus())
194 wis.setCurrent(wis.getMax())
196 # Increase will?
197 x = randint(1,100)
198 wil = self.getStat("wil")
199 if x <= wil.getChance() * 100:
200 wil.setMax(wil.getMax() + wil.getPlus())
201 wil.setCurrent(wil.getMax())
203 # Set new exp till next level maximum
204 exptnl_s.setMax(int(exptnl_s.getMax() * exptnl_s.getGrowthRate()))
206 # Carry over any experience that didn't go towards getting the last level
207 exptnl_s.setCurrent(int(exptnl_s.getMax() + exptnl_s.getCurrent()))
209 def getElemModifier(self,elem):
210 return 0.25
212 def getStatusModifier(self,stat):
213 return 1
215 def getStatus(self):
216 """Get status(es) of fighter."""
217 return self.__status
219 def setStatus(self,s):
220 """Set status(es) of fighter."""
221 self.__status = s
223 def addStatus(self,s):
224 """Add a status to status list for fighter."""
225 found = False
226 for i in self.__status:
227 if i == s:
228 found = True
229 break
231 if not found:
232 self.__status.append(s)
233 s.genEntrance()
234 else:
235 print 'ERROR: Status already in list!'
237 def removeStatus(self,s):
238 """Remove status s from status list for fighter."""
239 for i in self.__status:
240 if i == s:
241 found = True
242 break
244 if found == True:
245 self.__status.remove(s)
246 s.genExit(self)
247 else:
248 print 'ERROR: Status was not in list!'
250 def getStat(self,statName):
251 for stat in self.__stats:
252 if stat.getName() == statName:
253 return stat
254 print 'ERROR: No such Fighter stat.'
256 def getAllStats(self):
257 return self.__stats
259 def setAllStats(self,stats):
260 self.__stats = stats