Exemple #1
0
def look(command, splitIn, npcL, cRoom, cChar, cPlayer):
    if len(splitIn) == 1:
        npcCRoom = []
        for c in npcL:
            if npc.loadNpc(c, "mob").location == cChar.location:
                npcCRoom.append(c)
        print(cRoom.description)
        if len(npcCRoom) > 0:
            print("Also present: ", end="")
            for c in npcCRoom:
                mob = npc.loadNpc(c, "mob")
                if mob.angry:
                    print(colors.fg.red + mob.name + colors.reset, end="")
                elif not mob.angry:
                    print(colors.fg.green + mob.name + colors.reset, end="")
                if npcCRoom.index(mob.name) != len(npcCRoom):
                    print(", ", end="")
            print("")
    else:
        if splitIn[1] in cRoom.stuffDescription:
            print(cRoom.stuffDescription[splitIn[1]])
        elif splitIn[1] in cRoom.inventory:
            print(splitIn[1][0].upper() + splitIn[1][1:] + "--> " +
                  cRoom.inventory[splitIn[1]])
        elif splitIn[1] in cChar.inventory:
            print(splitIn[1][0].upper() + splitIn[1][1:] + "--> " +
                  cChar.inventory[splitIn[1]])
        elif splitIn[1] in ["inventory", "inv", "backpack", "sack"]:
            if len(cChar.inventory) > 0:
                items = cChar.inventory
                print(colors.fg.orange + "Inventory: ")
                print("-----------" + colors.fg.cyan)
                for key in items:
                    print(str(key)[0].upper() + str(key)[1:])
                print(colors.reset, end='')
            else:
                print("Your inventory is empty")
        elif splitIn[1] in [cChar.name.lower(), "self"]:
            character.checkLevel(cChar)
            print(colors.fg.orange + 'Name: ' + colors.fg.cyan +
                  str(cChar.name))
            print(colors.fg.orange + 'Race: ' + colors.fg.cyan +
                  str(cChar.race))
            print(colors.fg.orange + 'Job: ' + colors.fg.cyan + str(cChar.job))
            print(colors.fg.orange + 'Level: ' + colors.fg.purple +
                  str(cChar.level))
            print(colors.fg.orange + "Exp: [" + colors.fg.purple +
                  str(cChar.exp) + colors.reset + " / " + colors.fg.purple +
                  str(cChar.expneed) + colors.reset + "]")
            print(colors.fg.orange + 'Character Stats: ' + colors.fg.cyan +
                  str(cChar.stats))
            weapon = item.loadItem(cChar.onPerson['weapon'], "wpn")
            armor = item.loadItem(cChar.onPerson['armor'], "arm")
            shield = item.loadItem(cChar.onPerson['shield'], "shd")
            print(colors.fg.orange + 'Equipment StatBonus: ' + colors.fg.cyan +
                  '{wit: ' + str(weapon.giver['wit'] + armor.giver['wit'] +
                                 shield.giver['wit']) + ', strength: ' +
                  str(weapon.giver['strength'] + armor.giver['strength'] +
                      shield.giver['strength']) + ', agility: ' +
                  str(weapon.giver['agility'] + armor.giver['agility'] +
                      shield.giver['agility']) + ', luck: ' +
                  str(weapon.giver['luck'] + armor.giver['luck'] +
                      shield.giver['luck']) + '}')
            print(colors.fg.orange + 'Health: [' + colors.fg.green +
                  str(cChar.health) + colors.reset + ' / ' + colors.fg.green +
                  str(cChar.maxhealth) + colors.reset + ']')
            print()
            if len(cChar.inventory) > 0:
                items = cChar.inventory
                print(colors.fg.orange + "Inventory: ")
                print("-----------" + colors.fg.cyan)
                for key in items:
                    print(str(key)[0].upper() + str(key)[1:])
                print(colors.reset, end='')
                print()
            else:
                print("Your inventory is empty")
                print()
            print(colors.fg.orange + "Equipment: ")
            print("-----------")
            for key in cChar.onPerson:
                print(colors.fg.orange + key + " --> " + colors.fg.cyan +
                      cChar.onPerson[key])
                if key == 'weapon':
                    c = 'wpn'
                if key == 'armor':
                    c = 'arm'
                if key == 'shield':
                    c = 'shd'
                if not key == 'bag':
                    equip = item.loadItem(cChar.onPerson[key], c)
                    print(colors.fg.orange + 'StatBonus: ' + colors.fg.cyan +
                          str(equip.giver))
            print()
            if cPlayer.admin:
                print(
                    colors.fg.orange +
                    "You posess the power of the kitten. Use it in a pawsitive manner."
                )
            print(colors.reset, end='')
        elif splitIn[1] in ['name']:
            character.checkLevel(cChar)
            print(colors.fg.orange + 'Name: ' + colors.fg.cyan + cChar.name)
            print(colors.reset, end='')
        elif splitIn[1] in ['race', 'origin']:
            print(colors.fg.orange + 'Race: ' + colors.fg.cyan + cChar.race)
            print(raceDescriptions[cChar.race])
            print(colors.reset, end='')
        elif splitIn[1] in ['job', 'occupation', 'class']:
            print(colors.fg.orange + 'Job: ' + colors.fg.cyan + cChar.job)
            print(colors.reset, end='')
        elif splitIn[1] in ['equipment', 'on person', 'on me', 'worn']:
            print(colors.fg.orange + "Equipment: ")
            print("-----------")
            for key in cChar.onPerson:
                print(colors.fg.orange + key + " --> " + colors.fg.cyan +
                      cChar.onPerson[key])
                if key == 'weapon':
                    c = 'wpn'
                if key == 'armor':
                    c = 'arm'
                if key == 'shield':
                    c = 'shd'
                if not key == 'bag':
                    equip = item.loadItem(cChar.onPerson[key], c)
                    print(colors.fg.orange + 'StatBonus: ' + colors.fg.cyan +
                          str(equip.giver))
            print()
            if cPlayer.admin:
                print(
                    colors.fg.orange +
                    "You posess the power of the kitten. Use it in a pawsitive manner."
                )
            print(colors.reset, end='')
        elif splitIn[1] in ['stats']:
            print(colors.fg.orange + 'Stats: ' + colors.fg.cyan +
                  str(cChar.stats))
            weapon = item.loadItem(cChar.onPerson['weapon'], "wpn")
            armor = item.loadItem(cChar.onPerson['armor'], "arm")
            shield = item.loadItem(cChar.onPerson['shield'], "shd")
            print(colors.fg.orange + 'Equipment StatBonus: ' + colors.fg.cyan +
                  '{wit: ' + str(weapon.giver['wit'] + armor.giver[wit] +
                                 shield.giver['wit']) + ', strength: ' +
                  str(weapon.giver['strength'] + armor.giver['strength'] +
                      shield.giver['strength']) + ', agility: ' +
                  str(weapon.giver['agility'] + armor.giver['agility'] +
                      shield.giver['agility']) + ', luck: ' +
                  str(weapon.giver['luck'] + armor.giver[luck] +
                      shield.giver['luck']) + '}')
            print(colors.fg.orange + 'Health: [' + colors.fg.green +
                  str(cChar.health) + colors.reset + ' / ' + colors.fg.green +
                  str(cChar.maxhealth) + colors.reset + ']')
        elif splitIn[1] in ['str', 'strength']:
            print(colors.fg.orange + 'Strength: ' + colors.fg.cyan +
                  str(cChar.stats['strength']))
            print(colors.reset, end='')
        elif splitIn[1] in ['wits', 'wit', 'intelligence', 'int', 'brains']:
            print(colors.fg.orange + 'Wit: ' + colors.fg.cyan +
                  str(cChar.stats['wit']))
            print(colors.reset, end='')
        elif splitIn[1] in ['agi', 'agility']:
            print(colors.fg.orange + 'Agility: ' + colors.fg.cyan +
                  str(cChar.stats['agility']))
            print(colors.reset, end='')
        elif splitIn[1] in ['luck']:
            print(colors.fg.orange + 'Luck: ' + colors.fg.cyan +
                  str(cChar.stats['luck']))
            print(colors.reset, end='')
        elif splitIn[1] in ['hp', 'health']:
            print(colors.fg.orange + 'Health: [' + colors.fg.green +
                  str(cChar.health) + colors.reset + ' / ' + colors.fg.green +
                  str(cChar.maxhealth) + colors.reset + ']')
            print(colors.reset, end='')
        elif splitIn[1] in ['lvl', 'level']:
            print(colors.fg.orange + 'Level: ' + colors.fg.purple +
                  str(cChar.level))
            print(colors.reset, end='')
        elif splitIn[1] in ['exp', 'xp', 'experience']:
            print(colors.fg.orange + "Exp: [" + colors.fg.purple +
                  str(cChar.exp) + colors.reset + " / " + colors.fg.purple +
                  str(cChar.expneed) + colors.reset + "]")
            print(colors.reset, end='')
        elif splitIn[1] in npcL:
            print(npc.loadNpc(splitIn[1], "mob").description)
        else:
            print("There is no " + splitIn[1] + " here.")
Exemple #2
0
                    print(cRoom.inventory[splitIn[1]] + "\n You acquired " + splitIn[1])
                    cChar.inventory[splitIn[1]] = cRoom.inventory[splitIn[1]]
                else:
                    print("There is no such thing here, " + random.choice(["weirdo", "nutter", "whippersnapper", "beavus", "butthead", "you Thraal", "whacko"]) + ".")

        #========= wear ==========#

        elif command in ["wear", "don", "mount", 'equip']:
            if (len(splitIn) == 1) or ((len(splitIn) >1) and (splitIn[1] == " ")):
                print("You take off everything and stand naked in the middle of the room, wondering why. (Put your clothes back on!)")
            else:
                itemName = splitIn[1]
                if itemName in cChar.inventory:
                    for fIterator in os.listdir("../data/items/"):
                        if fIterator[4:-4] == itemName:
                            newItem = item.loadItem(itemName, fIterator[:3])
                            if fIterator[:3] == "wpn":
                                kind = "weapon"
                            elif fIterator[:3] == "arm":
                                kind = "armor"
                            elif fIterator[:3] == "shd":
                                kind = "shield"
                            oldItem = item.loadItem(cChar.onPerson[kind], fIterator[:3])
                            cChar.onPerson[kind] = newItem.name
                    if oldItem.name != "default":
                        cChar.inventory[oldItem.name] = oldItem.description
                    print("You put on " + newItem.name + " and take off " + oldItem.name + ".")
                else:
                    print("You either don't have this item or misssppeled its name or type.")

        #========= throw away ==========#
Exemple #3
0
def adminer(cPlayer, cChar, cRoom, roomL):
    print(
        "Commands are: room, mob, map, quit, createitem, additem, addtoroom, addroomdir , changestats, crown <username>"
    )
    while True:
        print()
        try:
            admIn = input(colors.fg.red + ">> " + colors.fg.pink)
            print(colors.reset, end='')
            commAdmin = ""
            splitMin = admIn.split(" ")
            for w in splitMin:
                w = w.lower()
            commAdmin = splitMin[0]
            print()
            if commAdmin == "room":
                coord = input(
                    "Please enter the coordinates (seperate by space): ")
                room.newRoom(int(coord.split(' ')[0]),
                             int(coord.split(' ')[1]))
                roomL = room.loadRooms()
                """
                elif commAdmin == "mob":
                    print("Creating new mob...")
                    npc.newMob()
                """
            elif commAdmin == "map":
                mapL = []
                print(cChar.location)
                for o in roomL:
                    oCoord = o[4:]
                    x = oCoord.split("_")[0]
                    y = oCoord.split("_")[1]
                    mapL.append((int(x), int(y)))
                bigY = max(mapL, key=operator.itemgetter(1))[1]
                bigX = max(mapL, key=operator.itemgetter(0))[0]
                litY = min(mapL, key=operator.itemgetter(1))[1]
                litX = min(mapL, key=operator.itemgetter(0))[0]
                mapper(litX, bigX, litY, bigY, mapL, cRoom)

            elif commAdmin == "createitem":
                kind = input("weapon, armor or shield: ").lower()
                if kind == "weapon":
                    item.newWeapon()
                elif kind == "shield":
                    item.newShield()
                elif kind == "armor":
                    item.newArmor()

            elif commAdmin == "changestats":
                changestats = 1
                while changestats == 1:
                    print(colors.fg.orange + 'Stats: ' + colors.fg.cyan +
                          str(cChar.stats))
                    print(colors.fg.orange + 'MaxHealth: ' + colors.fg.green +
                          str(cChar.maxhealth))
                    print()
                    print(colors.reset, end='')
                    print('what stat do you wish to modify ? (' +
                          colors.fg.orange + 'strength' + colors.reset +
                          ' / ' + colors.fg.orange + 'agility' + colors.reset +
                          ' / ' + colors.fg.orange + 'wit' + colors.reset +
                          ' / ' + colors.fg.orange + 'luck' + colors.reset +
                          ' / ' + colors.fg.green + 'maxhealth' +
                          colors.reset + ')')
                    choice = input('>').lower()

                    if choice in ['strength', 'agility', 'wit', 'luck']:
                        confirm = 1
                        while confirm == 1:
                            print('your ' + colors.fg.orange + str(choice) +
                                  colors.reset + ' is: ' + colors.fg.cyan +
                                  str(cChar.stats[str(choice)]) + colors.reset)
                            print()
                            print('input new value')
                            value = input('>')
                            try:
                                if (int(value) >= 0):
                                    cChar.stats[str(choice)] = int(value)
                                    print('your new ' + colors.fg.orange +
                                          str(choice) + colors.reset +
                                          ' is: ' + colors.fg.cyan +
                                          str(cChar.stats[str(choice)]) +
                                          colors.reset)
                                    answer = ''
                                    while answer not in [
                                            'y', 'yes', 'n', 'no'
                                    ]:
                                        print()
                                        print(
                                            'do you wish to continue modifying your stats ?'
                                        )
                                        print("[" + colors.fg.green + "yes" +
                                              colors.reset + "/" +
                                              colors.fg.red + "no" +
                                              colors.reset + "]")
                                        answer = input('>').lower()
                                        if answer in ['y', 'yes']:
                                            changestats = 1
                                            confirm = 0
                                        elif answer in ['n', 'no']:
                                            changestats = 0
                                            confirm = 0
                                            Print('Quitting ...')
                                        elif answer not in [
                                                'y', 'yes', 'n', 'no'
                                        ]:
                                            print(
                                                str(answer) +
                                                ' is not a valid input, try again :'
                                            )
                            except Exception as e:
                                print(e)
                                print(
                                    "Very clever... C'mon, I need numbers dude! N U M B E R S!"
                                )

                    if choice in ['maxhealth']:
                        confirm = 1
                        while confirm == 1:
                            print('your ' + colors.fg.orange + str(choice) +
                                  colors.reset + ' is: ' + colors.fg.cyan +
                                  str(cChar.maxhealth) + colors.reset)
                            print()
                            print('input new value')
                            value = input('>')
                            try:
                                if (int(value) >= 0):
                                    cChar.maxhealth = int(value)
                                    cChar.health = cChar.maxhealth
                                    print('your new ' + colors.fg.orange +
                                          str(choice) + colors.reset +
                                          ' is: ' + colors.fg.cyan +
                                          str(cChar.maxhealth) + colors.reset)
                                    answer = ''
                                    while answer not in [
                                            'y', 'yes', 'n', 'no'
                                    ]:
                                        print()
                                        print(
                                            'do you wish to continue modifying your stats ?'
                                        )
                                        print("[" + colors.fg.green + "yes" +
                                              colors.reset + "/" +
                                              colors.fg.red + "no" +
                                              colors.reset + "]")
                                        answer = input('>').lower()
                                        if answer in ['y', 'yes']:
                                            changestats = 1
                                            confirm = 0
                                        elif answer in ['n', 'no']:
                                            changestats = 0
                                            confirm = 0
                                            Print('Quitting ...')
                                        elif answer not in [
                                                'y', 'yes', 'n', 'no'
                                        ]:
                                            print(
                                                str(answer) +
                                                ' is not a valid input, try again :'
                                            )
                            except Exception as e:
                                print(e)
                                print(
                                    "Very clever... C'mon, I need numbers dude! N U M B E R S!"
                                )

                    elif choice in ['q', 'quit']:
                        quit = 1
                        while quit == 1:
                            print('Are you sure you wish to quit ?')
                            print("[" + colors.fg.green + "yes" +
                                  colors.reset + "/" + colors.fg.red + "no" +
                                  colors.reset + "]")
                            answer = input('>').lower()
                            if answer in ['y', 'yes']:
                                print('Quitting ...')
                                quit = 0
                                changestats = 0
                                confirm = 0
                                continue
                            elif answer in ['n', 'no']:
                                quit = 0
                                changestats = 1
                                confirm = 0
                                continue

                    elif choice not in [
                            'q', 'quit', 'strength', 'agility', 'wit', 'luck',
                            'health'
                    ]:
                        print(
                            'The status ' + colors.fg.orange + str(choice) +
                            colors.reset +
                            ' is not known to me or the game ... try again or enter'
                            + colors.fg.orange + ' quit' + colors.reset +
                            ' to abort')
                        continue

            elif commAdmin == "additem":
                kind = input("weapon, armor or shield: ")
                if kind == "weapon":
                    kind = 'wpn'
                elif kind == "shield":
                    kind = 'shd'
                elif kind == "armor":
                    kind = 'arm'
                print('Input the name of the item')
                name = input('>')
                cChar.inventory[name] = item.loadItem(name, kind).description
                print()
                if len(cChar.inventory) > 0:
                    items = cChar.inventory
                    print(colors.fg.orange + "Inventory: ")
                    print("-----------" + colors.fg.cyan)
                    for key in items:
                        print(str(key)[0].upper() + str(key)[1:])
                    print(colors.reset, end='')
                    print()
                else:
                    print("Your inventory is empty")
                    print()

            elif commAdmin == "addtoroom":
                rom = input("Room coords (<x> <y>): ")
                itemName = input("Item-name: ").lower()
                descr = input("Enter a description: ")
                addToInv = input("Add to inventory (y/n): ")
                coords = rom.split(" ")
                room.loadRoom("room" + coords[0] + "_" +
                              coords[1]).stuffDescription[itemName] = descr
                if addToInv == "y":
                    rom = room.loadRoom("room" + coords[0] + "_" + coords[1])
                    rom.inventory[itemName] = descr
                    rom.save()
                print("Added " + itemName + " to " + "room" + coords[0] + "_" +
                      coords[1] + ".")

            elif commAdmin == "addroomdir":
                rom = input("Room coords (<x> <y>): ")
                pointerDir = input("Direction: ")
                actualDir = input("Whereto: ")
                coords = rom.split(" ")
                rom = room.loadRoom("room" + coords[0] + "_" + coords[1])
                rom.possibleDirections[pointerDir] = actualDir
                rom.save()

            elif commAdmin == "crown":
                cPlayer.admin = True
                cPlayer.save()
                if cPlayer.admin:
                    print("Player " + cPlayer.username + " is now admin.")

            elif commAdmin == "quit":
                print()
                print("Returning to game...")
                print()
                return
            else:
                print(
                    "Possible commands are \"room\", \"mob\", \"map\", \"createitem\", \"additem\", \"addtoroom\", \"changestats\", \"crown <username>\" and \"quit\"."
                )
        except Exception as e:
            print(e)
            print(
                "Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee... Samfing diiidn't wörk."
            )
Exemple #4
0
def hit(attacker, defender):
    attWeapon = item.loadItem(attacker.onPerson["weapon"], "wpn")
    defArmor = item.loadItem(defender.onPerson["armor"], "arm")
    defShield = item.loadItem(defender.onPerson["shield"], "shd")
    ranDamage = random.randint(0, 51)
    attWeaponV = attWeapon.attackValue
    defArmorV = defArmor.defenceValue
    defShieldV = defShield.defenceValue

    # Special calcs for characters
    if type(attacker) == character.Character:
        attWeapon.health -= 1
        if ((attWeapon.kind == "dagger") and (attacker.job == "rogue")):
            if (attacker.level >= 3):
                chance = random.randint(0 + attacker.stats["luck"], 2 + attacker.stats["agility"])
                if chance in range(1 + npc.level*2 - attacker.level, 2 + attacker.stats["agility"]):
                    print()
                    print('! Double Strike !')
                    print()
                    attWeaponV += attacker.stats['agility'] * 2
            else:
                attWeaponV += attacker.stats['agility']

        if ((attWeapon.kind == "sword") and (attacker.job == "warrior")):
            if (attacker.level >= 3):
                chance = random.randint(0 + attacker.stats["luck"], 2 + attacker.stats["strength"])
                if chance in range(1 + npc.level*2 - attacker.level, 2 + attacker.stats["strength"]):
                    print()
                    print('! Heavy Strike !')
                    print()
                    attWeaponV += attacker.stats['strength'] * 2
            else:
                attWeaponV += attacker.stats['strength']

        ranDamage = random.randint(0 + attacker.stats["luck"], 51 + attacker.stats["luck"])
        ranDamage += attacker.stats["strength"]
    if type(defender) == character.Character:
        if defArmor.health == 0:
            print("Your armor is broken and fails to protect you.")
        if defShield.health == 0:
            print("Your shield is broken and fails to protect you.")
    # General calcs
    if defArmor.health > 0:
        defArmor.health -= 1
    elif defArmor.health == 0:
        defArmorV = 0
    if defShield.health > 0:
        defShield.health -= 1
    elif defShield.health == 0:
        defShieldV = 0

    Damage = ranDamage * attWeaponV - defArmorV - defShieldV
    if Damage < 0:
        Damage = 0

    oldHP = defender.health
    defender.health -= Damage
    print(attacker.name + " hit " + defender.name + " for " + str(Damage) + " damage. \n")

    if type(attacker) == npc.Mob and defender.health > 0 :
        if ((Damage *100)/oldHP) > 80:
            print("Dang!! That bastard almost killed you! Consider retreat weakling.")
        if ((Damage *100)/oldHP) <= 80 and ((Damage *100)/oldHP) > 50:
            print("Oh man, that was a hard hit. One more like this and you kick the bucket.")
        if ((Damage *100)/oldHP) <= 50 and ((Damage *100)/oldHP) > 30:
            print("Outch!! A big scratch for a big boy")
        if ((Damage *100)/oldHP) <= 30 and ((Damage *100)/oldHP) > 10:
            print("You're bleeding here and there, but nothing that could stop a proud "+defender.race+".")
        if ((Damage *100)/oldHP) <= 10:
            print("You didn't even flinch. Your enemy looks at you in shock. Kill that impotent whim.")

    return Damage
Exemple #5
0
def fight(char, npc):
    draw(npc)
    damageToll = 0
    while True:
        print()
        action = input("\033[31mo\033[33m-\033[90m(\033[37m==> ")
        print()
        if action in ["hit", "slash", "lunge", "stab"]:
            if item.loadItem(char.onPerson["weapon"], "wpn").health > 0:
                damageToll += hit(char, npc)
                time.sleep(1)
                if npc.health <= 0:
                    char.exp += npc.level * 50
                    levelBefore = char.level
                    character.checkLevel(char)
                    print('\033[08m')
                    os.system("clear")
                    print('\033[0m')
                    print()
                    print("You are victorious!")
                    print()
                    drawDead(npc)
                    print("Gained " + str(npc.level * 50) + " EXP.")
                    if char.level > levelBefore:
                        time.sleep(1)
                        job.jobLevelUp(char)
                    os.system("rm ../data/npcs/mob_" + npc.name + ".txt")
                    del npc
                    return "mob"
            else:
                print("Your weapon is broken and useless. You desperately try to punch a better equipped opponent, but fail miserably.")

        elif action in ["flee", "retreat", "run", "turn tail"]:
            chance = random.randint(0, 2 + char.stats["luck"])
            if chance == 0:
                print("You manage to flee the scene and sit in a corner, shivering like the coward that you are.")
                char.move(random.choice(room.loadRoom('room' + str(char.location[0]) + '_' + str(char.location[1])).possibleDirections.values()))
                return "none"
            else:
                print("The enemy hit you back into the room.")

        elif action in ["dodge", "roll", "parry", "evade"]:
            if char.job == 'rogue' and char.level >= 2: #(@lvl 2, rogue gains passive evasion buff)
                chance = random.randint(0, 2 + char.stats["agility"])
                if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                    print("You evade the enemy's attack.")
                    continue
                else:
                    chance = random.randint(0, 2 + char.stats["agility"])
                    if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                        print("You evade the enemy's attack.")
                        continue
                    else:
                        print("Bad luck. The enemy hit you anyways.")
            elif not char.job == 'rogue':
                chance = random.randint(0, 2 + char.stats["agility"])
                if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                    print("You evade the enemy's attack.")
                    continue
                else:
                    print("Bad luck. The enemy hit you anyways.")
        else:
            print("That is not an option...")
            continue
        hit(npc, char)
        if char.health <= 0:
            print("You have died.")
            char.location = [0,0]
            char.health = 500
            print()
            print("You have returned to the start-room.")
            print("".center(os.get_terminal_size().columns, "-"))
            return "char"
Exemple #6
0
def loadVillain(name, level='auto'):
	fileName = 'villains/%s.bbb'%name.lower().strip()
	try:
		with open(fileName,'r') as villainData:
			villain = character.Villain()
			fullData = villainData.read().splitlines()
			abilities = []
			if level != 'auto':
				exp = (level-1)**2*1000
			for data in fullData:
				try:
					key, value = data.split(' - ', 1)[0].strip().upper(), data.split(' - ', 1)[1].strip()
				except:
					key, value ='',''
				if key == 'TYPE':
					villain.type = value[0].upper() + value[1:].lower()
				elif key == 'RANDOMNAMES':
					villain.randomNames = [n.strip() for n in value.split(',')]
				elif key == 'TARGET':
					villain.combatRules['target'] = value.lower()
				elif key == 'PRIORITY':
					villain.combatRules['priority'] = value.lower()
				elif key == 'ALIGNMENT':
					villain.combatRules['alignment'] = value.lower()
				elif key == 'LEVEL' and level == 'auto':
					lv = int(value)
					exp = (lv-1)**2*1000
				elif key == 'BTH':
					villain.baseBTH = int(value)
				elif key == 'HB':
					villain.baseHB = int(value)
				elif key == 'SKR':
					villain.baseSKR = float(value)
				elif key == 'VOP':
					villain.baseVOP = int(value)
				elif key == 'RTM':
					villain.baseRTM = int(value)
				elif key == 'STA':
					villain.baseSTA = int(value)
				elif key == 'ABILITY':
					ab = value.split()[0]
					lv = value.split()[1]
					abilities.append((ab,lv))
				elif key == 'BONUS':
					villain.levelBonus.append(value)
				elif key == 'IMAGE':
					pic = value.strip('Q')
					villain.picture.append(pic)
				elif key == 'DESCRIPTION':
					villain.description.append(value)
				elif key == 'INVENTORY':
					obj = item.loadItem(value)
					villain.addInventory(obj)
				elif key == 'HASPICTURE':
					villain.hasPicture = True
			
			villain.addExperience(exp) 
			if villain.hasPicture:
				villain.initializePicture()
			for obj in villain.inventory:
				villain.equip(obj)
			for ab,lv in abilities:
				if villain.level >= int(lv):
					villain.abilities[ab] = getattr(ability, ab)(villain)		
			villain.restore()
		return villain
	except:
		return False