Esempio n. 1
0
def game1():
    #---Variable Setup---
    global my_weapons
    global my_items
    global money
    money = 0
    starter_weapon = Shop.all_weapons[0]
    my_weapons = [starter_weapon]
    my_items = Shop.Items
    #---Start Screen---
    print("WELCOME TO MIGHTY MAGIC ADVENTURES!")
    wait(2)
    cont = input("Press enter to continue: ")
    del cont
    ui.restartPage()
    #---Character Setup---
    protagonist = Character.set_up_character()
    ui.restartPage()
    print(protagonist)
    wait(3)
    cont = input("Press enter to continue: ")
    del cont
    ui.restartPage()
    #---Tutorial/Introduction---
    intro(protagonist, my_weapons[0], my_items, money)
    #---Savannah Levels---
    savannah1(protagonist, my_weapons[0], my_items, money)
    savannah2(protagonist, my_weapons[0], my_items, money)
Esempio n. 2
0
    def import_character(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file', "characters/",
                                            "XML Files (*.xml)")

        if fname[0] == '':
            return

        path = fname[0]
        character = Character.from_xml(path)
        self.parent.mainUI(character, path)
Esempio n. 3
0
    def new_character(self):

        splat, computer, drive, firearms, ok = New_Character_Dialog.set_UI(
            self)
        if ok:
            character = Character(splat=splat)

            # remove modern defaults
            del character.stats['computer']
            del character.stats['firearms']
            del character.stats['drive']

            # add replacements
            character.stats[computer] = 0
            character.stats[drive] = 0
            character.stats[firearms] = 0

            self.parent.mainUI(character, path=None)
            self.parent.edit_Action.setChecked(True)  # set checked
            self.parent.edit_mode()
Esempio n. 4
0
    def new_character(self):

        splat, computer, drive, firearms, ok = New_Character_Dialog.set_UI(
            self)

        if ok:
            self.character = Character(splat=splat)

            # remove modern defaults
            del self.character.stats['computer']
            del self.character.stats['firearms']
            del self.character.stats['drive']

            # add replacements
            self.character.stats[computer] = 0
            self.character.stats[drive] = 0
            self.character.stats[firearms] = 0

            self.sheet = Sheet(self.character)
            self.setCentralWidget(self.sheet)
            self.edit_Action.setChecked(True)  # set checked
            self.edit_mode()
Esempio n. 5
0
    def import_character(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file', "characters/",
                                            "XML Files (*.xml)")

        if fname[0] == '':
            return

        self.path = fname[0]

        self.character = Character.from_xml(self.path)
        # set as old_character copy for detecting further changes on quit
        self.old_character = copy.deepcopy(self.character)

        # redraw UI with new character object
        self.sheet = Sheet(self.character)
        self.setCentralWidget(self.sheet)
Esempio n. 6
0
 def __init__(self, game):
     self.game = game
     oShadowBoy = Shadow(
         pygmi.Sprite("img/fx/shadowHuman.png", 0, 0, 34, 10), 100 - 19,
         400 - 6)
     oBoy = Character(100, 400, oShadowBoy, self.game)
     oHUD = HUD(10, 10, oBoy)
     oShadowApathol = Shadow(
         pygmi.Sprite("img/fx/shadowApathol.png", 0, 0, 16, 6), 200 - 8,
         400)
     oApathol = Apathol(200, 400, oShadowApathol)
     bgStreet = pygmi.Object(
         pygmi.Sprite("img/bg/street.png", 0, 0, 800, 600), 0, 0)
     super().__init__("street", 1200, 600)
     self.addToRoom(bgStreet)
     self.addToRoom(oShadowBoy)
     self.addToRoom(oShadowApathol)
     self.addToRoom(oBoy)
     self.addToRoom(oHUD)
     self.addToRoom(oApathol)
Esempio n. 7
0
                #might look into making this a pop up dialogue instead
                index1 = text.find('"message"')
                index2 = text.find('\n', index1)
                chop = text[index1:index2]
                self.parent.statusBar.showMessage(chop)
                return
            #end of if statement for warning message

            #now include some rate limit protection
            remaining = int(res.getheader('X-RateLimit-Remaining'))
            reset = int(res.getheader('X-RateLimit-Reset')) - int(time.time())

            #reset should be the number of seconds until rate limit refreshed
            #In my experience it will reset faster than this
            #For now, it will add delays to messages if remaining message count is less than or equal to 2

            if remaining <= 2:
                self.parent.status_update(
                    "Rate Limit approaching. Next message delay is 2 seconds.")
                #already a 1 second delay between messages, so extra secound added here
                time.sleep(1)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    #initialise with a blank character object
    #when import added will skip this and instead ask for input or offer character creation at startup
    char = Character()
    dr = Main()
    sys.exit(app.exec_())
Esempio n. 8
0
    "wisdom": 12,
    "charisma": 8,
    "level": 8,
    "primary_attr": "str_mod",
    "ac": 17,
    "weapon": "d12",
    "hit_die": "d12",
    "fighting_style": None,
    "smite": "",
    "bless": "",
    "bane": ""
}
players = [
    Character(name="Great Axe GWM2",
              path="zealot",
              feats=["gwm2"],
              char_type="barbarian",
              weapon="d12",
              crit_type="HBC"),
    Character(name="Polearm Master GWF",
              path="zealot",
              feats=["polearm_master"],
              char_type="barbarian",
              weapon="d10",
              crit_type="HBC",
              fighting_style="GWF",
              fighter_level=3,
              level=5,
              archetype="champion"),
    Character(name="Great Axe GWM2 GWF",
              feats=["gwm2"],
              char_type="barbarian",
Esempio n. 9
0
def test_character_status_report_at_start():
    Tom = Character('Tom')
    assert Tom.return_health_status_report() == "Tom is in perfect health."
Esempio n. 10
0
def test_character_creation():
    Tom = Character('Tom')
    assert Tom.name == 'Tom'
Esempio n. 11
0
def test_every_health_status():
    Tom = Character('Tom')
    Tom_Sick = Character('Tom')
    Tim = Character('Tim')
    Sam = Character('Sam')

    Tom.health = 90
    assert Tom.return_health_status_report() == "Tom is feeling great."

    Tom_Sick.health = 75
    Tom_Sick.sick = True
    assert Tom_Sick.return_health_status_report(
    ) == "Tom is feeling good. (SICK)"

    Tim.health = 50
    assert Tim.return_health_status_report() == "Tim is feeling poor."

    Sam.health = 30
    Sam.sick = True
    assert Sam.return_health_status_report(
    ) == "Sam is in critical condition. (SICK)"
Esempio n. 12
0
    for p_stat in sorted(player_stats,
                         key=lambda x: float(x.get("eff", 0)),
                         reverse=True):
        for stat in display_stats:
            g_tokens.append("%s%s  " % (p_stat[stat], " " *
                                        (headers[stat] - len(p_stat[stat]))))
        g_tokens.append("\n")
    print "".join(g_tokens)
    #
    fig = plt.figure(figsize=(15, 9), tight_layout=1)
    fignum = 221  # 2 Rows, 2 Column, 1 Figure Number
    for plot_metric in ["ac", "level"]:
        if plot_metric == "ac":
            monsters = [
                Character(**{
                    "char_type": opponent.char_type,
                    plot_metric: metric_value
                }) for metric_value in range(21, 9, -1)
            ]
        else:
            monsters = [[
                Character(**dict(p.init_params, **{plot_metric: metric_value}))
                for p in players
            ] for metric_value in range(1, 21)]
        for plot_stat in ["eff", "dpr"]:
            plt.subplot(fignum)
            fignum += 1
            plot_chars(players, monsters, opponent, plot_stat, plot_metric,
                       independent_stats)

    plt.show()
Esempio n. 13
0
def savannah1(character, weapon, items, money):
    print("CHAPTER 1, PART 1: TRIALS OF THE SAVANNAH")
    wait(3)
    cont = input("Press enter to continue: ")
    del cont
    ui.restartPage()
    print_text_file('StoryTexts/SavannahTexts/savannah1.txt')
    option = input(
        "\nWhat would you like to do? \n(Fight [F]lowers, [P]yroball, [B]ubble Frog): "
    ).lower()
    while option not in ['f', 'p', 'b']:
        print("\nINVALID INPUT")
        option = input(
            "\nWhat would you like to do? \n(Fight [F]lowers, [P]yroballs, [B]ubble Frogs: "
        ).lower()
    if option == "f":
        enemy1 = Enemies(
            "Flower", "Nature",
            Spells(
                "Pollen Rush",
                40,
                "Nature",
                ("Water", "Fire"),
                1,
            ), 22, 14, 15, 19, 1)
        enemy2 = Enemies(
            "Flower", "Nature",
            Spells(
                "Pollen Rush",
                40,
                "Nature",
                ("Water", "Fire"),
                1,
            ), 21, 15, 15, 20, 1)
    elif option == "p":
        enemy1 = Enemies(
            "Pyroball", "Fire",
            Spells("Fireball", 45, "Fire", ("Nature", "Water"), 1), 17, 16, 18,
            19, 1)
        enemy2 = Enemies(
            "Pyroball", "Fire",
            Spells("Fireball", 45, "Fire", ("Nature", "Water"), 1), 18, 17, 17,
            17, 1)
    elif option == "b":
        enemy1 = Enemies(
            "Bubble Frog", "Water",
            Spells("Bubble Blast", 40, "Water", ("Fire", "Nature"), 1), 19, 15,
            20, 18, 1)
        enemy2 = Enemies(
            "Bubble Frog", "Water",
            Spells("Bubble Blast", 40, "Water", ("Fire", "Nature"), 1), 19, 15,
            20, 18, 1)
    ui.restartPage()
    my_spells = Character.spell_by_level(character)
    Combat.main_fight(character, weapon, my_spells, (enemy1, enemy2), items)
    wait(5)
    ui.restartPage()
    enemy1 = Enemies(
        "flower", "Nature",
        Spells(
            "Pollen Rush",
            40,
            "Nature",
            ("Water", "Fire"),
            1,
        ), 22, 14, 15, 19, 1)
    enemy2 = Enemies(
        "flower", "Nature",
        Spells(
            "Pollen Rush",
            40,
            "Nature",
            ("Water", "Fire"),
            1,
        ), 21, 15, 15, 20, 1)
    character.level_up((enemy1, enemy2), money)
    del (enemy1, enemy2)
    wait(3)
    ui.restartPage()
    print_text_file('StoryTexts/SavannahTexts/savannah2.txt')
    wait(10)
    cont = input("Press enter to continue: ")
    del cont
    return
Esempio n. 14
0
class Main(QMainWindow):
    '''
    Main window for displaying character sheet
    '''
    def __init__(self):
        super().__init__()
        self.character = None
        self.initUI()
        self.show()

    def initUI(self):
        self.setWindowTitle('Dicecord')
        self.setWindowIcon(QIcon(r'images\D10.ico'))
        self.setCentralWidget(Intro(self))
        self.setFixedSize(500, 200)

        image = QImage(r"images\splash.png")
        palette = QPalette()
        palette.setBrush(10, QBrush(image))

        self.setPalette(palette)

    def mainUI(self, character, path):
        palette = QPalette()
        self.setPalette(palette)
        self.move(100, 100)
        self.setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)
        self.setMinimumSize(0, 0)
        self.character = character
        # save original as a copy to detect changes on quit
        self.old_character = copy.deepcopy(character)
        self.path = path

        self.sheet = Sheet(self.character)
        self.setCentralWidget(self.sheet)

        # toolbar
        self.toolbar = self.addToolBar("Actions")
        ## roller
        roller_Action = QAction(QIcon(r'images\D10.ico'), 'Roll', self)
        roller_Action.setShortcut('Ctrl+R')
        roller_Action.triggered.connect(self.open_roller)
        self.toolbar.addAction(roller_Action)

        ## edit mode
        self.edit_Action = QAction(QIcon(r'images\edit.ico'), 'Edit', self)
        self.edit_Action.triggered.connect(self.edit_mode)
        self.edit_Action.setCheckable(True)
        self.toolbar.addAction(self.edit_Action)

        ## mage cast
        ##        if self.character.splat == 'mage':
        ##            self.cast_Action = QAction(QIcon(INSERTPATH), 'Cast', self)
        ##            self.cast_Action.triggered.connect(mageUI.castWindow)
        ##            self.toolbar.addAction(self.cast_Action)

        # file menu
        menubar = self.menuBar()
        file_Menu = menubar.addMenu('&File')
        ## New
        new_action = QAction('&New Character', self)
        new_action.setShortcut('Ctrl+N')
        file_Menu.addAction(new_action)
        new_action.triggered.connect(self.new_character)
        ## Open
        open_Action = QAction('&Open Character', self)
        open_Action.setShortcut('Ctrl+O')
        file_Menu.addAction(open_Action)
        open_Action.triggered.connect(self.import_character)
        ## Save
        save_Action = QAction('&Save Character', self)
        save_Action.setShortcut('Ctrl+S')
        file_Menu.addAction(save_Action)
        save_Action.triggered.connect(self.save)
        ## Save As
        save_as_Action = QAction('&Save Character As', self)
        save_as_Action.setShortcut('Ctrl+Shift+S')
        file_Menu.addAction(save_as_Action)
        save_as_Action.triggered.connect(lambda: self.save(save_as=True))
        ## Exit
        exit_Action = QAction('&Exit', self)
        exit_Action.setShortcut('Ctrl+Q')
        exit_Action.triggered.connect(self.close)
        file_Menu.addAction(exit_Action)

        # options menu
        options_Menu = menubar.addMenu('&Options')
        ## Bot Personality
        personality_action = QAction('&Personality Settings', self)
        personality_action.triggered.connect(self.personality)
        options_Menu.addAction(personality_action)

        # help menu
        help_Menu = menubar.addMenu('&Help')
        ## ReadMe Link
        readme_action = QAction('Instructions', self)
        readme_action.triggered.connect(self.link)
        help_Menu.addAction(readme_action)

        ## about
        about_Action = QAction('About', self)
        about_Action.triggered.connect(self.about_display)
        help_Menu.addAction(about_Action)

        ## Check for updates
        update_action = QAction('Check for updates', self)
        update_action.triggered.connect(self.update_client)
        help_Menu.addAction(update_action)

    def new_character(self):

        splat, computer, drive, firearms, ok = New_Character_Dialog.set_UI(
            self)

        if ok:
            self.character = Character(splat=splat)

            # remove modern defaults
            del self.character.stats['computer']
            del self.character.stats['firearms']
            del self.character.stats['drive']

            # add replacements
            self.character.stats[computer] = 0
            self.character.stats[drive] = 0
            self.character.stats[firearms] = 0

            self.sheet = Sheet(self.character)
            self.setCentralWidget(self.sheet)
            self.edit_Action.setChecked(True)  # set checked
            self.edit_mode()

    def update_client(self):
        req = urllib.request.Request(
            "http://further-reading.net/dicecord%20version.txt")
        try:
            response = urllib.request.urlopen(req)
        except urllib.error.HTTPError as e:
            message = QMessageBox()
            message.setWindowTitle("Error")
            message.setIcon(QMessageBox.Critical)
            message.setWindowIcon(QIcon(r'images\D10.ico'))
            message.setText("Unable to connect to server.")
            message.setInformativeText("Error Code: " + e.code)
            message.addButton("Okay", QMessageBox.AcceptRole)
            message.exec_()
            return
        except urllib.error.URLError:
            message = QMessageBox()
            message.setWindowTitle("Error")
            message.setWindowIcon(QIcon(r'images\D10.ico'))
            message.setIcon(QMessageBox.Critical)
            message.setText("Unable to connect to server.")
            message.setInformativeText("Please try again later.")
            message.addButton("Okay", QMessageBox.AcceptRole)
            message.exec_()
            return

        version = response.read()
        version = str(version)[1:].replace("'", "")
        if version == VERSION:
            message = QMessageBox()
            message.setWindowIcon(QIcon(r'images\D10.ico'))
            message.setWindowTitle("Up to Date")
            message.setIcon(QMessageBox.Information)
            message.setText("You are using the latest version.")
            message.addButton("Okay", QMessageBox.AcceptRole)
            message.exec_()

        else:
            message = QMessageBox()
            message.setWindowTitle("Update available")
            message.setWindowIcon(QIcon(r'images\D10.ico'))
            message.setIcon(QMessageBox.Warning)
            message.setText("Do you want to update to version " + version +
                            "?")
            message.addButton("Yes", QMessageBox.AcceptRole)
            message.addButton("No", QMessageBox.AcceptRole)
            message.exec_()

            clicked = message.clickedButton().text()

            if clicked == 'Yes':
                message = "This will open a link in your browser and close the client. Do you want to continue?"
                reply = QMessageBox.warning(self, 'Open Link', message,
                                            QMessageBox.Yes, QMessageBox.No)

                if reply == QMessageBox.Yes:
                    QDesktopServices.openUrl(
                        QUrl('http://further-reading.net/dicecord/'))
                    self.close()

    def link(self):
        message = "This will open a link in your browser. Do you want to continue?"
        reply = QMessageBox.warning(self, 'Open Link', message,
                                    QMessageBox.Yes, QMessageBox.No)

        if reply == QMessageBox.Yes:
            QDesktopServices.openUrl(
                QUrl('https://github.com/further-reading/Dicecord'))

    def personality(self):
        self.dialog = New_Window(Personality(self.character, parent=self),
                                 "Personality Settings")
        self.dialog.show()

    def edit_mode(self):
        if self.edit_Action.isChecked():
            # edit mode turned on, save current copy of character
            self.old_character = copy.deepcopy(self.character)

        # toggle edit mode on sheet
        self.sheet.edit_toggle(self.edit_Action.isChecked())

        if not self.edit_Action.isChecked():
            # edit mode turned off
            # check for changes
            if self.character.stats != self.old_character.stats:
                if self.path:
                    # bring up save/discard choice dialog
                    self.ask_save()
                else:
                    # no path yet
                    self.ask_save(new=True)

    def ask_save(self, new=False):
        message = QMessageBox()
        message.setWindowTitle("Save Changes")
        message.setWindowIcon(QIcon(r'images\D10.ico'))
        message.setIcon(QMessageBox.Question)
        message.setText("Do you want to export changes?")
        if not new:
            message.setInformativeText("Press 'reset' to undo all changes.")
            message.addButton("Save", QMessageBox.AcceptRole)
            message.addButton("Save As", QMessageBox.RejectRole)
            message.addButton("Reset", QMessageBox.RejectRole)
        else:
            message.addButton("Yes", QMessageBox.AcceptRole)
        message.addButton("No", QMessageBox.RejectRole)

        message.exec_()
        clicked = message.clickedButton().text()

        if clicked == 'Save':
            self.save()

        elif clicked == 'Save As' or clicked == "Yes":
            self.save(save_as=True)

        elif clicked == 'Reset':
            self.character = self.old_character
            self.sheet = Sheet(self.character)
            self.setCentralWidget(self.sheet)

    def save(self, save_as=False):

        if self.character.splat == 'mage':
            name = self.character.stats['shadow name']
        else:
            name = self.character.stats['name']

        if name == '':
            name = 'character'

        path = "characters/" + name

        if self.path == None or save_as:
            # open filedialog to get path
            fname = QFileDialog.getSaveFileName(self, 'Save file', path,
                                                "XML Files (*.xml)")
            if fname[0] == '':
                # nothing chosen, end function
                return

            self.path = fname[0]

        self.character.save_xml(self.path)

        # set as old_character copy for detecting further changes on quit
        self.old_character = copy.deepcopy(self.character)

    def import_character(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file', "characters/",
                                            "XML Files (*.xml)")

        if fname[0] == '':
            return

        self.path = fname[0]

        self.character = Character.from_xml(self.path)
        # set as old_character copy for detecting further changes on quit
        self.old_character = copy.deepcopy(self.character)

        # redraw UI with new character object
        self.sheet = Sheet(self.character)
        self.setCentralWidget(self.sheet)

    def open_roller(self):
        self.dialog = Roller(self.character)
        self.dialog.show()

    def about_display(self):
        file = open(r'LICENSE\ABOUT.txt', 'r')
        content = file.read()
        file.close()
        box = QLabel(content)
        self.dialog = New_Window(box, "Dicecord v" + VERSION)
        self.dialog.show()

    def closeEvent(self, event):

        if self.character == None:
            # if no character close
            event.accept()
            return

        # check changes
        stat_changed = self.character.stats != self.old_character.stats
        note_changed = self.character.notes != self.old_character.notes
        goodMessages_changed = self.character.goodMessages != self.old_character.goodMessages
        badMessages_changed = self.character.badMessages != self.old_character.badMessages
        goodRates_changed = self.character.goodRate != self.old_character.goodRate
        badRates_changed = self.character.badRate != self.old_character.badRate

        if stat_changed or note_changed or goodMessages_changed or badMessages_changed or goodRates_changed or badRates_changed:
            # unsaved changes
            message = QMessageBox()
            message.setWindowTitle("Save Changes")
            message.setWindowIcon(QIcon(r'images\D10.ico'))
            message.setIcon(QMessageBox.Question)
            message.setText("Do you want to save changes before exiting?")
            message.addButton("Yes", QMessageBox.AcceptRole)
            message.addButton("No", QMessageBox.ApplyRole)
            message.addButton("Cancel", QMessageBox.HelpRole)

            message.exec_()
            clicked = message.clickedButton().text()

            if clicked == "Yes":
                self.save(save_as=True)

            elif clicked == "Cancel":
                event.ignore()
                return

            event.accept()