예제 #1
0
    async def add_quest(ctx, *args):
        name = find_in_message('name', args)
        description = find_in_message('description', args)
        rewards = find_in_message('rewards', args)
        _points = find_in_message('points', args)
        try:
            points = int(_points)
        except ValueError:
            await ctx.send(
                embed=discord.Embed(title="Invalid points value",
                                    description="Please only input numbers",
                                    colour=Dependencies.error_embed_colour))
            return
        if (not name) or (not rewards) or (not points):
            await ctx.send(embed=discord.Embed(
                title='Quest name/rewards/points is not given!',
                colour=Dependencies.error_embed_colour))
            return

        x = Quest.Quest(name, description if description else '', rewards,
                        points)
        await ctx.send(embed=discord.Embed(
            title="Quest added!", colour=Dependencies.success_embed_colour))
        await quest_list(ctx,
                         args=str(
                             int(
                                 math.ceil(
                                     len(Quest.Quest.quests) /
                                     Dependencies.quests_per_page))))
        Quest.Quest.save()
예제 #2
0
    def __init__(self, nosql_type, dbcursor):

        self.nosql_type = nosql_type
        self.dbcursor = dbcursor

        self.q = Quest.Quest(self.nosql_type, self.dbcursor)
        logging.debug("  ...instantiated Quest instance '" + str(self.q) + "'")
예제 #3
0
	def display_quest_log(self, player_id, loc_name, loc_type, building_types):
		quests = characterInst.fetch_quests(player_id)
		location_id = locationInst.get_location_id(loc_name)
		print("Choose Quest From Quest Log by ID: (Type 'C' to Cancel) \n")
		table = []

		for index, item in enumerate(quests):
			finished = ""
			if int(item['finished']) == 1:
				finished = "yes"

			table.append([(index+1), item['description'], item['reward'], finished])
		print (tabulate(table, headers=['ID',
										'Description',
										'Reward',
										'Completed?'
										]))

		choice = input("Select: ")
		try:
			choice_id = int(choice)
			if choice_id <= len(quests):
				quest_id = quests[choice_id - 1]['quest_id']
				questInst = Quest.Quest()
				questInst.initiate_quest(quest_id, player_id, location_id)
			else:
				print("Oops, that's not a quest you have!")
				self.display_quest_log(player_id, loc_name, loc_type, building_types)
		except ValueError:
			self.location_options(player_id, loc_name, loc_type, building_types)
예제 #4
0
 def __init__(self, center_x, center_y, animation_images, player_level=1):
     super().__init__(center_x, center_y, animation_images)
     self._max_health = random.randint(200, 460)
     self._max_mana = self._max_stamina = 1000000
     self._level = player_level
     self._current_health = self._max_health
     self._current_stamina = self._max_stamina
     self._current_mana = self._max_mana
     self._speed_changing = 1
     self._amount_damage = random.randint(40, 50)
     self._passive_regeneration = 1
     self._regeneration_interval = 0.5
     self._attack_interval = 500
     self._animation_interval = 150
     self._changing_direction_interval = 1000
     self._experience_for_killing = 100 * (
         10 + self._level - player_level) / (10 + player_level)
     self._is_angry = False
     self._name = 'Beatrice'
     self._is_has_quest = True
     self._vision_quest_mark = True
     if self._is_has_quest:
         self._quest = Quest.Quest(self._level)
         self._quest_mark = QuestMark.QuestMark(
             self._rect.centerx, self._rect.top - 10,
             'resources/images/quest/quest_mark.png')
    def initiate_combat(self, player_id, monster_id, loc_id, quest_id):

        preCombatCharacter = Character()
        preCombatCharAttrs = preCombatCharacter.get_currplayer_attr(player_id)
        preCombatMonster = Monster.Monster()
        preCombatMonsterAttrs = preCombatMonster.get_monst_attrs(monster_id)
        monstHealth = preCombatMonsterAttrs['hitpoints']
        charHealth = preCombatCharAttrs['curr_hp']
        print("\nYou have entered combat!\n")
        while (monstHealth > 0 and charHealth > 0):
            characterInst = Character()
            monstInst = Monster.Monster()
            charAttrs = {}
            monstAttrs = {}
            loot = {}
            charAttrs = characterInst.get_currplayer_attr(player_id)
            monstAttrs = monstInst.get_monst_attrs(monster_id)

            preDefend = charAttrs['curr_defense']
            defend = False
            print("\nMonst Hit Points: {}\n".format(monstAttrs['hitpoints']))
            """CHARACTER OPTIONS"""
            print("1. Attack\n" "2. Defend\n" "3. Use Item\n")
            choice = input("Select: ")
            if choice == "1":
                #attack
                hitChance = randint(0, 10)
                #decide if player attacks or misses
                if (charAttrs['character_level'] < 5):
                    if (hitChance > 3):
                        hit = True
                    else:
                        hit = False
                else:
                    if (hitChance > 2):
                        hit = True
                    else:
                        hit = False

                #do a level comparison to decide a modifier
                diff = charAttrs['curr_attack'] - monstAttrs['defense']
                if (diff > 3):
                    #level check
                    levelDiff = charAttrs['character_level'] - monstAttrs[
                        'challenge_level']
                    if (levelDiff == 0):
                        mult = 1
                    elif (levelDiff < 0):
                        mult = .75
                    elif (levelDiff > 0):
                        mult = 1.25
                    totalDamage = charAttrs['curr_attack'] * mult
                else:
                    totalDamage = randint(1, 4)

                #There's a hit
                if hit == True:
                    print(
                        "\nThat's a hit for {} damage!\n".format(totalDamage))
                    oldHitP = monstAttrs['hitpoints']

                    if (oldHitP - totalDamage) < 0:
                        newHitP = 0
                    else:
                        newHitP = oldHitP - totalDamage

                    print("\nThe monster is down to {} hitpoints!\n".format(
                        newHitP))

                    if newHitP == 0:
                        print("\nYou've killed the monster!\n")

                    monstHealth = newHitP
                    self.connection.cursor.execute("""UPDATE Monster
                                                    SET hitpoints={}
                                                    WHERE monster_id={}""".
                                                   format(newHitP, monster_id))
                    self.connection.conn.commit()
                else:
                    print("\nYou've missed!\n")

            elif choice == "2":
                #defend
                defend = True
                curr_def = charAttrs['curr_defense'] + 5
                self.connection.cursor.execute("""UPDATE Test.Character 
                            SET curr_defense='{}' 
                            WHERE player_id ='{}'""".format(
                    curr_def, player_id))
                self.connection.conn.commit()
                print("Defense increased to {}".format(curr_def))

            elif choice == "3":
                loot = {}
                loot = characterInst.get_currplayer_loot(player_id)
                print("Select Battle Item From Inventory: \n")
                i = 0
                table = []
                if (len(loot) == 0):
                    print("No items!\n")
                else:
                    for item in loot:
                        table.append([
                            item['loot_name'], item['health_modifier'],
                            item['defense_modifier'], item['attack_modifier'],
                            item['quantity']
                        ])

                    print(
                        tabulate(table,
                                 headers=[
                                     'Name', 'Health Modifier',
                                     'Defense Modifier', 'Attack Modifier',
                                     'Quantity'
                                 ],
                                 showindex='always'))

                    choice = input("Select: ")
                    choiceInt = int(choice)
                    itemChoice = loot[choiceInt]

                    #decrement quantity of item
                    newQuant = itemChoice['quantity'] - 1
                    if newQuant == 0:
                        #drop item from table
                        self.connection.cursor.execute(
                            """DELETE FROM Character_loot
                                    WHERE Character_loot.loot_id IN
                                    (SELECT loot_id FROM Loot WHERE loot_name='{}')
                                    AND Character_loot.player_id = {}""".
                            format(itemChoice['loot_name'], player_id))
                        self.connection.conn.commit
                    else:
                        self.connection.cursor.execute("""
                            UPDATE Character_loot
                            SET quantity={}
                            WHERE Character_loot.loot_id IN
                                  (SELECT loot_id FROM Loot WHERE loot_name='{}')
                            AND Character_loot.player_id = {}""".format(
                            newQuant, itemChoice['loot_name'], player_id))
                        self.connection.conn.commit()

                    print("\nYou chose: {}\n".format(itemChoice['loot_name']))
                    #defense modifier
                    if (itemChoice['defense_modifier'] > 0):
                        increment = charAttrs['base_defense'] * itemChoice[
                            'defense_modifier']
                        curr_def = charAttrs['curr_defense'] + increment
                        self.connection.cursor.execute(
                            """UPDATE Test.Character 
                                SET curr_defense='{}' 
                                WHERE player_id ='{}'""".format(
                                curr_def, player_id))
                        self.connection.conn.commit()
                        print("Defense increased by {}!".format(increment))
                        print("Defense now at {}".format(curr_def))
                    #health modifier
                    elif (itemChoice['health_modifier'] > 0):
                        increment = charAttrs['max_hp'] * itemChoice[
                            'health_modifier']
                        if (charAttrs['curr_hp'] +
                                increment) >= charAttrs['max_hp']:
                            curr_health = charAttrs['max_hp']
                        else:
                            curr_health = charAttrs['curr_hp'] + increment
                        #run query
                        self.connection.cursor.execute(
                            """UPDATE Test.Character 
                                SET curr_hp='{}' 
                                WHERE player_id ='{}'""".format(
                                curr_health, player_id))
                        self.connection.conn.commit()

                        print("Health increased by {}!\n".format(increment))
                        print("Health now at {}\n".format(curr_health))
                    #attack modifier
                    elif (itemChoice['attack_modifier'] > 0):
                        increment = charAttrs['base_damage'] * itemChoice[
                            'attack_modifier']
                        curr_attack = charAttrs['curr_attack'] + increment
                        #run query
                        self.connection.cursor.execute(
                            """UPDATE Test.Character 
                                SET curr_attack='{}' 
                                WHERE player_id ='{}'""".format(
                                curr_attack, player_id))
                        self.connection.conn.commit()
                        print("Attack increased by {}!".format(increment))
                        print("Attack now at {}\n".format(curr_attack))

            #get the attributes again for monster attack, they probably have changed
            afterAttackChar = Character()
            charAttrs = afterAttackChar.get_currplayer_attr(player_id)
            monstAttrs = monstInst.get_monst_attrs(monster_id)

            if (monstHealth != 0):
                """MONSTER ATTACK"""
                hitChance = randint(0, 10)
                #decide if monster attacks or misses
                if (monstAttrs['challenge_level'] < 5):
                    if (hitChance > 3):
                        hit = True
                    else:
                        hit = False
                else:
                    if (hitChance > 2):
                        hit = True
                    else:
                        hit = False

                #do a level comparison to decide a modifier
                diff = monstAttrs['damage'] - charAttrs['curr_defense']
                if (diff > 3):
                    #level check
                    levelDiff = monstAttrs['challenge_level'] - charAttrs[
                        'character_level']
                    if (levelDiff == 0):
                        mult = 1
                    elif (levelDiff < 0):
                        mult = .75
                    elif (levelDiff > 0):
                        mult = 1.25
                    totalDamage = monstAttrs['damage'] * mult
                else:
                    totalDamage = randint(1, 4)

                #There's a hit
                if hit == True:
                    print("\nMonster has hit you for {} damage!\n".format(
                        totalDamage))
                    oldHealth = charAttrs['curr_hp']

                    if (oldHealth - totalDamage) < 0:
                        newHealth = 0
                    else:
                        newHealth = oldHealth - totalDamage

                    print("\nYou are down to {} HP!\n".format(newHealth))

                    if newHealth == 0:
                        print("\nYou've been killed!\n")
                        quit()

                    charHealth = newHealth
                    self.connection.cursor.execute("""UPDATE Test.Character
                                                    SET curr_hp={}
                                                    WHERE player_id={}""".
                                                   format(
                                                       newHealth, player_id))
                    self.connection.conn.commit()
                else:
                    print("\nThe monster missed!\n")
            else:
                pass
                #give reward
                # lootInst = Loot()
                # reward = {}
                # reward = lootInst.determine_reward(player_id, "Monster drop")
                # for key in reward:
                #     self.connection.cursor.execute("""SELECT loot_name FROM Loot WHERE loot_id = {}"""
                #                             .format(key))
                #     loot_name = self.connection.cursor.fetchall()[0][0]
                #     print("\nYou've received a {}. {} of them!".format(loot_name, reward[key]))
                #     lootInst.add_to_inventory(player_id, key, reward[key])

            if defend:
                self.connection.cursor.execute("""UPDATE Test.Character 
                            SET curr_defense='{}' 
                            WHERE player_id ='{}'""".format(
                    preDefend, player_id))
                self.connection.conn.commit()

        #set player/monster attributes to pre-combat attrs
        self.connection.cursor.execute(
            """UPDATE Test.Character SET curr_defense='{}', curr_attack='{}' 
                        WHERE player_id ='{}'""".format(
                preCombatCharAttrs['curr_defense'],
                preCombatCharAttrs['curr_attack'], player_id))
        self.connection.conn.commit()

        self.connection.cursor.execute(
            """UPDATE Test.Monster SET defense='{}', damage='{}', hitpoints='{}' 
                        WHERE monster_id ='{}'""".format(
                preCombatMonsterAttrs['defense'],
                preCombatMonsterAttrs['damage'],
                preCombatMonsterAttrs['hitpoints'], monster_id))

        self.connection.conn.commit()

        questInst = Quest.Quest()
        questType = questInst.get_quest_type(quest_id)
        if questType == 'K':
            print("You've killed the monster!\n")
        elif questType == 'R':
            print("You notice a person in the darkness...\n")
            print(
                "\"My God! I never thought I'd get out of here. Thank you, hero!\"\n"
            )
        elif questType == 'F':
            print("You notice a shiny object on the ground...\n")
            print("It's a goblet! Must be what that person was looking for\n")

        questInst.finish_quest(quest_id, player_id)
        print(
            "You'll be transported back to the town where you received the quest\n"
        )
        locInst = Location()
        optionsInst = Options.Options()
        name = preCombatCharacter.get_char_name(player_id)
        location = locInst.get_location(name)
        optionsInst.location_options(player_id, location['city_name'],
                                     location['town_description'],
                                     location['buildings'])
예제 #6
0
 def __addQuest(self, quest, tables, areaTrigger):
     """only used by constructor"""
     newQuest = Quest(quest, tables, areaTrigger)
     self.qList[newQuest.id] = newQuest
예제 #7
0
# Инициация локаций
armor_shop = Location('Лавка продавца брони', player, armor_merchant)
street = Location('Улица', player, weapon_merchant, bandit, {armor_shop}, {'money': 1})
armor_shop.where_to_go = {street}
tavern = Location('Таверна', player, boozy_hacksmith, where_to_go = {street}, is_inn = 1)
forge = Location('Кузница', player, where_to_go = {street})
street.where_to_go.add(tavern)
street.where_to_go.add(forge)

location = street

# Инициация предметов
small_helmet = Armor('Маленький шлем', 1, 500, 'head', 0.5)
mail_shirt = Armor('Кольчуга', 7, 2000, 'body', 2)
armor_merchant.goods = {small_helmet, mail_shirt}
##    armor_merchant.goods.add(small_helmet)
##    armor_merchant.goods.add(mail_shirt)
jacket = Armor('Куртка', 1, 100, 'body', 0.3)
pants = Armor('Штаны', 0.5, 50, 'legs', 0)
old_medallion = Item('Старый медальон', 0.1, 300)
##    player.add_item(small_helmet)
player.add_item(old_medallion)
player.slots['body'] = jacket
player.slots['legs'] = pants

# Инициализация квестов
quest_list = []
quest1 = Quest('Найти Таверну', 'Должна же здесь где-то быть таверна',
     0, 'go_to_tavern')
quest_list.append(quest1)