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 statistic
import *
20 from os
import listdir
22 from equiption
import *
24 from eventtype
import *
25 class ConsoleController
:
26 def __init__(self
,debug
,battle
,view
):
28 self
.__battle
= battle
31 battle
.setController(self
)
33 view
.setController(self
)
34 view
.setBattle(battle
)
40 def getCommand(self
,p
,f
):
44 print "\033[1;34m[SELCT]\033[1;0m Turn:" + f
.getName() + "; HP:" + str(f
.getStat("hp").getCurrent()) + "/" + str(f
.getStat("hp").getMax())
46 self
.__view
.printEventTypeMenu(f
)
48 t
= self
.__battle
.getEventType(f
.getEventTypes()[int(n
)-1])
50 if t
.getName() == "quit":
53 self
.__view
.printEnemySelectMenu(p
)
55 d
= p
.getFighter(int(n
)-1)
66 """Retrieves events from Parties and Executes all Events in queue per iteration"""
68 print "Battle Starts."
69 self
.__view
.printState()
71 # initialize the event checker boolean
74 while not self
.__battle
.isOver():
76 wereEvents
= self
.__battle
.nextTurn()
78 # only print out state if something actually happened
80 self
.__view
.printState()
82 if self
.__battle
.getParty1().isAlive():
83 # sum exp from enemy party
85 for f
in self
.__battle
.getParty2().getFighters():
86 exp
+= f
.getStat("exp").getMax()
89 self
.__battle
.getParty1().giveExp(exp
)
92 print "============================================================="
93 self
.__view
.printParty(self
.__battle
.getParty1())
94 print "============================================================="
95 print "Victory Fanfare. Hand's party wins "+str(exp
)+" exp!"
97 print "Game Over. Asgard mourns."
104 dir = listdir('./data/eventtypes/')
106 self
.__battle
.setEventTypeList([])
112 et
= './data/eventtypes/'+et
114 lines
= fptr
.readlines()
119 # retrieve a list of statuses that the event type afflicts
120 if lines
[3].strip() != "":
121 status_list
= lines
[3].strip().split(",")
123 # elemental tuple loading
125 while x
< len(lines
):
126 elem
= lines
[x
].split(",")
127 # elemental name, base, error
128 elem_list
.append((elem
[0].strip(),int(elem
[1].strip()),float(elem
[2].strip())))
131 et_o
= EventType(lines
[1].strip(),lines
[0].strip(),status_list
,elem_list
,int(lines
[2].strip()))
132 self
.__battle
.getEventTypeList().append(et_o
)
134 ### Loading parties ###
135 self
.__battle
.setParty1(None)
136 self
.__battle
.setParty2(None)
137 dir = listdir('./data/party/')
143 p
= './data/party/'+p
145 lines
= fptr
.readlines()
146 if int(lines
[0]) == 1:
147 self
.__battle
.setParty1(Party(lines
[1].strip()))
148 elif int(lines
[0]) == 2:
149 self
.__battle
.setParty2(Party(lines
[1].strip()))
152 ### Loading fighters ###
153 dir = listdir('./data/fighter/')
158 # f cannot be a "." file
162 # Change file into pathname
163 f
= './data/fighter/'+f
165 # Open file f for 'r'eading
168 # Place lines in file f into list
169 lines
= fptr
.readlines()
172 name
= lines
[0].strip()
173 jobname
= lines
[1].strip()
175 job_fptr
= open('./data/job/'+jobname
.lower(),'r')
177 job_lines
= job_fptr
.readlines()
181 tom
= round((1/float(lines
[11])*100))
183 statlist
.append(Statistic("level",int(lines
[2]),99,False,1,1,0))
184 statlist
.append(Statistic("exp",int(lines
[3]),int(lines
[3]),True,0,0,0))
185 statlist
.append(Statistic("exptnl",int(lines
[5]),int(lines
[4]),True,0,0,float(job_lines
[1])))
186 statlist
.append(Statistic("hp",int(lines
[7]),int(lines
[6]),True,int(job_lines
[2]),float(job_lines
[10]),0))
187 statlist
.append(Statistic("mp",int(lines
[9]),int(lines
[8]),True,int(job_lines
[3]),float(job_lines
[11]),0))
188 statlist
.append(Statistic("str",int(lines
[10]),int(lines
[10]),False,int(job_lines
[4]),float(job_lines
[12]),0))
189 statlist
.append(Statistic("spd",int(lines
[11]),int(lines
[11]),False,int(job_lines
[5]),float(job_lines
[13]),0))
190 statlist
.append(Statistic("dex",int(lines
[12]),int(lines
[12]),False,int(job_lines
[6]),float(job_lines
[14]),0))
191 statlist
.append(Statistic("agl",int(lines
[13]),int(lines
[13]),False,int(job_lines
[7]),float(job_lines
[15]),0))
192 statlist
.append(Statistic("wis",int(lines
[14]),int(lines
[14]),False,int(job_lines
[8]),float(job_lines
[16]),0))
193 statlist
.append(Statistic("wil",int(lines
[15]),int(lines
[15]),False,int(job_lines
[9]),float(job_lines
[17]),0))
194 statlist
.append(Statistic("tom",tom
,tom
,False,0,0,0))
197 playable
= bool(int(lines
[16].strip()))
198 head
= lines
[17].strip()
199 body
= lines
[18].strip()
200 left
= lines
[19].strip()
201 right
= lines
[20].strip()
206 #this time of move calc. might should be moved to the fighter constructor
208 # create equiption object
209 equip
= Equiption(head
,body
,left
,right
)
212 fighter1
= Fighter(name
,jobname
,playable
,statlist
,equip
,[])
215 # Add fighter to respective party (1 or 2)
217 self
.__battle
.getParty1().addFighter(fighter1
)
219 self
.__battle
.getParty2().addFighter(fighter1
)
227 for f
in self
.__battle
.getParty1().getFighters():
228 fptr
= open("./data/fighter/" + f
.getName(),"w")
231 fptr
.write(f
.getName() + "\n")
232 fptr
.write(f
.getJobType() + "\n")
233 fptr
.write(str(f
.getStat("level").getCurrent()) + "\n")
234 fptr
.write(str(f
.getStat("exp").getMax()) + "\n")
235 fptr
.write(str(f
.getStat("exptnl").getMax()) + "\n")
236 fptr
.write(str(f
.getStat("exptnl").getCurrent()) + "\n")
237 fptr
.write(str(f
.getStat("hp").getMax()) + "\n")
238 fptr
.write(str(f
.getStat("hp").getCurrent()) + "\n")
239 fptr
.write(str(f
.getStat("mp").getMax()) + "\n")
240 fptr
.write(str(f
.getStat("mp").getCurrent()) + "\n")
241 fptr
.write(str(f
.getStat("str").getMax()) + "\n")
242 fptr
.write(str(f
.getStat("spd").getMax()) + "\n")
243 fptr
.write(str(f
.getStat("dex").getMax()) + "\n")
244 fptr
.write(str(f
.getStat("agl").getMax()) + "\n")
245 fptr
.write(str(f
.getStat("wis").getMax()) + "\n")
246 fptr
.write(str(f
.getStat("wil").getMax()) + "\n")
249 fptr
.write(str(1) + "\n")
251 fptr
.write(str(0) + "\n")
253 fptr
.write(e
.getHead() + "\n")
254 fptr
.write(e
.getArmor() + "\n")
255 fptr
.write(e
.getLeft() + "\n")
256 fptr
.write(e
.getRight() + "\n")
257 fptr
.write(str(1) + "\n")