Exemplo n.º 1
0
def command_mgoto(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_mgoto")
        entity.send_output(syntax, break_line=False)
        return False

    target, room, last_message = goto_entity_handler(entity, argument, "mobs")
    if not target or not room:
        return False

    if entity.location.IS_ROOM:
        old_coords = "%d %d %d" % (entity.location.x, entity.location.y, entity.location.z)
    else:
        old_coords = "$l"
    old_area_code = entity.location.area.code

    goto_message(entity, room, "mgoto")
    entity = entity.from_location(1, use_repop=True)
    entity.to_location(room, use_look=True)
    entity.act("$n arriva tramite un goto da %s %s" % (old_coords, old_area_code), TO.ADMINS)

    entity.send_output(put_final_dot(last_message))
    return True
Exemplo n.º 2
0
def command_extract(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_extract")
        entity.send_output(syntax, break_line=False)
        return False

    arg, argument = one_argument(argument)
    if argument:
        quantity, argument = quantity_argument(argument)
    else:
        quantity = 1

    target = entity.find_entity_extensively(arg, quantity=quantity)
    if not target:
        entity.send_output("Nessuna entità trovata con argomento [white]%s[close]." % arg)
        return False

    if target.IS_PLAYER:
        entity.send_output("Non ti è possibile estrarre dei personaggi, se c'è un problema con un giocatore contattare i capoccia del Mud.")
        return False

    if quantity == 0:
        quantity = target.quantity

    entity.act("Esegui uno extract su $N!", TO.ENTITY, target)
    entity.act("$n esegue un extract su $N!", TO.OTHERS, target)
    target.act("$n esegue un extract su di te!", TO.TARGET, target)
    target.extract(quantity, use_repop=True)
    return True
Exemplo n.º 3
0
def command_delexit(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_delexit")
        entity.send_output(syntax, break_line=False)
        return False

    if not entity.location.IS_ROOM:
        entity.send_output("Non ti trovi in una stanza ma in %s" % entity.location.code)
        return False

    room = entity.location

    arg1, argument = one_argument(argument)
    direction = get_direction(arg1)
    if direction == DIR.NONE:
        entity.send_output("Direzione non valida ricavata dall'argomento %s" % arg1)
        return False

    if direction not in room.exits:
        entity.send_output("Non c'è nessuna uscita %s da distruggere." % direction.to_dir)
        return False

    del(room.exits[direction])
    entity.send_output("E' stata cancellata l'uscita %s." % direction.to_dir)
    return True
Exemplo n.º 4
0
def command_goto(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_goto")
        entity.send_output(syntax, break_line=False)
        return False

    target, room, last_message = goto_entity_handler(entity, argument,
                                                     "players")
    if not target or not room:
        return False

    if entity.location.IS_ROOM:
        old_coords = "%d %d %d" % (entity.location.x, entity.location.y,
                                   entity.location.z)
    else:
        old_coords = "$l"
    old_area_code = entity.location.area.code

    goto_message(entity, room, "goto")
    entity = entity.from_location(1, use_repop=True)
    entity.to_location(room, use_look=True)
    entity.act(
        "$n arriva tramite un goto da %s %s" % (old_coords, old_area_code),
        TO.ADMINS)

    entity.send_output(put_final_dot(last_message))
    return True
Exemplo n.º 5
0
def command_title(entity, argument=""):
    """
    Permette al giocatore d'inserire un proprio title al personaggio.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_title")
        entity.send_output(syntax, break_line=False)
        return False

    if not entity.IS_PLAYER:
        entity.send_output("Non ti è possibile impostare un titolo.")
        return

    if is_same(argument, "cancella") or is_same(argument, "delete"):
        entity.title = ""
        entity.send_output("Il tuo titolo è stato cancellato.")
        return True

    color_qty = count_colors(argument)
    # (TD) In futuro non farlo dipendente dal livello ma da qualche achievement o quest
    if color_qty > entity.level / 2:
        entity.send_output("Devi crescere di livello se vuoi colorare maggiormente il tuo titolo.")
        return False

    entity.title = close_color(argument)
    entity.send_output("Il tuo titolo è stato modificato in: '%s'" % entity.title)
    return True
Exemplo n.º 6
0
def command_speak(entity, argument="", verbs=VERBS):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        syntax = get_command_syntax(entity, "command_speak")
        entity.send_output(syntax, break_line=False)
        return False

    target = entity.find_entity_extensively(argument)
    if not target:
        entity.act("Non c'è nessuno [white]%s[close] qui attorno con cui puoi %s." % (argument, verbs["infinitive"]))
        entity.act("$n sembra stia cercando qualcuno qui attorno senza trovarlo.", TO.OTHERS)
        return False

    for dialog in target.dialogs:
        if dialog.code == "speak":
            break
    else:
        entity.send_output("%s non sembra avere molto da dirti." % target.get_name())
        return

    # (TD) aggiungere il check trigger

    # (TD) splittare target

    entity.flags += FLAG.CONVERSING
    entity.send_output(dialog.introduction)
    dialog.send_statement(target, entity)
    return True
Exemplo n.º 7
0
def command_slay(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_slay")
        entity.send_output(syntax, break_line=False)
        return False

    target = entity.find_entity_extensively(argument)
    if not target:
        entity.send_output("Nessuna entità trovata con argomento [green]%s[close]." % argument)
        return False

    if target.IS_PLAYER and entity.trust < TRUST.IMPLEMENTOR:
        entity.send_output("Non ti è possibile slayare dei personaggi, se c'è un problema con un giocatore contattare i capoccia del Mud.")
        return False

    entity.act("Esegui uno slay su $N!", TO.ENTITY, target)
    entity.act("$n esegue uno slay su $N!", TO.OTHERS, target)
    target.act("$n esegue uno slay su di te!", TO.TARGET, target)
    target.dies(opponent=None)
    return True
Exemplo n.º 8
0
def command_restore(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        if entity.life >= entity.max_life:
            syntax = get_command_syntax(entity, "command_restore")
            entity.send_output(syntax, break_line=False)
            return False
        else:
            argument = entity.code

    target = entity.find_entity_extensively(argument)
    if not target:
        entity.send_output(
            "Nessuna entità trovata con argomento [white]%s[close]." %
            argument)
        return False

    if target.IS_PLAYER and entity.trust < TRUST.IMPLEMENTOR:
        entity.send_output(
            "Non ti è possibile ripristinare i punti dei personaggi.")
        return False

    # Ripristino prima di inviare il messaggio cosicché il prompt visualizza
    # correttamente il tutto
    target.life = target.max_life
    target.mana = target.max_mana
    target.vigour = target.max_vigour
    if target.IS_ACTOR:
        target.thirst = 0
        target.hunger = 0
        target.sleep = 0
        target.drunkness = 0
        target.adrenaline = 0
        target.mind = 0
        target.emotion = 0
        target.bloodthirst = 0

    if entity == target:
        entity.act("Ti invii un flusso d'energia per ripristinarti!",
                   TO.ENTITY, target)
        entity.act("$n si invia un flusso d'energia per ripristinarsi!",
                   TO.OTHERS, target)
    else:
        entity.act("Invii un flusso d'energia su di $N che lo ripristina!",
                   TO.ENTITY, target)
        entity.act("$n invia un flusso d'energia su di $N che lo ripristina!",
                   TO.OTHERS, target)
        target.act(
            "$n ti invia un flusso d'energia su di te che ti ripristina!",
            TO.TARGET, target)

    return True
Exemplo n.º 9
0
def command_snoopers(entity, argument=""):
    """
    Permette di visualizzare tutto l'output di uno o più entità.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    target = None
    if argument:
        target = entity.find_entity(argument,
                                    entity_tables=["players"],
                                    avoid_equipment=False)
        if not target:
            entity.send_output(
                "Non trovi nessun amministratore con argomento [white]%s[close]"
                % argument)
            return False
        if target.trust < TRUST.MASTER:
            entity.send_output("Il giocatore %s non è un amministratore." %
                               target.name)
            return False
        syntax = get_command_syntax(entity, "command_snoopers")
        entity.send_output(syntax, break_line=False)
        return False

    snooped_by = {}
    players_founded = False
    players = database["players"].values()
    for admin in players:
        if admin.trust < TRUST.MASTER or admin.trust > entity.trust:
            continue
        if target and admin != target:
            continue
        snooped_by[admin] = []
        for player in players + database["mobs"].values(
        ) + database["items"].values():
            if admin in player.snoopers:
                snooped_by[admin].append(player)
                players_founded = True

    lines = []
    for admin, snooped_players in snooped_by.iteritems():
        if not snooped_players:
            continue
        lines.append("Entità snoopate da %s:" % admin.name)
        for snooped_player in snooped_players:
            lines.append(snooped_player.name)

    if players_founded:
        entity.send_output("\n".join(lines))
    else:
        entity.send_output("Nessun giocatore snoopato dagli amministratori.")

    return True
Exemplo n.º 10
0
def invoke_handler(entity, argument, command_name, table_name):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    if not command_name:
        log.bug("command_name non è un parametro valido: %r" % command_name)
        return False

    if not table_name:
        log.bug("table_name non è un parametro valido: %r" % table_name)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, command_name)
        entity.send_output(syntax, break_line=False)
        return False

    if table_name == "players":
        # Esegue l'invoke solo tra i giocatori online
        target = search_online_player(argument, only_exact=True)
        if not target:
            target = entity.find_entity(argument, entity_tables=[table_name], avoid_equipment=False)
            if not target:
                entity.send_output("Non è stato trovato nessun player con argomento [green]%s[close]." % argument)
            elif not target.game_request:
                entity.send_output("%s non è un player attualmente online." % target.name)
            else:
                entity.send_output("Devi digitare il nome per intero se intendevi il player %s altrimenti digitane un'altro sempre per intero." % target.name)
            return False
    else:
        target = entity.find_entity(argument, entity_tables=[table_name], avoid_equipment=False)
        if not target:
            entity.send_output("Non è stato trovato nessun %s con argomento [green]%s[close]." % (table_name, argument))
            return False

    if entity == target:
        entity.send_output("Non è saggio invocare sé stessi!")
        return False

    entity.act("Apri un [royalblue]misterioso portale[close] con cui risucchiare $N.", TO.ENTITY, target)
    entity.act("$n apre un [royalblue]misterioso portale[close] con cui risucchiare $N.", TO.OTHERS, target)

    if entity.location == target.location:
        entity.act("Vieni risucchiato in un [royalblue]misterioso portale[close] aperto da $n!", TO.TARGET, target)
    else:
        entity.act("$N viene risucchiato in un [royalblue]misterioso portale[close].", TO.OTHERS, target, send_to_location=target.location)
        entity.act("Vieni risucchiato in un [royalblue]misterioso portale[close]!", TO.TARGET, target, send_to_location=target.location)

    target = target.from_location(1, use_repop=True)
    target.to_location(entity.location, use_look=True if target.IS_ACTOR else False)

    return True
Exemplo n.º 11
0
def command_commands(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    syntax = get_command_syntax(entity, "command_commands")
    entity.send_output(syntax, break_line=False)

    return commands_skills_socials_handler(entity, argument, "command")
Exemplo n.º 12
0
def command_commands(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    syntax = get_command_syntax(entity, "command_commands")
    entity.send_output(syntax, break_line=False)

    return commands_skills_socials_handler(entity, argument, "command")
Exemplo n.º 13
0
def command_setrace(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_setrace")
        entity.send_output(syntax, break_line=False)
        return False

    arg, argument = one_argument(argument)
    target = entity.find_entity_extensively(arg)
    if not target:
        entity.send_output(
            "Nessuna entità trovata con argomento [white]%s[close]" % arg)
        return False

    if not argument:
        entity.send_output("Che razza vuoi impostare a [white]%s[close]?" %
                           target.get_name(entity))
        return False

    new_race = get_element_from_name(RACE, argument)
    if not new_race:
        new_race = get_enum_element(argument, quiet=True)
        if not new_race:
            new_race = get_enum_element("RACE." + argument.upper(), quiet=True)
            if not new_race:
                entity.send_output(
                    "Nessuna razza trovata con argomento [white]%s[close]" %
                    argument)
                return False

    if target.race == new_race:
        if target == entity:
            entity.send_output("La tua razza è già %s" % new_race)
        else:
            entity.send_output("La razza di %s è già %s" %
                               (target.get_name(looker), new_race))
        return False

    if target == entity:
        entity.send_output("Cambi la tua razza da %s in %s." %
                           (target.race, new_race))
    else:
        entity.send_output("Cambi la razza dell'entità %s da %s in %s." %
                           (target.get_name(entity), target.race, new_race))
    target.race = new_race
    return True
Exemplo n.º 14
0
def command_coords(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    results = []

    if argument:
        area = nifty_value_search(database["areas"], argument)
        if not area:
            entity.send_output(
                "Codice d'area simile a [green]%s[close] inesistente." %
                argument)
            return False
    else:
        results.append(get_command_syntax(entity, "command_coords") + "\n")
        area = entity.area
        if not area:
            results.append("\nNon ti trovi in un'area valida.")
            entity.send_output("".join(results))
            return False

    results.append('''<table class="mud" rules="rows" frame="below">''')
    results.append('''<tr>''')
    results.append('''<th class="nowrap" align="left">X Y Z</th>''')
    results.append('''<th align="left">Code</th>''')
    results.append('''<th align="left">Name</th>''')
    results.append('''<th align="left">Short</th>''')
    results.append('''</tr>''')
    for coord in sorted(area.rooms):
        room = area.rooms[coord]
        short_tooltip = ""
        if room.short_night:
            short_tooltip = create_tooltip(entity.get_conn(),
                                           "ShortNight: %s" % room.short_night,
                                           room.short)
        else:
            short_tooltip = room.short
        javascript_code = '''javascript:parent.sendInput('rgoto %s');''' % room.get_destination(
        )
        results.append('''<tr>''')
        results.append(
            '''<td class="nowrap">%s</td><td><a href="%s">%s</a></td><td>%s</td><td>%s</td>'''
            % (coord, javascript_code, room.code, room.name, short_tooltip))
        results.append('''</tr>''')
    results.append('''</table>''')

    entity.send_output("".join(results), break_line=False)
    return True
Exemplo n.º 15
0
def command_snoopers(entity, argument=""):
    """
    Permette di visualizzare tutto l'output di uno o più entità.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    target = None
    if argument:
        target = entity.find_entity(argument, entity_tables=["players"], avoid_equipment=False)
        if not target:
            entity.send_output("Non trovi nessun amministratore con argomento [white]%s[close]" % argument)
            return False
        if target.trust < TRUST.MASTER:
            entity.send_output("Il giocatore %s non è un amministratore." % target.name)
            return False
        syntax = get_command_syntax(entity, "command_snoopers")
        entity.send_output(syntax, break_line=False)
        return False

    snooped_by = {}
    players_founded = False
    players = database["players"].values()
    for admin in players:
        if admin.trust < TRUST.MASTER or admin.trust > entity.trust:
            continue
        if target and admin != target:
            continue
        snooped_by[admin] = []
        for player in players + database["mobs"].values() + database["items"].values():
            if admin in player.snoopers:
                snooped_by[admin].append(player)
                players_founded = True

    lines = []
    for admin, snooped_players in snooped_by.iteritems():
        if not snooped_players:
            continue
        lines.append("Entità snoopate da %s:" % admin.name)
        for snooped_player in snooped_players:
            lines.append(snooped_player.name)

    if players_founded:
        entity.send_output("\n".join(lines))
    else:
        entity.send_output("Nessun giocatore snoopato dagli amministratori.")

    return True
Exemplo n.º 16
0
def command_restore(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        if entity.life >= entity.max_life:
            syntax = get_command_syntax(entity, "command_restore")
            entity.send_output(syntax, break_line=False)
            return False
        else:
            argument = entity.code

    target = entity.find_entity_extensively(argument)
    if not target:
        entity.send_output("Nessuna entità trovata con argomento [white]%s[close]." % argument)
        return False

    if target.IS_PLAYER and entity.trust < TRUST.IMPLEMENTOR:
        entity.send_output("Non ti è possibile ripristinare i punti dei personaggi.")
        return False

    # Ripristino prima di inviare il messaggio cosicché il prompt visualizza
    # correttamente il tutto
    target.life = target.max_life
    target.mana = target.max_mana
    target.vigour = target.max_vigour
    if target.IS_ACTOR:
        target.thirst      = 0
        target.hunger      = 0
        target.sleep       = 0
        target.drunkness   = 0
        target.adrenaline  = 0
        target.mind        = 0
        target.emotion     = 0
        target.bloodthirst = 0

    if entity == target:
        entity.act("Ti invii un flusso d'energia per ripristinarti!", TO.ENTITY, target)
        entity.act("$n si invia un flusso d'energia per ripristinarsi!", TO.OTHERS, target)
    else:
        entity.act("Invii un flusso d'energia su di $N che lo ripristina!", TO.ENTITY, target)
        entity.act("$n invia un flusso d'energia su di $N che lo ripristina!", TO.OTHERS, target)
        target.act("$n ti invia un flusso d'energia su di te che ti ripristina!", TO.TARGET, target)

    return True
Exemplo n.º 17
0
def command_examine(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_examine")
            entity.send_output(syntax, break_line=False)
        return False

    # (TD)
    return command_look(entity, argument, behavioured=behavioured, use_examine=True)
Exemplo n.º 18
0
def command_usedrooms(entity, argument):
    if not entity:
        log.bug("entity non un parametro è valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_usedrooms")
        entity.send_output(syntax, break_line=False)
        return False

    number_of_resets = 0
    arg, argument = one_argument(argument)
    try:
        number_of_resets = int(arg)
    except ValueError:
        entity.send_output("Il primo argomento dev'essere un [white]numero[close] che rappresenta la quantità di [blue]reset[close] voluti.")
        return False

    proto_room_resets_counter = {}
    for proto_room_code in database["proto_rooms"]:
        if argument and not is_prefix(argument, proto_room_code):
            continue
        reset_counter = 0
        for room_code in database["rooms"]:
            if is_prefix(proto_room_code, room_code):
                reset_counter += 1
        proto_room_resets_counter[proto_room_code] = reset_counter

    for proto_room_code, reset_counter in proto_room_resets_counter.iteritems():
        if reset_counter == number_of_resets:
            entity.send_output("%s: %s" % (proto_room_code, database["proto_rooms"][proto_room_code].name))

    if len(proto_room_resets_counter) > 0:
        entity.send_output("\n")

    plural = "a" if len(proto_room_resets_counter) == 1 else "e"
    result = "Trovat%s [white]%d[close] stanz%s prototipo resettate [white]%d[close] volte" % (
        plural, len(proto_room_resets_counter), plural, number_of_resets)
    if argument:
        result += " il cui codice è (o inizia per) [white]%s[close]" % argument
    else:
        result += "."

    entity.send_output(result)
    return True
Exemplo n.º 19
0
def command_links(entity, argument="", behavioured=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    results = []

    if argument:
        area = nifty_value_search(database["areas"], argument)
        if not area:
            entity.send_output("Codice d'area simile a [green]%s[close] inesistente." % argument)
            return False
        areas = [area, ]
    else:
        results.append(get_command_syntax(entity, "command_links") + "\n")
        areas = sorted(database["areas"].values())

    results.append('''<table class="mud" rules="rows" frame="below" width="100%">''')
    results.append('''<tr>''')
    results.append('''<th class="nowrap" align="left">From Room</th>''')
    results.append('''<th class="nowrap" align="left">To Area</th>''')
    results.append('''<th class="nowrap" align="left">To Coords</th>''')
    results.append('''<th class="nowrap" align="left">Current Room At Coords</th>''')
    results.append('''</tr>''')
    for area in areas:
        for proto_room in area.proto_rooms.itervalues():
            for exit in proto_room.exits.itervalues():
                if not exit.destination:
                    continue
                if exit.destination.area != area:
                    results.append('''<tr>''')
                    results.append('''<td>%s</td><td>%s</td><td class="nowrap">%d %d %d</td>''' % (
                        proto_room.code,
                        exit.destination.area.code,
                        exit.destination.x, exit.destination.y, exit.destination.z))
                    destination_room = exit.destination.get_room()
                    if destination_room:
                        results.append('''<td>%s</td>''' % destination_room.prototype.code)
                    else:
                        results.append('''<td>Nessuna resettata al momento</td>''')
                    results.append('''</tr>''')
    results.append('''</table>''')

    entity.send_output("".join(results).rstrip("\n"), break_line=False)
    return True
Exemplo n.º 20
0
def command_exit(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Dove vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_exit")
            entity.send_output(syntax)
        return False

    # (TD) aggiungervi il check_trigger
    # (TD) finirlo
    return True
Exemplo n.º 21
0
def command_exit(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Dove vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_exit")
            entity.send_output(syntax)
        return False

    # (TD) aggiungervi il check_trigger
    # (TD) finirlo
    return True
Exemplo n.º 22
0
def command_rgoto(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_rgoto")
        entity.send_output(syntax, break_line=False)
        return False

    room, more_search = get_room_from_coords(entity, argument)
    if not room:
        if more_search:
            room = entity.find_room(argument)
            if not room:
                if " " in argument and argument[0] not in "'\"":
                    entity.send_output(
                        "Stanza non trovata con argomento [green]%s[close], se l'argomento cercato è formato da una frase con spazi inserirlo tra virgolette."
                        % argument)
                else:
                    entity.send_output(
                        "Stanza non trovata con argomento [green]%s[close]." %
                        argument)
                return False
        else:
            return False

    goto_message(entity, room, "rgoto")
    entity = entity.from_location(1, use_repop=True)
    entity.to_location(room, use_look=True)
    if entity.previous_location():
        if entity.previous_location().IS_ROOM:
            entity.act(
                "$n arriva tramite un rgoto da %s" %
                entity.previous_location().get_destination(), TO.ADMINS)
        else:
            entity.act(
                "$n arriva tramite un rgoto da %s" %
                entity.previous_location().get_name(), TO.ADMINS)
    else:
        entity.act("$n arriva tramite un rgoto", TO.ADMINS)

    return True
Exemplo n.º 23
0
def command_coords(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    results = []

    if argument:
        area = nifty_value_search(database["areas"], argument)
        if not area:
            entity.send_output("Codice d'area simile a [green]%s[close] inesistente." % argument)
            return False
    else:
        results.append(get_command_syntax(entity, "command_coords") + "\n")
        area = entity.area
        if not area:
            results.append("\nNon ti trovi in un'area valida.")
            entity.send_output("".join(results))
            return False

    results.append('''<table class="mud" rules="rows" frame="below">''')
    results.append('''<tr>''')
    results.append('''<th class="nowrap" align="left">X Y Z</th>''')
    results.append('''<th align="left">Code</th>''')
    results.append('''<th align="left">Name</th>''')
    results.append('''<th align="left">Short</th>''')
    results.append('''</tr>''')
    for coord in sorted(area.rooms):
        room = area.rooms[coord]
        short_tooltip = ""
        if room.short_night:
            short_tooltip = create_tooltip(entity.get_conn(), "ShortNight: %s" % room.short_night, room.short)
        else:
            short_tooltip = room.short
        javascript_code = '''javascript:parent.sendInput('rgoto %s');''' % room.get_destination()
        results.append('''<tr>''')
        results.append('''<td class="nowrap">%s</td><td><a href="%s">%s</a></td><td>%s</td><td>%s</td>''' % (
            coord, javascript_code, room.code, room.name, short_tooltip))
        results.append('''</tr>''')
    results.append('''</table>''')

    entity.send_output("".join(results), break_line=False)
    return True
Exemplo n.º 24
0
def command_setrace(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_setrace")
        entity.send_output(syntax, break_line=False)
        return False

    arg, argument = one_argument(argument)
    target = entity.find_entity_extensively(arg)
    if not target:
        entity.send_output("Nessuna entità trovata con argomento [white]%s[close]" % arg)
        return False

    if not argument:
        entity.send_output("Che razza vuoi impostare a [white]%s[close]?" % target.get_name(entity))
        return False

    new_race = get_element_from_name(RACE, argument)
    if not new_race:
        new_race = get_enum_element(argument, quiet=True)
        if not new_race:
            new_race = get_enum_element("RACE." + argument.upper(), quiet=True)
            if not new_race:
                entity.send_output("Nessuna razza trovata con argomento [white]%s[close]" % argument)
                return False

    if target.race == new_race:
        if target == entity:
            entity.send_output("La tua razza è già %s" % new_race)
        else:
            entity.send_output("La razza di %s è già %s" % (target.get_name(looker), new_race))
        return False

    if target == entity:
        entity.send_output("Cambi la tua razza da %s in %s." % (target.race, new_race))
    else:
        entity.send_output("Cambi la razza dell'entità %s da %s in %s." %(target.get_name(entity), target.race, new_race))
    target.race = new_race
    return True
Exemplo n.º 25
0
def command_examine(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_examine")
            entity.send_output(syntax, break_line=False)
        return False

    # (TD)
    return command_look(entity,
                        argument,
                        behavioured=behavioured,
                        use_examine=True)
Exemplo n.º 26
0
def command_emote(entity, argument="", behavioured=False):
    """
    Permette di inviare liberamente dei messaggi per poter esprimere sentimenti
    o gesti.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    force_return = check_trigger(entity, "before_emote", entity, argument, behavioured)
    if force_return:
        return True

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_emote")
            entity.send_output(syntax, break_line=False)
        return False

    if len(argument) > config.max_google_translate:
        entity.act("Non puoi %s in maniera così prolissa." % verbs["you2"])
        entity.act("Non riesce ad %s adeguatamente e si impappina." % verbs["it2"])
        return False

    argument = put_final_dot(argument)

    # Mostra a tutti ciò che il giocatore vuole esprimere
    if "$n" in argument:
        argument = color_first_upper(argument)
        entity.act(argument.replace("$n", entity.name), TO.ENTITY)
        entity.act(argument, TO.OTHERS)
    else:
        entity.act("%s %s" % (entity.name, argument), TO.ENTITY)
        entity.act("$n %s" % argument, TO.OTHERS)

    force_return = check_trigger(entity, "after_emote", entity, argument, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 27
0
def command_usedexits(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_usedexits")
        entity.send_output(syntax, break_line=False)
        return False

    number_of_exits = 0
    arg, argument = one_argument(argument)
    try:
        number_of_exits = int(arg)
    except ValueError:
        entity.send_output(
            "Il primo argomento dev'essere un numero che rappresenta la quantità di uscite volute."
        )
        return False

    counter = 0
    for room in database["rooms"].itervalues():
        if len(room.exits) == number_of_exits:
            entity.send_output("%s: %s" % (room.code, room.name))
            counter += 1

    if counter > 0:
        entity.send_output("\n")

    plural = "a" if counter == 1 else "e"
    result = "Trovat%s [white]%d[close] stanz%s con [white]%d[close] uscite" % (
        plural, counter, plural, number_of_exits)
    if arg2:
        result += " il cui codice è (o inizia per) [white]%s[close]" % arg2
    else:
        result += "."

    entity.send_output(result)
    return True
Exemplo n.º 28
0
def command_usedexits(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_usedexits")
        entity.send_output(syntax, break_line=False)
        return False

    number_of_exits = 0
    arg, argument = one_argument(argument)
    try:
        number_of_exits = int(arg)
    except ValueError:
        entity.send_output("Il primo argomento dev'essere un numero che rappresenta la quantità di uscite volute.")
        return False

    counter = 0
    for room in database["rooms"].itervalues():
        if len(room.exits) == number_of_exits:
            entity.send_output("%s: %s" % (room.code, room.name))
            counter += 1

    if counter > 0:
        entity.send_output("\n")

    plural = "a" if counter == 1 else "e"
    result = "Trovat%s [white]%d[close] stanz%s con [white]%d[close] uscite" % (
        plural, counter, plural, number_of_exits)
    if arg2:
        result += " il cui codice è (o inizia per) [white]%s[close]" % arg2
    else:
        result += "."

    entity.send_output(result)
    return True
Exemplo n.º 29
0
def command_rgoto(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_rgoto")
        entity.send_output(syntax, break_line=False)
        return False

    room, more_search = get_room_from_coords(entity, argument)
    if not room:
        if more_search:
            room = entity.find_room(argument)
            if not room:
                if " " in argument and argument[0] not in "'\"":
                    entity.send_output("Stanza non trovata con argomento [green]%s[close], se l'argomento cercato è formato da una frase con spazi inserirlo tra virgolette." % argument)
                else:
                    entity.send_output("Stanza non trovata con argomento [green]%s[close]." % argument)
                return False
        else:
            return False

    goto_message(entity, room, "rgoto")
    entity = entity.from_location(1, use_repop=True)
    entity.to_location(room, use_look=True)
    if entity.previous_location():
        if entity.previous_location().IS_ROOM:
            entity.act("$n arriva tramite un rgoto da %s" % entity.previous_location().get_destination(), TO.ADMINS)
        else:
            entity.act("$n arriva tramite un rgoto da %s" % entity.previous_location().get_name(), TO.ADMINS)
    else:
        entity.act("$n arriva tramite un rgoto", TO.ADMINS)

    return True
Exemplo n.º 30
0
def command_split(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che [white]cosa[close] vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_split")
            entity.send_output(syntax)
        return False

    force_return = check_trigger(entity, "before_split", entity, target1, target2)
    if force_return:
        return True


    force_return = check_trigger(entity, "after_split", entity, target1, target2)
    if force_return:
        return True

    return True
Exemplo n.º 31
0
def command_drink(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Comando che serve per mangiare un entità.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    # (TD) controllo sulle posizioni, possibilità di muovere la bocca come
    # per bere nel sonno

    if not argument:
        entity.send_output("Cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_eat")
            entity.send_output(syntax, break_line=False)
        return False

    # (TD) futura ricerca allucinogena, se si è pazzi è difficile trovare
    # qualsiasi entità, probabilmente il sistema verrà integrato nel metodo
    # find_entity

    # Cerca l'entità da bere prima nel proprio inventario e poi utilizza
    # il comando get per prendere la bevanda da qualsiasi altra parte
    target = entity.find_entity(argument, location=entity)
    if not target:
        # (TD) Manca la ricerca se il cibo si trova dentro o sopra target, da fare
        # quando ci saranno i contenitori e quando le entità si potranno appoggiare
        entity.act(
            "Non trovi nessun [white]%s[close] da poter %s." %
            (argument, verbs["infinitive"]), TO.ENTITY)
        entity.act(
            "$n si guarda attorno cercando qualcosa." % verbs["infinitive"],
            TO.OTHERS)
        return False

    # Ricava il peso di un morso in proporzione al proprio, viene ricavato
    # un peso in grammi. Il pezzo è più grande se si sta divorando
    if devours:
        bite_weight = entity.weight / 50
    else:
        bite_weight = entity.weight / 100
    if target.weight < bite_weight:
        bite_weight = target.weight

    # Ricava il peso di quello che si può ingerire prima di non sentire più fame
    # il doppio di questo valore è il peso massimo che lo stomaco può sopportare
    # In sostanza per ogni 50kg di peso proprio si suppone che prima di non
    # sentire più fame bisogna ingerire 1kg, viene ricavato un peso in grammi
    eatable_weight = entity.weight * 1000 / 50000

    # Ricava il peso delle cose ingerite
    eated_weight = 0
    for something in entity.iter_contains():
        if FLAG.INGESTED in something.flags:
            eated_weight += something.weight

    if eated_weight + bite_weight > eatable_weight * 2:
        if entity.trust >= TRUST.MASTER:
            entity.send_to_admin(
                "Mangi l'entità nonostante tu abbia la pancia piena")
        else:
            entity.act(
                "Hai la pancia troppo piena per riuscire ad ingurgitare $N.",
                TO.ENTITY, target)
            entity.act(
                "$n cerca di %s $N, ma sembra che abbia la pancia piena." %
                verbs["infinitive"], TO.OTHERS, target)
            entity.act(
                "$n cerca di %s, ma sembra che abbia la pancia piena." %
                verbs["you2"], TO.TARGET, target)
            return False

    # Se l'entità non è un cibo allora si comporta in maniera differente a
    # seconda della tipologia della stessa
    if not target.food_type:
        if target == entity:
            input = "nail %s" % target.get_numbered_keyword(looker=entity)
            send_input(entity,
                       input,
                       "en",
                       show_input=False,
                       show_prompt=False)
            return True
        elif target.IS_ACTOR:
            input = "nibble %s" % target.get_numbered_keyword(looker=entity)
            send_input(entity,
                       input,
                       "en",
                       show_input=False,
                       show_prompt=False)
            return True
        else:
            if target.weight > bite_weight:
                if entity.trust == TRUST.PLAYER:
                    entity.act(
                        "Cerchi di %s $N ma ti rendi conto che è troppo grande da ingoiare."
                        % verbs["infinitive"], TO.ENTITY, target)
                    entity.act(
                        "$n cerca di %s $N ma senza grossi risultati..." %
                        verbs["infinitive"], TO.OTHERS, target)
                    entity.act("$n cerca di %s... Ouch!" % verbs["you2"],
                               TO.TARGET, target)
                    return False
                else:
                    entity.send_to_admin(
                        "Ingoi quest'oggetto nonostante sia troppo grande")
            entity.act("%s $N" % verbs["you"], TO.ENTITY, target)
            entity.act("$n %s $N" % verbs["it"], TO.OTHERS, target)
            entity.act("$n ti %s" % verbs["it"], TO.TARGET, target)
            digestion_loop.add(entity, target)
            return True

    # (TD) Splitting di un oggetto da un gruppo di oggetti

    # (TD) Probabilità che il cibo cada per terra se si sta combattimento

    # Controlla se l'entità segue la dieta necessaria per mangiare target.
    # Se sta divorando non si guarda per il sottile e si mangia un po' di tutto
    if devours:
        acceptability = 50
    else:
        acceptability = 25
    if FLAG.CARNIVOROUS in entity.flags and target.food_type.vegetable >= acceptability:
        entity.act(
            "Non puoi %s $N, è fatto più d'erba che carne!" %
            verbs["infinitive"], TO.ENTITY, target)
        entity.act(
            "$n guarda perpless$o $N, sembra che non $gli vada a genio...",
            TO.OTHERS, target)
        entity.act(
            "$n ti guarda perpless$o, sembra che non $gli vai a genio...",
            TO.TARGET, target)
        return False
    elif FLAG.HERBIVORE in entity.flags and target.food_type.animal >= acceptability:
        entity.act(
            "Non puoi %s $N, è fatto più di sangue che di vegetali!" %
            verbs["infinitive"], TO.ENTITY, target)
        entity.act(
            "$n guarda perpless$o $N, sembra che non $gli vada a genio...",
            TO.OTHERS, target)
        entity.act(
            "$n ti guarda perpless$o, sembra che non $gli vai a genio...",
            TO.TARGET, target)
        return False

    # Diminuisce la fame di una certa percentuale pari al peso mangiato rispetto
    # a quello ingeribile.
    # (TD) Tutto da rifare, la hunger sarà un effetto, verrà presa una
    # percentuale dell'effetto a seconda della grandezza del morso
    # (TD) A seconda delle condizioni e delle ore passate il cibo
    # ha più o meno consistenza o è più o meno mangiabile
    if entity.IS_ACTOR:
        entity.hunger -= (bite_weight * 100 / eatable_weight) * 2
        if entity.hunger < 0:
            entity.hunger = 0

    # I messaggi devono essere visualizzati solo dopo aver diminuito la hunger
    target.food_type.send_messages(entity, target, verbs)

    # Viene visualizza l'eventuale descrizione del gusto, ma solo se non si sta
    # mangiando normalmente
    if not devours:
        # Anche qui l'eat scatena il gamescript before_taste e after_taste
        descr = target.get_descr("taste", looker=entity)
        if descr:
            entity.send_output('''<div style="width:66%%">%s</div>''' % descr)

    # Inserisce l'oggetto nello stomaco e ne inizia la digestione
    # (TD) le cose bevute vanno estratte e non digerite, al limite ne rimane
    # il contenitore, cosa da fare anche per i food
    digestion_loop.add(entity, target)

    # (TD) aggiunta degli effetti del cibo sul giocatore

    # (TD) social vomito e rimozione di alcuni oggetti dallo stomaco
    #if eated_weight + bite_weight == eatable_weight * 2:
    # pass
    if eated_weight + bite_weight > eatable_weight * 1.5:
        entity.act("Il tuo stomaco è scosso da degli spasmi... Sei pien$o!",
                   TO.ENTITY, target)
        entity.act(
            "$n si tiene la pancia con una $hand... Che abbia %sto troppo?" %
            verbs["it"], TO.OTHERS, target)
        entity.act(
            "Puoi constatare in prima persona che lo stomaco di $n è pieno.",
            TO.TARGET, target)
    elif not devours and eated_weight + bite_weight > eatable_weight:
        # Se si sta divorando in fretta non si lascia il tempo di capire che sta arrivando la nausea
        entity.act(
            "Comincia a venirti una certa nausea per il cibo... Sei quasi pien$o!",
            TO.ENTITY, target)
        entity.act(
            "$n si passa una $hand sullo stomaco... Che sia ormai sazi$o?",
            TO.OTHERS, target)
        entity.act(
            "Puoi constatare in prima persona che lo stomaco di $n è quasi pieno.",
            TO.TARGET, target)

    if entity.IS_PLAYER:
        if target.prototype.code in entity.drinked_entities:
            entity.drinked_entities[target.prototype.code] += 1
        else:
            entity.drinked_entities[target.prototype.code] = 1
            reason = "per aver bevuto per la prima volta %s" % target.get_name(
                looker=entity)
            entity.give_experience(target.level, reason=reason)

    return True
Exemplo n.º 32
0
def command_countflags(entity, argument=""):
    """
    Permette di raggiungere il primo oggetto trovato con la flag passata.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_countflags")
        entity.send_output(syntax, break_line=False)
        return False

    argument = argument.upper().replace(" ", "_")
    if "." in argument:
        enum_element = get_enum_element(argument, quiet=True)
    else:
        for enum_name in ("FLAG.", "CONTAINER.", "DOOR.", "PORTAL.", "WEAPONFLAG."):
            enum_element = get_enum_element(enum_name + argument, quiet=True)
            if not enum_element:
                continue
            else:
                break

    if not enum_element:
        entity.send_output("Nessun elemento di enumerazione trovato con argomento [green]%s[close]" % argument)
        return False

    if enum_element.enum.name == "FLAG":
        path = "flags"
    elif enum_element.enum.name == "CONTAINER":
        path = "container_type.flags"
    elif enum_element.enum.name == "DOOR":
        path = "door_type.flags"
    elif enum_element.enum.name == "PORTAL":
        path = "portal_type.flags"
    elif enum_element.enum.name == "WEAPONFLAG":
        path = "weapon_type.flags"
    else:
        entity.send_output("L'enumerazione %s non è ancora supportata, se serve basta dirlo al coder." % enum_element.enum.name)
        return False

    output = []
    for table_name, goto_input in (("items", "igoto"), ("mobs", "mgoto"), ("players", "goto")):
        counter = 0
        entities = []
        # Crea prima la lista per poi ordinarla
        for target in database[table_name].itervalues():
            attr = getattr_from_path(target, path)
            if attr and enum_element in attr:
                entities.append(target)

        if entities:
            output.append('''<table class="mud">''')
            output.append('''<tr><th>Code:</th><th>Name:</th><th>Short:</th></tr>''')
            for target in sorted(entities, key=operator.attrgetter("code")):
                javascript = '''javascript:parent.sendInput('%sgoto %s');''' % (
                    goto_input, target.keywords_name.split()[0])
                output.append('''<tr>''')
                output.append('''<td><a href="%s">%s</td><td>%s</td>''' % (
                    javascript, target.code, target.name))
                if target.short_night:
                    tooltip = create_tooltip(entity.get_conn(), "ShortNight: %s" % room.short_night, room.short)
                    output.append('''<td><>%s</td>''' % tooltip)
                else:
                    output.append('''<td>%s</td>''' % target.short)
                output.append('''</tr>''')
                counter += 1
            output.append('''</table>''')
            output.append('''Sono stati trovati %s %s con la flag %s\n\n''' % (counter, table_name, enum_element.code))
        else:
            output.append('''Non è stato trovato nessun %s con la flag %s\n\n''' % (table_name[:-1], enum_element.code))

    entity.send_output("".join(output).rstrip())
    return True
Exemplo n.º 33
0
def command_sell(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di vendere entità ai commercianti.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        for dealer in entity.location.iter_contains():
            if dealer.shop and SHOP.DISPENSER in dealer.shop.types:
                entity.act("Cerchi di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer)
                entity.act("$n cerca di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer)
                entity.act("$n cerca di %s qualcosa ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target)
                return False

        entity.send_output("Cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_sell")
            entity.send_output(syntax, break_line=False)
        return False

    # Ricava la quantità da vendere e poi l'eventuale valore facoltativo del negoziante
    quantity, argument = quantity_argument(argument)
    arg, argument = one_argument(argument)

    target = entity.find_entity(arg, quantity=quantity, location=entity)
    if not target:
        entity.act("Non trovi nessun [white]%s[close] da %s nel tuo inventario." % (arg, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sta cercando qualcosa senza trovarla", TO.OTHERS)
        return False

    # Controlla se la quantità da vendere sia sufficente rispetto a quello che si possiede
    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act("Non puoi %s $N perché ne possiedi solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target)
        entity.act("$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target)
        return False

    if argument:
        dealer = entity.find_entity_extensively(argument)
        if not dealer:
            entity.act("Non trovi nessun negoziante chiamato [white]%s[close] a cui %s $N." % (argument, verbs["infinitive"]), TO.ENTITY, target)
            entity.act("$n sembra cercare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target)
            return False
        if not dealer.shop:
            entity.act("$N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.ENTITY, dealer, target)
            entity.act("$n si accorge che $N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.OTHERS, dealer, target)
            entity.act("$n si accorge che tu non sei un negoziante a cui %s $a." % verbs["infinitive"], TO.TARGET, dealer, target)
            return False
    else:
        for dealer in entity.location.iter_contains():
            if dealer.shop:
                break
        else:
            entity.act("Qui non trovi nessun negoziante a cui %s $N." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n non sembra trovare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target)
            return False

    # Controlla se il negoziante si trova in una locazione che fa, per lui, da negozio
    if not dealer.shop.in_location(dealer):
        entity.act("Non puoi %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.ENTITY, dealer)
        entity.act("$n non può %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.OTHERS, dealer)
        entity.act("$n non può %s nulla da te se non ti trovi nel tuo negozio." % verbs["infinitive"], TO.TARGET, dealer)
        return False

    # Indica che un'entità vuole interagire con il dealer
    if entity not in dealer.interactions:
        dealer.interactions.append(entity)

    if FLAG.NO_DROP in target.flags:
        if entity.trust > TRUST.MASTER:
            entity.send_output("{Questa sarebbe in realtà un'entità NO_DROP e potresti venderla}")
        else:
            entity.act("Appena cerchi di %s $a a $N te lo ritrovi, con un balzo, in $hand." % verbs["infinitive"], TO.ENTITY, target, dealer)
            entity.act("Appena $n cerca di %s $a a $N se lo ritrova, con un balzo, in $hand." % verbs["infinitive"], TO.OTHERS, target, dealer)
            entity.act("Appena $n cerca di %s a $a gli ritorni in $hand con un balzo." % verbs["you2"], TO.TARGET, target, dealer)
            entity.act("Appena $n cerca di %s $a questi gli ritorna in $hand con un balzo." % verbs["you2"], TO.TARGET, dealer, target)
            return False

    if not target.is_empty():
        entity.act("Non puoi %s $N a $a perché contiene qualcosa." % verbs["infinitive"], TO.ENTITY, target, dealer)
        entity.act("$n non può %s $N a $a perché contiene qualcosa." % verbs["infinitive"], TO.OTHERS, target, dealer)
        entity.act("$n non può %s a $a perché contieni qualcosa." % verbs["you2"], TO.TARGET, target, dealer)
        entity.act("$n non può %s $a perché contiene qualcosa." % verbs["you2"], TO.TARGET, dealer, target)
        return False

    if SHOP.DISPENSER in dealer.shop.types:
        entity.act("Cerchi di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer, target)
        entity.act("$n cerca di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer, target)
        entity.act("$n cerca di %s $a ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target)
        entity.act("$n cerca di %s a $N ma ciò non è possibile perché è un distributore." % verbs["you2"], TO.TARGET, target, dealer)
        return False

    sellable = dealer.shop.get_sellable(target)
    if not sellable:
        dealer.shop.send_uninterested_messages(entity, target, dealer)
        return False

    if target.value <= 0:
        entity.act("$N guarda senza molto interesse $a: è senza valore!", TO.ENTITY, dealer, target)
        entity.act("$N guarda senza molto interesse $a mostrato da $n: è senza valore.", TO.OTHERS, dealer, target)
        entity.act("Guardi senza molto interesse $a mostrato da $n: è senza valore...", TO.TARGET, dealer, target)
        entity.act("$a ti guarda senza molto interesse: sei senza valore...", TO.TARGET, target, dealer)
        return False

    # I negozianti ora pagano con denaro virtuale, in questa maniera non devono averne apposta addosso
    #if not can_afford(target.value * quantity, dealer):
    #    entity.act("$a vale più di quanto $N possa permettersi di pagarti.", TO.ENTITY, dealer, target)
    #    entity.act("$a vale più di quanto $N possa permettersi di pagare $n.", TO.OTHERS, dealer, target)
    #    entity.act("$a vale più di quanto tu possa permetterti di pagare $n.", TO.TARGET, dealer, target)
    #    entity.act("Vale più di quanto $N possa permettersi di pagare $n.", TO.TARGET, target, dealer)
    #    return False

    storage = dealer.shop.get_storage(dealer)
    if not storage:
        if dealer.shop.proto_storages and dealer.shop.proto_storages[0].IS_MOB:
            from_where = "a chi dare"
        else:
            from_where = "ove mettere"
        entity.act("Non puoi %s nulla a $N perché non ha %s la mercanzia!" % (verbs["infinitive"], from_where), TO.ENTITY, dealer)
        entity.act("$n non può %s nulla a $N perché non ha %s la mercanzia!" % (verbs["infinitive"], from_where), TO.OTHERS, dealer)
        entity.act("$n non può %s nulla perché non hai %s la mercanzia!" % (verbs["you2"], from_where), TO.TARGET, dealer)
        return False

    # Attenzione che qui target non è ancora la quantità giusta
    force_return = check_trigger(entity, "before_sell", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "before_selling", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_sold", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True

    price = math.trunc((target.value * sellable.percent) / 100) * quantity
    pretty_price = pretty_money_value(price, extended=True)
    dealer.shop.send_sell_messages(entity, target, dealer, verbs, quantity, pretty_price)

    dealer.shop.add_buyable(dealer, target, sellable, quantity)
    target = target.from_location(quantity)
    target.to_location(storage)
    give_moneys(dealer, entity, price)

    # Dona un po' di esperienza ai giocatori che hanno venduto per la prima
    # volta l'entità
    if entity.IS_PLAYER:
        if target.prototype.code in entity.selled_entities:
            entity.selled_entities[target.prototype.code] += 1
        else:
            entity.selled_entities[target.prototype.code] = 1
            reason = "per aver venduto per la prima volta %s" % target.get_name(looker=entity)
            entity.give_experience(target.level*10, reason=reason)

    force_return = check_trigger(entity, "after_sell", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "after_selling", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_sold", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 34
0
def command_loop(entity, argument):
    """
    Permette di freezare il loop del gioco. Comodo per disattivare i behaviour
    in fase di test.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        output = []
        output.append(get_command_syntax(entity, "command_loop"))
        output.append('''<table class="mud">''')
        for loop in LOOPS:
            loop_name = loop.__class__.__name__.replace("Loop", "").lower()
            output.append('''<tr><td>Attualmente %s%s</td>''' % ("l'" if is_vowel(loop_name[0]) else "il ", loop_name))
            output.append('''<td>%sè[close] in pausa</td>''' % ("[red]" if loop.paused else "[white]non "))
            output.append('''<td>e%sè[close] stoppato.</td></tr>''' % (" [white]non " if loop.running else "d [red]"))
        output.append('''</table>''')
        output.append('''Ricordo che i reset non fanno parte dei loop, ma di un sistema di deferred separato.''')
        entity.send_output("".join(output))
        return False

    # -------------------------------------------------------------------------

    arg, argument = one_argument(argument)

    for loop in LOOPS:
        loop_name = loop.__class__.__name__.replace("Loop", "").lower()
        if is_prefix(arg, loop_name):
            break
    else:
        entity.send_output("Non esiste nessun loop chiamato [white]%s[close]" % arg)
        return False

    if not argument:
        entity.send_output("Vuoi eseguire una [green]pausa[close] o un [green]continua[close] %s%s?" % (
            "all'" if is_vowel(loop_name[0]) else "al ", loop_name))
        return False

    article = "L'" if is_vowel(loop_name[0]) else "Il "

    if is_prefix(argument, ("pausa", "pause")):
        if loop.paused:
            entity.send_output("%s%s si trova già in pausa." % (article, loop_name))
        else:
            entity.send_output("%s%s ora è stato messo in pausa" % (article, loop_name))
            loop.paused = True
    elif is_prefix(argument, ("continua", "continue")):
        if loop.paused:
            entity.send_output("%s%s ora ricomincerà a girare." % (article, loop_name))
            loop.paused = False
        else:
            entity.send_output("%s%s sta già girando." % (article, loop_name))
    else:
        entity.send_output("[white]%s[close] non è un argomento valido da passare al comando loop." % argument)
        return False

    return True
Exemplo n.º 35
0
def command_use(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di usare un'entità, tenterà di usare il comando relativo all'entità
    e al suo stato.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_use")
            entity.send_output(syntax, break_line=False)
        return False

    original_argument = argument
    arg, argument = one_argument(argument)

    target_for_eat_drink  = entity.find_entity(arg, location=entity)
    target_for_open_close = entity.find_entity_extensively(arg, inventory_pos="last")
    target_for_enter      = entity.find_entity_extensively(arg)
    target_for_read       = entity.find_entity_extensively(arg, inventory_pos="first")
    target_for_remove     = entity.find_equipped_entity(arg, entity)

    target = target_for_eat_drink or target_for_open_close or target_for_enter or target_for_read or target_for_remove
    if not target:
        entity.act("Non trovi nessun [white]%s[close] da %s." % (arg, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sembra cercare qualcosa che non riesce proprio a trovare.", TO.ENTITY)
        return False

    # È voluto che i trigger di use scattino anche su entità che non hanno una
    # struttura di entitype valida, questo per dare la possibilità di inserire
    # trigger su entità qualsiasi in maniera tale da poterle utilizzare per far
    # scattare una qualsiasi cosa usandoli.
    # Ricordo che se in un trigger viene ritornato un valore True il normale
    # flusso di codice viene fermato, ecco cosa serve il force_return.
    force_return = check_trigger(entity, "before_use", entity, target, argument, behavioured)
    if force_return:
        return True

    force_return = check_trigger(target, "before_used", entity, target, argument, behavioured)
    if force_return:
        return True

    # -------------------------------------------------------------------------

    if target_for_open_close and target_for_open_close.entitype == ENTITYPE.CONTAINER and CONTAINER.CLOSABLE in target_for_open_close.container_type.flags:
        if CONTAINER.BOLTED in target_for_open_close.container_type.flags:
            return command_unbolt(entity, original_argument, behavioured=behavioured)
        elif CONTAINER.LOCKED in target_for_open_close.container_type.flags:
            return command_unlock(entity, original_argument, behavioured=behavioured)
        elif CONTAINER.CLOSED in target_for_open_close.container_type.flags:
            return command_open(entity, original_argument, behavioured=behavioured)
        else:
            return command_close(entity, original_argument, behavioured=behavioured)

    elif target_for_open_close and target_for_open_close.entitype == ENTITYPE.DOOR and DOOR.CLOSABLE in target_for_open_close.door_type.flags:
        if DOOR.BOLTED in target_for_open_close.door_type.flags:
            return command_unbolt(entity, original_argument, behavioured=behavioured)
        elif DOOR.LOCKED in target_for_open_close.door_type.flags:
            return command_unlock(entity, original_argument, behavioured=behavioured)
        elif DOOR.CLOSED in target_for_open_close.door_type.flags:
            return command_open(entity, original_argument, behavioured=behavioured)
        else:
            return command_close(entity, original_argument, behavioured=behavioured)

    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.DRINK:
        return command_drink(entity, original_argument, behavioured=behavioured)

    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.FOOD:
        return command_eat(entity, original_argument, behavioured=behavioured)

    # La ricerca del seme nel comando seme è uguale a quella del cibo e delle
    # bevande, ecco perchè viene utilizzato comunque target_for_eat_drink
    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.SEED:
        return command_seed(entity, original_argument, behavioured=behavioured)

    # La ricerca della pianta è uguale a quella del seme più sotto
    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.PLANT:
        return command_plant(entity, original_argument, behavioured=behavioured)

    elif target_for_enter and target_for_enter.entitype == ENTITYPE.PORTAL:
        return command_enter(entity, original_argument, behavioured=behavioured)

    # C'è da notare relativamente al read che con il comando use non è possibile
    # leggere entità dentro altre entità, poco male direi...
    elif target_for_read and target_for_read.entitype == ENTITYPE.READABLE:
        return command_read(entity, original_argument, behavioured=behavioured)

    # Stesse considerazioni dette per il tipo seed
    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.WEAR:
        return command_wear(entity, original_argument, behavioured=behavioured)

    # Stesse considerazioni dette per il tipo seed
    elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.WEAPON:
        return command_wield(entity, original_argument, behavioured=behavioured)

    elif target_for_remove and target_for_remove.entitype == ENTITYPE.WEAR:
        return command_remove(entity, original_argument, behavioured=behavioured)

    #elif target.entitype == ENTITYPE.CORPSE:
    #elif target.entitype == ENTITYPE.FISHING:
    #elif target.entitype == ENTITYPE.FLOWER:
    #elif target.entitype == ENTITYPE.FRUIT:
    #elif target.entitype == ENTITYPE.GROUND:
    #elif target.entitype == ENTITYPE.INSTRUMENT:
    #elif target.entitype == ENTITYPE.KEY:
    #elif target.entitype == ENTITYPE.KEYRING:
    #elif target.entitype == ENTITYPE.MENHIR:
    #elif target.entitype == ENTITYPE.MONEY:

    # -------------------------------------------------------------------------

    entity.act("Non sai proprio come poter %s $N." % verbs["infinitive"], TO.ENTITY, target)
    entity.act("$n non sa proprio come poter %s $N." % verbs["infinitive"], TO.OTHERS, target)
    entity.act("$n non sa proprio come poter %s." % verbs["you2"], TO.TARGET, target)

    # Per saperne di più sul perché questi trigger si trovato a questo livello
    # è bene leggersi il commento in alto relativo agli altri trigger che vale
    # anche per questa coppia
    force_return = check_trigger(entity, "after_use", entity, target, argument, behavioured)
    if force_return:
        return True

    force_return = check_trigger(target, "after_used", entity, target, argument, behavioured)
    if force_return:
        return True

    return False
Exemplo n.º 36
0
def command_drop(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di abbandonare oggetti per terra oppure posarli in un luogo preciso.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if entity.sended_inputs and is_prefix("abbandon",
                                          entity.sended_inputs[-1]):
        verbs = VERBS2

    if not argument:
        entity.send_output("Che cosa vorresti %s." % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_drop")
            entity.send_output(syntax, break_line=False)
        return False

    # Ricava l'eventuale quantità d'oggetti da posare
    quantity, argument = quantity_argument(argument)

    # (TD) Controllo del mental state deviato

    # Ricerca dell'oggetto nell'inventario, non viene utilizzata la extended
    target = entity.find_entity(argument, quantity=quantity, location=entity)
    if not target:
        entity.act(
            "Non riesci a trovare nessun [white]%s[close] da poter %s." %
            (argument, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sembra cercare qualcosa ma senza risultato.", TO.OTHERS)
        return False

    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act(
            "Non puoi %s $N perché ne hai solo %d e non %d." %
            (verbs["infinitive"], target.quantity, quantity), TO.ENTITY,
            target)
        entity.act(
            "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s"
            % verbs["infinitive"], TO.OTHERS, target)
        entity.act(
            "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s"
            % verbs["infinitive"], TO.TARGET, target)
        return False

    if FLAG.NO_DROP in target.flags:
        if entity.trust > TRUST.MASTER:
            entity.send_to_admin(
                "Questa sarebbe in realtà un'entità NO_DROP e non potresti lasciarla"
            )
        else:
            entity.act(
                "Appena cerchi di %s $N te lo ritrovi, con un balzo, in $hand."
                % verbs["infinitive"], TO.ENTITY, target)
            entity.act(
                "Appena $n cerca di %s $N se lo ritrova, con un balzo, in $hand."
                % verbs["infinitive"], TO.OTHERS, target)
            entity.act(
                "\nAppena $n cerca di %s gli ritorni in $hand con un balzo." %
                verbs["you2"], TO.TARGET, target)
            return False

    # Non permette di droppare oggetti nelle stanze con flag di NO_DROP
    if entity.location.IS_ROOM and ROOM.NO_DROP in entity.location.flags:
        if entity.trust > TRUST.MASTER:
            entity.send_to_admin(
                "Questa sarebbe in realtà una stanza NO_DROP in cui non poter lasciar entità"
            )
        else:
            entity.act(
                "Appena %s $N te lo ritrovi in %hand come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!"
                % verbs["you"], TO.ENTITY, target)
            entity.act(
                "Appena $n lascia andare $N, con l'intenzione di %s, se lo ritrova in $hand come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!"
                % verbs["noun"], TO.OTHERS, target)
            entity.act(
                "\nAppena $n ti %s ritorni nella sua $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!"
                % verbs["it"], TO.TARGET, target)
            return False

    # (TD) posare monete

    # (TD) argomento all, ultima cosa da supportare

    # Ricava la locazione in cui posare l'oggetto
    # (TD)
    location = entity.location

    force_return = check_trigger(entity, "before_drop", entity, target,
                                 location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_dropped", entity, target,
                                 location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "before_drop_from_location", entity,
                                 target, location, behavioured)
    if force_return:
        return True

    entity.act("%s $N in $l." % color_first_upper(verbs["you"]), TO.ENTITY,
               target)
    entity.act("$n %s $N in $l." % verbs["it"], TO.OTHERS, target)
    entity.act("$n ti %s in $l." % verbs["it"], TO.TARGET, target)
    if not location.IS_ROOM:
        entity.act("$n ti %s qualcosa." % verbs["it"], TO.TARGET, location)

    if FLAG.INGESTED in target.flags:
        if entity.trust >= TRUST.MASTER:
            entity.send_to_admin("%s %s anche se lo stai digerendo." %
                                 (verbs["you"], target.get_name(entity)))
        else:
            log.bug(
                "I giocatori non dovrebbero poter manipolare oggetti ingeriti")
            entity.send_output(
                "[cyan]Errore di digestione nel comando, gli amministratori sono stati avvertiti del problema.[close]"
            )
            return False
        target.stop_digestion()

    target = target.from_location(quantity, use_repop=True)
    target.to_location(location)

    force_return = check_trigger(entity, "after_drop", entity, target,
                                 location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_dropped", entity, target,
                                 location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "after_drop_from_location", entity,
                                 target, location, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 37
0
def command_unbolt(entity, argument="", verbs=VERBS, behavioured=False, container_only=False):
    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

    # -------------------------------------------------------------------------

    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_unbolt")
            entity.send_output(syntax)
        return False

    target = entity.find_entity_extensively(argument, inventory_pos="last")
    if not target or (target.is_secret_door() and len(argument) < config.min_secret_arg_len):
        entity.act("Cerchi di %s %s che però non riesci a trovare." % (verbs["infinitive"], argument), TO.ENTITY)
        entity.act("$n cerca qualcosa che non sembra riuscire a trovare.", TO.OTHERS)
        return False

    # Nel caso che la porta, nel lato della stanza in cui si trova entity, sia
    # già aperta prova a controllare l'eventuale porta dall'altro lato, ma solo
    # se si tratta di una porta asincrona
    if (target.door_type and DOOR.CLOSED not in target.door_type.flags
    and DOOR.ASYNCHRONOUS in target.door_type.flags):
        reverse_target = entity.find_entity_extensively(argument, direct_search=False)
        if reverse_target:
            target = reverse_target

    if not target.door_type and not target.container_type:
        if entity == target:
            entity.act("Cerchi di %s te stess$o, senza molto successo..." % verbs["infinitive"], TO.ENTITY)
            entity.act("$n cerca di %s sé stess$o, senza molto successo..." % verbs["infinitive"], TO.OTHERS)
        else:
            entity.act("Cerchi di %s $N, ma non trovi modo di farlo." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, ma non sembra trovare modo di farlo." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, ma non sembra trovare modo di farlo." % verbs["you2"], TO.TARGET, target)
        return False

    if container_only and not target.container_type and target.door_type:
        entity.act("Cerchi di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, ma non sembra essere un contenitore." % verbs["you2"], TO.TARGET, target)
        return False

    if container_only:
        entitype_priority = "container"
    else:
        entitype_priority = target.get_open_close_priority()
    if entitype_priority != "door" and entitype_priority != "container":
        log.bug("entitype_priority è un valore errato: %s" % entitype_priority)
        return False

    if entitype_priority == "door":
        if not target.is_hinged():
            entity.act("Come puoi %s $N se si trova fuori dai cardini?" % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, sarà un po' dura visto che non si trova sui cardini." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, sarà un po' dura visto che non ti trovi sui cardini..." % verbs["you2"], TO.TARGET, target)
            return False

        if DOOR.BASHED in target.door_type.flags:
            entity.act("Cerchi di %s $N, ma l$O trovi sfondat$O." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, ma l$O trova sfondat$O." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, ma ti trova sfondat$O." % verbs["you2"], TO.TARGET, target)
            return False

        entitype = target.door_type
        # (TD) queste flag spostarle nei vari entitype
        closed_flag   = DOOR.CLOSED
        locked_flag   = DOOR.LOCKED
        boltable_flag = DOOR.BOLTABLE
        bolted_flag   = DOOR.BOLTED

        destination, direction = get_destination_room_from_door(entity, target)
        if destination:
            reverse_destination = destination.get_destination(direction.reverse_dir)
            if reverse_destination:
                reverse_destination_room = reverse_destination.get_room()
                if entity.location != reverse_destination_room:
                    destination = None
                    direction = DIR.NONE
    else:
        entitype = target.container_type
        closed_flag   = CONTAINER.CLOSED
        locked_flag   = CONTAINER.LOCKED
        boltable_flag = CONTAINER.BOLTABLE
        bolted_flag   = CONTAINER.BOLTED
        destination = None  # (TD) supportarlo
        direction = None

    if entitype_priority == "container" and CONTAINER.BOLTABLE  not in entitype.flags:
        entity.act("Cerchi di %s $N, ma ti è impossibile." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, ma $gli è impossibile" % verbs["infinitive"], TO.OTHERS, target)
        if destination:
            entity.act("Qualcuno, dall'altra parte, cerca di %s $N, ma gli è impossibile." % (
                verbs["infinitive"]), TO.OTHERS, target, send_to_location=destination)
        entity.act("$n cerca di %s, ma $gli è impossibile." % verbs["you2"], TO.TARGET, target)
        return False

    if boltable_flag in entitype.flags and bolted_flag not in entitype.flags:
        entity.act("Cerchi di %s $N, ma l$O trovi già svincolat$O." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, ma l$O trova già svincolat$O." % verbs["infinitive"], TO.OTHERS, target)
        if destination:
            entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova già svincolat$O." % (
                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
        entity.act("$n cerca di %s, ma ti trova già svincolat$O." % verbs["you2"], TO.TARGET, target)
        return False

###    if locked_flag in entitype.flags:
###        entity.act("Cerchi di %s $N, ma scopri che è già chius$O a chiave." % verbs["infinitive"], TO.ENTITY, target)
###        entity.act("$n cerca di %s $N, scoprendo che è già chius$O a chiave." % verbs["infinitive"], TO.OTHERS, target)
###        if destination:
###            entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è già chius$O a chiave." % (
###                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
###        entity.act("$n cerca di %s , scoprendo che sei già chius$O a chiave." % verbs["you2"], TO.TARGET, target)
###        return False

##
##    if bolted_flag in entitype.flags:
##        entity.act("Cerchi di %s $N, ma scopri che è chius$O con $a." % verbs["infinitive"], TO.ENTITY, target, entitype.bolt)
##        entity.act("$n cerca di %s $N, scoprendo che è chius$O con $a." % verbs["infinitive"], TO.OTHERS, target, entitype.bolt)
##        if destination:
##            entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è chius$O con $a." % (
##                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, entitype.bolt, send_to_location=destination)
##        entity.act("$n cerca di %s, scoprendo che sei chius$O con $a." % verbs["you2"], TO.TARGET, target, entitype.bolt)
##        return False

#    key = None
#    if entitype.key_code:
#        for generic_key in entity.iter_contains():
#            if not entity.can_see(generic_key):
#                continue
#            if generic_key.prototype.code == entitype.key_code:
#                key = entitype.key_code
#
#    if not entitype.key_code or not key:
#        entity.act("Cerchi di %s $N, ma non riesci a trovarne la chiave." % verbs["infinitive"], TO.ENTITY, target)
#        entity.act("$n cerca di %s $N, armeggindo inutilmente." % verbs["infinitive"], TO.OTHERS, target)
#        entity.act("$n cerca di %s, ma non vi riesce perché non ha la chiave." % verbs["you2"], TO.TARGET, target)
#        if destination:
#            entity.act("Qualcuno, dall'altra parte, armeggia inutilmente sulla serratura ma non riesce a %s $N %s." % (
#                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
#        return False

    reverse_target = None
    if destination and entitype_priority == "door" and DOOR.ASYNCHRONOUS not in entitype.flags:
        reverse_target = target.location.get_door(direction, direct_search=False)

    force_return = check_trigger(entity, "before_unbolt", entity, target, reverse_target, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_unbolted", entity, target, reverse_target, behavioured)
    if force_return:
        return True

    entitype.send_unbolt_messages(entity, target, verbs, direction, destination)
    entitype.flags -= bolted_flag
    if reverse_target and reverse_target.door_type:
        reverse_target.door_type.flags -= bolted_flag

    # Serve a cambiare lo status della porta o del contenitore tramite il
    # meccanismo di repop allo stato originario
    if target.repop_later:
        target.deferred_repop = target.repop_later.defer_check_status()
    if reverse_target and reverse_target.repop_later:
        reverse_target.deferred_repop = reverse_target.repop_later.defer_check_status()

    # Dona un po' di esperienza ai giocatori che hanno svincolato per la prima
    # volta l'entità
    if entity.IS_PLAYER:
        if target.prototype.code in entity.unbolted_entities:
            entity.unbolted_entities[target.prototype.code] += 1
        else:
            entity.unbolted_entities[target.prototype.code] = 1
            reason = "per aver svincolato per la prima volta %s" % target.get_name(looker=entity)
            entity.give_experience(target.level*10, reason=reason)

    force_return = check_trigger(entity, "after_unbolt", entity, target, reverse_target, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_unbolted", entity, target, reverse_target, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 38
0
def command_countraces(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    only_items = False

    if not argument:
        syntax = get_command_syntax(entity, "command_countraces")
        entity.send_output(syntax, break_line=False)
    else:
        arg, argument = one_argument(argument)
        if is_same(arg, "items") or (argument and is_same(argument, "items")):
            only_items = True

    if only_items:
        attr_suffix = "items"
    else:
        attr_suffix = "mobs"

    counter = {}
    counter["totale"] = EnumElementDict()
    for area in database["areas"].itervalues():
        counter[area] = EnumElementDict()
        targets = getattr(area, attr_suffix)
        for target in targets:
            if target.race == RACE.NONE:
                continue
            if target.race not in counter[area]:
                counter[area][target.race] = 0
            counter[area][target.race] += 1
            if target.race not in counter["totale"]:
                counter["totale"][target.race] = 0
            counter["totale"][target.race] += 1

    if only_items:
        entity.send_output(
            "\nLista del numero di razze degli oggetti suddivisi per area.",
            break_line=False)
    else:
        entity.send_output(
            "\nLista del numero di razze dei mob suddivisi per area.",
            break_line=False)

    output = []
    for area in counter:
        if not counter[area] or area == "totale":
            continue
        output.append('''<br>[%s]%s[close] (%s):''' %
                      (area.color.web_name, area.name, area.code))
        output.append('''<table class="mud" style="width:75%">''')
        for race_element in RACE.elements:
            if race_element not in counter[area]:
                continue
            output.append(
                '''<tr><td style="width:33%%">%s</td><td style="width:33%%">%s</td><td>%d</td></tr>'''
                %
                (race_element.code, race_element, counter[area][race_element]))
        output.append('''</table>''')

    if output:
        output.append('''<br>[white]Gran Totale[close]:''')
        output.append('''<table class="mud" style="width:75%">''')
        for race_element in RACE.elements:
            if race_element not in counter["totale"]:
                continue
            output.append(
                '''<tr><td style="width:33%%">%s</td><td style="width:33%%">%s</td><td>%d</td></tr>'''
                % (race_element.code, race_element,
                   counter["totale"][race_element]))
        output.append('''</table>''')
        entity.send_output("".join(output))
    else:
        entity.send_output('''<br>Nessuna!''')

    return True
Exemplo n.º 39
0
def send_note(entity, argument, command_name, note_type, note_singular,
              note_plural, note_class, grammar_genre):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # argument può essere una stringa vuota

    if not command_name:
        log.bug("command_name non è un parametro valido: %r" % command_name)
        return False

    if not note_type:
        log.bug("note_type non è un parametro valido: %r" % note_type)
        return False

    if not note_singular:
        log.bug("note_singular non è un parametro valido: %r" % note_singular)
        return False

    if not note_class:
        log.bug("note_class non è un parametro valido: %r" % note_class)
        return False

    if not grammar_genre:
        log.bug("grammar_genre non è un parametro valido: %r" % grammar_genre)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, command_name)
        entity.send_output(syntax, break_line=False)
        return False

    if not entity.IS_PLAYER:
        entity.send_output(
            "Solo i giocatori possono inviare %s." %
            (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                         GRAMMAR.SINGULAR)))
        return False

    if config.max_account_typos == 0:
        entity.send_output(
            "L'invio %s è stata disabilitata." %
            (add_article(note_plural, grammar_genre, GRAMMAR.INDETERMINATE,
                         GRAMMAR.PLURAL)))
        return False

    # Non dovrebbe mai capitare, ma non si sa mai, in teoria comunque non è un baco
    if not entity.account:
        entity.send_output(
            "La sessione del tuo account è scaduta, devi riaccedere nuovamente al sito per poter inviare %s"
            % (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                           GRAMMAR.SINGULAR)))
        return False

    # Anche questa non dovrebbe mai capitare
    if not entity.location:
        entity.send_output(
            "Ti è impossibile inviare %s da questo luogo." %
            (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                         GRAMMAR.SINGULAR)))
        log.bug(
            "entity.location non è valido (%r) per entity %s mentre stava cercando di inviare una nota %s"
            % (entity.location, entity.code, note_type))
        return False

    # Crea il codice per la nota
    code_to_check = entity.account.name + "#"
    sended_notes = getattr(entity.account, "sended_%ss" % note_type)
    code = code_to_check + str(sended_notes)

    # Se il codice già esiste nel database probabilmente c'è una dicrepanza
    # tra il dato di account e quelli delle note quindi il codice si
    # incrementa fino a trovare un numero libero
    counter = 1
    while code in database[note_type + "s"]:
        code = code_to_check + str(sended_notes + counter)
        setattr(entity.account, "sended_%ss" % note_type,
                sended_notes + counter + 1)
        counter += 1

    who = entity.code
    if entity.IS_PLAYER and entity.account:
        who += " dell'account %s" % entity.account.name
    if entity.location.IS_ROOM:
        where = "%s (%r)" % (entity.location.code,
                             entity.location.get_destination())
    else:
        where = "%s in %r  " % (entity.location.get_name(),
                                entity.get_in_room.get_destination())
    when = "%s (%s %s %s %s)" % (datetime.datetime.now(), calendar.minute,
                                 calendar.hour, calendar.day, calendar.month)

    note = note_class(code, who, where, when, argument)
    if not note:
        log.bug("note non è valido (%r) per la tipologia %s" %
                (note, note_type))
        entity.send_output(
            "Impossibile segnalare un%s nuov%s %s." %
            ("" if grammar_genre == GRAMMAR.MASCULINE else "a", "o"
             if grammar_genre == GRAMMAR.MASCULINE else "a", note_singular))
        return False

    # Evitare di inviare una nota subito dopo averne inviata un'altra,
    # così da evitare eventuali spammer
    last_note_sended_at = getattr(entity.account,
                                  "last_%s_sended_at" % note_type)
    if (datetime.datetime.now() - last_note_sended_at).days <= 0:
        # (TD) Python 2.7, così non servirà più il check su days
        #total_seconds = (datetime.datetime.now() - last_note_sended_at).total_seconds()
        total_seconds = (datetime.datetime.now() - last_note_sended_at).seconds
        if total_seconds < config.sending_interval:
            remaining_seconds = config.sending_interval - total_seconds
            random_id = random.random()
            entity.send_output(
                '''Potrai inviare %s solo tra <span id="%s">%d %s</span><script>parent.countdown("%s");</script>'''
                %
                (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                             GRAMMAR.SINGULAR, GRAMMAR.POSSESSIVE), random_id,
                 remaining_seconds, "secondo"
                 if remaining_seconds == 1 else "secondi", random_id))
            return False

    # Inserisce un tetto massimo di note ancora aperte inviabili contando se
    # effettivamente le note dell'account ancora aperte sono così tante
    counter = 0
    for note_code in database[note_type + "s"]:
        if note_code.startswith(code_to_check):
            counter += 1
    if counter >= getattr(config, "max_account_%ss" % note_type):
        entity.send_output(
            "Hai raggiunto il massimo di %s attualmente segnalabili, riprova tra qualche minuto."
            % (note_plural, config.game_name))
        log.monitor(
            "%s ha raggiunto il numero massimo di %s inviabili, controllare e chiudere quelle obsolete cosicché possa inviarne delle altre.",
            (entity.code, note_plural))
        return False

    # Controlla che le altre note non abbiano lo stesso testo, altrimenti ci
    # troviamo davanti ad un possibile spammer, il sistema quindi fa finta
    # di salvarsi la nota e intanto segnala agli Amministratori lo spammer
    for other_note in database[note_type + "s"].itervalues():
        if other_note.text == argument and other_note.code.startswith(
                code_to_check):
            entity.send_output("%s è stato salvato. Grazie!" % (add_article(
                note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                GRAMMAR.SINGULAR, GRAMMAR.POSSESSIVE).capitalize()))
            log.warning(
                "Qualcuno per sbaglio invia due volte la stessa nota %s. Se continua esageratemente è un possibile spammer (%s)"
                % (note_singular, entity.get_conn().get_id()))
            return False

    database[note_type + "s"][note.code] = note

    # Le note sono uno di quei dati slegati dal gioco che possono essere
    # scritti subito sul disco vista la relativa rarità del suo invio e quindi
    # la bassa probabilità che vada ad inficiare sulle prestazioni globali
    note_path = "data/%ss/%s.dat" % (note_type, note.code)
    try:
        note_file = open(note_path, "w")
    except IOError:
        entity.send_output(
            "Per un errore interno al server è impossibile salvare %s." %
            (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                         GRAMMAR.SINGULAR, GRAMMAR.POSSESSIVE)))
        log.bug("Impossibile aprire il file %s in scrittura" % note_path)
        return False
    fwrite(note_file, note)
    note_file.close()

    # Poiché è stato salvata la nota bisogna anche salvare l'account che
    # contiene il numero di note inviate da sempre incrementato giusto qui
    # (TT) Bisogna fare attenzione al salvataggio facile dell'account,
    # potrebbero in futuro esservi informazioni duplicate o erroneamente
    # incrementate (dopo un crash) a seconda delle dipendenze tra i dati
    # nell'account ed altre tipologie di dati che non verrebbero salvate
    # se non alla chisura del Mud
    setattr(entity.account, "sended_%ss" % note_type, sended_notes + 1)
    setattr(entity.account, "last_%s_sended_at" % note_type,
            datetime.datetime.now())
    account_path = "persistence/accounts/%s.dat" % entity.account.name
    try:
        account_file = open(account_path, "w")
    except IOError:
        entity.send_output(
            "Per un errore interno al server è impossibile salvare %s." %
            (add_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                         GRAMMAR.SINGULAR, GRAMMAR.POSSESSIVE)))
        log.bug("Impossibile aprire il file %s in scrittura" % account_path)
        return False
    fwrite(account_file, entity.account)
    account_file.close()

    entity.send_output("Hai appena segnalato %s%d° %s. Grazie!" % (get_article(
        note_singular, grammar_genre, GRAMMAR.DETERMINATE, GRAMMAR.SINGULAR,
        GRAMMAR.POSSESSIVE), sended_notes + 1, note_singular))

    # Invia la mail
    subject = "Invio %s" % note_singular
    text = "L'account %s ha appena segnalato %s%d° %s." % (
        entity.account.name,
        get_article(note_singular, grammar_genre, GRAMMAR.DETERMINATE,
                    GRAMMAR.SINGULAR), sended_notes + 1, note_singular)
    text += "\nWho: %s" % note.who
    text += "\nWhere: %s" % note.where
    text += "\nWhen: %s" % note.when
    text += "\nText: %s" % note.text

    mail.send_to_admins(subject, text, show_players=False)
    return True
Exemplo n.º 40
0
def command_tell(entity, argument=""):
    """
    Permette di parlare con tutti nel Mud, in maniera off-gdr.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        entity.send_output("Vuoi %s a qualcuno che cosa?" % CHANNEL.TELL)
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_tell")
            entity.send_output(syntax, break_line=False)
        return False

    # Qui per la ricerca di target non viene utilizzata la find_entity perché
    # deve cercare solo i giocatori online
    # (TD) oltre alla ricerca di admin che possiedono mob o oggetti
    arg, argument = one_argument(argument)
    target = search_for_player(entity, arg)
    if not target:
        # (TD) se non è stato tovato allora cerca tra gli identificativi
        # personali relativi ai personaggi invisibili (implementazione
        # alternativa del reply)
        entity.send_output(
            "Non è stato trovato nessun giocatore con argomento [white]%s[close]"
            % arg)
        return False

    # (TD) possibile implementazione di NOTELL, anche se è preferibile punizione
    # classica di NO_ENTER_IN_GAME per tot giorni

    if entity == target:
        entity.send_output("Non puoi comunicare con [white]te stess$o[close]!")
        return False

    if not target.game_request:
        entity.send_output(
            "Il giocatore [white]%s[close] è attualmente [darkslategray]offline[close]."
            % target.name)
        return False

    if not argument:
        entity.send_output(
            "Che messaggio privato vorresti inviare a [white]%s[close]?" %
            target.name)
        return False

    channel_color = get_first_color(str(CHANNEL.TELL))

    afk_status = ""
    if FLAG.AFK in target.flags:
        if entity.account and OPTION.ITALIAN in entity.account.options:
            afk_status = " (LDT)"
        else:
            afk_status = " (AFK)"

    if is_vowel(remove_colors(target.name)[0]):
        preposition = "ad"
    else:
        preposition = "a"

    entity.send_output("%s %s%s[close] %s: %s'%s'" %
                       (CHANNEL.TELL.verb_you, channel_color, preposition,
                        target.name, afk_status, argument),
                       avoid_snoop=True)
    # (TD) inviare anche il soft beep per avvertire che ha ricevuto un messaggio
    # ed aggiungere l'opzione apposita
    if target.get_conn().get_browser():
        numbered_keyword = entity.get_numbered_keyword(looker=target)
        javascript = '''javascript:putInput('%s %s ');''' % (translate_input(
            target, "tell", "en"), numbered_keyword)
        target.send_output("""\n<a href="%s">%s%s ti[close]%s</a>: '%s'""" %
                           (javascript, entity.name, channel_color,
                            CHANNEL.TELL.verb_it, argument),
                           avoid_snoop=True)
    else:
        target.send_output(
            """\n%s %sti[close]%s: '%s'""" %
            (entity.name, channel_color, CHANNEL.TELL.verb_it, argument),
            avoid_snoop=True)
    target.send_prompt()

    return True
Exemplo n.º 41
0
def command_force(entity, argument=""):
    """
    Forza l'esecuzione di un comando da parte di un'altra entità.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_force")
        entity.send_output(syntax, break_line=False)
        return False

    arg1, argument = one_argument(argument)
    target = entity.find_entity_extensively(arg1, inventory_pos="first")
    if not target:
        target = entity.find_entity_extensively(arg1)
        if not target:
            entity.send_output("Nessuna entità trovata con argomento [white]%s[close]" % arg1)
            return False

    arg2, argument = one_argument(argument)
    if not arg2:
        entity.send_output("Che comando vorresti [red]forzare[close] a %s?" % target.get_name(entity))
        return False

    input, huh_input, input_lang = multiple_search_on_inputs(entity, arg2)
    if not input:
        entity.send_output("L'argomento %s non è relativo ad un comando valido." % arg2)
        return False

    if input.command and input.command.fun_name == "command_force":
        entity.send_output("Non puoi forzare un force.")
        return False

    translated_input = translate_input(target, arg2, input_lang)
    if not translated_input:
        entity.send_output("Non è stato possibile tradurre l'input %s per %s (lingua originale: %s)" % (
            arg2, target.get_name(entity), input_lang))
        return False

    target.send_output("\n")
    execution_result = interpret(target, "%s %s" % (translated_input, argument), force_position=True, show_input=False)
    if not execution_result:
        if target == entity:
            entity.send_output("\nL'esecuzione dell'input [limegreen]%s[close] forzato su di [white]te stess%c[close] non è andata a buon fine." % (
                arg2, grammar_gender(entity)))
        else:
            entity.send_output("\nL'esecuzione dell'input %s forzato su di %s non è andata a buon fine." % (
                arg2, target.get_name(entity)))
            if not entity.incognito:
                target.send_output("\n%s ti ha forzato a fare qualcosa." % entity.get_name(target))
            log.admin("%s ha cercato di forzare %s a fare: %s %s" % (entity.name, target.name, arg2, argument))
        return False

    if target == entity:
        message = "\n" + format_for_admin("Il force dell'input [green]%s[close] su [white]te stess%c[close] sembra essere andato a buon fine." % (
            arg2, grammar_gender(entity)))
        entity.send_output(message)
    else:
        message = "\n" + format_for_admin("Il force dell'input [green]%s[close] su di %s sembra andato a buon fine." % (
            arg2, target.get_name(entity)))
        entity.send_output(message)
        if not entity.incognito:
            target.send_output("\n%s ti ha forzato a fare qualcosa." % entity.get_name(target))
        log.admin("%s ha forzato %s a fare: %s %s" % (entity.name, target.name, arg2, argument))

    return True
Exemplo n.º 42
0
def command_tell(entity, argument=""):
    """
    Permette di parlare con tutti nel Mud, in maniera off-gdr.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        entity.send_output("Vuoi %s a qualcuno che cosa?" % CHANNEL.TELL)
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_tell")
            entity.send_output(syntax, break_line=False)
        return False

    # Qui per la ricerca di target non viene utilizzata la find_entity perché
    # deve cercare solo i giocatori online
    # (TD) oltre alla ricerca di admin che possiedono mob o oggetti
    arg, argument = one_argument(argument)
    target = search_for_player(entity, arg)
    if not target:
        # (TD) se non è stato tovato allora cerca tra gli identificativi
        # personali relativi ai personaggi invisibili (implementazione
        # alternativa del reply)
        entity.send_output("Non è stato trovato nessun giocatore con argomento [white]%s[close]" % arg)
        return False

    # (TD) possibile implementazione di NOTELL, anche se è preferibile punizione
    # classica di NO_ENTER_IN_GAME per tot giorni

    if entity == target:
        entity.send_output("Non puoi comunicare con [white]te stess$o[close]!")
        return False

    if not target.game_request:
        entity.send_output("Il giocatore [white]%s[close] è attualmente [darkslategray]offline[close]." % target.name)
        return False

    if not argument:
        entity.send_output("Che messaggio privato vorresti inviare a [white]%s[close]?" % target.name)
        return False

    channel_color = get_first_color(str(CHANNEL.TELL))

    afk_status = ""
    if FLAG.AFK in target.flags:
        if entity.account and OPTION.ITALIAN in entity.account.options:
            afk_status = " (LDT)"
        else:
            afk_status = " (AFK)"

    if is_vowel(remove_colors(target.name)[0]):
        preposition = "ad"
    else:
        preposition = "a"

    entity.send_output("%s %s%s[close] %s: %s'%s'" % (
        CHANNEL.TELL.verb_you, channel_color, preposition, target.name, afk_status, argument), avoid_snoop=True)
    # (TD) inviare anche il soft beep per avvertire che ha ricevuto un messaggio
    # ed aggiungere l'opzione apposita
    if target.get_conn().get_browser():
        numbered_keyword = entity.get_numbered_keyword(looker=target)
        javascript = '''javascript:putInput('%s %s ');''' % (translate_input(target, "tell", "en"), numbered_keyword)
        target.send_output("""\n<a href="%s">%s%s ti[close]%s</a>: '%s'""" % (javascript, entity.name, channel_color, CHANNEL.TELL.verb_it, argument), avoid_snoop=True)
    else:
        target.send_output("""\n%s %sti[close]%s: '%s'""" % (entity.name, channel_color, CHANNEL.TELL.verb_it, argument), avoid_snoop=True)
    target.send_prompt()

    return True
Exemplo n.º 43
0
def command_lock(entity, argument="", verbs=VERBS, behavioured=False, container_only=False):
    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

    # -------------------------------------------------------------------------

    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, command_lock)
            entity.send_output(entity, "command_lock", break_line=False)
        return False

    target = entity.find_entity_extensively(argument, inventory_pos="last")
    if not target:
        entity.act("Cerchi di %s %s che però non riesci a trovare." % (verbs["infinitive"], argument), TO.ENTITY)
        entity.act("$n cerca qualcosa che non sembra riuscire a trovare.", TO.OTHERS)
        return False

    # Nel caso che la porta, nel lato della stanza in cui entity si trova, sia
    # già chiusa NON prova a controllare l'eventuale porta dall'altro lato, come
    # invece succede col comando open, perché sarebbe impossibile da raggiungere

    if not target.door_type and not target.container_type:
        if entity == target:
            entity.act("Cerchi di %s te stess$o, senza molto successo..." % verbs["infinitive"], TO.ENTITY)
            entity.act("$n cerca di %s sé stess$o, senza molto successo..." % verbs["infinitive"], TO.OTHERS)
        else:
            entity.act("Cerchi di %s $N, ma non trovi modo di farlo." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, ma non sembra trovare modo di farlo." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, ma non sembra trovare modo di farlo." % verbs["you2"], TO.TARGET, target)
        return False

    if container_only and not target.container_type and target.door_type:
        entity.act("Cerchi di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, ma non sembra essere un contenitore." % verbs["you2"], TO.TARGET, target)
        return False

    if container_only:
        entitype_priority = "container"
    else:
        entitype_priority = target.get_open_close_priority()
    if entitype_priority != "door" and entitype_priority != "container":
        log.bug("entitype_priority è un valore errato: %s" % entitype_priority)
        return False

    if entitype_priority == "door":
        if not target.is_hinged():
            entity.act("Come puoi %s $N se si trova fuori dai cardini?" % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, sarà un po' dura visto che non si trova sui cardini." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, sarà un po' dura visto che non ti trovi sui cardini..." % verbs["you2"], TO.TARGET, target)
            return False

        if DOOR.BASHED in target.door_type.flags:
            entity.act("Cerchi di %s $N, ma l$O trovi sfondat$O." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, ma l$O trova sfondat$O." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, ma ti trova sfondat$O." % verbs["you2"], TO.TARGET, target)
            return False

        entitype      = target.door_type
        bolted_flag   = DOOR.BOLTED
        locked_flag   = DOOR.LOCKED
        closed_flag   = DOOR.CLOSED
        closable_flag = DOOR.CLOSABLE

        destination, direction = get_destination_room_from_door(entity, target)
        # Se c'è una stanza di destinazione al di là della porta allora controlla
        # che da quella stanza sia possibile arrivare a questa, altrimenti non fa
        # visualizzare i messaggi remoti
        if destination:
            reverse_destination = destination.get_destination(direction.reverse_dir)
            if reverse_destination:
                reverse_destination_room = reverse_destination.get_room()
                if entity.location != reverse_destination_room:
                    destination = None
                    direction = DIR.NONE
    else:
        entitype      = target.container_type
        bolted_flag   = CONTAINER.BOLTED
        locked_flag   = CONTAINER.LOCKED
        closed_flag   = CONTAINER.CLOSED
        closable_flag = CONTAINER.CLOSABLE
        destination   = None  # (TD) supportarlo
        direction     = None

    #if closed_flag not in entitype.flags:
    #    entity.act("Cerchi di %s $N, ma l$O trovi apert$O." % verbs["infinitive"], TO.ENTITY, target)
    #    entity.act("$n cerca di %s $N, ma l$O trova apert$O." % verbs["infinitive"], TO.OTHERS, target)
    #    entity.act("$n cerca di %s, ma ti trova apert$O." % verbs["you2"], TO.TARGET, target)
    #    if destination:
    #        entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova apert$O." % (
    #            verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
    #    return False

### qui invece è ideale ma manca sapere se c'è la sua key
#    if closed_flag in entitype.flags and locked_flag not in entitype.flags:
#        entity.act("Cerchi di %s $N, ma l$O trovi già chius$O." % verbs["infinitive"], TO.ENTITY, target)
#        entity.act("$n cerca di %s $N, ma l$O trova già chius$O." % verbs["infinitive"], TO.OTHERS, target)
#        entity.act("$n cerca di %s, ma ti trova già chius$O." % verbs["you2"], TO.TARGET, target)
#        if destination:
#            entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova già chius$O." % (
#                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
#        return True
#        ##return False

    # (TD) forse qui è come il test del locked sotto, oppure devo aggiungere
    # una flag che mi indichi se il bolt permetta o meno di chiudere la porta
#    if bolted_flag in entitype.flags:
#        entity.act("Cerchi di %s $N, scopri che è già chius$O con $a." % verbs["infinitive"], TO.ENTITY, target, entitype.bolt)
#        entity.act("$n cerca di %s $N, scoprendo che è già chius$O con $a." % verbs["infinitive"], TO.OTHERS, target, entitype.bolt)
#        entity.act("$n cerca di %s, scoprendo che sei già chius$O con $a." % verbs["you2"], TO.TARGET, target, entitype.bolt)
#        if destination:
#            entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è già chius$O con $a." % (
#                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
#        return False

    if locked_flag in entitype.flags:
        entity.act("Cerchi di %s $N, ma non vi riesci perché lo è già." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, ma per qualche motivo non ci riesce." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, ma non vi riesce perché lo sei già." % verbs["you2"], TO.TARGET, target)
        if destination:
            entity.act("Qualcuno, dall'altra parte, non riesce a %s $N %s perché lo è già." % (
                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
        return False

    if closable_flag not in entitype.flags:
        entity.act("Non ti è possibile %s $N." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n fa gesto di voler %s $N, ma gli è impossibile." % verbs["infinitive"], TO.OTHERS, target)
        if destination:
            entity.act("Qualcuno, dall'altra parte, cerca di %s $N, scoprendo che gli è impossibile." % (
                verbs["infinitive"]), TO.OTHERS, target, send_to_location=destination)
        entity.act("$n fa gesto di volerti %s, ma gli è impossibile." % verbs["infinitive"], TO.TARGET, target)
        return False

    key = None
    if entitype.key_code:
        for generic_key in entity.iter_contains():
            if generic_key.IS_PLAYER:
                continue
            if not entity.can_see(generic_key):
                continue
            if generic_key.prototype.code == entitype.key_code:
                 key = entitype.key_code

    if entitype.key_code == "" or not key:
        entity.act("Cerchi di %s $N, ma non riesci a trovarne la chiave." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N, armeggindo inutilmente." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, ma non vi riesce perché non ha la chiave." % verbs["you2"], TO.TARGET, target)
        if destination:
            entity.act("Qualcuno, dall'altra parte, armeggia inutilmente sulla serratura ma non riesce a %s $N %s." % (
                verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination)
        return False

    force_return = check_trigger(entity, "before_lock", entity, target, reverse_target, key, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_locked", entity, target, reverse_target, key, behavioured)
    if force_return:
        return True

    reverse_target = None
    if destination and entitype_priority == "door" and DOOR.ASYNCHRONOUS not in target.door_type.flags:
        reverse_target = target.location.get_door(direction, direct_search=False)

    entitype.send_lock_messages(entity, target, verbs, direction, destination)
    entitype.flags += locked_flag
    if reverse_target and reverse_target.door_type:
        reverse_target.door_type.flags += locked_flag

    # Serve a cambiare lo status della porta o del contenitore tramite il
    # meccanismo di repop allo stato originario
    if target.repop_later:
        target.deferred_repop = target.repop_later.defer_check_status()
    if reverse_target and reverse_target.repop_later:
        reverse_target.deferred_repop = reverse_target.repop_later.defer_check_status()

    force_return = check_trigger(entity, "after_lock", entity, target, reverse_target, key, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_locked", entity, target, reverse_target, key, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 44
0
def command_wield(entity, argument="", verbs=VERBS, behavioured=False, command_name="wield"):
    """
    Permette di prendere un oggetto nella mano secondaria o, se quest'ultima
    è occupata, in quella primaria.
    """
    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

    if command_name not in ("wield", "hold"):
        log.bug("command_name non è un parametro valido: %r" % command_name)
        return False

    # -------------------------------------------------------------------------

    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_wield")
            entity.send_output(syntax, break_line=False)
        return False

    # (TD) Controllo sul mental state dell'entità

    target = entity.find_entity(argument, location=entity)
    if not target:
        entity.act("Non riesci a trovare nessun [white]%s[close] da %s." % (argument, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sembra voler %s qualcosa che non trova." % verbs["infinitive"], TO.OTHERS)
        return False

    if target == entity:
        entity.act("Cerchi di %s da sol$o... impossibile!" % verbs["you2_min"], TO.ENTITY)
        entity.act("$n cerca di %s da sol$o... sarà dura!" % verbs["self_min"], TO.OTHERS)
        return False

    if FLAG.NO_HOLD in target.flags:
        if entity.trust >= TRUST.MASTER:
            entity.send_to_admin("Raccogli l'oggetto anche se è NO_HOLD")
        else:
            entity.act("Cerchi di $a $N... ma [darkgray]senza successo[close].", TO.ENTITY, target, verbs["infinitive"])
            entity.act("$n cerca di $a $N... [darkgray]senza successo[close].", TO.OTHERS, target, verbs["infinitive"])
            entity.act("\n$n cerca di $a... [darkgray]senza successo[close].", TO.TARGET, target, verbs["you"])
            return False

    if ((    entity.location.IS_ROOM and ROOM.NO_HOLD in entity.location.flags)
    or  (not entity.location.IS_ROOM and FLAG.NO_HOLD in entity.location.flags)):
        if entity.trust >= TRUST.MASTER:
            entity.send_to_admin("Raccogli l'oggetto anche se la stanza è NO_HOLD")
        else:
            entity.act("Cerchi di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo l$o respinge." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingerl$o." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("\n$n cerca di %s, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingerl$o." % verbs["you2"], TO.TARGET, target)
            return False

    already_use_hold = entity.get_holded_entity()
    already_use_wield = entity.get_wielded_entity()
    if already_use_hold and already_use_wield:
        entity.act("Non puoi, hai tutte e due le $hands occupate per poter %s $N." % verbs["infinitive_min"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N ma ha tutte e due le $hands occupate." % verbs["infinitive_min"], TO.OTHERS, target)
        entity.act("\n$n cerca di %s ma ha tutte e due le $hands occupate." % verbs["you2_min"], TO.TARGET, target)
        return False

    # Si salva quali mani si stanno utilizzando per l'operazione
    if command_name == "wield":
        if already_use_wield:
            if already_use_wield.weapon_type and WEAPONFLAG.TWO_HANDS in already_use_wield.weapon_type.flags:
                hands = [HAND.RIGHT, HAND.LEFT]
            else:
                if entity.IS_ITEM:
                    hands = [HAND.RIGHT]
                else:
                    hands = [entity.hand.reverse]
        else:
            if entity.IS_ITEM:
                hands = [HAND.LEFT]
            else:
                hands = [entity.hand]
    else:
        if already_use_hold:
            if already_use_hold.weapon_type and WEAPONFLAG.TWO_HANDS in already_use_hold.weapon_type.flags:
                hands = [HAND.RIGHT, HAND.LEFT]
            else:
                if entity.IS_ITEM:
                    hands = [HAND.LEFT]
                else:
                    hands = [entity.hand]
        else:
            if entity.IS_ITEM:
                hands = [HAND.RIGHT]
            else:
                hands = [entity.hand.reverse]

    # Raccoglie i dati per una successiva gestione generica dei due comandi
    if command_name == "wield":
        first_hand_to_use = "$hand1"
        second_hand_to_use = "$hand2"
        already_use_check = already_use_wield
        already_use_flag = PART.HOLD
        normal_flag = PART.WIELD
        if target.level > entity.level:
            tooltip = create_tooltip(entity.get_conn(), "Ciò significa che il suo livello è troppo alto rispetto al tuo", "{?}")
            entity.act("Senti che non potrai usufruire al meglio del danno di $N. %s" % tooltip, TO.ENTITY, target)
            entity.act("$n non si sente a suo agio con in mano $N.", TO.OTHERS, target)
            entity.act("$n non si sente a suo agio con te in mano.", TO.TARGET, target)
    else:
        first_hand_to_use = "$hand2"
        second_hand_to_use = "$hand1"
        already_use_check = already_use_hold
        already_use_flag = PART.WIELD
        normal_flag = PART.HOLD

    # Gestione delle armi a due mani
    if command_name == "wield" and target.weapon_type and WEAPONFLAG.TWO_HANDS in target.weapon_type.flags and (already_use_hold or already_use_wield):
        entity.act("Non puoi, devi avere tutte e due le $hands libere per poter %s $N." % WIELD_VERBS["infinitive_min"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N ma non ha tutte e due le $hands libere." % WIELD_VERBS["infinitive_min"], TO.OTHERS, target)
        entity.act("\n$n cerca di %s ma non ha tutte e due le $hands libere." % WIELD_VERBS["you2_min"], TO.TARGET, target)
        return False
    if len(hands) == 2:
        entity.act("Non puoi, hai tutte e due le $hands occupate per poter %s $N." % WIELD_VERBS["infinitive_min"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N ma ha tutte e due le $hands occupate." % WIELD_VERBS["infinitive_min"], TO.OTHERS, target)
        entity.act("\n$n cerca di %s ma ha tutte e due le $hands occupate." % WIELD_VERBS["you2_min"], TO.TARGET, target)
        return False

    force_return = check_trigger(entity, "before_" + command_name, entity, target, hands, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_" + command_name + "ed", entity, target, hands, behavioured)
    if force_return:
        return True

    # Gli oggetti non hanno le mani, quindi utilizzano dei verbi non specifici
    if entity.IS_ITEM:
        entity.act("%s $N." % (color_first_upper(verbs["you_min"])), TO.ENTITY, target)
        entity.act("$n %s $N." % (verbs["it_min"]), TO.OTHERS, target)
        entity.act("\n$n %s" % (verbs["you3_min"]), TO.TARGET, target)
        if already_use_check:
            target.wear_mode = Flags(already_use_flag)
        else:
            target.wear_mode = Flags(normal_flag)
    elif target.weapon_type and WEAPONFLAG.TWO_HANDS in target.weapon_type.flags:
        entity.act("%s $N con tutte e due le $hands." % color_first_upper(verbs["you_min"]), TO.ENTITY, target)
        entity.act("$n %s $N con tutte e due le $hands." % verbs["it_min"], TO.OTHERS, target)
        entity.act("\n$n %s con tutte e due le $hands," % verbs["you3_min"], TO.TARGET, target)
        target.wear_mode = Flags(normal_flag, already_use_flag)
    elif already_use_check:
        entity.act("Cerchi di %s con la %s $N ma essendo già occupata utilizzi la %s." % (
            verbs["infinitive_min"], first_hand_to_use, second_hand_to_use), TO.ENTITY, target)
        entity.act("$n cerca di %s $N con la %s ma essendo già occupata utilizza la %s." % (
            verbs["infinitive_min"], first_hand_to_use, second_hand_to_use), TO.OTHERS, target)
        entity.act("\n$n cerca di %s con la %s ma essendo già occupata utilizza la %s." % (
            verbs["you2_min"], first_hand_to_use, second_hand_to_use), TO.TARGET, target)
        target.wear_mode = Flags(already_use_flag)
    else:
        entity.act("%s $N con la %s." % (color_first_upper(verbs["you_min"]), first_hand_to_use), TO.ENTITY, target)
        entity.act("$n %s $N con la %s." % (verbs["it_min"], first_hand_to_use), TO.OTHERS, target)
        entity.act("\n$n %s con la %s" % (verbs["you3_min"], first_hand_to_use), TO.TARGET, target)
        target.wear_mode = Flags(normal_flag)

    for affect in target.affects:
        affect.apply()

    # Poiché l'entità è stata impugnata forse ha un valore nel gioco e non
    # verrà quindi purificata
    if target.deferred_purification:
        target.stop_purification()

    # Serve a cambiare il wear mode dell'oggetto allo stato originario
    if target.repop_later:
        target.deferred_repop = target.repop_later.defer_check_status()

    force_return = check_trigger(entity, "after_" + command_name, entity, target, hands, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_" + command_name + "ed", entity, target, hands, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 45
0
def give_or_put(entity, argument, verbs, behavioured, entity_tables, noflag,
                noroom, gamescript_suffix1, gamescript_suffix2,
                gamescript_suffix3, preposition):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # argument può essere una stringa vuota

    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

    if not entity_tables:
        log.bug("entity_tables non è un parametro valido: %r" % entity_tables)
        return False

    if noflag not in (FLAG.NO_PUT, FLAG.NO_GIVE):
        log.bug("noflag non è un parametro valido: %r" % noflag)
        return False

    if noroom not in (ROOM.NO_PUT, ROOM.NO_GIVE):
        log.bug("noroom non è un parametro valido: %r" % noroom)
        return False

    if gamescript_suffix1 not in ("put", "give"):
        log.bug("gamescript_suffix1 non è un parametro valido: %r" %
                gamescript_suffix1)
        return False

    if gamescript_suffix2 not in ("putted", "gave"):
        log.bug("gamescript_suffix2 non è un parametro valido: %r" %
                gamescript_suffix2)
        return False

    if gamescript_suffix3 not in ("putting", "giving"):
        log.bug("gamescript_suffix3 non è un parametro valido: %r" %
                gamescript_suffix3)
        return False

    if preposition not in ("in", "a"):
        log.bug("gamescript_suffix non è un parametro valido: %r" %
                gamescript_suffix)
        return False

    # -------------------------------------------------------------------------

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output(
            "Che [white]cosa[close] vorresti %s %s [white]%s[close]?" %
            (verbs["infinitive"], preposition,
             "qualcuno" if preposition == "a" else "qualcosa"))
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_put")
            entity.send_output(syntax)
        return False

    # Ricava l'eventuale quantità d'oggetti da posare
    quantity, argument = quantity_argument(argument)
    arg1, argument = one_argument(argument)

    # (TD) Controllo del mental state deviato

    # Ricerca nell'inventario dell'entità quella da dare o mettere
    target = entity.find_entity(arg1, quantity=quantity, location=entity)

    arg2 = ""
    receiver = None
    if argument:
        arg2, argument = one_argument(argument)
        # Rimuove eventuali argomenti facoltativi
        if argument and arg2 == "a":
            arg2, argument = one_argument(argument)
        # Ricerca dell'entità bersaglio a cui dare l'entità target
        receiver = entity.find_entity_extensively(arg2,
                                                  entity_tables=entity_tables)

        # Controlla se si vuole inserire una porta sui cardini di un'uscita
        direction = get_direction(arg2)
        if target and not receiver and direction != DIR.NONE:
            if not entity.location.IS_ROOM:
                entity.act(
                    "Vorresti %s $N sui cardini di un'eventuale uscita %s, ma non ti trovi in una stanza."
                    % (verbs["infinitive"], direction.to_dir), TO.ENTITY,
                    target)
                entity.act(
                    "$n vorrebbe %s $N sui cardini di un'eventuale uscita %s, ma non vi trovate in una stanza."
                    % (verbs["infinitive"], direction.to_dir), TO.OTHERS,
                    target)
                entity.act(
                    "$n ti vorrebbe %s sui cardini di un'eventuale uscita %s, ma non vi trovate in una stanza."
                    % (verbs["infinitive"], direction.to_dir), TO.TARGET,
                    target)
                return False
            if not direction in entity.location.exits:
                entity.act(
                    "Vorresti %s $N sui cardini di un'eventuale uscita %s, ma questa non esiste."
                    % (verbs["infinitive"], direction.to_dir), TO.ENTITY,
                    target)
                entity.act(
                    "$n vorrebbe %s $N sui cardini di un'eventuale uscita %s, ma questa non esiste."
                    % (verbs["infinitive"], direction.to_dir), TO.OTHERS,
                    target)
                entity.act(
                    "$n ti vorrebbe %s sui cardini di un'eventuale uscita %s, ma questa non esiste."
                    % (verbs["infinitive"], direction.to_dir), TO.TARGET,
                    target)
                return False
            exit_door = entity.location.exits[direction].door
            if exit_door:
                entity.act(
                    "Vorresti %s $N sui cardini dell'uscita %s, ma questa possiede già $a."
                    % (verbs["infinitive"], direction.to_dir), TO.ENTITY,
                    target, exit_door)
                entity.act(
                    "$n vorrebbe %s $N sui cardini dell'uscita %s, ma questa possiede già $a."
                    % (verbs["infinitive"], direction.to_dir), TO.OTHERS,
                    target, exit_door)
                entity.act(
                    "$n ti vorrebbe %s sui cardini dell'uscita %s, ma questa possiede già $a."
                    % (verbs["infinitive"], direction.to_dir), TO.TARGET,
                    target, exit_door)
                return False
            if not target.door_type:
                entity.act(
                    "Vorresti %s sui cardini dell'uscita %s $N, ma quest'ultim$O non è una porta."
                    % (verbs["infinitive"], direction.to_dir), TO.ENTITY,
                    target, exit_door)
                entity.act(
                    "$n vorrebbe %s sui cardini dell'uscita %s $N, ma quest'ultim$O non è una porta."
                    % (verbs["infinitive"], direction.to_dir), TO.OTHERS,
                    target, exit_door)
                entity.act(
                    "$n ti vorrebbe %s sui cardini dell'uscita %s, ma non sei una porta."
                    % (verbs["infinitive"], direction.to_dir), TO.TARGET,
                    target, exit_door)
                return False
            if quantity > 1:
                entity.act(
                    "Vorresti %s sui cardini dell'uscita %s $N, ma è possibile inserirne solo un$O."
                    % (verbs["infinitive"], direction.to_dir), TO.ENTITY,
                    target, exit_door)
                entity.act(
                    "$n vorrebbe %s sui cardini dell'uscita %s $N, ma è possibile inserirne solo un$O"
                    % (verbs["infinitive"], direction.to_dir), TO.OTHERS,
                    target, exit_door)
                entity.act(
                    "$n ti vorrebbe %s sui cardini dell'uscita %s, ma è possibile inserirti solo in un'unità."
                    % (verbs["infinitive"], direction.to_dir), TO.TARGET,
                    target, exit_door)
                return False

            force_return = check_trigger(entity,
                                         "before_" + gamescript_suffix1,
                                         entity, target, None, direction,
                                         behavioured)
            if force_return:
                return True
            force_return = check_trigger(target,
                                         "before_" + gamescript_suffix2,
                                         entity, target, None, direction,
                                         behavioured)
            if force_return:
                return True
            force_return = check_trigger(receiver,
                                         "before_" + gamescript_suffix3,
                                         entity, target, None, direction,
                                         behavioured)
            if force_return:
                return True

            entity.act(
                "%s $N sui cardini dell'uscita %s." %
                (verbs["you"], direction.to_dir), TO.ENTITY, target)
            entity.act(
                "$n %s $N sui cardini dell'uscita %s." %
                (verbs["it"], direction.to_dir), TO.OTHERS, target)
            entity.act(
                "$n ti %s sui cardini dell'uscita %s." %
                (verbs["it"], direction.to_dir), TO.TARGET, target)
            target = target.from_location(1)
            target.to_location(entity.location)
            entity.location.exits[direction].door = target

            force_return = check_trigger(entity, "after_" + gamescript_suffix1,
                                         entity, target, None, direction,
                                         behavioured)
            if force_return:
                return True
            force_return = check_trigger(target, "after_" + gamescript_suffix2,
                                         entity, target, None, direction,
                                         behavioured)
            if force_return:
                return True
            force_return = check_trigger(receiver,
                                         "after_" + gamescript_suffix3, entity,
                                         target, None, direction, behavioured)
            if force_return:
                return True

            return True

    # -------------------------------------------------------------------------

    if not arg2:
        arg2 = "qualcuno" if preposition == "a" else "qualcosa"

    # Se l'entità a cui dare si trova nell'inventario allora lo indica
    on_message_you = ""
    on_message_it = ""
    if receiver and receiver.location and receiver.location == entity:
        if receiver and len(receiver.wear_mode) > 0:
            on_message_you = " che stai [khaki]indossando[close]"
            on_message_it = " che sta [khaki]indossando[close]"
        else:
            on_message_you = " nel tuo [yellow]inventario[close]"
            on_message_it = " nel suo [yellow]inventario[close]"

    # Gestisce le varie combinazioni di entità non trovate e/o uguali
    # all'entità che ha digitato il comando
    if target:
        if not receiver:
            entity.act(
                "Cerchi di %s $N %s [white]%s[close] che non trovi da nessuna parte."
                % (verbs["infinitive"], preposition, arg2), TO.ENTITY, target)
            entity.act(
                "$n cerca di %s $N %s [white]%s[close] che non sembra trovare da nessuna parte."
                % (verbs["infinitive"], preposition, arg2), TO.OTHERS, target)
            entity.act(
                "$n cerca di %s %s [white]%s[close] che non sembra trovare da nessuna parte."
                % (verbs["you2"], preposition, arg2), TO.TARGET, target)
            return False
        elif receiver == entity:
            entity.act(
                "Cerchi di %s $N %s te stess$o, ma è già tu$O!" %
                (verbs["infinitive"], preposition), TO.ENTITY, target)
            entity.act(
                "$n cerca di %s $N %s se stess$o, ma è già su$O." %
                (verbs["infinitive"], preposition), TO.OTHERS, target)
            entity.act(
                "$n cerca di %s $N %s se stess$o, ma è già su$O." %
                (verbs["infinitive"], preposition), TO.TARGET, target)
            return False
        elif receiver == target:
            entity.act(
                "Cerchi di %s $N %s se stess$o, ma ciò è impossibile!" %
                (verbs["infinitive"], preposition), TO.ENTITY, target)
            entity.act(
                "$n cerca di %s $N %s se stess$o, ma ciò è impossibile." %
                (verbs["infinitive"], preposition), TO.OTHERS, target)
            entity.act(
                "$n cerca di %s $N %s te stess$o, ciò è impossibile." %
                (verbs["infinitive"], preposition), TO.TARGET, target)
            return False
    elif not target:
        if not receiver:
            entity.act(
                "Cerchi di %s [white]%s[close] %s [white]%s[close], ma non trovi nulla e nessuno nel tuo inventario."
                % (verbs["infinitive"], arg1, preposition, arg2), TO.ENTITY)
            entity.act(
                "$n cerca di %s [white]qualcosa[close] %s [white]quacuno[close], ma senza molti risultati nel suo inventario."
                % (verbs["infinitive"], preposition), TO.OTHERS)
            return False
        elif receiver == entity:
            if entity.IS_ITEM:
                entity.act(
                    "Cerchi di [orange]passarti [white]%s[close], ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]."
                    % arg1, TO.ENTITY, receiver)
                entity.act(
                    "$n cerca di [orange]passarsi [white]qualcosa[close] che [gray]non sembra trovare[close] nel suo [yellow]inventario[close].",
                    TO.OTHERS, receiver)
            else:
                entity.act(
                    "Cerchi di [orange]passarti[close] da una $hand all'altra [white]%s[close], ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]."
                    % arg1, TO.ENTITY, receiver)
                entity.act(
                    "$n cerca di [orange]passarsi[close] da una $hand all'altra [white]qualcosa[close] che [gray]non sembra trovare[close] nel suo [yellow]inventario[close].",
                    TO.OTHERS, receiver)
            return False
        else:
            if on_message_you and on_message_it:
                entity.act(
                    "Cerchi di %s un [white]%s[close] %s $N%s, ma non trovi [gray]nulla del genere[close]."
                    % (verbs["infinitive"], arg1, preposition, on_message_you),
                    TO.ENTITY, receiver)
                entity.act(
                    "$n cerca di %s [white]qualcosa[close] %s $N%s, ma non sembra trovare [gray]nulla del genere[close]."
                    % (verbs["infinitive"], preposition, on_message_it),
                    TO.OTHERS, receiver)
                entity.act(
                    "$n cerca di %s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close]."
                    % (verbs["infinitive"]), TO.TARGET, receiver)
            else:
                entity.act(
                    "Cerchi di %s un [white]%s[close] %s $N, ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]."
                    % (verbs["infinitive"], arg1, preposition), TO.ENTITY,
                    receiver)
                entity.act(
                    "$n cerca di %s [white]qualcosa[close] %s $N, ma non sembra trovare [gray]nulla del genere[close] nel suo [yellow]inventario[close]."
                    % (verbs["infinitive"], preposition[2:]), TO.OTHERS,
                    receiver)
                entity.act(
                    "$n cerca di %s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close] nel suo [yellow]inventario[close]."
                    % (verbs["infinitive"]), TO.TARGET, receiver)
            return False

    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act(
            "Non puoi %s $N perché ne possiedi solo %d e non %d." %
            (verbs["infinitive"], target.quantity, quantity), TO.ENTITY,
            target)
        entity.act(
            "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s"
            % verbs["infinitive"], TO.OTHERS, target)
        entity.act(
            "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s"
            % verbs["infinitive"], TO.TARGET, target)
        return False

    if receiver.container_type and CONTAINER.CLOSED in receiver.container_type.flags:
        entity.act(
            "Cerchi di %s $a %s $N ma l$O trovi chius$O." %
            (verbs["infinitive"], preposition), TO.ENTITY, receiver, target)
        entity.act(
            "$n cerca di %s $a %s $N ma l$O trova chius$O." %
            (verbs["infinitive"], preposition), TO.OTHERS, receiver, target)
        return False

    # Se l'obiettivo a cui dare l'entità è un oggetto e non è un contenitore
    # allora solo gli admin possono eseguire l'azione
    if receiver.IS_ITEM and not receiver.container_type:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin(
                "Il ricevitore non è un contenitore ma tu puoi eseguire comunque l'azione"
            )
        else:
            entity.act(
                "Cerchi di %s $N %s $a, ma quest'ultimo non ti sembra un contenitore."
                % (verbs["infinitive"], preposition), TO.ENTITY, target,
                receiver)
            entity.act(
                "$n cerca di %s $N %s $a, ma non riesce a trovare modo per farlo non essendo un contenitore."
                % (verbs["infinitive"], preposition), TO.OTHERS, target,
                receiver)
            entity.act(
                "$n cerca di %s %s $a, ma non sembra riuscirvi visto che quest'ultimo non è un contenitore."
                % (verbs["you2"], preposition), TO.TARGET, target, receiver)
            entity.act(
                "$n cerca di %s $a, ma avrà ben poca fortuna visto che non sei un contenitore."
                % verbs["you"], TO.TARGET, receiver, target)
            return False

    # Se l'entità che ha inviato il comando ha la noflag viene evitata
    # l'azione
    if noflag in entity.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Tu avresti in realtà la flag NO_GIVE")
        else:
            entity.act(
                "Cerchi di %s $N %s $a, ma qualche [blueroyal]forza misteriosa[close] ti blocca l'azione."
                % (verbs["infinitive"], preposition), TO.ENTITY, target,
                receiver)
            entity.act(
                "$n cerca di %s $N %s $a, ma sembra essere bloccat$n da una [royalblue]forza misteriosa[close]."
                % (verbs["infinitive"], preposition), TO.OTHERS, target,
                receiver)
            entity.act(
                "$n cerca di %s %s $a, ma sembra essere essere bloccat$o da una [royalblue]forza misteriosa[close]."
                % (verbs["you2"], preposition), TO.TARGET, target, receiver)
            entity.act(
                "$n cerca di %s $a, ma sembre essere bloccat$o da una [royalblue]forza misteriosa[close]."
                % verbs["you"], TO.TARGET, receiver, target)
            return False

    # Se l'oggetto da dare ha la flag NO_GIVE allora evita di farsi
    if noflag in target.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin(
                "L'entità da dare avrebbe in realtà la flag NO_GIVE")
        else:
            if entity.IS_ITEM:
                entity.act(
                    "Appena cerchi di %s $N %s $a te lo ritrovi, con un [cyan]balzo[close] addosso."
                    % (verbs["infinitive"], preposition), TO.ENTITY, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s $N %s $a se lo ritrova, con un [cyan]balzo[close] addosso."
                    % (verbs["infinitive"], preposition), TO.OTHERS, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a gli [cyan]rimbalzi[close] addosso."
                    % (verbs["you2"], preposition), TO.TARGET, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s $a se lo ritrova, con un [cyan]balzo[close] addosso."
                    % verbs["you2"], TO.TARGET, receiver, target)
            else:
                entity.act(
                    "Appena cerchi di %s $N %s $a te lo ritrovi, con un [cyan]balzo[close], in $hand."
                    % (verbs["infinitive"], preposition), TO.ENTITY, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s $N %s $a se lo ritrova, con un [cyan]balzo[close], in $hand."
                    % (verbs["infinitive"], preposition), TO.OTHERS, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a gli [cyan]rimbalzi[close] in $hand."
                    % (verbs["you2"], preposition), TO.TARGET, target,
                    receiver)
                entity.act(
                    "Appena $n cerca di %s $a se lo ritrova, con un [cyan]balzo[close], in $hand."
                    % verbs["you2"], TO.TARGET, receiver, target)
            return False

    # Se l'entità a cui dare l'oggetto ha la flag NO_GIVE allora non lo accetta
    if noflag in receiver.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin(
                "L'entità a cui dare avrebbe in realtà la flag NO_GIVE")
        else:
            if entity.IS_ITEM:
                entity.act(
                    "Cerchi di %s $N %s $a, ma questi te l$O ridà." %
                    (verbs["infinitive"], preposition), TO.ENTITY, target,
                    receiver)
                entity.act(
                    "$n cerca di %s $N %s $a, ma questi gliel$O ridà." %
                    (verbs["infinitive"], preposition), TO.OTHERS, target,
                    receiver)
                entity.act(
                    "$n cerca di %s %s $a, ma questi gliel$O ridà." %
                    (verbs["you2"], preposition), TO.TARGET, target, receiver)
                entity.act(
                    "$n cerca di %s $a, ma gliel%s ridai." %
                    (verbs["you2"], grammar_gender(target)), TO.TARGET,
                    receiver, target)
            else:
                entity.act(
                    "Cerchi di %s $N %s $a, ma questi te l$O ridà in $hand." %
                    (verbs["infinitive"], preposition), TO.ENTITY, target,
                    receiver)
                entity.act(
                    "$n cerca di %s $N %s $a, ma questi gliel$O ridà in $hand."
                    % (verbs["infinitive"], preposition), TO.OTHERS, target,
                    receiver)
                entity.act(
                    "$n cerca di %s %s $a, ma questi gliel$O ridà in $hand." %
                    (verbs["you2"], preposition), TO.TARGET, target, receiver)
                entity.act(
                    "$n cerca di %s $a, ma gliel%s ridai in $hand." %
                    (verbs["you2"], grammar_gender(target)), TO.TARGET,
                    receiver, target)
            return False

    # Se la stanza ha la flag NO_GIVE non permette di dare oggetti
    if entity.location.IS_ROOM and noroom in entity.location.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin(
                "Questa stanza avrebbe in realtà la flag di NO_GIVE")
        else:
            if entity.IS_ITEM:
                entity.act(
                    "Appena cerchi di %s $N %s $a%s te l$O ritrovi addosso come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!"
                    % (verbs["infinitive"], preposition, on_message_you),
                    TO.ENTITY, target, receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a%s $N se l$O ritrova addosso come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!"
                    % (verbs["infinitive"], preposition, on_message_it),
                    TO.OTHERS, target, receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a%s gli ritorni addosso grazie ad una [royalblue]forza misteriosa[close] del luogo!"
                    % (verbs["you2"], preposition, on_message_it), TO.TARGET,
                    target, receiver)
                entity.act(
                    "Appena $n cerca di %s $a gli ritorna addosso grazie ad una [royalblue]forza misteriosa[close] del luogo!"
                    % (verbs["you2"]), TO.TARGET, receiver, target)
            else:
                entity.act(
                    "Appena cerchi di %s $N %s $a%s te l$O ritrovi in $hand come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!"
                    % (verbs["infinitive"], preposition, on_message_you),
                    TO.ENTITY, target, receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a%s $N se l$O ritrova in $hand come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!"
                    % (verbs["infinitive"], preposition, on_message_it),
                    TO.OTHERS, target, receiver)
                entity.act(
                    "Appena $n cerca di %s %s $a%s gli ritorni in $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!"
                    % (verbs["you2"], preposition, on_message_it), TO.TARGET,
                    target, receiver)
                entity.act(
                    "Appena $n cerca di %s $a gli ritorna in $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!"
                    % (verbs["you2"]), TO.TARGET, receiver, target)
            return False

    # (TD) dare monete

    # (TD) gestione dell'argomento all, ultima cosa da supportare

    # Se il peso dell'entità da dare supera quello sopportabile dall'obiettivo
    # a cui darlo allora avverte e evita l'azione
    # (TD) size e carry_number come il get?
    if not receiver.can_carry_target(target, quantity=quantity):
        if receiver.trust > TRUST.PLAYER:
            receiver.send_to_admin(
                "Riesci comunque a %s %s anche se è troppo pesante per te." %
                (verbs["infinitive"], target.get_name(entity)))
        elif entity.trust > TRUST.PLAYER and not receiver.IS_PLAYER:
            entity.send_to_admin(
                "Riesci comunque a %s %s anche se è troppo pesante per %s." %
                (verbs["infinitive"], target.get_name(entity),
                 receiver.get_name(entity)))
        else:
            entity.act(
                "Non riesci %s %s $N a $a, non può portare con sé tutto quel peso."
                % (verbs["infinitive"], preposition), TO.ENTITY, target,
                receiver)
            entity.act(
                "$n non riesce a %s $N %s $a, non può portare con sé tutto quel peso."
                % (verbs["infinitive"], preposition), TO.OTHERS, target,
                receiver)
            entity.act(
                "$n non riesce a %s %s $a, non può portare con sé tutto il tuo peso."
                % (verbs["you2"], preposition), TO.TARGET, target, receiver)
            entity.act(
                "$n non riesce a %s $a, non puoi portare con te tutto quel peso."
                % verbs["you2"], TO.TARGET, receiver, target)
            return False

    force_return = check_trigger(entity, "before_" + gamescript_suffix1,
                                 entity, target, receiver, DIR.NONE,
                                 behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_" + gamescript_suffix2,
                                 entity, target, receiver, DIR.NONE,
                                 behavioured)
    if force_return:
        return True
    force_return = check_trigger(receiver, "before_" + gamescript_suffix3,
                                 entity, target, receiver, DIR.NONE,
                                 behavioured)
    if force_return:
        return True

    if on_message_you and on_message_it:
        entity.act(
            "%s $N %s $a%s." %
            (color_first_upper(verbs["you"]), preposition, on_message_you),
            TO.ENTITY, target, receiver)
        entity.act(
            "$n %s $N %s $a%s." % (verbs["it"], preposition, on_message_it),
            TO.OTHERS, target, receiver)
        entity.act(
            "$n ti %s %s $a%s." % (verbs["it"], preposition, on_message_it),
            TO.TARGET, target, receiver)
        entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, receiver, target)
    else:
        entity.act(
            "%s $N %s $a." % (color_first_upper(verbs["you"]), preposition),
            TO.ENTITY, target, receiver)
        entity.act("$n %s $N %s $a." % (verbs["it"], preposition), TO.OTHERS,
                   target, receiver)
        entity.act("$n ti %s %s $a." % (verbs["it"], preposition), TO.TARGET,
                   target, receiver)
        entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, receiver, target)

    target = target.from_location(quantity, use_repop=True)
    target.to_location(receiver)

    force_return = check_trigger(entity, "after_" + gamescript_suffix1, entity,
                                 target, receiver, DIR.NONE, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_" + gamescript_suffix2, entity,
                                 target, receiver, DIR.NONE, behavioured)
    if force_return:
        return True
    force_return = check_trigger(receiver, "after_" + gamescript_suffix3,
                                 entity, target, receiver, DIR.NONE,
                                 behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 46
0
def command_get(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    # (TD) Fare altrimenti il passaggio d'argomento verboso per il get e take,
    # creando il command_take?
    if entity.sended_inputs and is_prefix("racco", entity.sended_inputs[-1]):
        verbs = VERBS2

    if not argument:
        entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_get")
            entity.send_output(syntax, break_line=False)
        return False

    original_argument = argument

    # Ricava l'eventuale quantità d'oggetti da raccogliere
    quantity, argument = quantity_argument(argument)
    arg1, argument = one_argument(argument)

    # (TD) Controllo sul mental state dell'entità

    # Rimuove l'eventuali parole opzionali
    from_descr = ""
    if argument and is_prefix(argument, ("da ", "from ")):
        from_descr = "da"
        dummy_arg2, argument = one_argument(argument)

    if argument:
        location = entity.find_entity_extensively(argument, quantity=quantity)
        # (TD) sperimentale, utilizzarlo in altri comandi se va bene
        # Qui si cerca di risolvere il parsing di un eventuale argomento di
        # questo tipo: prendi camicia a tunica cassa
        if not location:
            arg1, argument = reverse_one_argument(original_argument)
            if is_number(arg1):
                quantity = int(arg1)
                arg1, argument = one_argument(argument)
            location = entity.find_entity_extensively(argument, quantity=quantity)
        if not from_descr:
            from_descr = "su"  # (bb)
    else:
        location = entity.location
        if entity.location.IS_ROOM:
            if not from_descr:
                from_descr = "in"
        else:
            if not from_descr:
                from_descr = "da"

    if not location or (location.is_secret_door() and argument and len(argument) < config.min_secret_arg_len):
        entity.act("Non riesci a trovare nessun [white]%s[close] da cui %s [white]%s[close]." % (argument, verbs["infinitive"], arg1), TO.ENTITY)
        entity.act("$n sta cercando di %s qualcosa dentro qualcos'altro, ma senza molto successo." % verbs["infinitive"], TO.OTHERS)
        return False

    if not location.IS_ROOM and location.container_type and CONTAINER.CLOSED in location.container_type.flags:
        execution_result = False
        if entity.IS_PLAYER and entity.account and OPTION.AUTO_OPEN in entity.account.options:
            execution_result = command_open(entity, location.get_numbered_keyword(looker=entity))
        if not execution_result:
            entity.act("Cerchi di %s %s da $N ma l$O trovi chius$O." % (verbs["infinitive"], arg1), TO.ENTITY, location)
            entity.act("$n cerca di %s %s da $N ma l$O trova chius$O." % (verbs["infinitive"], arg1), TO.OTHERS, location)
            entity.act("$n cerca di %s %s ma ti trova chius$O." % (verbs["you2"], arg1), TO.TARGET, location)
            return False

    if argument:
        avoid_equipment = True
        if location.IS_ITEM:
            avoid_equipment = False
        target = entity.find_entity(arg1, location=location, avoid_equipment=avoid_equipment)
    else:
        target = entity.find_entity_extensively(arg1, inventory_pos="last")

    if ((location.IS_ACTOR and not location.container_type and entity.location != location)
    or (not target and location.IS_ITEM and not location.container_type)
    or (target and location.IS_ITEM and not location.container_type and len(target.wear_mode) <= 0)):
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Anche se non è un contenitore lo puoi manipolare comunque")
        else:
            entity.act("Non riesci a %s %s da $N." % (verbs["infinitive"], arg1), TO.ENTITY, location)
            entity.act("Non riesce a %s nulla da $N." % verbs["infinitive"], TO.OTHERS, location)
            entity.act("Non riesce a %s nulla da te." % verbs["infinitive"], TO.TARGET, location)
            return False

    if not target or (target.is_secret_door() and len(arg1) < config.min_secret_arg_len):
        if location.IS_ROOM:
            entity.act("Non riesci a trovare nessun [white]%s[close] da %s." % (arg1, verbs["infinitive"]), TO.ENTITY)
            entity.act("$n sta cercando qualcosa, ma senza molto successo.", TO.OTHERS)
        else:
            entity.act("Non riesci a trovare nessun [white]%s[close] da %s %s $N." % (arg1, verbs["infinitive"], from_descr), TO.ENTITY, location)
            entity.act("$n sta cercando qualcosa dentro $N, ma senza molto successo.", TO.OTHERS, location)
        return False

    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act("Non puoi %s $N perché ve ne sono solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target)
        entity.act("$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target)
        return False

    # Di default si raccoglie da terra
    if not location:
        location = entity.location

    force_return = check_trigger(target, "before_try_to_get", entity, target, location, behavioured)
    if force_return:
        return True

    if target == entity:
        entity.act("Cerchi di %s da sol$o... impossibile!" % verbs["you2"], TO.ENTITY)
        entity.act("$n cerca di %s da sol$o... sarà dura che ce la faccia!" % verbs["self"], TO.OTHERS)
        return False

    if target.location == entity:
        entity.act("Cerchi di %s $N ma ti accorgi di averl$O già con te." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N ma si accorge di averl$O già con sé." % verbs["infinitive"], TO.OTHERS, target)
        return False

    # Controlla che il peso ((TD) e lo spazio) attualmente trasportato dall'entità
    # permetta o meno il get
    # (TD) il bard aveva anche il can_carry_number
    if not entity.can_carry_target(target, quantity=quantity):
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Riesci comunque a %s %s anche se è troppo pesante per te." % (
                verbs["infinitive"], target.get_name(entity)))
        else:
            entity.act("Non puoi %s $N, non riesci a portare con te tutto quel peso." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n non può %s $N, non riesce a portare con sé tutto quel peso." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n non può %s, non riesce a portare con sé tutto il tuo peso." % verbs["you2"], TO.TARGET, target)
            return False

    # Evita di far rubare a meno che non ci si trovi proprio nell'inventario della vittima
    if location.IS_PLAYER and location != entity.location:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli da un giocatore anche se non potresti")
        else:
            entity.act("Cerchi di %s qualcosa da $a, ma ti fermi prima di compiere un [gray]furto[close]." % verbs["infinitive"], TO.ENTITY, target, location)
            entity.act("$n cerca di %s qualcosa da $N, tuttavia si ferma prima di compiere un [gray]furto[close]." % verbs["infinitive"], TO.OTHERS, location)
            entity.act("\n$n cerca di %s qualcosa da $a, ma si ferma prima di compiere un [gray]furto[close]." % verbs["you2"], TO.TARGET, target, location)
            entity.act("\n$n cerca di %s qualcosa, tuttavia si ferma prima di compiere un [gray]furto[close]." % verbs["you2"], TO.TARGET, location, target)
            return False

    # Se non è passato del tempo il cadavere non è lootabile
    if target.corpse_type and target.corpse_type.was_player and target.corpse_type.decomposition_rpg_hours <= len(CORPSE_DESCRS):
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli da un cadavere di giocatore anche se non potresti")
        else:
            entity.act("Cerchi di %s qualcosa da $a, ma ti fermi prima di compiere un [gray]furto[close]." % verbs["infinitive"], TO.ENTITY, target, location)
            entity.act("$n cerca di %s qualcosa da $N, tuttavia si ferma prima di compiere un [gray]furto[close]." % verbs["infinitive"], TO.OTHERS, location)
            entity.act("\n$n cerca di %s qualcosa da $a, ma si ferma prima di compiere un [gray]furto[close]." % verbs["you2"], TO.TARGET, target, location)
            entity.act("\n$n cerca di %s qualcosa, tuttavia si ferma prima di compiere un [gray]furto[close]." % verbs["you2"], TO.TARGET, location, target)
            return False

    if FLAG.NO_GET in target.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli l'oggetto anche se è NO_GET")
        else:
            entity.act("Cerchi di $a $N... ma [darkgray]senza successo[close].", TO.ENTITY, target, verbs["infinitive"])
            entity.act("$n cerca di $a $N... [darkgray]senza successo[close].", TO.OTHERS, target, verbs["infinitive"])
            entity.act("$n cerca di $a... [darkgray]senza successo[close].", TO.TARGET, target, verbs["you2"])
            if not location.IS_ROOM:
                entity.act("$n cerca di $a $N da te... [darkgray]senza successo[close].", TO.TARGET, target, verbs["infinitive"])
            return False

    if location.IS_ROOM and ROOM.NO_GET in location.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli l'oggetto anche se la stanza è NO_GET")
        else:
            entity.act("Cerchi di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo respinge la tua $hand." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingere la sua $hand." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("\n$n cerca di %s, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingere la sua $hand." % verbs["you2"], TO.TARGET, target)
            return False

    if not location.IS_ROOM and location == entity.location and len(target.wear_mode) > 0:
        entity.act("Stai per %s $N svestendo $a, ma poi ti fermi, non è proprio il caso." % verbs["infinitive"], TO.ENTITY, target, location)
        entity.act("$ sembra voler %s $N svestendo $a, ma poi si ferma." % verbs["infinitive"], TO.OTHERS, target, location)
        entity.act("$n sembra voler %s $N da te, ma poi si ferma." % verbs["infinitive"], TO.TARGET, target, location)
        return False

    if FLAG.BURIED in target.flags:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli l'oggetto anche se è BURIED rimuovendo tale flag")
        else:
            log.bug("Oggetto buried gettabile da un giocatore senza trust: %s" % target.code)
            return False

    # Ricava l'attributo corretto
    if target.IS_PLAYER:
        if entity.trust > TRUST.PLAYER:
            entity.send_to_admin("Raccogli il giocatore anche se non potresti")
        else:
            entity.act("Cerchi di %s $N, ma ti fermi per [indianred]rispetto[close] nei suoi confronti." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N, tuttavia si ferma per [indianred]rispetto[close] nei suoi confronti." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("\n$n cerca di %s, tuttavia si ferma per [indianred]rispetto[close] nei tuoi confronti." % verbs["you2"], TO.TARGET, target)
            if not location.IS_ROOM:
                entity.act("$n cerca di %s $a da te, tuttavia si ferma per [indianred]rispetto[close] nei tuoi e suoi confronti." % verbs["infinitive"], TO.TARGET, location, target)
            return False

    # Nel caso l'oggetto era addosso ad un altro oggetto (è meglio tenere
    # queste righe di codice prima del check del trigger before_get visto
    # che a volte negli script vengono modificate le flag di wear)
    if len(target.wear_mode) > 0:
        target.wear_mode.clear()
        target.under_weared = None

    # In questa maniera crea l'entità finale che verrà manipolata dai trigger
    # in maniera omogenea senza dover attendere la chiamata della from_location
    target = target.split_entity(quantity)

    force_return = check_trigger(entity, "before_get", entity, target, location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_getted", entity, target, location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "before_get_from_location", entity, target, location, behavioured)
    if force_return:
        return True

    if quantity <= 1:
        entity.act("%s $N da $a." % color_first_upper(verbs["you"]), TO.ENTITY, target, location)
        entity.act("$n %s $N da $a." % verbs["it"], TO.OTHERS, target, location)
        entity.act("$n ti %s da $a." % verbs["it"], TO.TARGET, target, location)
    else:
        entity.act("%s $N, per una quantità di %d, da $a." % (color_first_upper(verbs["you"]), quantity), TO.ENTITY, target, location)
        entity.act("$n %s $N, per una quantità di %d, da $a." % (verbs["it"], quantity), TO.OTHERS, target, location)
        entity.act("$n ti %s, per una quantità di %d, da $a." % (verbs["it"], quantity), TO.TARGET, target, location)
    if not location.IS_ROOM:
        entity.act("$n ti %s qualcosa." % verbs["it"], TO.TARGET, location)

    target = target.from_location(quantity)
    target.to_location(entity)

    # Nel caso sia un seme e fosse stato un admin a gettarlo:
    target.flags -= FLAG.BURIED
    # (TT) forse questo pezzo di codice andrebbe meglio in from_location
    if target.seed_type:
        target.seed_type.stop_growth()
    if target.plant_type:
        target.plant_type.stop_growth()

    # Se il comando get è stato eseguito tramite un behaviour allora l'oggetto
    # raccolto ha una probabilità di essere purificato, queste righe di codice
    # devono trovarsi DOPO la chiamata alla to_location, che esegue una pulizia
    # della deferred relativa alla purificazione
    if behavioured:
        target.start_purification(config.purification_rpg_hours)

    force_return = check_trigger(entity, "after_get", entity, target, location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_getted", entity, target, location, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "after_get_from_location", entity, target, location, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 47
0
def command_offer(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di vendere entità ai commercianti.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if not argument:
        for dealer in entity.location.iter_contains():
            if dealer.shop:
                break
        if SHOP.DISPENSER in dealer.shop.types:
            entity.act(
                "Cerchi di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore."
                % verbs["infinitive"], TO.ENTITY, dealer)
            entity.act(
                "$n cerca di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore."
                % verbs["infinitive"], TO.OTHERS, dealer)
            entity.act(
                "$n cerca di %s qualcosa ma ciò non è possibile perché sei un distributore."
                % verbs["you2"], TO.TARGET, dealer, target)
            return False

        entity.send_output("Cosa vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_offer")
            entity.send_output(syntax, break_line=False)
        return False

    # Ricava la quantità da offrire e poi l'eventuale valore facoltativo del negoziante
    quantity, argument = quantity_argument(argument)
    arg, argument = one_argument(argument)

    target = entity.find_entity(arg, quantity=quantity, location=entity)
    if not target:
        entity.act(
            "Non trovi nessun [white]%s[close] da %s nel tuo inventario." %
            (arg, verbs["infinitive"]), TO.ENTITY)
        entity.act(
            "$n sta cercando qualcosa senza trovarla" % verbs["infinitive"],
            TO.OTHERS)
        return False

    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act(
            "Non puoi %s $N perché ne possiedi solo %d e non %d." %
            (verbs["infinitive"], target.quantity, quantity), TO.ENTITY,
            target)
        entity.act(
            "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s"
            % verbs["infinitive"], TO.OTHERS, target)
        entity.act(
            "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s"
            % verbs["infinitive"], TO.TARGET, target)
        return False

    if argument:
        dealer = entity.find_entity_extensively(argument)
        if not dealer:
            entity.act(
                "Non trovi nessun negoziante chiamato [white]%s[close] a cui %s $N."
                % (argument, verbs["infinitive"]), TO.ENTITY, target)
            entity.act(
                "$n sembra cercare qualcuno a cui %s $N." %
                verbs["infinitive"], TO.OTHERS, target)
            return False
        if not dealer.shop:
            entity.act(
                "$N non sembra essere un negoziante a cui %s $a." %
                verbs["infinitive"], TO.ENTITY, dealer, target)
            entity.act(
                "$n si accorge che $N non sembra essere un negoziante a cui %s $a."
                % verbs["infinitive"], TO.OTHERS, dealer, target)
            entity.act(
                "$n si accorge che tu non sei un negoziante a cui %s $a." %
                verbs["infinitive"], TO.TARGET, dealer, target)
            return False
    else:
        for dealer in entity.location.iter_contains():
            if dealer.shop:
                break
        else:
            entity.act(
                "Qui non trovi nessun negoziante a cui %s $N." %
                verbs["infinitive"], TO.ENTITY, target)
            entity.act(
                "$n non sembra trovare qualcuno a cui %s $N." %
                verbs["infinitive"], TO.OTHERS, target)
            return False

    # Controlla se il negoziante si trova in una locazione che fa, per lui, da negozio
    if not dealer.shop.in_location(dealer):
        entity.act(
            "Non puoi %s nulla da $N se non si trova nel suo negozio." %
            verbs["infinitive"], TO.ENTITY, dealer)
        entity.act(
            "$n non può %s nulla da $N se non si trova nel suo negozio." %
            verbs["infinitive"], TO.OTHERS, dealer)
        entity.act(
            "$n non può %s nulla da te se non ti trovi nel tuo negozio." %
            verbs["infinitive"], TO.TARGET, dealer)
        return False

    # Indica che un'entità vuole interagire con il dealer
    if entity not in dealer.interactions:
        dealer.interactions.append(entity)

    if SHOP.DISPENSER in dealer.shop.types:
        entity.act(
            "Cerchi di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore."
            % verbs["infinitive"], TO.ENTITY, dealer, target)
        entity.act(
            "$n cerca di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore."
            % verbs["infinitive"], TO.OTHERS, dealer, target)
        entity.act(
            "$n cerca di %s $a ma ciò non è possibile perché sei un distributore."
            % verbs["you2"], TO.TARGET, dealer, target)
        entity.act(
            "$n cerca di %s a $N ma ciò non è possibile perché è un distributore."
            % verbs["you2"], TO.TARGET, target, dealer)
        return False

    sellable = dealer.shop.get_sellable(target)
    if not sellable:
        dealer.shop.send_uninterested_messages(entity, target, dealer)
        return False

    price = math.trunc((target.value * sellable.percent) / 100) * quantity
    if price <= 0:
        entity.act("$N guarda senza molto interesse $a: è senza valore!",
                   TO.ENTITY, dealer, target)
        entity.act(
            "$N guarda senza molto interesse $a mostrato da $n: è senza valore.",
            TO.OTHERS, dealer, target)
        entity.act(
            "Guardi senza molto interesse $a mostrato da $n: è senza valore...",
            TO.TARGET, dealer, target)
        entity.act("$a ti guarda senza molto interesse: sei senza valore...",
                   TO.TARGET, target, dealer)
        return False

    # Attenzione che qui target non è ancora la quantità giusta
    force_return = check_trigger(entity, "before_offer", entity, dealer,
                                 target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "before_offering", entity, dealer,
                                 target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_offered", entity, dealer,
                                 target, quantity, behavioured)
    if force_return:
        return True

    pretty_price = pretty_money_value(price, extended=True)
    dealer.shop.send_offer_messages(entity, target, dealer, verbs, quantity,
                                    pretty_price)

    force_return = check_trigger(entity, "after_offer", entity, dealer, target,
                                 quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "after_offering", entity, dealer,
                                 target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_offered", entity, dealer,
                                 target, quantity, behavioured)
    if force_return:
        return True

    return True
Exemplo n.º 48
0
def command_incognito(entity, argument=""):
    """
    Forza l'esecuzione di un comando da parte di un'altra entità.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # -------------------------------------------------------------------------

    if not argument:
        syntax = get_command_syntax(entity, "command_incognito")
        entity.send_output(syntax, break_line=False)

        players = []
        for player in database["players"].itervalues():
            if player.incognito:
                players.append(player)

        mobs = []
        for mob in database["mobs"].itervalues():
            if mob.incognito:
                mobs.append(mob)

        items = []
        for item in database["items"].itervalues():
            if item.incognito:
                items.append(item)

        if not players and not mobs and not items:
            entity.send_output("Nessuna entità in incognito.")

        if players:
            entity.send_output("Giocatori in incognito:")
            for player in players:
                entity.send_output("- %s" % player.name)
            if mobs or items:
                entity.send_output("\n")

        if mobs:
            entity.send_output("Mob in incognito:")
            for mob in mobs:
                entity.send_output("- %s" % mob.name)
            if items:
                entity.send_output("\n")

        if items:
            entity.send_output("Oggetti in incognito:")
            for item in items:
                entity.send_output("- %s" % item.name)

        return True

    # -------------------------------------------------------------------------

    if entity.trust < TRUST.MASTER:
        entity.send_output("Solo gli [yellow]amministratori[close] di livello superiore a %s possono rendere [darkslategray]incognito[close] un personaggio qualsiasi." % TRUST.MASTER)
        return False

    # Cerca prima tra i giocatori online
    target = search_online_player(argument)
    if not target:
        target = entity.find_entity(argument, entity_tables=["players", "mobs", "items"])
        if not target:
            entity.send_output("Non esiste nessun'entità con argomento [green]%s[close]" % argument)
            return False

    if target.incognito:
        target.incognito = False
        if target == entity:
            entity.send_output("Esci dalle [royalblue]pieghe dimensionali[close] [red]a[gold]ariatiane[close] dell'incognito.")
            # Questo e il messaggio di log sotto non dovrebbero servire visto
            # che l'incognito viene effettuato senza danni su se stessi (ovvero
            # volontariamente)
            #log.admin("%s esce dalle pieghe dimensionali aaritiane dell'incognito" % entity.name)
        else:
            entity.send_output("Fai uscire dalle [royalblue]pieghe dimensionali[close] [red]a[gold]ariatiane[close] dell'incognito %s." % target.get_name(entity))
            log.admin("%s fa uscire dalle pieghe dimensionali aaritiane dell'incognito %s" % (entity.name, target.name))
    else:
        target.incognito = True
        if target == entity:
            entity.send_output("Entri nelle [royalblue]pieghe dimensionali[close] [red]a[gold]ariatiane[close] dell'incognito.")
            #log.admin("%s entra nelle pieghe dimensionali aaritiane dell'incognito" % entity.name)
        else:
            entity.send_output("Fai entrare nalle [royalblue]pieghe dimensionali[close] [red]a[gold]ariatiane[close] dell'incognito %s." % target.get_name(entity))
            log.admin("%s fa entrare nelle pieghe dimensionali aaritiane dell'incognito %s" % (entity.name, target.name))

    return True