Exemplo n.º 1
0
def use_scroll_new(player, scroll):
    """Functionality for using a scroll when the transport is ownerless

    - rename the transport
    - set player as the owner
    - inform the player
    - remove scroll
    - put player out and into transport mode so the name of the ship updates
    """

    transport = get_player_transport(player)
    scroll_name = get_scroll_custom_name(scroll)
    transport_name = get_transport_name(scroll_name, player.Name)

    rename_transport(transport, transport_name)
    set_transport_owner(transport, player)

    send_info_to_player(
        PLAYER_MESSAGES['transport_renamed'].format(
            transport_name=scroll_name), player)
    send_info_to_player(
        PLAYER_MESSAGES['transport_is_mine'].format(
            transport_name=scroll_name), player)

    scroll.Quantity -= 1

    # Move player out of transport and then into transport
    # This way, the new name of the transport will appear
    transport.Apply(player, 0)
    transport.Apply(player, 0)
Exemplo n.º 2
0
def use_door(player, door):
    """Use the door

    This will teleport the player inside the cabin and start tracking
    the ship, so the player can return to it afterwards.
    """

    transport = get_player_transport(player)

    # put player out of transport mode
    #   (otherwise the client breaks down)
    transport.Apply(player, 0)

    # teleport player to the cabin

    # get cabin map and entrance
    cabin_map = door.Slaying
    cabin_x = door.HP
    cabin_y = door.SP
    # prepare map
    map_ = Crossfire.ReadyMap(cabin_map)
    # teleport player
    player.Teleport(map_, cabin_x, cabin_y)

    # start tracking transport and save tracking ID to internal cabin door
    transport_tracking_id = tracking_system.add_tracker(transport)
    internal_cabin_door = find_internal_cabin_door(transport, map_)
    internal_cabin_door.WriteKey(
        INTERNAL_CABIN_DOOR_ATTR_TRACKING_ID,
        transport_tracking_id,
        1,
    )
Exemplo n.º 3
0
def use_scroll(player, scroll):
    """Use the "Add anchor" scroll"""

    # Generate anchor id
    id_ = generate_feature_id()

    # Create andhor and add it to the transport's inventory
    create_anchor(player, scroll, id_)

    # Create keys and add them to player's inventory
    create_anchor_keys(player, scroll, id_)

    # Inform the player
    send_info_to_player(
        PLAYER_MESSAGES['anchor_added'],
        player,
    )

    # Remove the scroll
    scroll.Quantity -= 1

    # Get player out and into transport mode to display the new feature
    transport = get_player_transport(player)
    transport.Apply(player, 0)
    transport.Apply(player, 0)
Exemplo n.º 4
0
def create_cabin_door(player, scroll, map_location, id_):
    """Create a door that leads to the cabin and add it to the transport

    Args:
        player
        scroll
        map_location: Absolute path corresponding to the cabin

    Returns:
        A reference to the created door.
    """

    transport = get_player_transport(player)

    # Create door inside transport's inventory
    door = transport.CreateObject(EXTERNAL_CABIN_DOOR_ARCHETYPE)
    door.WriteKey(PRIVATE_TRANSPORT_FEATURE_ATTRS['flag'], '1', 1)
    set_private_transport_feature_type(door, 'cabin')
    set_private_transport_feature_id(door, id_)

    # Set door name
    door.Name = EXTERNAL_CABIN_DOOR_NAME.format(id_=id_)
    door.NamePl = EXTERNAL_CABIN_DOOR_NAME.format(id_=id_)

    # Link door to cabin
    door.Slaying = path.abs2map(map_location)
    door.HP = int(transport.ReadKey(PRIVATE_TRANSPORT_ATTRS['cabin_entrance_x']))
    door.SP = int(transport.ReadKey(PRIVATE_TRANSPORT_ATTRS['cabin_entrance_y']))

    return door
Exemplo n.º 5
0
def use_scroll(player, scroll):
    """Make a player use a Ship Rename Scroll

    Usage has already been validated, so player is on a private ship,
    either one which is ownerless, or one which the player owns.
    """
    transport = get_player_transport(player)
    if is_transport_owned_by_player(transport, player):
        use_scroll_already_owned(player, scroll)
    else:
        use_scroll_new(player, scroll)
Exemplo n.º 6
0
def check_if_player_can_use_scroll(player, scroll):
    """Verify if player can use scroll

    If player can't use scroll, raise an ActionError.
    """

    # player must be inside a private transport they own
    check_if_player_inside_private_transport_they_own(player)

    # there can only be 1 anchor per ship
    transport = get_player_transport(player)
    num_anchors = get_number_of_anchors(transport)
    if num_anchors >= 1:
        raise CanOnlyHaveOneAnchor
Exemplo n.º 7
0
def decide_template_to_use(player, scroll):
    """Decide which template to use when creating a cabin map

    Returns an *absolute* path to the template file.
    """

    transport = get_player_transport(player)
    template = transport.ReadKey(PRIVATE_TRANSPORT_ATTRS['cabin_template'])
    if not template:
        raise InternalError(
            "Failed to create cabin. Private transport without \"%s\" property."
            "" % PRIVATE_TRANSPORT_ATTRS['cabin_template']
        )
    template_abs = path.map2abs(template)

    return template_abs
Exemplo n.º 8
0
def check_if_player_can_use_scroll(player, scroll):
    """Verify if player can use scroll

    If the player cannot use the scroll, raise an ActionError, which
    will contain the appropriate message to send to the player.

    Otherwise (if the player can use the scroll and it would take
    effect), this function is NOP.
    """

    # player must be inside a private transport that they own
    check_if_player_inside_private_transport_they_own(player)

    # number of cabins after applying the scroll must be <= cabin limit
    transport = get_player_transport(player)
    cabin_limit = get_cabin_limit(transport)
    current_cabin_count = get_current_cabin_count(transport)
    if current_cabin_count + 1 > cabin_limit:
        raise CannotCreateMoreCabins
Exemplo n.º 9
0
def create_anchor(player, scroll, id_):
    """Create an anchor with a certain id_

    Returns:
        A reference to the newly created anchor object.
    """

    transport = get_player_transport(player)

    # Create anchor
    anchor = transport.CreateObject(ANCHOR_ARCHETYPE)
    set_private_transport_feature_flag(anchor)
    set_private_transport_feature_type(anchor, 'anchor')
    set_private_transport_feature_id(anchor, id_)

    # Set anchor name (so we can match it with key)
    anchor.Name = ANCHOR_NAME.format(id_=id_)
    anchor.NamePl = ANCHOR_NAME.format(id_=id_)

    return anchor
Exemplo n.º 10
0
def use_scroll(player, scroll):
    """Use the "Create cabin" scroll

    After this operation, we will have:

    - A cabin map built for the player
    - A door inside the transport that leads to the cabin
    - Keys that allow a non-owner of the transport to go to the cabin

    The keys only work with the specific cabin door.

    Oh, and the scroll will be removed :)
    """

    # Generate cabin id
    id_ = generate_feature_id()

    # Create cabin map
    map_location = create_cabin_map(player, scroll, id_)

    # Create cabin door and add it to the transport's inventory
    create_cabin_door(player, scroll, map_location, id_)

    # Remove the player and put him back on the transport so that the
    # added cabin becomes visible
    transport = get_player_transport(player)
    transport.Apply(player, 0)
    transport.Apply(player, 0)

    # Create keys and add them to player inventory
    create_cabin_keys(player, scroll, id_)

    # Vanish with the scroll
    # Note: Remove() will remove all stacked scrolls at once
    scroll.Quantity -= 1

    # Inform the player
    inform_player_of_new_cabin_added(player, scroll, id_)
Exemplo n.º 11
0
def use_anchor(player, anchor):
    """Use an anchor"""

    transport = get_player_transport(player)
    toggle_anchored(player, transport, anchor)