Ejemplo n.º 1
0
def encounter(SAVE_DATA):
    ''' Randomly find gold, potions, and scrolls in this encounter'''
    clear_screen()
    name = ("bandit", "adventurer", "mercenary")
    name_plural = ("bandits", "adventurers", "mercenaries")
    print("You stumbled upon an abandoned "
          + name[random.randrange(0, len(name))]+" Camp")
    print("You look around and found some items the "
          + name_plural[random.randrange(0, len(name_plural))]+" left behind.")
    gold = random.randrange(SAVE_DATA["player_data"]["level"],
                            SAVE_DATA["player_data"]["level"] * 3) + 10
    potions = 0
    scrolls = 0
    for _ in range(3):
        if rng(35):
            potions += 1
    if rng(25):
        scrolls += 1
    print("\n\tYou picked up:")
    print("\t\t"+str(gold)+" gold")
    SAVE_DATA["player_data"]["item_data"]["gold"] += gold
    if potions != 0:
        print("\t\t"+str(potions)+" recovery potions")
        SAVE_DATA["player_data"]["item_data"]["potions"] += potions
    if scrolls != 0:
        print("\t\t"+str(scrolls)+" resurection scrolls")
        SAVE_DATA["player_data"]["item_data"]["scrolls"] += scrolls
    SAVE_DATA = gain_exp(3, SAVE_DATA)
    input("Press any key to continue")
    clear_screen()
    return SAVE_DATA
Ejemplo n.º 2
0
def new_rarity(common=80, uncommon=15, rare=5):
    '''Returns a rarity value based off the chances. Default to 80:15:5'''
    if rng(common):
        rarity = "common"
    elif rng(uncommon, (uncommon + rare)):
        rarity = "uncommon"
    else:
        rarity = "rare"
    return rarity
Ejemplo n.º 3
0
def if_hit(dexterity):
    '''calculate if the hit succeeded based on dexterity
    0 dexterity provides 80% accuracy
    with diminishing returns nearing 100% hit rate
    * returns boolean'''
    hit_rate =  round(0.2 * dexterity/(dexterity + 100), ) * 100 + 80
    return rng(hit_rate)
Ejemplo n.º 4
0
def adventure(SAVE_DATA):
    '''chooses an encounter based on rng'''
    if rng(80):
        SAVE_DATA = battle(SAVE_DATA)
    else:
        SAVE_DATA = encounter(SAVE_DATA)
    SAVE_DATA["shop_data"]["new_items"] = True
    return SAVE_DATA
Ejemplo n.º 5
0
def generate_enemies(SAVE_DATA, boss = False):
    '''generate a random set of enemies to fight'''
    # Generate number of enemies(1:60%, 2:30%, 3:10%)
    # two enemies only possible after player lvl 5
    # three enemies only possible after player lvl 10
    ENEMY_DATA = {}
    enemies = ["enemy1"]
    if SAVE_DATA["player_data"]["level"] > 5:
        if rng(10):
            enemies.append("enemy2")
            if SAVE_DATA["player_data"]["level"] > 10:
                enemies.append("enemy3")
        elif rng(30):
            enemies.append("enemy2")
        if rng(5):
            boss = True
            ENEMY_DATA["enemy1"]["boss"] = "Y"
    for x in enemies:
        # Generate a set of equipment for each enemy
        ENEMY_DATA[x] = {}
        if boss:
            ENEMY_DATA["enemy1"]["boss"] = "Y"
            ENEMY_DATA[x]["level"] =  SAVE_DATA["player_data"]["level"] + random.randint(3, 5)
            if ENEMY_DATA[x]["level"] <= 1:
                ENEMY_DATA[x]["level"] = 1
            ENEMY_DATA[x]["weapon"] = new_weapon(0, 100, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["armor"] = new_armor(0, 100, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["ring"] = new_ring(0, 100, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["max_hp"] = round(new_max_hp(ENEMY_DATA[x]["level"]) * 1.15)
        else:
            ENEMY_DATA["enemy1"]["boss"] = "N"
            ENEMY_DATA[x]["level"] = SAVE_DATA["player_data"]["level"] + random.randint(-2, 2)
            if ENEMY_DATA[x]["level"] <= 1:
                ENEMY_DATA[x]["level"] = 1
            ENEMY_DATA[x]["weapon"] = new_weapon(100, 0, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["armor"] = new_armor(100, 0, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["ring"] = new_ring(100, 0, 0, ENEMY_DATA[x]["level"])
            ENEMY_DATA[x]["max_hp"] = round(new_max_hp(ENEMY_DATA[x]["level"]) * 0.5)
        ENEMY_DATA[x]["hp"] = ENEMY_DATA[x]["max_hp"]
        ENEMY_DATA[x]["name"] = new_enemy_name(ENEMY_DATA[x], boss)
        ENEMY_DATA[x]["dexterity"] = 80 + ENEMY_DATA[x]["armor"]["dexterity"] + \
                                     ENEMY_DATA[x]["ring"]["dexterity"]                        
        boss = False
    return ENEMY_DATA
Ejemplo n.º 6
0
def calculate_crit(dexterity):
    '''calculate if the hit is a critical strike
    each 100% critical strike gives 25% additional damage
    returns crit_multiplier'''
    crit = rng(dexterity % 100)
    if crit:
        crit_multiplier = 1 + ((math.floor(dexterity/100)+1) * 0.25)
    else:
        crit_multiplier = 1 + (math.floor(dexterity/100) * 0.25)
    return crit_multiplier
Ejemplo n.º 7
0
def new_armor(common=80, uncommon=15, rare=5, level=1):
    '''Generates a new armor based on the player's level'''
    armor_rarity = new_rarity(common, uncommon, rare)
    armor_type = new_armor_type()
    armor_name = new_armor_name(armor_rarity, armor_type)
    # Generate Resistance values within a range.
    armor_resistance = int((15 + level * 0.5)
                           + (level * (random.randrange(-50, 50, 1)/1000)))
    # Generate the amount of additional stats
    if armor_rarity == "common":
        stat_amount = 1
    elif armor_rarity == "uncommon":
        stat_amount = random.randint(2, 3)
    elif armor_rarity == "rare":
        stat_amount = 4
    # Generate the stats
    bonus_health = 0
    bonus_energy = 0
    bonus_dexterity = 0
    for _ in range(stat_amount):
        if rng(1, 3):
            bonus_health = bonus_health + (int(math.sqrt(level)*5) + 10)
        elif rng(1, 2):
            bonus_energy = bonus_energy + (int(math.sqrt(level)*1.5) + 1)
        else:
            bonus_dexterity = bonus_dexterity + (int(math.sqrt(level)) + 5)
    # Calculate cost of armor
    armor_value = math.floor(level/10)*3 + 50 + random.randrange(-3, 3)
    # Packs the data into a dictionary to return
    armor_data = {
        "item": "armor",
        "level": level,
        "rarity": armor_rarity,
        "type": armor_type,
        "name": armor_name,
        "resistance": armor_resistance,
        "health": bonus_health,
        "energy": bonus_energy,
        "dexterity": bonus_dexterity,
        "value": armor_value
        }
    return armor_data
Ejemplo n.º 8
0
def new_ring(common=70, uncommon=20, rare=10, level=1):
    '''Generates a new ring based on the player's level'''
    ring_rarity = new_rarity(common, uncommon, rare)
    ring_name = new_ring_name(ring_rarity)
    # Generate Resistance values within a range.
    # Generate the amount of additional stats
    if ring_rarity == "common":
        stat_amount = 2
    elif ring_rarity == "uncommon":
        stat_amount = random.randint(3, 4)
    elif ring_rarity == "rare":
        stat_amount = random.randint(5, 6)
    # Generate the stats
    bonus_attack = 0
    bonus_health = 0
    bonus_energy = 0
    bonus_dexterity = 0
    for _ in range(stat_amount):
        if rng(1, 4):
            bonus_attack = bonus_attack + (int(math.sqrt(level)) + 2)
        elif rng(1, 3):
            bonus_health = bonus_health + (int(math.sqrt(level)*3) + 1)
        elif rng(1, 2):
            bonus_energy = bonus_energy + (int(math.sqrt(level)*1.5) + 1)
        else:
            bonus_dexterity = bonus_dexterity + (int(math.sqrt(level)) + 1)
    # Calculate cost of armor
    ring_value = math.floor(level/10)*3 + 50 + random.randrange(-3, 3)
    # Packs the data into a dictionary to return
    ring_data = {
        "item": "ring",
        "level": level,
        "rarity": ring_rarity,
        "name": ring_name,
        "health": bonus_health,
        "energy": bonus_energy,
        "dexterity": bonus_dexterity,
        "attack": bonus_attack,
        "value": ring_value
        }
    return ring_data
Ejemplo n.º 9
0
def new_shop_items(SAVE_DATA):
    '''Generate new items set of items to be sold in the shop'''
    lvl = SAVE_DATA["player_data"]["level"]
    if rng(25):
        SAVE_DATA["shop_data"]["item3"] = new_ring(100, 0, 0, lvl)
    elif rng(35, 75):
        SAVE_DATA["shop_data"]["item3"] = new_weapon(100, 0, 0, lvl)
    else:
        SAVE_DATA["shop_data"]["item3"] = new_armor(100, 0, 0, lvl)

    if rng(25):
        SAVE_DATA["shop_data"]["item4"] = new_ring(100, 0, 0, lvl)
    elif rng(35, 75):
        SAVE_DATA["shop_data"]["item4"] = new_weapon(100, 0, 0, lvl)
    else:
        SAVE_DATA["shop_data"]["item4"] = new_armor(100, 0, 0, lvl)

    if rng(25):
        SAVE_DATA["shop_data"]["item5"] = new_ring(100, 0, 0, lvl)
    elif rng(35, 75):
        SAVE_DATA["shop_data"]["item5"] = new_weapon(100, 0, 0, lvl)
    else:
        SAVE_DATA["shop_data"]["item5"] = new_armor(100, 0, 0, lvl)
    # Turns new_items flag off
    SAVE_DATA["shop_data"]["new_items"] = False
    return SAVE_DATA
Ejemplo n.º 10
0
def new_enemy_name(enemy_data, boss = False):
    '''Generate enemy name based off armour type and if boss'''
    name = ""
    # Jobs based off armor type
    if enemy_data["armor"]["type"] == "plate":
        if rng(1,2) == True:
            name += "Ogre"
        else:
            name += "Troll"
    elif enemy_data["armor"]["type"] == "leather":
        if rng(1,2) == True:
            name += "Goblin"
        else:
            name += "Bandit"
    elif enemy_data["armor"]["type"] == "chain":
        if rng(1,2) == True:
            name += "Gremlin"
        else:
            name += "Kobold"
    elif enemy_data["armor"]["type"] == "robe":
        if rng(1,2) == True:
            name += "Vampire"
        else:
            name += "Draconian"
    # Jobs based off weapon type and Boss
    if boss == True:
        name += " "+"Boss"
    else:
        if enemy_data["weapon"]["type"] == "slash":
            if rng(1,2) == True:
                name += " Scout"
            else:
                name += " Hunter"
        elif enemy_data["weapon"]["type"] == "impact":
            if rng(1,2) == True:
                name += " Brute"
            else:
                name += " Warrior"
        elif enemy_data["weapon"]["type"] == "magic":
            if rng(1,2) == True:
                name += " Sorcerer"
            else:
                name += " Mage"
        elif enemy_data["weapon"]["type"] == "spirit":
            if rng(1,2) == True:
                name += " Witch Doctor"
            else:
                name += " Shaman"
    return name
Ejemplo n.º 11
0
def victory(SAVE_DATA, ENEMY_DATA):
    '''calculates victory rewards
    * returns SAVE_DATA'''
    print("\n\t\tVICTORY!")
    input("\nPress Enter to continue")
    clear_screen()
    # gain exp based on enemy levels
    exp_gain = get_max_exp(ENEMY_DATA["enemy1"]["level"])
    try:
        exp_gain = get_max_exp(ENEMY_DATA["enemy2"]["level"])
        exp_gain = get_max_exp(ENEMY_DATA["enemy3"]["level"])
    except:
        pass
    exp_gain = round(exp_gain * 0.05)
    SAVE_DATA = gain_exp(exp_gain, SAVE_DATA)
    input("\n\tPress Enter to continue")
    clear_screen()
    # check if ability leveled up
    abilities = ["ability1","ability2"]
    for x in abilities:
        max_exp = (50 + (SAVE_DATA["player_data"]["ability_data"][x]["level"])*5)
        if SAVE_DATA["player_data"]["ability_data"][x]["experience"] > max_exp:
            SAVE_DATA["player_data"]["ability_data"][x]["experience"] -= max_exp
            # increase energy cost
            SAVE_DATA["player_data"]["ability_data"][x]["energy"] += 3 * SAVE_DATA["player_data"]["ability_data"][x]["level"]
            # increase level of ability
            SAVE_DATA["player_data"]["ability_data"][x]["level"] += 1
            print("Your "+SAVE_DATA["player_data"]["ability_data"][x]["name"]+" has leveled up.")
            input("\n\tPress Enter to continue")
    clear_screen()
    # gain gold based on player level and number of enemies
    gold_earned = random.randrange(exp_gain*15, exp_gain*50)
    SAVE_DATA["player_data"]["item_data"]["gold"] += gold_earned
    print("You have earned "+str(gold_earned)+" gold")
    input("\n\tPress Enter to continue")
    clear_screen()
    # gain item drop based on enemy level
    print("You have found")
    if rng(25):
        item_drop = new_ring(70, 20, 10, SAVE_DATA["player_data"]["level"])
        print_ring_info(item_drop)
        item_drop_type = "ring"
    elif rng(35, 75):
        item_drop = new_weapon(70, 20, 10, SAVE_DATA["player_data"]["level"])
        print_weapon_info(item_drop)
        item_drop_type = "weapon"
    else:
        item_drop = new_armor(70, 20, 10, SAVE_DATA["player_data"]["level"])
        print_armor_info(item_drop)
        item_drop_type = "armor"
    input("\n\tPress Enter to continue")
    clear_screen()
    # Check to see if player will keep the new item
    looping = True
    while looping:
        if item_drop_type == "ring":
            print("Currently equipped rings:\n1 = ")
            print_ring_info(SAVE_DATA["player_data"]["item_data"]["ring1"])
            print("2 = ")
            print_ring_info(SAVE_DATA["player_data"]["item_data"]["ring2"])
            print("New ring = ")
            print_ring_info(item_drop)
            command = input("Which Ring do you wish to replace? (Enter 'N' to sell the new ring instead)\n")
            clear_screen()
            if command == "1":
                SAVE_DATA = update_stats(SAVE_DATA, item_drop, "ring1")
                SAVE_DATA["player_data"]["item_data"]["ring1"] = item_drop
                looping = False
            elif command == "2":
                SAVE_DATA = update_stats(SAVE_DATA, item_drop, "ring2")
                SAVE_DATA["player_data"]["item_data"]["ring2"] = item_drop
                looping = False
        elif item_drop_type == "weapon":
            print("Currently equipped weapon:")
            print_weapon_info(SAVE_DATA["player_data"]["item_data"]["weapon"])
            print("Replace with this new weapon?")
            print_weapon_info(item_drop)
            command = input("\nY = Replace\nN = Sell\n")
            clear_screen()
            if command.lower() == "y":
                SAVE_DATA["player_data"]["item_data"]["weapon"] = item_drop
                looping = False
        elif item_drop_type == "armor":
            print("Currently equipped armor:")
            print_armor_info(SAVE_DATA["player_data"]["item_data"]["armor"])
            print("Replace with this new armor?")
            print_armor_info(item_drop)
            command = input("\nY = Replace\nN = Sell\n")
            clear_screen()
            if command.lower() == "y":
                SAVE_DATA["player_data"]["item_data"]["armor"] = item_drop  
                SAVE_DATA = update_stats(SAVE_DATA, item_drop, "armor")
                looping = False
        if command.lower() == "n":# Sell the item for gold
            print("You will sell the dropped item for "+str(item_drop["value"])+" gold")
            command = input("\nY = Confirm\n")
            if command.lower() == "y":
                SAVE_DATA["player_data"]["item_data"]["gold"] += item_drop["value"]
                looping = False
                clear_screen()
            else:
                continue
    # gain ability tome based on boss drops
    if ENEMY_DATA["enemy1"]["boss"] == "Y":
        SAVE_DATA = ability_tome(SAVE_DATA)
    return SAVE_DATA