コード例 #1
0
def attack_handler(update, context):
    username = update.message.from_user.first_name
    response = ""
    if len(context.args) == 0 or not context.args[0].isdigit():
        response = "attack usage: /a <skill>\r\n\t\twhere <skill> is your weapon skill + any combat modifiers"
    else:
        response = attack(int(context.args[0]), username)
    context.bot.send_message(chat_id=update.effective_chat.id, text=response)
コード例 #2
0
ファイル: humans.py プロジェクト: shane-kerr/cota
    def take_turn(self, m, actors_by_pos, histories):
        # use take_turn() from the super class
        Personality.take_turn(self, m, actors_by_pos, histories)

        # attack anyone next to me (TODO: remember and chase)
        # XXX

        # warn if anyone gets too close
        my_x = self.human_item.pos[0]
        my_y = self.human_item.pos[1]
        view = m.view(my_x, my_y, 17, 17, 8)

        # attack anyone standing next to the observer
        for x in range(7, 10):
            for y in range(7, 10):
                if (x == 8) and (y == 8):
                    continue
                if view[x][y].view()[0] in ('p', '@'):
                    for history in histories:
                        history.add('%s says, I warned you... HAAAA!' %
                                    self.human_item.name)
                    victim = actors_by_pos[(x+my_x-8, y+my_y-8)]
                    # XXX: single history...
                    combat.attack(self.human_info, self.human_item.name, 
                                  self.human_info.equip["right hand"],
                                  victim.human_info, victim.human_item.name,
                                  histories[0])
                    return

        # attack anyone standing next to the observer
        for x in range(6, 11):
            for y in range(6, 11):
                if (x == 8) and (y == 8):
                    continue
                if view[x][y].view()[0] in ('p', '@'):
                    for history in histories:
                        history.add('%s says, "Don\'t get too close..."' %
                                    self.human_item.name)
コード例 #3
0
 def test_attack_subtracts_properly_with_health_remaining(self):
     player = {"Name": "Vlad", "Health": 10}
     monster = {"Name": "Orc", "Health": 5}
     combat.attack(6, monster, player)
     self.assertEqual(4, player["Health"])
コード例 #4
0
 def test_attack_that_overkills(self):
     player = {"Name": "Vlad", "Health": 10}
     monster = {"Name": "Orc", "Health": 5}
     combat.attack(11, monster, player)
     self.assertEqual(0, player["Health"])
コード例 #5
0
def enemy(char, enemy):
    """
    Enemy Battle Menu, list is returned to minus off player's HP and show ratking defeated
    """
    defeat_ratking = False
    #Menu for combat
    combat_mode = True

    while combat_mode == True:  #Loop for combat menu
        user_hp = char.hp
        enemy.toString()
        print("(1) Attack (2) Run")
        choice = input("Enter Choice: ")  #Menu choice
        print(" ")
        if choice == "1":
            """
            Attack
            """
            if enemy.name == "Rat King":
                """
                Attacking Ratking
                """
                hit = combat.ratkingattack(char, enemy)  #damage to rat king
            else:
                """
                Attacking Rat
                """
                hit = combat.attack(char, enemy)  #damage to rat
            print("You deal {0} damage to the {1}".format(hit, enemy.name))
            """
             Hit = hp lost, enemy hp is subtracted
             """
            enemy.hp = enemy.hp - hit
            if enemy.hp <= 0:  #rat hp below zero
                """
                Rat dies, end
                """
                print("The {} is dead! You are victorious!".format(enemy.name))
                if enemy.name == "Rat King":
                    """
                    If Ratking defeated, override main menu with ending
                    """
                    defeat_ratking = True
                break  #End combat
                combat_mode = False
            else:
                """
                Enemy/Ratking attacks player
                """
                hit = combat.enemy_attack(char.defence)  #damage to player
                print("Ouch! The {0} hit you for {1} damage! \n".format(
                    enemy.name, hit))
                user_hp = user_hp - hit
                if user_hp < 0:
                    """
                    Sets hp to be zero
                    """
                    user_hp = 0  #player's HP cant go below 0
                print("You have {} HP left.".format(user_hp))
                if user_hp <= 0:
                    """
                    Ends combat as player dies
                    """
                    print("Your HP is zero. You are dead")
                    break  #End combat
                    combat_mode = False
        elif choice == "2":
            """
             Run, ends combat
             """
            print("You run and hide.")
            break  #End combat
            combat_mode = False
        else:
            print("Invalid Choice"
                  )  #Reloads loop, no effect on both enemy and player
        while combat_mode == False:
            return [user_hp, defeat_ratking]
コード例 #6
0
def player_move(player, ai):
    print("\n\n1. atak")
    if player.type == "mage":
        print("2. fireball")
        print("3. blizzard")

    elif player.type == "palladyn":
        print("2. lay on hands")
        print("3. smite")

    elif player.type == "warrior":
        print("2. shield slam")
        print("3. mortal strike")

    elif player.type == "rouge":
        print("2. smoke bomb")
        print("3. eviscerate")

    elif player.type == "warlock":
        print("2. drain soul")
        print("3. hellfire")

    elif player.type == "priest":
        print("2. bless")
        print("3. shadow word")

    elif player.type == "hunter":
        print("2. hunters mark")
        print("3. snipe")

    elif player.type == "dk":
        print("2. frost blade")
        print("3. corrupted blade")

    elif player.type == "shaman":
        print("2. healing ritual")
        print("3. hex")

    tmp = int(input("twój ruch: "))

    if tmp == 1:
        combat.attack(player, ai)

    else:

        if player.type == "mage":
            if tmp == 2:
                combat.fireball(player, ai)
            elif tmp == 3:
                combat.blizzard(player, ai)

        elif player.type == "palladyn":
            if tmp == 2:
                combat.lay_on_hands(player, player)
            elif tmp == 3:
                combat.smite(player, ai)

        elif player.type == "warrior":
            if tmp == 2:
                combat.shield_slam(player, ai)
            elif tmp == 3:
                combat.mortal_strike(player, ai)

        elif player.type == "rouge":
            if tmp == 2:
                combat.smoke_bomb(player, ai)
            elif tmp == 3:
                combat.eviscerate(player, ai)

        elif player.type == "warlock":
            if tmp == 2:
                combat.drain_soul(player, ai)
            elif tmp == 3:
                combat.hellfire(player, ai)

        elif player.type == "priest":
            if tmp == 2:
                combat.bless(player, player)
            elif tmp == 3:
                combat.shadow_word(player, ai)

        elif player.type == "hunter":
            if tmp == 2:
                combat.hunters_mark(player, ai)
            elif tmp == 3:
                combat.snipe(player, ai)

        elif player.type == "shaman":
            if tmp == 2:
                combat.healing_ritual(player, player)
            elif tmp == 3:                 \
                                combat.hex(player, ai)

        elif player.type == "dk":
            if tmp == 2:
                combat.frost_blade(player, ai)
            elif tmp == 3:
                combat.corrupted_blade(player, ai)
コード例 #7
0
def ai_move(ai, player):
    combat.attack(ai, player)
コード例 #8
0
def ai_move():
    ##status check
    if isinstance(ai,monster):
        combat.attack(ai,player)
コード例 #9
0
 def attack(self, target):
     attack_result = combat.attack(self, target)
     print(attack_result)
     target.HP -= attack_result.damage
     self.hunger += 1
コード例 #10
0
ファイル: training.py プロジェクト: shane-kerr/cota
def school(ui, backgrounds, skill_list, pc):
    bg_by_name = { }
    for bg in backgrounds:
        bg_by_name[bg.name] = bg

    ui.clear()
    stuff = items.ItemCollection(items.ItemDefinitions(skill_list))
    m = grid.Map(80, 24, stuff)
    apply_school_map(m, stuff)
    mm = grid.MapMemory(m)


    actors_by_pos = { }

    # add our boss
    npc_body = stuff.create_item('p', (textui.RED, textui.BLACK, textui.NORMAL),
                                 transparent=True, name="Iudictus",
                                 blocking=False)
    npc_stats = humans.Human()
    npc_stats.STR = 14
    npc_stats.CON = 15
    npc_stats.DEX = 14
    npc_stats.SIZ = 15
    npc_stats.compute()
    npc_stats.set_default_skills(bg_by_name["Legionary"], skill_list)
    npc_stats.skill_levels["Dodge"] = 100
    npc_stats.skill_levels["Sword - Short"] = 140
    gladius = stuff.create_item_from_def("gladius")
    npc_stats.equip_item(npc_stats.get_item(gladius))
    tunic = stuff.create_item_from_def("tunic")
    npc_stats.equip_item(npc_stats.get_item(tunic))
    boots = stuff.create_item_from_def("boots")
    npc_stats.equip_item(npc_stats.get_item(boots))
    npc = humans.Observer(npc_stats, npc_body)
    m.drop_item_at(npc.human_item, 8, 12)
    actors_by_pos[(8, 12)] = npc

    # add some Christians
    npc_x = 4
    npc_y = 3
    for name in [ "Matthew", "Mark", ]:
        npc_body = stuff.create_item('p', NPC_COLOR, transparent=True,
                                     name="Christian", blocking=False)
        npc_stats = humans.Human()
        npc_stats.set_default_skills(bg_by_name["Christian"], skill_list)
        toga = stuff.create_item_from_def("toga")
        npc_stats.equip_item(npc_stats.get_item(toga))
        sandals = stuff.create_item_from_def("sandals")
        npc_stats.equip_item(npc_stats.get_item(sandals))
        npc = humans.Martyr(npc_stats, npc_body)
        m.drop_item_at(npc.human_item, npc_x, npc_y)
        actors_by_pos[(npc_x, npc_y)] = npc
        npc_x = npc_x + 2
        npc_y = npc_y + 2

    # add our player
    player = stuff.create_item('@', PLAYER_COLOR, True, blocking=False,
                               name="you")
    player_x = 8
    player_y = 5
    pc.equip_item(pc.get_item(stuff.create_item_from_def("toga")))
    pc.equip_item(pc.get_item(stuff.create_item_from_def("sandals")))
    things_here = m.items_at(player_x, player_y)
    m.drop_item_at(player, player_x, player_y)
    player_actor = humans.Personality(pc, player)
    actors_by_pos[(player_x, player_y)] = player_actor

    (width, height) = ui.get_screen_size()
    player_history = history.history(width)

    # sprinkle some weapons around
    for club_loc in [(4,6), (5,7), (7,6), (8,6), (10,8)]:
        club = stuff.create_item_from_def("club")
        m.drop_item_at(club, club_loc[0], club_loc[1])
    for shield_loc in [(2,6), (3,6), (5,6), (6, 7), (9, 8)]:
        shield = stuff.create_item_from_def("medium shield")
        m.drop_item_at(shield, shield_loc[0], shield_loc[1])

    inv_ofs = 0

    while True:
        player_state = pc.check_health()
        if player_state != "okay":
            return player_state

        textui.wait_for_minimum_size(ui, 80, 24)
        (width, height) = ui.get_screen_size()
        h_size = (width - 40) | 1
        h_half = h_size // 2
        v_size = ((height * 2) // 3) | 1
        v_half = v_size // 2
        view = mm.look_at(player_x - h_half, player_y - v_half,
                          player_x + h_half, player_y + v_half, 8)
        display.main_display(ui, width, height, view, pc, player_history)

        # figure out what item we would get if we picked something up
        item_to_get = None
        for n in range(len(things_here)-2, -1, -1):
            if things_here[n].movable:
                item_to_get = n

        disabled = [ ]
        if item_to_get is None:
            disabled.append("g")
        if not m.can_move_onto(player_x, player_y-1):
            disabled.append("Up")
        if not m.can_move_onto(player_x, player_y+1):
            disabled.append("Down")
        if not m.can_move_onto(player_x-1, player_y):
            disabled.append("Left")
        if not m.can_move_onto(player_x+1, player_y):
            disabled.append("Right")
        attack = [ ]
        for (actor_x, actor_y) in actors_by_pos.keys():
            if (actor_x == player_x-1) and (actor_y == player_y):
                attack.append("Left")
            elif (actor_x == player_x+1) and (actor_y == player_y):
                attack.append("Right")
            elif (actor_x == player_x) and (actor_y == player_y-1):
                attack.append("Up")
            elif (actor_x == player_x) and (actor_y == player_y+1):
                attack.append("Down")
        display.show_keys_help(ui, width, height,
                  ("Esc", "Up", "Down", "Left", "Right", "g", "i"),
                  disabled, attack)

        event = ui.get_input()
        if event is None: continue
        if event.event_type == 'resize':
            ui.clear()
            continue
        elif event.event_type == 'mouse':
            continue

        player_moved = False

        new_x = player_x
        new_y = player_y
        if event.event_type == 'keyboard':
            if event.key in keymap.keys_ul:
                new_x = player_x - 1
                new_y = player_y - 1
            elif event.key in keymap.keys_u:
                new_y = player_y - 1
            elif event.key in keymap.keys_ur:
                new_x = player_x + 1
                new_y = player_y - 1
            elif event.key in keymap.keys_l:
                new_x = player_x - 1
            elif event.key in keymap.keys_r:
                new_x = player_x + 1
            elif event.key in keymap.keys_dl:
                new_x = player_x - 1
                new_y = player_y + 1
            elif event.key in keymap.keys_d:
                new_y = player_y + 1
            elif event.key in keymap.keys_dr:
                new_x = player_x + 1
                new_y = player_y + 1
            elif event.key == ord('g'):
                if len(things_here) > 1:
                    # TODO: need a menu of stuff to pick up
                    if item_to_get is not None:
                        if pc.get_item(things_here[item_to_get],
                                       player_history):
                            m.pickup_item(things_here[item_to_get])
                        player_moved = True
            elif event.key == ord('i'):
                [ inv_ofs, drops ] = inventory(ui, pc, inv_ofs, player_history)
                for item in drops:
                    m.drop_item_at(item, player_x, player_y)
                m.pickup_item(player)
                m.drop_item_at(player, player_x, player_y)
                ui.clear()
            elif event.key == textui.KEY_ESC:
                return

        # check for bump combat
        del actors_by_pos[(player_x, player_y)]
        if (new_x, new_y) in actors_by_pos:
            victim = actors_by_pos[(new_x, new_y)]
            victim_start_state = victim.human_info.check_health()
            combat.attack(pc, "You", pc.equip["right hand"], 
                          victim.human_info, "the %s" % victim.human_item.name,
                          player_history)
            victim_end_state = victim.human_info.check_health()
            if victim_start_state == "okay":
                if victim_end_state == "dead":
                    player_history.add("The %s dies" % victim.human_item.name)
                    die_at(victim, m, new_x, new_y, player_history)
                    del actors_by_pos[(new_x, new_y)]
                elif victim_end_state == "unconscious":
                    player_history.add("The %s loses consciousness" % 
                                       victim.human_item.name)
            elif victim_start_state == "unconscious":
                if victim_end_state == "dead":
                    player_history.add("The %s dies" % victim.human_item.name)
                    die_at(victim, m, new_x, new_y, player_history)
                    del actors_by_pos[(new_x, new_y)]

            # we don't actually want to move, but we do use a turn
            new_x = player_x
            new_y = player_y
            player_moved = True
        # otherwise move
        elif m.can_move_onto(new_x, new_y):
            m.pickup_item(player)
            player_x, player_y = new_x, new_y
            things_here = m.items_at(player_x, player_y)
            if things_here:
                thing_str = map(lambda t: "a " + t.name.lower(), things_here)
                player_history.add("You see " + human_list(list(thing_str)) + 
                                   " here")
            m.drop_item_at(player, player_x, player_y)
            player_moved = True
        actors_by_pos[(player_x, player_y)] = player_actor

        # if the player moved, the non-players can move too
        if player_moved:
            player.can_parry = True
            player.can_block = True
            player.can_dodge = True
            for actor in actors_by_pos.values():
                if actor is player_actor:
                    continue
                histories = [ ]
                if grid.item_in_view(actor.human_item, view):
                    # TODO: each actor also needs a history...
                    histories.append(player_history)
                if actor.human_info.check_health() == "okay":
                    actor.take_turn(m, actors_by_pos, histories)
コード例 #11
0
        if action == 'A':
            for item, _ in player.combat['Weapons'].items():
                options.append(item)
        else:
            options = player.spellsknown['1']
        print('Select an option')

        for option in options:
            print(option)
        selection = None
        while selection not in options:
            selection = input('?')
            sleep(1)
        if action == 'A':
            weapon = player.combat['Weapons'][selection]
            if combat.attack(weapon['Bonus'], monster.combat['Armor Class']):
                damage = roll(weapon['Damage'])
                print(
                    f'You have hit {monster.name} for {damage} points of damage.'
                )
                sleep(1)
            else:
                print('Miss')
        else:
            with sqlite3.connect('spells.db') as conn:
                conn.row_factory = dict_factory
                c = conn.cursor()
                c.execute(f'SELECT * FROM spells WHERE name="{selection}"')
                spell = c.fetchone()
            if player.currentslots[str(spell['level'])] == 0:
                print(f'You have no slots left of level {spell["level"]}.')
コード例 #12
0
	def attack(self, target):
		attack_result = combat.attack(self, target)
		print(attack_result)
		target.HP -= attack_result.damage
		self.hunger += 1