Beispiel #1
0
 def chooseAnEvent(self, areaType):
     areaChoices = areaType["events"][::]
     currentEvent = areaChoices[0]
     highRoll = rollDice(currentEvent[1])
     for event in areaChoices[1:]:
         newRoll = rollDice(event[1])
         if newRoll > highRoll:
             currentEvent = event
             highRoll = newRoll
     return currentEvent[0]
    def __init__(self, data, weapons, armor, misc, modifiers):
        self.name = generateString(data)
        self.eID = data["eID"]
        self.desc = generateString(data, "desc")
        self.hpMax = rollDice(data["hp"])
        self.damage = data["damage"]
        self.xp = data["xp"]
        if data["weapon"]:
            self.weapon = generateWeapon(weapons[random.choice(
                data["weapon"])])
        # Adds modifiers to the enemy
        if data["modifier"]:
            # Calculates the chance for each mod
            mods = []
            for mod in data["modifier"]:
                mods += [mod[0]] * mod[1]
            # Chooses a mod
            mod = random.choice(mods)
            # If the mod is not none add the info
            if mod != "None":
                mod = modifiers[mod].getInfo()
                # modifies the enemy's name to match the effect
                self.name = "%s %s" % (mod["n"], self.name)
                # Gets into the mod's effects
                if mod["e"] == "damage":
                    self.damage += ";%s" % (mod["s"])
                elif mod["e"] == "health":
                    self.hpMax += rollDice(mod["s"])
        # Wait until modifiers are added to set the starting health
        self.hp = self.hpMax

        armorType = random.choice(data["armor"])
        if armorType != "None":
            self.armor = Armor(armor[armorType])
        else:
            self.armor = None
        self.deathMsg = random.choice(data["deathMsg"])
        self.itemChance = data["itemChance"]
        if self.itemChance > 0:
            self.itemDrop = copy.copy(random.choice(data["itemDrops"]))
            try:
                if self.itemDrop[0] in weapons.keys():
                    self.itemDrop[0] = generateWeapon(
                        weapons[self.itemDrop[0]])
                elif self.itemDrop[0] in armor.keys():
                    self.itemDrop[0] = Armor(armor[self.itemDrop[0]])
                elif self.itemDrop[0] in misc.keys():
                    self.itemDrop[0] = Misc(misc[self.itemDrop[0]])
            except:
                print("Error loading {} item reward.".format(self.name))

        if self.xp < 1:
            self.xp = 1
Beispiel #3
0
 def getArmorDefence(self):
     if self.armor:
         armor = rollDice(self.armor.defence)
         self.disp.dprint("Player defended with {} armor".format(armor))
         return armor
     else:
         return 0
    def randomAreaChoices(self):
        '''This randomly generates areas for the player to choose from.'''
        choices = []
        # This is to guarantee that no "limited" areas are used more than once
        usedAreas = []

        # Grab all required areas and throw them into a seperate list. This is to
        # guarantee that they are generated.
        areatypes = self.currentArea.newAreaTypes[::]
        required = []
        for area in areatypes:
            if len(area) > 2:
                for flag in area[2]:
                    if flag == "required":
                        required.append(area)

        # Actually generate areas:
        for i in range(1, self.currentArea.newArea + 1):
            if len(required) > 0:
                newArea = required.pop(0)
            else:
                areatypes = self.currentArea.newAreaTypes[::]
                highroll = 0
                for aType in areatypes:
                    newroll = rollDice(aType[1])
                    alreadyUsed = False
                    if len(aType) > 2:
                        if "limited" in aType[2]:
                            if aType[0] in usedAreas:
                                alreadyUsed = True
                    if newroll > highroll and not alreadyUsed:
                        newArea = aType
                        highroll = newroll
            generatedArea = Area(self.areas[newArea[0]])
            usedAreas.append(newArea[0])
            choices.append(generatedArea)
        return choices
    def fightEnemies(self):
        ##### Fighting Code #####
        if self.currentArea.enemy != []:
            self.disp.clearScreen()
            for areaEnemy in self.currentArea.enemy:
                enemyhp = areaEnemy.getHealth()
                while enemyhp > 0 and self.player.hp:
                    self.disp.dprint("Enemy Danger Level:   {}".format(
                        areaEnemy.getDanger()))
                    self.disp.dprint("Enemy Max Health:     {}".format(
                        areaEnemy.hpMax))
                    self.disp.dprint("Enemy Current Health: {}".format(
                        areaEnemy.hp))
                    self.disp.dprint("Enemy Strength:       {}".format(
                        areaEnemy.getStrength()))
                    self.disp.dprint("Enemy Weapon Damage:  {}".format(
                        areaEnemy.getRawWeaponDamage()))

                    cmd = -1
                    self.disp.clearScreen()
                    while not ((int(cmd) <= 2 and int(cmd) >= 0) or
                               (cmd == 90 and DEBUG)):
                        self.disp.displayHeader("Enemy Encountered - %s" %
                                                (areaEnemy.name))
                        self.disp.display(
                            "%s The enemy has a danger level of %d." %
                            (areaEnemy.desc, areaEnemy.getDanger()), 1, 1)
                        self.disp.displayHeader("Info")
                        self.disp.display("Player: %s - %dHP" %
                                          (self.player.name, self.player.hp))
                        self.disp.display(
                            "HP: %s" % ("#" * self.player.getHealth()), 0)
                        self.disp.display(
                            "Weapon: %s" % (str(self.player.weapon)), 0)
                        self.disp.display("Enemy: %s - %dHP" %
                                          (areaEnemy.name, areaEnemy.hp))
                        self.disp.display(
                            "HP: %s" % ("#" * areaEnemy.getHealth()), 0)
                        self.disp.display(
                            "Weapon: %s" % (str(areaEnemy.weapon)), 0, 1)
                        self.disp.displayHeader("Actions")
                        self.disp.display("1. Use your weapon (%s)" %
                                          str(self.player.weapon))
                        self.disp.display("2. Attempt to escape", 0)
                        self.disp.display("0. Player Menu")
                        self.disp.closeDisplay()
                        try:
                            # cmd = int(input())
                            cmd = self.disp.get_input(True)
                            if not self.disp.window_is_open:
                                self.player.quit = True
                                return None
                            self.disp.clearScreen()
                        except ValueError:
                            self.disp.clearScreen()
                            cmd = -1
                        if cmd == 0:
                            self.player.playerMenu(self.currentQuests,
                                                   self.completedQuests)
                            if self.player.quit:
                                # TODO Exit the game completely
                                return None
                        elif cmd in (9, 90) and DEBUG:
                            self.disp.dprint("Healing player fully.")
                            self.player.hp = self.player.getMaxHP()
                        elif cmd not in (1, 2, 0):
                            self.disp.displayHeader("Error")
                            self.disp.display("That was not a valid response.",
                                              1, 1)

                    if cmd == 1 or cmd == 90:
                        self.disp.clearScreen()
                        damage = self.player.getWeaponDamage()
                        if DEBUG and cmd == 90:
                            damage *= 10
                        msg = self.player.getWeaponAction()
                        damage -= int(areaEnemy.getArmorDefence())
                        if damage < 0:
                            damage = 0
                        areaEnemy.hp -= damage
                        self.disp.displayHeader("You")
                        self.disp.display(
                            "%s You dealt %d damage." % (msg, damage), 1, 1)
                        self.disp.displayHeader(areaEnemy.name)
                        damage = areaEnemy.getWeaponDamage()
                        if self.player.armor:
                            damage -= self.player.getArmorDefence()
                        if damage < 0:
                            damage = 0
                        self.player.hp -= damage
                        self.disp.display("%s %s dealt %d damage." %
                                          (areaEnemy.weapon.getAction(),
                                           areaEnemy.name, damage))
                        self.disp.closeDisplay()
                        time.sleep(DELAY)
                        # input("\nEnter to continue.")
                        self.disp.wait_for_enter()
                    elif cmd == 2:
                        self.disp.clearScreen()
                        escape = False
                        if random.randint(
                                0,
                                self.player.getArmorDefence() +
                                areaEnemy.getWeaponDamage()
                        ) < areaEnemy.getArmorDefence():
                            escape = True
                        if escape:
                            self.disp.displayHeader("Escape Successful")
                            self.disp.display(
                                "You successfully escape from %s." %
                                (areaEnemy.name))
                        else:
                            self.disp.displayHeader("Escape Failed")
                            self.disp.display(
                                "You fail to escape from %s." %
                                (areaEnemy.name), 1, 1)
                            self.disp.displayHeader(areaEnemy.name)
                            damage = areaEnemy.weapon.damage
                            if self.player.armor:
                                damage += "-{0}".format(
                                    self.player.getArmorDefence())
                            damage = rollDice(damage)
                            if damage < 0:
                                damage = 0
                            self.player.hp -= damage
                            self.disp.display("%s %s dealt %d damage." %
                                              (areaEnemy.weapon.getAction(),
                                               areaEnemy.name, damage))
                        self.disp.closeDisplay()
                        time.sleep(DELAY)
                        # input("\nEnter to continue")
                        self.disp.wait_for_enter()
                        if escape:
                            break

                    self.disp.clearScreen()
                    enemyhp = areaEnemy.hp

                if self.player.hp > 0 and areaEnemy.hp <= 0:
                    self.disp.clearScreen()
                    self.disp.displayHeader("Victory")
                    self.disp.display(
                        "You defeated the enemy, and got %d experience." %
                        areaEnemy.xp)
                    self.importantQuestInfo.append(
                        ["isKilled", areaEnemy.eID, True, False])
                    self.disp.display("%s %s" %
                                      (areaEnemy.name, areaEnemy.deathMsg))
                    if random.randint(1, 100) < areaEnemy.itemChance:
                        self.disp.display("")
                        self.disp.displayHeader("Reward")
                        self.disp.display(areaEnemy.itemDrop[1])
                        self.disp.display("You recieved %s." %
                                          (areaEnemy.itemDrop[0].name))
                        self.player.inv.append(areaEnemy.itemDrop[0])
                    self.disp.closeDisplay()
                    # time.sleep(DELAY)
                    # input("\nEnter to continue")
                    self.disp.wait_for_enter()
                    self.player.giveXP(areaEnemy.xp)

                # UPDATE QUEST INFO
                self.updateQuestInfo()
                self.workOnBacklog()
Beispiel #6
0
 def getWeaponDamage(self):
     if self.weapon:
         return rollDice(self.weapon.damage)
     else:
         return 0
 def getArmorDefence(self):
     if self.armor:
         return rollDice(self.armor.defence) - 1
     else:
         return 0
 def getWeaponDamage(self, rand=True):
     if self.weapon:
         return rollDice(self.damage) + rollDice(self.weapon.damage)
     else:
         return rollDice(self.damage)