######################################################################################## # This file is part of Spheres. # Copyright (C) 2019 Jesusalva # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ######################################################################################## # Mission Selection & Quest Handling init python: ######################## Server Communications def loadquest(quest_id, party_id=1): import json raw=send_packet("begin_quest", questdata(quest_id, party_id)) bt=json_decode(raw) if (bt == ERR_JSONDECODER): return ERR_JSONDECODER return bt def loadbattle(new_arrange): raw=send_packet("battle", battledata(new_arrange, use_sphere)) bt=json_decode(raw) if (bt == ERR_JSONDECODER): return ERR_JSONDECODER return bt ################################################################### # TODO: Quest menus and selections should be auto-generated # World map structure: ["name", min_level, {quest1}, {quest2} ...] label quest_select: $ show_img("bg battle2", False, ext=".jpg") scene bg battle2 play music MUSIC_WORLDMAP.id() fadein 0.5 python: worldmap=[] areamap=[] for arx in allworld: arena=copy.copy(arx) name=arena.pop(0) req=arena.pop(0) if Player["quest"] >= req: worldmap.append((name, arena)) # Display world map menu worldmap.append(("Return", -1)) mapselected=renpy.display_menu(worldmap) del worldmap if mapselected == -1: renpy.jump("restore") # Now we have the mapselected array, with dict for arx in mapselected: quest=copy.copy(arx) name=quest["name"] qid=quest["quest_id"] # We also want to show cost and requeriments entry=dl_search(allquests, "quest_id", qid) if entry != ERR_INVALID: cost=entry["cost"] req=entry["requeriment"] else: cost=-1 req=99999 # Add entry (if valid) if Player["quest"] >= req: if Player["ap"] >= cost: areamap.append(("%s (%d AP)" % (name, cost), qid)) else: areamap.append(("{s}%s (%d AP){/s}" % (name, cost), None)) # Display area menu areamap.append(("Return", -1)) qid=renpy.display_menu(areamap) del areamap if qid == -1 or qid is None: renpy.jump("quest_select") jump quest_selected ################################################################### label quest_selected: # Get quest data python: quest=dl_search(allquests, "quest_id", qid) # Uhm, how did this happen? Means client-data is not fully updated! if (quest == ERR_INVALID): renpy.call_screen("msgbox", "ERROR:\n\nRequested Quest does not exist client-side\nAn update is required. We'll now close the app.") raise KeyboardInterrupt() # Confirm the quest cost $apmsg=_("Quest cost: %d/%d AP" % (quest["cost"], Player["ap"])) menu: "[apmsg]" "Accept Quest" if Player["ap"] >= quest["cost"]: pass "Decline Quest": jump quest_select # Begin the quest $ Battle=loadquest(qid) # Check for error if (Battle in [FAILUREMSG, OFFLINEMSG, ERR_JSONDECODER, ERR_LOGIN_DEFAULT]): $ renpy.call_screen("msgbox", "Error:\n\n%s\nYou'll be taken to town." % Battle) jump restore # Reduce the paid AP python: # Consume the AP update_ap(-(quest["cost"])) # Before fighting, should we perhaps show story? if Player["quest"] < qid: story=dl_search(allstory, "quest_id", qid) if (story != ERR_INVALID): hud_story() print ".:: Story logs (%d) ::." % qid if isinstance(story["pre_dialog"], str) or isinstance(story["pre_dialog"], unicode): renpy.call_in_new_context(story["pre_dialog"]) else: bg_is_showing=False for dial in story["pre_dialog"]: # Background if str(dial["bg"]) != "": if bg_is_showing: renpy.hide("sbg") show_img("bg "+dial["bg"], tag="sbg", ext=".jpg") bg_is_showing=True show_img("dialog_"+dial["left_sprite"], at_list=[left], tag="l") show_img("dialog_"+dial["center_sprite"], at_list=[center], tag="c") show_img("dialog_"+dial["right_sprite"], at_list=[right], tag="r") renpy.say(dial["name"], dial["message"]) renpy.hide("l") renpy.hide("c") renpy.hide("r") print "%s: %s" % (dial["name"], dial["message"]) # Background Clean up if bg_is_showing: renpy.hide("sbg") del bg_is_showing # Okay, story-telling time is over: To arms! play music MUSIC_BATTLE.id() fadein 0.5 $ renpy.free_memory() window hide jump combat