Exemple #1
0
def request_pick_up():
    """Tell server to pick up an item at the player's feet."""
    items = []
    for item in CS.map.grid[CS.u.x][CS.u.y].items:
        items.append(item.oid)

    Network.request(',', (tuple(items), ))
Exemple #2
0
def request_pick_up():
    """Tell server to pick up an item at the player's feet."""
    items = []
    for item in CS.map.grid[CS.u.x][CS.u.y].items:
        items.append(item.oid)

    Network.request(',', (tuple(items),))
Exemple #3
0
 def move(self, dx, dy=None):
     """Move by (dx, dy) cells."""
     dx, dy = flatten_args(dx, dy)
     Network.request('m', (dx, dy))
Exemple #4
0
 def attack(self, target):
     """Attack a target oid."""
     Network.request('F', (target.oid,))
Exemple #5
0
def handle_events():
    """Handle input events."""
    for event in pygame.event.get():
        if event.type == pgl.QUIT:
            quit_game()
        elif event.type == pgl.KEYDOWN:
            CS.key = event
        elif event.type == pgl.KEYUP:
            CS.key = None
        elif event.type == pgl.MOUSEBUTTONDOWN:
            CS.button = event.button
        elif event.type == pgl.MOUSEBUTTONUP:
            CS.button = None
        elif event.type == pgl.MOUSEMOTION:
            pass
        elif event.type == pgl.VIDEORESIZE:
            gui.handle_resize(event.w, event.h)

        # Handle scrolling
        CS.x_scrollbar.handle_event(event)
        CS.y_scrollbar.handle_event(event)
        CS.log_scrollbar.handle_event(event)

    if CS.key:
        key_code, char, mod = CS.key.key, CS.key.unicode, CS.key.mod
        CS.key = None
    else:
        key_code, char, mod = None, None, None

    if CS.mode == cfg.ST_PLAYING:
        # Handle all keypresses
        if key_code:
            handled = False
            key_combo = ''

            if mod & pgl.KMOD_SHIFT:
                if char not in CS.pkeys[pgl.KMOD_NONE]:
                    key_combo = 'Shift + '

                if (key_code in CS.pkeys[pgl.KMOD_SHIFT] and
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].action):
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_CTRL:
                key_combo = 'Ctrl + '

                if (key_code in CS.pkeys[pgl.KMOD_CTRL] and
                    CS.pkeys[pgl.KMOD_CTRL][key_code].action):
                    CS.pkeys[pgl.KMOD_CTRL][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_ALT:
                key_combo = 'Alt + '

                if (key_code in CS.pkeys[pgl.KMOD_ALT] and
                    CS.pkeys[pgl.KMOD_ALT][key_code].action):
                    CS.pkeys[pgl.KMOD_ALT][key_code].perform_action()
                    handled = True

            if not handled:
                # First, look up by char.  If it's not found, then look up by
                # key_code.
                if (char in CS.pkeys[pgl.KMOD_NONE] and
                    CS.pkeys[pgl.KMOD_NONE][char].action):
                    CS.pkeys[pgl.KMOD_NONE][char].perform_action()
                    handled = True
                elif (key_code in CS.pkeys[pgl.KMOD_NONE] and
                      CS.pkeys[pgl.KMOD_NONE][key_code].action):
                    CS.pkeys[pgl.KMOD_NONE][key_code].perform_action()
                    handled = True

            if key_code not in CS.ignore_keys and handled is False:
                if char in CS.pkeys[pgl.KMOD_NONE]:
                    key_to_print = char
                else:
                    key_to_print = pygame.key.name(key_code)
                    client_message("Unknown command '{0}{1}'.".format(
                            key_combo, key_to_print))

    elif CS.mode == cfg.ST_MENU:
        if key_code:
            if len(char) == 1:
                index = ord(char) - ord('a')
                if index >= 0 and index < len(CS.menu_options):
                    if CS.menu == 'use':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('a', (item.oid,))

                    elif CS.menu == 'drop':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('d', (item.oid,))
                else:
                    CS.mode = cfg.ST_PLAYING  # Exit menu
            else:
                CS.mode = cfg.ST_PLAYING  # Exit menu

    elif CS.mode == cfg.ST_TARGETING:
        if CS.button:
            x, y = pygame.mouse.get_pos()
            x, y = gui.mouse2cell(x, y)

            # Accept the target if the player clicked in FOV, and in
            # case a range is specified, if it's in that range
            if CS.button == cfg.BUTTON_L and CS.u.fov_map.in_fov(x, y):
                targeting_function = CS.targeting_function.pop(0)
                success = targeting_function(CS.targeting_item, x, y)

                # If this targeting is the result of an item use,
                # destroy the item
                if CS.targeting_item and success:
                    CS.u.inventory.remove(CS.targeting_item)
                    del ClientObject.obj_dict[CS.targeting_item.oid]
                    CS.targeting_item = None

            CS.mode = cfg.ST_PLAYING
        elif key_code:
            client_message('Cancelled')
            CS.mode = cfg.ST_PLAYING
    elif CS.mode == cfg.ST_PLAYBACK:
        pass
    elif CS.mode == cfg.ST_QUIT:
        # Do nothing; let the main loop exit on its own.
        pass
    else:
        impossible('Unknown state: ' + CS.mode)
Exemple #6
0
def handle_events():
    """Handle input events."""
    for event in pygame.event.get():
        if event.type == pgl.QUIT:
            quit_game()
        elif event.type == pgl.KEYDOWN:
            CS.key = event
        elif event.type == pgl.KEYUP:
            CS.key = None
        elif event.type == pgl.MOUSEBUTTONDOWN:
            CS.button = event.button
        elif event.type == pgl.MOUSEBUTTONUP:
            CS.button = None
        elif event.type == pgl.MOUSEMOTION:
            pass
        elif event.type == pgl.VIDEORESIZE:
            gui.handle_resize(event.w, event.h)

        # Handle scrolling
        CS.x_scrollbar.handle_event(event)
        CS.y_scrollbar.handle_event(event)
        CS.log_scrollbar.handle_event(event)

    if CS.key:
        key_code, char, mod = CS.key.key, CS.key.unicode, CS.key.mod
        CS.key = None
    else:
        key_code, char, mod = None, None, None

    if CS.mode == cfg.ST_PLAYING:
        # Handle all keypresses
        if key_code:
            handled = False
            key_combo = ''

            if mod & pgl.KMOD_SHIFT:
                if char not in CS.pkeys[pgl.KMOD_NONE]:
                    key_combo = 'Shift + '

                if (key_code in CS.pkeys[pgl.KMOD_SHIFT]
                        and CS.pkeys[pgl.KMOD_SHIFT][key_code].action):
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_CTRL:
                key_combo = 'Ctrl + '

                if (key_code in CS.pkeys[pgl.KMOD_CTRL]
                        and CS.pkeys[pgl.KMOD_CTRL][key_code].action):
                    CS.pkeys[pgl.KMOD_CTRL][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_ALT:
                key_combo = 'Alt + '

                if (key_code in CS.pkeys[pgl.KMOD_ALT]
                        and CS.pkeys[pgl.KMOD_ALT][key_code].action):
                    CS.pkeys[pgl.KMOD_ALT][key_code].perform_action()
                    handled = True

            if not handled:
                # First, look up by char.  If it's not found, then look up by
                # key_code.
                if (char in CS.pkeys[pgl.KMOD_NONE]
                        and CS.pkeys[pgl.KMOD_NONE][char].action):
                    CS.pkeys[pgl.KMOD_NONE][char].perform_action()
                    handled = True
                elif (key_code in CS.pkeys[pgl.KMOD_NONE]
                      and CS.pkeys[pgl.KMOD_NONE][key_code].action):
                    CS.pkeys[pgl.KMOD_NONE][key_code].perform_action()
                    handled = True

            if key_code not in CS.ignore_keys and handled is False:
                if char in CS.pkeys[pgl.KMOD_NONE]:
                    key_to_print = char
                else:
                    key_to_print = pygame.key.name(key_code)
                    client_message("Unknown command '{0}{1}'.".format(
                        key_combo, key_to_print))

    elif CS.mode == cfg.ST_MENU:
        if key_code:
            if len(char) == 1:
                index = ord(char) - ord('a')
                if index >= 0 and index < len(CS.menu_options):
                    if CS.menu == 'use':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('a', (item.oid, ))

                    elif CS.menu == 'drop':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('d', (item.oid, ))
                else:
                    CS.mode = cfg.ST_PLAYING  # Exit menu
            else:
                CS.mode = cfg.ST_PLAYING  # Exit menu

    elif CS.mode == cfg.ST_TARGETING:
        if CS.button:
            x, y = pygame.mouse.get_pos()
            x, y = gui.mouse2cell(x, y)

            # Accept the target if the player clicked in FOV, and in
            # case a range is specified, if it's in that range
            if CS.button == cfg.BUTTON_L and CS.u.fov_map.in_fov(x, y):
                targeting_function = CS.targeting_function.pop(0)
                success = targeting_function(CS.targeting_item, x, y)

                # If this targeting is the result of an item use,
                # destroy the item
                if CS.targeting_item and success:
                    CS.u.inventory.remove(CS.targeting_item)
                    del ClientObject.obj_dict[CS.targeting_item.oid]
                    CS.targeting_item = None

            CS.mode = cfg.ST_PLAYING
        elif key_code:
            client_message('Cancelled')
            CS.mode = cfg.ST_PLAYING
    elif CS.mode == cfg.ST_PLAYBACK:
        pass
    elif CS.mode == cfg.ST_QUIT:
        # Do nothing; let the main loop exit on its own.
        pass
    else:
        impossible('Unknown state: ' + CS.mode)
Exemple #7
0
 def move(self, dx, dy=None):
     """Move by (dx, dy) cells."""
     dx, dy = flatten_args(dx, dy)
     Network.request('m', (dx, dy))
Exemple #8
0
 def attack(self, target):
     """Attack a target oid."""
     Network.request('F', (target.oid, ))