Exemplo n.º 1
0
    def _compile(self, widj, ev):
        fname = "ADV_{}.py".format(self.mytree.raw_vars["unique_id"])

        # First, check for errors.
        myerrors = self.mytree.get_errors()
        if myerrors:
            pbge.BasicNotification("{} has errors. Check the console.".format(fname))
            for e in myerrors:
                print(e)
            return

        myprog = self.mytree.compile()
        fname = "ADV_{}.py".format(self.mytree.raw_vars["unique_id"])
        if FormatCode:
            fullprog, changed = FormatCode(myprog["main"])
        else:
            fullprog = myprog["main"]

        with open(pbge.util.user_dir("content", fname), 'wt') as fp:
            fp.write(fullprog)

        pbge.BasicNotification("{} has been written. You can start the scenario from the main menu.".format(fname))
        game.content.ghplots.reload_plot_module(fname.rpartition('.')[0])
        for k, v in myprog.items():
            if k != "main":
                print("Leftover section: {}".format(k))
Exemplo n.º 2
0
 def t_UPDATE(self, camp):
     if self.adv.is_completed():
         if not self.gave_ending_message:
             if self.adv.is_won():
                 if "WIN_MESSAGE" in self.elements:
                     pbge.alert(self.elements["WIN_MESSAGE"])
                 pbge.BasicNotification("Mission Complete", count=160)
             elif "LOSS_MESSAGE" in self.elements:
                 pbge.alert(self.elements["LOSS_MESSAGE"])
                 pbge.BasicNotification("Mission Failed", count=160)
             self.gave_ending_message = True
         if self.elements.get("AUTO_EXIT",
                              False) and not self.exited_mission:
             self.exit_the_mission(camp)
Exemplo n.º 3
0
def import_arena_character(tsrd):
    pbge.please_stand_by()
    myfiles = gears.oldghloader.GH1Loader.seek_gh1_files()
    mymenu = pbge.rpgmenu.Menu(TitleScreenRedraw.MENU_DEST.dx,
                               TitleScreenRedraw.MENU_DEST.dy,
                               TitleScreenRedraw.MENU_DEST.w,
                               TitleScreenRedraw.MENU_DEST.h,
                               predraw=tsrd,
                               font=pbge.my_state.huge_font)

    for f in myfiles:
        try:
            mygears = gears.oldghloader.GH1Loader(f)
            mygears.load()
            egg = mygears.get_egg()
            mymenu.add_item(str(egg.pc), egg)
        except Exception as e:
            pbge.alert("Warning: File {} can't be parsed. {}".format(f, e))
    mymenu.sort()

    if not mymenu.items:
        mymenu.add_item('[No GH1 characters found]', None)

    myegg = mymenu.query()
    if myegg:
        myegg.save()
        pbge.BasicNotification("{} has been imported.".format(myegg.pc.name))
Exemplo n.º 4
0
    def record_hotkey(self, mykey):
        option_string = self.name_current_option()

        pbge.util.config.set("HOTKEYS", mykey, option_string)
        pbge.BasicNotification("New hotkey set: {} = {}".format(
            mykey, option_string),
                               count=200)
        # Export the new config options.
        with open(pbge.util.user_dir("config.cfg"), "wt") as f:
            pbge.util.config.write(f)
Exemplo n.º 5
0
    def record_hotkey(self, mykey):
        option_string = self.name_current_option()

        pbge.util.config.set("HOTKEYS", mykey, option_string)
        pbge.BasicNotification("New hotkey set: {} = {}".format(mykey, option_string), count=200)
        # Export the new config options.
        current_use = pbge.my_state.key_is_in_use(mykey)
        if current_use:
            pbge.alert("Warning: Key {} is currently in use by \"{}\". It can't be used as a hotkey unless you change your key configuration.".format(mykey, current_use))

        with open(pbge.util.user_dir("config.cfg"), "wt") as f:
            pbge.util.config.write(f)
Exemplo n.º 6
0
    def go(self):
        self.no_quit = True
        self.order = None

        global current_explo
        current_explo = self

        self.update_scene()
        #self.scene.update_party_position(self.camp)

        # Clear the event queue, in case switching scenes took a long time.
        pygame.event.clear([pbge.TIMEREVENT, pygame.KEYDOWN])

        # Do one view first, just to prep the model map and mouse tile.
        self.view()
        pbge.my_state.do_flip()
        #self.record_count = 120

        del pbge.my_state.notifications[:]
        pbge.BasicNotification(str(self.scene))

        # Do a start trigger, unless we're in combat.
        if not self.camp.fight:
            if hasattr(self.scene, "exploration_music"):
                pbge.my_state.start_music(self.scene.exploration_music)
            self.camp.check_trigger("START")
            self.camp.check_trigger("ENTER", self.scene)
        self.camp.check_trigger("UPDATE")
        self.update_npcs()

        while self.keep_exploring():
            first_pc_pos = self.camp.first_active_pc().pos
            if self.camp.fight:
                self.camp.check_trigger("STARTCOMBAT")
                self.order = None
                self.camp.fight.go(self)
                if pbge.my_state.got_quit or not self.camp.fight.no_quit:
                    self.no_quit = False
                    self.camp.fight.no_quit = True
                    break
                else:
                    self.camp.fight = None
                    self.camp.check_trigger("ENDCOMBAT")

            # Get input and process it.
            gdi = pbge.wait_event()

            if not self.keep_exploring():
                pass
            elif gdi.type == pbge.TIMEREVENT:
                self.view.overlays.clear()
                self.threat_viewer.update(self.view, self.threat_tiles)
                self.view.overlays[self.view.mouse_tile] = (self.mapcursor, 0)
                self.view()

                # Display info for this tile.
                my_info = self.scene.get_tile_info(self.view.mouse_tile)
                if my_info:
                    my_info.popup()

                pbge.my_state.do_flip()

                if self.record_count > 0:
                    pygame.image.save(
                        pbge.my_state.screen,
                        pbge.util.user_dir(
                            "exanim_{}.png".format(100000 -
                                                   self.record_count)))
                    self.record_count -= 1

                self.time += 1
                if hasattr(self.scene, "exploration_music"):
                    pbge.my_state.start_music(self.scene.exploration_music)

                if self.order:
                    if not self.order(self):
                        self.order = None
                    #self.update_npcs()
                    pcpos = {pc.pos for pc in self.camp.get_active_party()}
                    if pcpos.intersection(self.threat_tiles):
                        self.update_npcs()

                if self.time % 50 == 0:
                    self.update_npcs()

                if self.time % 150 == 0:
                    self.update_enchantments()

            elif not self.order:
                # Set the mouse cursor on the map.
                #self.view.overlays[ self.view.mouse_tile ] = maps.OVERLAY_CURSOR

                if gdi.type == pygame.KEYDOWN:
                    if gdi.unicode == "Q":
                        #self.camp.save(self.screen)
                        self.no_quit = False
                    elif gdi.unicode == "c":
                        pc = self.camp.first_active_pc()
                        pbge.my_state.view.focus(pc.pos[0], pc.pos[1])
                    elif gdi.unicode == "m":
                        memobrowser.MemoBrowser.browse(self.camp)
                    elif gdi.unicode == "R" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        print(self.camp.renown)
                    elif gdi.unicode == "A" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.record_count = 30

#                    elif gdi.unicode == "K" and pbge.util.config.getboolean( "GENERAL", "dev_mode_on" ):
#                        self.camp.pc.hp_damage += 100

                    elif gdi.unicode == "&" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for x in range(self.scene.width):
                            for y in range(self.scene.height):
                                self.scene.set_visible(x, y, True)
                    elif gdi.unicode == "C" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for sc in self.camp.contents:
                            print(sc)
                            if sc.name.endswith(" Base"):
                                for pc in sc.contents:
                                    print('--> {}'.format(pc))
                    elif gdi.unicode == "!" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.egg.credits += 1000000
                        for mpc in self.camp.get_active_party():
                            pc = mpc.get_pilot()
                            if pc:
                                for skill in pc.statline:
                                    if skill in gears.stats.ALL_SKILLS:
                                        pc.statline[skill] += 10
                    elif gdi.unicode == "@" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.scene.contents:
                            if hasattr(thing, "pos"):
                                print("{}: {}".format(thing, thing.pos))
                    elif gdi.unicode == "P" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.camp.active_plots():
                            print("{}".format(thing.__class__.__name__))
                    elif gdi.unicode == "L" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in self.camp.get_active_party():
                            if hasattr(pc, "relationship") and pc.relationship:
                                print("{} {} {} OK:{}".format(
                                    pc, pc.renown, pc.relationship.hilights(),
                                    pc.relationship.can_do_development()))
                    elif gdi.unicode == "V" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in list(self.camp.party):
                            if pc in self.scene.contents and isinstance(
                                    pc, gears.base.Mecha
                            ) and not pc.is_operational():
                                pc.free_pilots()
                                print(pc)
                                self.camp.party.remove(pc)
                    elif gdi.unicode == "T" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for card in self.camp.active_tarot_cards():
                            print(card.__class__.__name__)
                    elif gdi.unicode == "H":
                        fieldhq.FieldHQ.create_and_invoke(self.camp)
                    elif gdi.key == pygame.K_ESCAPE:
                        mymenu = configedit.PopupGameMenu()
                        mymenu(self)

                elif gdi.type == pygame.QUIT:
                    #self.camp.save(self.screen)
                    self.no_quit = False

                elif gdi.type == pygame.MOUSEBUTTONUP:
                    if gdi.button == 1:
                        # Left mouse button.
                        if (self.view.mouse_tile != self.camp.pc.get_root().pos
                            ) and self.scene.on_the_map(*self.view.mouse_tile):
                            npc = self.view.modelmap.get(self.view.mouse_tile)
                            if npc and npc[0].is_operational(
                            ) and self.scene.is_an_actor(npc[0]):
                                npteam = self.scene.local_teams.get(npc[0])
                                if npteam and self.scene.player_team.is_enemy(
                                        npteam):
                                    self.activate_foe(npc[0])
                                elif not isinstance(
                                        npc[0],
                                    (gears.base.Prop, gears.base.Monster)):
                                    self.order = TalkTo(self, npc[0])
                                    self.view.overlays.clear()
                            else:
                                self.order = MoveTo(self, self.view.mouse_tile)
                                self.view.overlays.clear()
                        elif self.scene.on_the_map(*self.view.mouse_tile):
                            # Clicking the same tile where the PC is standing; get an item.
                            self.get_item()
                    else:
                        pc = self.scene.get_main_actor(self.view.mouse_tile)
                        ExploMenu(self, pc)

        if not self.no_quit:
            self.camp.save()
        else:
            self.camp.check_trigger("END")

        current_explo = None
 def CHALLENGE_WIN(self, camp):
     pbge.BasicNotification("Challenge complete!", count=160)
     camp.check_trigger("WIN", self)
     self.end_plot(camp)
Exemplo n.º 8
0
    def go(self):
        self.no_quit = True
        self.order = None

        global current_explo
        current_explo = self

        self.update_scene()
        # self.scene.update_party_position(self.camp)

        # Clear the event queue, in case switching scenes took a long time.
        pygame.event.clear([pbge.TIMEREVENT, pygame.KEYDOWN])

        # Do one view first, just to prep the model map and mouse tile.
        self.view()
        pbge.my_state.do_flip()
        # self.record_count = 120

        del pbge.my_state.notifications[:]
        pbge.BasicNotification(str(self.scene))

        # Do a start trigger, unless we're in combat.
        if not self.camp.fight:
            if hasattr(self.scene, "exploration_music"):
                pbge.my_state.start_music(self.scene.exploration_music)
            self.camp.check_trigger("START")
            self.camp.check_trigger("ENTER", self.scene)
        self.camp.check_trigger("UPDATE")
        self.update_npcs()

        while self.keep_exploring():
            first_pc_pos = self.camp.first_active_pc().pos
            if self.camp.fight:
                self.camp.check_trigger("STARTCOMBAT")
                self.order = None
                self.camp.fight.go(self)
                if pbge.my_state.got_quit or not self.camp.fight.no_quit:
                    self.no_quit = False
                    self.camp.fight.no_quit = True
                    break
                else:
                    self.camp.fight = None
                    self.camp.check_trigger("ENDCOMBAT")

            # Get input and process it.
            gdi = pbge.wait_event()

            if not self.keep_exploring():
                pass
            elif gdi.type == pbge.TIMEREVENT:
                self.view.overlays.clear()
                self.threat_viewer.update(self.view, self.threat_tiles)
                self.view()

                # Display info for this tile.
                my_info = self.scene.get_tile_info(self.view)
                if my_info:
                    my_info.view_display()

                pbge.my_state.do_flip()

                if self.record_count > 0:
                    pygame.image.save(
                        pbge.my_state.screen,
                        pbge.util.user_dir(
                            "exanim_{}.png".format(100000 -
                                                   self.record_count)))
                    self.record_count -= 1

                self.time += 1
                if hasattr(self.scene, "exploration_music"):
                    pbge.my_state.start_music(self.scene.exploration_music)

                if self.order:
                    if not self.order(self):
                        self.order = None
                    # self.update_npcs()
                    pcpos = {pc.pos for pc in self.camp.get_active_party()}
                    if pcpos.intersection(self.threat_tiles):
                        self.update_npcs()

                if self.time % 80 == 0:
                    self.update_npcs()

                if self.time % 150 == 0:
                    self.update_enchantments()

                if self.time > 0 and self.time % (pbge.util.config.getint(
                        "GENERAL", "frames_per_second") * 30) == 0:
                    self.camp.check_trigger("HALFMINUTE")

            elif not self.order:
                # Set the mouse cursor on the map.
                # self.view.overlays[ self.view.mouse_tile ] = maps.OVERLAY_CURSOR

                if gdi.type == pygame.KEYDOWN:
                    if pbge.my_state.is_key_for_action(gdi, "quit_game"):
                        # self.camp.save(self.screen)
                        self.no_quit = False
                    elif pbge.my_state.is_key_for_action(gdi, "center_on_pc"):
                        pc = self.camp.first_active_pc()
                        pbge.my_state.view.focus(pc.pos[0], pc.pos[1])

                    elif pbge.my_state.is_key_for_action(gdi, "memo_browser"):
                        memos.MemoBrowser(self.camp)()

                    elif pbge.my_state.is_key_for_action(gdi, "field_hq"):
                        fieldhq.FieldHQ.create_and_invoke(self.camp)

                    elif pbge.my_state.is_key_for_action(gdi, "inventory"):
                        fieldhq.backpack.BackpackWidget.create_and_invoke(
                            self.camp, self.camp.pc.get_root())

                    elif gdi.key == pygame.K_ESCAPE:
                        mymenu = configedit.PopupGameMenu()
                        mymenu(self)

                    elif pbge.my_state.is_key_for_action(gdi, "cursor_click"):
                        if gdi.mod & pygame.KMOD_SHIFT:
                            pc = self.scene.get_main_actor(
                                self.view.mouse_tile)
                            ExploMenu(self, pc)
                        else:
                            self.click_left()

                    elif gdi.unicode == "R" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        print(self.camp.renown)
                    elif gdi.unicode == "A" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.record_count = 30

                    elif gdi.unicode == "X" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        pc = self.camp.first_active_pc()
                        myinvo = pbge.effects.Invocation(
                            fx=geffects.DoCrash(),
                            area=pbge.scenes.targetarea.SingleTarget())
                        myinvo.invoke(self.camp, None, [
                            pc.pos,
                        ], pbge.my_state.view.anim_list)
                        pbge.my_state.view.handle_anim_sequence()

                    elif gdi.unicode == "K" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for lm in self.camp.get_active_party():
                            pc: gears.base.Being = lm.get_pilot()
                            pc.hp_damage += 99999999999999

                    elif gdi.unicode == "J" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        # Experimenting with JSON serialization. It isn't going well.
                        GHEncoder.save_by_json(self.camp)

                    elif gdi.unicode == "&" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for x in range(self.scene.width):
                            for y in range(self.scene.height):
                                self.scene.set_visible(x, y, True)

                    elif gdi.unicode == "!" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.egg.credits += 1000000
                        for mpc in self.camp.get_active_party():
                            pc = mpc.get_pilot()
                            if pc:
                                for skill in pc.statline:
                                    if skill in gears.stats.ALL_SKILLS:
                                        pc.statline[skill] += 10

                    elif gdi.key == pygame.K_F1 and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        pygame.image.save(pbge.my_state.screen,
                                          pbge.util.user_dir("screenshot.png"))

                    elif gdi.unicode == "@" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.scene.contents:
                            if hasattr(thing, "pos"):
                                print("{}: {}".format(thing, thing.pos))

                    elif gdi.unicode == "*" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.camp.all_contents(self.camp):
                            if isinstance(thing, gears.base.Character):
                                print("{}: {}/{}".format(
                                    thing, thing.faction,
                                    thing.scene.get_root_scene()))

                    elif gdi.unicode == "+" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.pc.inv_com.append(
                            gears.selector.get_design_by_full_name("Meat"))

                    elif gdi.unicode == "P" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.camp.active_plots():
                            print("{}".format(thing.__class__.__name__))
                    elif gdi.unicode == "C" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        myfac = self.camp.faction_relations.get(
                            self.scene.get_metro_scene().faction)
                        print(myfac.enemies)
                    elif gdi.unicode == "L" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in self.camp.get_active_party():
                            if hasattr(pc, "relationship"
                                       ) and pc.relationship and hasattr(
                                           pc, "renown"):
                                print("{} {} {} OK:{}".format(
                                    pc, pc.renown, pc.relationship.hilights(),
                                    pc.relationship.can_do_development()))
                    elif gdi.unicode == "V" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in list(self.camp.party):
                            if pc in self.scene.contents and isinstance(
                                    pc, gears.base.Mecha
                            ) and not pc.is_operational():
                                pc.free_pilots()
                                print(pc)
                                self.camp.party.remove(pc)
                    elif gdi.unicode == "F" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for k in self.camp.faction_relations.keys():
                            if self.camp.is_unfavorable_to_pc(k):
                                print("{}: Enemy".format(k))
                            elif self.camp.is_favorable_to_pc(k):
                                print("{}: Ally".format(k))

                    elif gdi.unicode == "E" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        mymenu = pbge.rpgmenu.AlertMenu(
                            "Do you want to end this campaign?")
                        mymenu.add_item("Yes, time to quit.", True)
                        mymenu.add_item("No, I pressed the wrong key.", False)
                        if mymenu.query():
                            self.camp.eject()

                    elif gdi.unicode == "O" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.version = "v0.100"

                elif gdi.type == pygame.QUIT:
                    # self.camp.save(self.screen)
                    self.no_quit = False

                elif gdi.type == pygame.MOUSEBUTTONUP:
                    if gdi.button == 1:
                        self.click_left()
                    else:
                        pc = self.scene.get_main_actor(self.view.mouse_tile)
                        ExploMenu(self, pc)

        if not self.no_quit:
            self.camp.save()
        else:
            self.camp.check_trigger("END")

        current_explo = None