random stuff
[asgard.git] / fighter.py
blobd594d013e46f6dadd9e1147540136374212f37d6
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 # Playable fighters have battle menu
105 if self.getPlayable():
106 # Show battle menu and choose event from battle menu
107 command = cont.getCommand(eparty,self)
108 d = command[0]
109 t = command[1]
111 # Nonplayable fighters
112 elif currentTime >= self.__timeOfMove:
113 x = randint(0,eparty.sizeOfParty()-1)
114 while not eparty.getFighter(x).isAlive():
115 x = randint(0,eparty.sizeOfParty()-1)
117 d = eparty.getFighter(x)
119 x = randint(0,len(self.getEventTypes()))
120 t = getEventTypes()[x]
122 self.__timeOfMove += round((1/float(self.getStat("spd").getMax()))*100)
123 return Event(self,d,[],t)
125 def isAlive(self):
126 """If hp is greater than 0... return true"""
127 return (self.getStat("hp").getCurrent() > 0)
129 def getEventTypes(self):
130 """Return list of events available to fighter."""
131 if self.__jobType == "blackmage":
132 return ["attack","fire1","ice1","harm","poison","quit"]
133 elif self.__jobType == "swordsman":
134 return ["attack","cure1","sleep","quit"]
135 elif self.__name == "Roc":
136 return ["attack","ice1"]
137 elif self.__name == "Imp":
138 return ["attack"]
139 else:
140 return ["attack"]
142 def receiveExp(self,exp):
143 """Fighter receives experience for leveling up."""
144 # Add on exp
145 exp_s = self.getStat("exp")
146 exp_s.setCurrent(exp_s.getCurrent() + exp)
148 # Tax off exp from expTillNextLevel
149 exptnl_s = self.getStat("exptnl")
150 exptnl_s.setCurrent(exptnl_s.getCurrent() - exp)
152 # Level up?
153 while exptnl_s.getCurrent() <= 0:
154 # Increase level number
155 level_s = self.getStat("level")
156 level_s.setMax(level_s.getMax() + 1)
158 ## Increase stats...
160 # Increase hp?
161 x = randint(1,100)
162 hp = self.getStat("hp")
163 if x <= hp.getChance() * 100:
164 hp.setMax(hp.getMax() + hp.getPlus())
166 # Increase strength?
167 x = randint(1,100)
168 str = self.getStat("str")
169 if x <= str.getChance() * 100:
170 str.setMax(str.getMax() + str.getPlus())
171 str.setCurrent(str.getCurrent() + str.getPlus())
174 # Increase speed?
175 x = randint(1,100)
176 spd = self.getStat("spd")
177 if x <= spd.getChance() * 100:
178 spd.setMax(spd.getMax() + spd.getPlus())
179 spd.setCurrent(spd.getCurrent() + spd.getPlus())
181 # Increase dexterity?
182 x = randint(1,100)
183 dex = self.getStat("dex")
184 if x <= dex.getChance() * 100:
185 dex.setMax(dex.getMax() + dex.getPlus())
186 dex.setCurrent(dex.getCurrent() + dex.getPlus())
188 # Increase agility?
189 x = randint(1,100)
190 agl = self.getStat("agl")
191 if x <= agl.getChance() * 100:
192 agl.setMax(agl.getMax() + agl.getPlus())
193 agl.setCurrent(agl.getCurrent() + agl.getPlus())
195 # Increase wisdom?
196 x = randint(1,100)
197 wis = self.getStat("wis")
198 if x <= wis.getChance() * 100:
199 wis.setMax(wis.getMax() + wis.getPlus())
200 wis.setCurrent(wis.getCurrent() + wis.getPlus())
202 # Increase will?
203 x = randint(1,100)
204 wil = self.getStat("wil")
205 if x <= wil.getChance() * 100:
206 wil.setMax(wil.getMax() + wil.getPlus())
207 wil.setCurrent(wil.getCurrent() + wil.getPlus())
209 # Set new exp till next level maximum
210 exptnl_s.setMax(int(exptnl_s.getMax() * exptnl.getGrowthRate()))
212 # Carry over any experience that didn't go towards getting the last level
213 exptnl_s.setCurrent(int(exptnl.getMax() + exptnl.getCurrent()))
215 def getElemModifier(self,elem):
216 return 0.25
218 def getStatModifier(self,stat):
219 return 0.25
221 def getStatus(self):
222 """Get status(es) of fighter."""
223 return self.__status
225 def setStatus(self,s):
226 """Set status(es) of fighter."""
227 self.__status = s
229 def addStatus(self,s):
230 """Add a status to status list for fighter."""
231 for i in self.__status:
232 if i == s:
233 found = True
234 break
236 if not found:
237 self.__status.append(s)
238 s.genEntrance()
239 else:
240 print 'ERROR: Status already in list!'
242 def removeStatus(self,s):
243 """Remove status s from status list for fighter."""
244 for i in self.__status:
245 if i == s:
246 found = True
247 break
249 if found == True:
250 self.__status.remove(s)
251 s.genExit(self)
252 else:
253 print 'ERROR: Status was not in list!'
255 def getStat(self,statName):
256 for stat in self.__stats:
257 if stat.getName() == statName:
258 return stat
259 print 'ERROR: No such Fighter stat.'
261 def getAllStats(self):
262 return self.__stats
264 def setAllStats(self,stats):
265 self.__stats = stats