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
)
38 def getCommand(self
,vp
,hp
,f
):
42 print "\033[1;34m[SELCT]\033[1;0m Turn:" + f
.getName() + "; HP:" + str(f
.getStat("hp").getCurrent()) + "/" + str(f
.getStat("hp").getMax())
44 self
.__view
.printEventTypeMenu(f
)
46 t
= self
.__battle
.getEventType(f
.getEventTypes()[int(n
)-1])
48 if t
.getName() == "quit":
51 self
.__view
.printTargetSelectMenu(vp
,hp
)
54 if vp
.sizeOfParty() - int(n
) >= 0:
55 d
= vp
.getFighter(int(n
)-1)
58 d
= hp
.getFighter(int(n
)-vp
.sizeOfParty()-1)
68 """Retrieves events from Parties and Executes all Events in queue per iteration"""
70 # temporarily new game by default
71 self
.loadStaticData(True)
73 print "Battle Starts."
74 self
.__view
.printState()
76 # initialize the event checker boolean
79 while not self
.__battle
.isOver():
81 wereEvents
= self
.__battle
.nextTurn()
83 # only print out state if something actually happened
85 self
.__view
.printState()
87 if self
.__battle
.getParty1().isAlive():
88 # sum exp from enemy party
90 for f
in self
.__battle
.getParty2().getFighters():
91 exp
+= f
.getStat("exp").getMax()
94 self
.__battle
.getParty1().giveExp(exp
)
97 print "============================================================="
98 self
.__view
.printParty(self
.__battle
.getParty1())
99 print "============================================================="
100 print "Victory Fanfare. Hand's party wins "+str(exp
)+" exp!"
103 print "Game Over. Asgard mourns."
107 def loadStaticData(self
,newGame
):
108 """Load static game data: eventtypes, fighters (with stats and jobs)"""
111 dir = listdir('./data/eventtypes/')
113 self
.__battle
.setEventTypeList([])
120 etTree
= libxml2
.parseFile('./data/eventtypes/'+et
)
123 #eventType = EventType(etTree)
124 #self.__battle.getEventTypeList().append(eventType)
126 ### Loading parties ###
127 self
.__battle
.setParty1(Party("Heroes"))
128 self
.__battle
.setParty2(Party("Villains"))
130 ### Loading fighters ###
131 dir = listdir('./data/fighter/')
134 # f cannot be a "." file
138 # Create Fighter XML Tree
139 fTree
= libxml2
.parseFile('./data/fighter/'+f
)
141 # Find correct job XML file
142 j
= fTree
.xpathEval("//job")[0].content
+ '.xml'
144 # Create Job XML Tree
145 jTree
= libxml2
.parseFile('./data/job/'+j
)
147 # Create Fighter Object
148 fighter
= Fighter(jTree
,fTree
)
150 # Add fighter to respective party (1 or 2)
151 print fighter
.getPlayable()
152 if fighter
.getPlayable() and newGame
:
153 print fighter
.getName()
154 self
.__battle
.getParty1().addFighter(fighter
)
156 self
.__battle
.getMonsters().append(fighter
)
160 for f
in self
.__battle
.getParty1().getFighters():
161 fptr
= open("./data/fighter/" + f
.getName(),"w")
164 fptr
.write(f
.getName() + "\n")
165 fptr
.write(f
.getJobType() + "\n")
166 fptr
.write(str(f
.getStat("level").getCurrent()) + "\n")
167 fptr
.write(str(f
.getStat("exp").getMax()) + "\n")
168 fptr
.write(str(f
.getStat("exptnl").getMax()) + "\n")
169 fptr
.write(str(f
.getStat("exptnl").getCurrent()) + "\n")
170 fptr
.write(str(f
.getStat("hp").getMax()) + "\n")
171 fptr
.write(str(f
.getStat("hp").getCurrent()) + "\n")
172 fptr
.write(str(f
.getStat("mp").getMax()) + "\n")
173 fptr
.write(str(f
.getStat("mp").getCurrent()) + "\n")
174 fptr
.write(str(f
.getStat("str").getMax()) + "\n")
175 fptr
.write(str(f
.getStat("spd").getMax()) + "\n")
176 fptr
.write(str(f
.getStat("dex").getMax()) + "\n")
177 fptr
.write(str(f
.getStat("agl").getMax()) + "\n")
178 fptr
.write(str(f
.getStat("wis").getMax()) + "\n")
179 fptr
.write(str(f
.getStat("wil").getMax()) + "\n")
182 fptr
.write(str(1) + "\n")
184 fptr
.write(str(0) + "\n")
186 fptr
.write(e
.getHead() + "\n")
187 fptr
.write(e
.getArmor() + "\n")
188 fptr
.write(e
.getLeft() + "\n")
189 fptr
.write(e
.getRight() + "\n")
190 fptr
.write(str(1) + "\n")