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 os
import listdir
21 from equiption
import *
24 class ConsoleController
:
25 def __init__(self
,debug
,battle
,view
):
27 self
.__battle
= battle
30 battle
.setController(self
)
32 view
.setController(self
)
33 view
.setBattle(battle
)
39 def getCommand(self
,p
,f
):
43 print "\033[1;34m[SELCT]\033[1;0m Turn:" + f
.getName() + "; HP:" + str(f
.getHpCurrent()) + "/" + str(f
.getHpMax())
45 self
.__view
.printEnemySelectMenu(p
)
47 d
= p
.getFighter(int(n
)-1)
49 self
.__view
.printEventTypeMenu(f
)
51 t
= f
.getEventTypes()[int(n
)-1]
62 """Retrieves events from Parties and Executes all Events in queue per iteration"""
64 print "Battle Starts."
65 self
.__view
.printState()
67 # initialize the event checker boolean
70 while not self
.__battle
.isOver():
72 wereEvents
= self
.__battle
.nextTurn()
74 # only print out state if something actually happened
76 self
.__view
.printState()
78 if self
.__battle
.getParty1().isAlive():
79 # sum exp from enemy party
81 for f
in self
.__battle
.getParty2().getFighters():
85 self
.__battle
.getParty1().giveExp(exp
)
88 print "============================================================="
89 self
.__view
.printParty(self
.__battle
.getParty1())
90 print "============================================================="
91 print "Victory Fanfare. Heros win "+str(exp
)+" exp!"
93 print "Game Over. Imps win."
99 ### Loading job classes ###
100 dir = listdir('./data/job')
101 self
.__battle
.setJobList([])
109 lines
= fptr
.readlines()
110 self
.__battle
.getJobList().append(Job(lines
[0].strip(),float(lines
[1]),int(lines
[2]),int(lines
[3]),int(lines
[4]),int(lines
[5]),int(lines
[6]),int(lines
[7]),int(lines
[8]),float(lines
[9]),float(lines
[10]),float(lines
[11]),float(lines
[12]),float(lines
[13]),float(lines
[14]),float(lines
[15])))
113 ### Loading parties ###
114 self
.__battle
.setParty1(None)
115 self
.__battle
.setParty2(None)
116 dir = listdir('./data/party/')
122 p
= './data/party/'+p
124 lines
= fptr
.readlines()
125 if int(lines
[0]) == 1:
126 self
.__battle
.setParty1(Party(lines
[1].strip()))
127 elif int(lines
[0]) == 2:
128 self
.__battle
.setParty2(Party(lines
[1].strip()))
131 ### Loading fighters ###
132 dir = listdir('./data/fighter/')
134 # f cannot be a "." file
137 # Change file into pathname
138 f
= './data/fighter/'+f
139 # Open file f for 'r'eading
141 # Place lines in file f into list
142 lines
= fptr
.readlines()
145 name
= lines
[0].strip()
146 jobname
= lines
[1].strip()
147 level
= int(lines
[2])
149 exptnlm
= int(lines
[4])
150 exptnl
= int(lines
[5])
151 maxhp
= int(lines
[6])
152 currenthp
= int(lines
[7])
154 speed
= int(lines
[9])
156 agility
= int(lines
[11])
157 wisdom
= int(lines
[12])
158 will
= int(lines
[13])
159 playable
= bool(int(lines
[14].strip()))
160 head
= lines
[15].strip()
161 body
= lines
[16].strip()
162 left
= lines
[17].strip()
163 right
= lines
[18].strip()
166 #this tom calc. might should be moved to the fighter constructor
167 tom
= round((1/float(speed
))*100)
168 equip
= Equiption(head
,body
,left
,right
)
170 for job
in self
.__battle
.getJobList():
171 if job
.getName() == jobname
:
174 # Create fighter(name,hp,str,dex,head,l,r,body)
175 fighter1
= Fighter(name
,level
,exp
,exptnlm
,exptnl
,maxhp
,currenthp
,str,speed
,dex
,agility
,wisdom
,will
,tom
,playable
,equip
,job
)
178 # Add fighter to respective party (1 or 2)
180 self
.__battle
.getParty1().addFighter(fighter1
)
182 self
.__battle
.getParty2().addFighter(fighter1
)
188 for f
in self
.__battle
.getParty1().getFighters():
189 fptr
= open("./data/fighter/" + f
.getName(),"w")
192 fptr
.write(f
.getName() + "\n")
193 fptr
.write(j
.getName() + "\n")
194 fptr
.write(str(f
.getLevel()) + "\n")
195 fptr
.write(str(f
.getExp()) + "\n")
196 fptr
.write(str(f
.getExpTillNextLevelMax()) + "\n")
197 fptr
.write(str(f
.getExpTillNextLevel()) + "\n")
198 fptr
.write(str(f
.getHpMax()) + "\n")
199 fptr
.write(str(f
.getHpCurrent()) + "\n")
200 fptr
.write(str(f
.getStrength()) + "\n")
201 fptr
.write(str(f
.getSpeed()) + "\n")
202 fptr
.write(str(f
.getDexterity()) + "\n")
203 fptr
.write(str(f
.getAgility()) + "\n")
204 fptr
.write(str(f
.getWisdom()) + "\n")
205 fptr
.write(str(f
.getWill()) + "\n")
208 fptr
.write(str(1) + "\n")
210 fptr
.write(str(0) + "\n")
212 fptr
.write(e
.getHead() + "\n")
213 fptr
.write(e
.getArmor() + "\n")
214 fptr
.write(e
.getLeft() + "\n")
215 fptr
.write(e
.getRight() + "\n")
216 fptr
.write(str(1) + "\n")