Beispiel #1
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
Beispiel #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
Beispiel #3
0
def interpret_or_echo(entity, argument, looker=None, behavioured=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    if MIML_SEPARATOR in argument:
        argument = entity.parse_miml(argument)
    if not argument:
        return

    if "$" in argument:
        argument = looker.replace_act_tags(argument, target=entity)
    if "$" in argument:
        argument = looker.replace_act_tags_name(argument, looker=looker, target=entity)

    original_argument = argument
    arg, argument = one_argument(argument)

    input, huh_input, lang = multiple_search_on_inputs(entity, arg, exact=True)
    if input:
        interpret(entity, original_argument, use_check_alias=False, show_input=False, show_prompt=False, behavioured=behavioured)
    else:
        entity.location.echo(original_argument)
Beispiel #4
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
Beispiel #5
0
def get_see_also_links(entity, see_also):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return ""

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

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

    help_translation = translate_input(entity, "help", "en")
    if not help_translation:
        log.bug("help_translation non valido: %r" % help_translation)
        help_translation = "aiuto"

    output = "[white]Vedi anche[close]: "

    # Supporto ai SeeAlso composti da solo link
    if see_also.lower().startswith("<a "):
        return output + see_also

    for help_code in see_also.split():
        help_code = help_code.strip(",")
        if help_code not in database["helps"]:
            log.bug("help_code %s non si trova tra gli helps" % help_code)
            continue
        help = database["helps"][help_code]
        if entity.IS_PLAYER and OPTION.ITALIAN in entity.account.options:
            help_keyword, dummy = one_argument(help.italian_keywords)
        else:
            help_keyword, dummy = one_argument(help.english_keywords)
        javascript_code = '''javascript:parent.sendInput('%s %s');''' % (
            help_translation, help_keyword)
        output += '''<a href="%s">%s</a>, ''' % (javascript_code, help_keyword)

    return output.rstrip(", ")
Beispiel #6
0
def get_see_also_links(entity, see_also):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return ""

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

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

    help_translation = translate_input(entity, "help", "en")
    if not help_translation:
        log.bug("help_translation non valido: %r" % help_translation)
        help_translation = "aiuto"

    output = "[white]Vedi anche[close]: "

    # Supporto ai SeeAlso composti da solo link
    if see_also.lower().startswith("<a "):
        return output + see_also

    for help_code in see_also.split():
        help_code = help_code.strip(",")
        if help_code not in database["helps"]:
            log.bug("help_code %s non si trova tra gli helps" % help_code)
            continue
        help = database["helps"][help_code]
        if entity.IS_PLAYER and OPTION.ITALIAN in entity.account.options:
            help_keyword, dummy = one_argument(help.italian_keywords)
        else:
            help_keyword, dummy = one_argument(help.english_keywords)
        javascript_code = '''javascript:parent.sendInput('%s %s');''' % (
            help_translation, help_keyword)
        output += '''<a href="%s">%s</a>, ''' % (javascript_code, help_keyword)

    return output.rstrip(", ")
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
def commands_skills_socials_handler(entity, argument, inputs_type):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # argument può essere una stringa vuota

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

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

    arg, argument = one_argument(argument)

    # Ricava in che lingua visualizzare i comandi
    language = "en"
    if entity.IS_PLAYER and OPTION.ITALIAN in entity.account.options:
        language = "it"

    if arg:
        if is_same(arg, ("italiano", "italian")):
            language = "it"
        if is_same(arg, ("inglese", "english")):
            language = "en"

    # Esegue il controllo degli argomenti
    if not arg or is_same(arg, ("italiano", "italian", "inglese", "english")):
        return show_list_normal(entity, language, inputs_type)
    elif is_same(arg,
                 ("traduzione", "translation", "traduzioni", "translations")):
        return show_list_translation(entity, language, inputs_type)
    elif inputs_type == "command" and is_same(
            arg, ("tipo", "type", "tipi", "types")):
        return show_list_type(entity, language, inputs_type)
    elif entity.trust >= TRUST.MASTER and is_same(
            arg, ("fiducia", "trust", "fiduce", "trusts")):
        return show_list_trust(entity, language, inputs_type)
    else:
        return show_list_found(entity, language, inputs_type, arg)
Beispiel #11
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
Beispiel #12
0
def commands_skills_socials_handler(entity, argument, inputs_type):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # argument può essere una stringa vuota

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

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

    arg, argument = one_argument(argument)

    # Ricava in che lingua visualizzare i comandi
    language = "en"
    if entity.IS_PLAYER and OPTION.ITALIAN in entity.account.options:
        language = "it"

    if arg:
        if is_same(arg, ("italiano", "italian")):
            language = "it"
        if is_same(arg, ("inglese", "english")):
            language = "en"

    # Esegue il controllo degli argomenti
    if not arg or is_same(arg, ("italiano", "italian", "inglese", "english")):
        return show_list_normal(entity, language, inputs_type)
    elif is_same(arg, ("traduzione", "translation", "traduzioni", "translations")):
        return show_list_translation(entity, language, inputs_type)
    elif inputs_type == "command" and is_same(arg, ("tipo", "type", "tipi", "types")):
        return show_list_type(entity, language, inputs_type)
    elif entity.trust >= TRUST.MASTER and is_same(arg, ("fiducia", "trust", "fiduce", "trusts")):
        return show_list_trust(entity, language, inputs_type)
    else:
        return show_list_found(entity, language, inputs_type, arg)
Beispiel #13
0
def interpret_or_echo(entity, argument, looker=None, behavioured=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    if MIML_SEPARATOR in argument:
        argument = entity.parse_miml(argument)
    if not argument:
        return

    if "$" in argument:
        argument = looker.replace_act_tags(argument, target=entity)
    if "$" in argument:
        argument = looker.replace_act_tags_name(argument,
                                                looker=looker,
                                                target=entity)

    original_argument = argument
    arg, argument = one_argument(argument)

    input, huh_input, lang = multiple_search_on_inputs(entity, arg, exact=True)
    if input:
        interpret(entity,
                  original_argument,
                  use_check_alias=False,
                  show_input=False,
                  show_prompt=False,
                  behavioured=behavioured)
    else:
        entity.location.echo(original_argument)
Beispiel #14
0
def rpg_channel(entity,
                argument,
                channel,
                ask=False,
                exclaim=False,
                behavioured=False):
    """
    Gestisce i canali rpg, ha le seguenti caratteristiche:
    - supporto per gli smile
    - supporto per i modi di esprimersi con esclamativo e punto di domanda
    - supporto per gli emote
    - gestione del bersaglio che può essere un'entità, il gruppo o sé stessi
    - (TD) parlata da ubriaco
    - (TD) espansione della potenza della voce in altre stanze
    - (TD) espressioni per le stanze attorno, anche per coloro che riconoscono la voce,
           pensare anche alla suddivisione tra social gestuali e 'rumorosi' per gli smile-espressioni around
    - (TD) modulazione della voce a seconda delle dimensioni di chi parla e della sua voice_potence
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    if entity.IS_ROOM:
        return False

    objective = OBJECTIVE_ROOM  # obiettivo del messaggio
    # Linguaggio utilizzato per dire il messaggio
    if entity.IS_ITEM:
        language = LANGUAGE.COMMON
    else:
        language = entity.speaking
    smile = ""  # conterrà l'eventuale espressione di uno smile-social
    emote = ""  # conterrà l'eventuale emote inviato con il messaggio tra due asterischi
    expres_entity = ""  # espressione per chi parla
    expres_room = ""  # espressione per chi sta ascoltando nella stanza
    expres_objective = ""  # espressione per chi riceverà il messaggio

    # Ricava i verbi e il colore relativi al canale
    # Se si sta parlando normalmente la propria lingua vengono utilizzati
    # i verbi razziali per descriverne timbro, flessione o pronuncia
    if channel == CHANNEL.SAY:
        verb_you, verb_it = entity.race.say_verb_you, entity.race.say_verb_it
    else:
        verb_you, verb_it = channel.verb_you, channel.verb_it
    color = get_first_color(channel.name)

    # Se non è stato passato nessun messaggio esce
    if not argument or not remove_colors(argument):
        entity.send_output("Cosa vorresti %s?" % channel)
        return False

    if len(argument) > config.max_google_translate:
        entity.send_output("Non puoi %s un messaggio così logorroico." %
                           channel)
        return False

    # Copia l'argomento originale, in alcuni casi serve recuperarlo poi
    original_argument = argument

    # Controlla se si sta parlando a qualcuno, il controllo sulla particella
    # la esegue in minuscolo, dando per sottinteso che quando uno scrive
    # maiuscolo voglia iniziare un discorso
    target = None
    if argument[0:2] == "a ":
        arg, argument = one_argument(argument)
        # Se sta parlando a qualcuno cerca di acquisirlo dal nome successivo
        objective_name, argument = one_argument(argument)
        target = entity.find_entity_extensively(objective_name)
        # con me e self esegue un check senza la is_same volutamente, per evitare
        # ricerche con nome di player che iniziano con Me o Self
        if target == entity or objective_name in ("me", "self"):
            objective = OBJECTIVE_SELF
            # Se si parla da soli lo si fa utilizzando la lingua madre
            language = entity.race.natural_language
        elif target:
            objective = OBJECTIVE_TARGET
            # Se si parla con qualcuno della stessa razza lo si fa utilizzando
            # la lingua preferita dalla razza, è un fattore culturale
            if entity.race == target.race:
                language = entity.race.natural_language
        else:
            # Se non ha trovato nessun 'a <nome bersaglio>' riprende
            # l'argument originale
            argument = original_argument
    # Stessa cosa di sopra ma qui controlla se si stia parlando al gruppo
    elif argument[0:3] == "al ":
        arg, argument = one_argument(argument)
        objective_name, argument = one_argument(argument)
        if is_prefix(objective_name, "gruppo"):
            if not entity.group:
                entity.send_output("Non fai parte di nessun gruppo.")
                return False
            # Questa variabile verrà utilizza poi nell'invio del messaggio
            group_members = entity.get_members_here(entity.location)
            if not group_members:
                entity.send_output(
                    "Non trovi nessun membro del gruppo vicino a te con cui poter parlare."
                )
                return False
            objective = OBJECTIVE_GROUP
            # Se si parla in un gruppo in cui tutti sono formati dalla stessa
            # razza si preferirà parlare con la lingua della propria razza
            for group_member in group_members:
                if group_member.race != entity.race:
                    break
            else:
                language = entity.race.natural_language
        else:
            # Se il personaggio non vuole parlare al gruppo recupera
            # il valore originale inviato
            argument = original_argument

    # (TD) Gestisce il caso in cui l'entità si trovi immersa in un liquido
    #if entity.is_immersed():
    #    entity.send_output("Tenti di %s qualcosa ma subito l'acqua ti riempie la gola soffocandoti!" % channel)
    #    entity.points.life -= random.randint(entity.level / 6, entity.level / 4) + 1
    #    return False

    if not entity.location:
        log.bug(
            "entity %s non si trova in una locazione valida: %r (original_argument: %s)"
            % (entity.code, entity.location, original_argument))
        return False

    # Gestisce le stanze che obbligano al silenzio
    if entity.location.IS_ROOM:
        if ROOM.SILENCE in entity.location.flags:
            entity.send_output(
                "Il silenzio del luogo ti blocca la gola impedendoti di %s." %
                channel)
            return False

        # (TT) Se nella stanza c'è molto casino, tante persone etc etc è difficile
        # parlare piano
        if entity.location.mod_noise > 75 and channel <= CHANNEL.SAY:
            entity.send_output("Non puoi %s con tutta questa confusione!" %
                               channel)
            return False

    # Invia l'appropriato messaggio nel caso in cui trovi argument vuoto
    if not argument:
        send_not_argument_message(entity, objective, channel)
        return False

    # Cerca eventuali smiles nella stringa controllando gli ultimi caratteri
    for social in database["socials"].itervalues():
        if not social.smiles:
            continue
        for single_smile in social.smiles.split():
            if single_smile in argument[-config.chars_for_smile:]:
                break
        else:
            # Se non trova nessun smile esce dal ciclo dei social e continua
            # col prossimo set di smiles trovato
            continue

        cut_smile = argument.rfind(single_smile)
        # Se argument è formato solo dallo smile invia il corrispondente social
        if cut_smile == 0:
            social_name = social.fun_name[len("social_"):]
            if objective == OBJECTIVE_TARGET:
                input_to_send = "%s %s" % (social_name, target.name)
            elif objective == OBJECTIVE_SELF:
                input_to_send = "%s %s" % (social_name, entity.name)
            else:
                input_to_send = social_name

            send_input(entity,
                       input_to_send,
                       "en",
                       show_input=False,
                       show_prompt=False)
            return True

        # Altrimenti ne ricava l'espressione dello smile-social e toglie lo
        # smile da argument, se il carattere dopo lo smile era un simbolo di
        # punteggiatura lo attacca alla frase togliendo gli spazi
        first_part = argument[:cut_smile]
        second_part = argument[cut_smile + len(single_smile):]
        if second_part.strip() and second_part.strip()[0] in "!?.,:;":
            first_part = first_part.rstrip()
            second_part = second_part.lstrip()
        argument = first_part.rstrip() + second_part.rstrip()
        smile = " %s" % social.expression
        break

    # Elabora i punti esclamativi e interrogativi per il canale say.
    # Qui viene utilizzata l'opzione chars_for_smile visto che si sta facendo
    # una cosa simile a sopra, ovvero considerare solo l'ultima parte
    # dell'argomento passato.
    exclamations = argument[-config.chars_for_smile:].count("!")
    questions = argument[-config.chars_for_smile:].count("?")
    if exclamations > questions:
        if channel == CHANNEL.SAY:
            verb_you = "Esclami"
            verb_it = " esclama"
        exclaim = True
    elif exclamations < questions:
        if channel == CHANNEL.SAY:
            verb_you = "Domandi"
            verb_it = " domanda"
        ask = True
    # Questo elif sottintende che exclamations e questions siano uguali
    elif exclamations != 0 and questions != 0:
        # Con una stessa quantità di ! e di ? l'ultimo che viene trovato
        # ha maggiore peso rispetto all'altro
        exclamation_pos = argument.rfind("!")
        question_pos = argument.rfind("?")
        if exclamation_pos > question_pos:
            if channel == CHANNEL.SAY:
                verb_you = "Esclami"
                verb_it = " esclama"
            exclaim = True
        else:
            if channel == CHANNEL.SAY:
                verb_you = "Domandi"
                verb_it = " domanda"
            ask = True

    # Supporto per piccoli emote separati da * ad inizio argument
    if argument[0] == "*":
        cut_emote = argument[1:].find("*")
        if cut_emote != -1:
            emote = " %s" % argument[1:cut_emote + 1].strip()
            if smile:
                emote = " e%s" % emote
            argument = argument[cut_emote + 2:].strip()

    # Unisce i vari pezzi per formare l'output
    expres_entity = verb_you
    expres_room = verb_it
    expres_target = ""
    if objective == OBJECTIVE_TARGET:
        name = target.get_name(entity)
        expres_entity += " a %s" % name
        expres_room += " a %s" % name
        expres_target += " ti%s" % verb_it
    elif objective == OBJECTIVE_SELF:
        expres_entity += " a te stess%s" % grammar_gender(entity)
        expres_room += " a sé stess%s" % grammar_gender(entity)
    elif objective == OBJECTIVE_GROUP:
        members = entity.get_members_here(entity.location)
        if len(members) == 1:
            expres_entity += " a %s" % members[0].name
            expres_room += " a %s" % members[0].name
            expres_target += " ti%s" % verb_it
        else:
            if len(members) > 5:
                many = "folto "
            else:
                many = ""
            expres_entity += " al gruppo"
            expres_room += " ad un %sgruppo" % many
            expres_target += "%s al gruppo" % verb_it
    # Aggiunge le eventuali espressioni dello smile e dell'emote
    expres_entity += smile + emote
    expres_room += smile + emote
    expres_target += smile + emote

    if not argument:
        send_not_argument_message(entity, objective, channel)
        return False

    # Prepara il pezzo riguardante la lingua utilizzata
    language = ""
    if not entity.IS_ITEM and entity.speaking != LANGUAGE.COMMON:
        language = " in lingua %s" % entity.speaking

    # Mischia il testo se si è ubriachi
    original_argument = argument = color_first_upper(argument)
    argument = drunk_speech(argument, entity)

    # Parlando si impara la lingua
    if not entity.IS_ITEM:
        learn_language(entity, channel, entity.speaking)

    # Controlla se vi sono parolacce o parole offrpg e logga i relativi argument
    if entity.IS_PLAYER:
        check_for_badwords(entity, argument)

    # Invia il messaggio a tutti coloro che lo possono sentire
    for location in expand_voice_around(entity, channel):
        if not location:
            log.bug(
                "location per il canale %s e per l'entità %s non è valida: %r"
                % (channel, entity.code, location))
            continue
        for listener in location.iter_contains(use_reversed=True):
            if listener.position <= POSITION.SLEEP:
                continue

            if listener == entity:
                force_return = check_trigger(entity, "before_rpg_channel",
                                             listener, entity, target,
                                             argument, ask, exclaim,
                                             behavioured)
                if force_return:
                    continue
                force_return = check_trigger(
                    entity, "before_" + channel.trigger_suffix, listener,
                    entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue

                # Invia all'entità il suo stesso messaggio
                first_part = (close_color(color) + expres_entity).rstrip()
                message = "%s: '%s'" % (first_part, close_color(argument))
                send_channel_message(entity, message, True)

                force_return = check_trigger(entity, "after_rpg_channel",
                                             listener, entity, target,
                                             argument, ask, exclaim,
                                             behavioured)
                if force_return:
                    continue
                force_return = check_trigger(entity,
                                             "after_" + channel.trigger_suffix,
                                             listener, entity, target,
                                             argument, ask, exclaim,
                                             behavioured)
                if force_return:
                    continue
            else:
                # Fa ascoltare solo ad un'entità di un eventuale gruppo fisico
                listener = listener.split_entity(1)

                force_return = check_trigger(listener,
                                             "before_listen_rpg_channel",
                                             listener, entity, target,
                                             argument, ask, exclaim,
                                             behavioured)
                if force_return:
                    continue
                force_return = check_trigger(
                    listener, "before_listen_" + channel.trigger_suffix,
                    listener, entity, target, argument, ask, exclaim,
                    behavioured)
                if force_return:
                    continue

                # Prepara alcune cose a seconda della stanza di provenienza del messaggio
                if entity.location == listener.location:
                    entity_name = entity.get_name(listener)
                    entity_name = color_first_upper(entity_name)
                    from_direction = ""
                elif entity.location.IS_ROOM:
                    # (TD) invia qualcuno a meno che non lo si abbia conosciuto
                    # precedentemente con il sistema di presentazione
                    entity_name = "Qualcuno"
                    from_direction = get_from_direction(
                        listener.location.x, listener.location.y,
                        listener.location.z, entity.location.x,
                        entity.location.y, entity.location.z)
                elif entity.location.IS_ACTOR:
                    if entity.location != listener:
                        entity_name = "Qualcuno"  # (TD) come sopra
                    from_direction = " dall'inventario di %s" % entity.location.get_name(
                        listener)
                else:
                    entity_name = "Qualcuno"  # (TD) come sopra
                    from_direction = " da dentro %s" % entity.location.get_name(
                        listener)

                # Prepara la prima parte, quella senza il messaggio
                if objective == OBJECTIVE_ROOM:
                    output = "%s%s%s%s" % (entity_name,
                                           close_color(color) + expres_room,
                                           language, from_direction)
                elif objective == OBJECTIVE_TARGET or OBJECTIVE_SELF:
                    if listener == target:
                        output = "%s%s%s%s" % (
                            entity_name, close_color(color) + expres_target,
                            language, from_direction)
                    else:
                        output = "%s%s%s%s" % (
                            entity_name, close_color(color) + expres_room,
                            language, from_direction)
                elif objective == OBJECTIVE_GROUP:
                    if listener in group_members:
                        output = "%s%s%s%s" % (
                            entity_name, close_color(color) + expres_target,
                            language, from_direction)
                    else:
                        output = "%s%s%s%s" % (
                            entity_name, close_color(color) + expres_room,
                            language, from_direction)

                output = "<br>%s: '%s'" % (close_color(output).rstrip(),
                                           close_color(argument))
                send_channel_message(listener, output, False)
                listener.send_prompt()

                force_return = check_trigger(listener,
                                             "after_listen_rpg_channel",
                                             listener, entity, target,
                                             argument, ask, exclaim,
                                             behavioured)
                if force_return:
                    continue
                force_return = check_trigger(
                    listener, "after_listen_" + channel.trigger_suffix,
                    listener, entity, target, argument, ask, exclaim,
                    behavioured)
                if force_return:
                    continue

    return True
Beispiel #15
0
def command_repaint(entity, argument=""):
    """
    Permette di modificare la short, nome e descrizione di una stanza.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        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

    if not argument:
        syntax = get_command_syntax(entity, "command_repaint")
        entity.send_output(syntax)

        output = "[white]%s[close]:\n" % room.code
        output += '''<table class='mud'>'''
        output += '''<tr><td>Name:</td><td>%s</td></tr>''' % room.name
        if room.short:
            output += '''<tr><td>Short:</td><td>%s</td></tr>''' % room.short
        if room.short_night:
            output += '''<tr><td>ShortNight:</td><td>%s</td></tr>''' % room.short_night
        output += '''<tr><td valign="top">Descr:</td><td>%s</td></tr>''' % room.descr
        if room.descr_night:
            output += '''<tr><td valign="top">DescrNight:</td><td>%s</td></tr>''' % room.descr_night
        if room.descr_hearing:
            output += '''<tr><td valign="top">DescrHearing:</td><td>%s</td></tr>''' % room.descr_hearing
        if room.descr_hearing_night:
            output += '''<tr><td valign="top">DescrHearingNight:</td><td>%s</td></tr>''' % room.descr_hearing_night
        if room.descr_smell:
            output += '''<tr><td valign="top">DescrSmell:</td><td>%s</td></tr>''' % room.descr_smell
        if room.descr_smell_night:
            output += '''<tr><td valign="top">DescrSmellNight:</td><td>%s</td></tr>''' % room.descr_smell_night
        if room.descr_touch:
            output += '''<tr><td valign="top">DescrTouch:</td><td>%s</td></tr>''' % room.descr_touch
        if room.descr_touch_night:
            output += '''<tr><td valign="top">DescrTouchNight:</td><td>%s</td></tr>''' % room.descr_touch_night
        if room.descr_taste:
            output += '''<tr><td valign="top">DescrTaste:</td><td>%s</td></tr>''' % room.descr_taste
        if room.descr_taste_night:
            output += '''<tr><td valign="top">DescrTasteNight:</td><td>%s</td></tr>''' % room.descr_taste_night
        if room.descr_sixth:
            output += '''<tr><td valign="top">DescrSixth:</td><td>%s</td></tr>''' % room.descr_sixth
        if room.descr_sixth_night:
            output += '''<tr><td valign="top">DescrSixthNight:</td><td>%s</td></tr>''' % room.descr_sixth_night
        output += '''</table>'''
        entity.send_output(output, break_line=False)
        return False

    arg1, argument = one_argument(argument)
    attribute = ""
    if is_prefix(arg1, ("name", "nome")):
        attribute = "name"
        attr_descr = "il nome"
    elif is_prefix(arg1, ("short", "corta")):
        attribute = "short"
        attr_descr = "la short"
    elif is_prefix(arg1,
                   ("ShortNight", "short_night", "CortaNotte", "corta_notte")):
        attribute = "short_night"
        attr_descr = "la short notturna"
    elif is_prefix(arg1, ("Descr", "descr", "Descrizione", "description")):
        attribute = "descr"
        attr_descr = "la descrizione"
    elif is_prefix(arg1, ("DescrNight", "descr_night")):
        attribute = "descr_night"
        attr_descr = "la descrizione notturna"
    elif is_prefix(arg1, ("DescrHearing", "descr_hearing")):
        attribute = "descr_hearing"
        attr_descr = "la descrizione uditiva"
    elif is_prefix(arg1, ("DescrHearingNight", "descr_hearing_night")):
        attribute = "descr_hearing_night"
        attr_descr = "la descrizione uditiva notturna"
    elif is_prefix(arg1, ("DescrSmell", "descr_smell")):
        attribute = "descr_smell"
        attr_descr = "la descrizione olfattiva"
    elif is_prefix(arg1, ("DescrSmellNight", "descr_smell_night")):
        attribute = "descr_smell_night"
        attr_descr = "la descrizione olfattiva notturna"
    elif is_prefix(arg1, ("DescrTouch", "descr_touch")):
        attribute = "descr_touch"
        attr_descr = "la descrizione tattile"
    elif is_prefix(arg1, ("DescrTouchNight", "descr_touch_night")):
        attribute = "descr_touch_night"
        attr_descr = "la descrizione tattile notturna"
    elif is_prefix(arg1, ("DescrTaste", "descr_taste")):
        attribute = "descr_taste"
        attr_descr = "la descrizione gustativa"
    elif is_prefix(arg1, ("DescrTasteNight", "descr_taste_night")):
        attribute = "descr_taste_night"
        attr_descr = "la descrizione gustativa notturna"
    elif is_prefix(arg1, ("DescrSixth", "descr_sixth")):
        attribute = "descr_sixth"
        attr_descr = "la descrizione intuitiva"
    elif is_prefix(arg1, ("DescrSixthNight", "descr_sixth_night")):
        attribute = "descr_sixth_night"
        attr_descr = "la descrizione intuitiva notturna"

    if not attribute:
        syntax = "L'etichetta da modificare all'entità '%s' è errata: %s" % (
            room.code, arg1)
        syntax += get_command_syntax(entity, "command_repaint")
        entity.send_output(syntax, break_line=False)
        return False

    if not argument:
        syntax = "Il testo da sostituire nell'etichetta è vuoto."
        syntax += get_command_syntax(entity, "command_repaint")
        entity.send_output(syntax, break_line=False)
        return False

    if not check_colors(argument):
        entity.send_output("Errore nella colorazione del testo: %s" % argument)
        return False

    if getattr(room, attribute) == argument:
        entity.send_output(
            "Inutile modificare %s di '%s' con un'altra stringa uguale." %
            (attr_descr, room.code))
        return False

    setattr(room, attribute, argument)
    entity.send_output(
        "Hai modificato il testo dell'etichetta %s di '%s' in %s" %
        (to_capitalized_words(attribute), room.code, argument))
    return True
Beispiel #16
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
Beispiel #17
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
Beispiel #18
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
Beispiel #19
0
def command_restring(entity, argument=""):
    """
    Permette di modificare la short il nome e la descrizione dell'oggetto voluto.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

    if not argument:
        syntax = get_command_syntax(entity, "command_restring")
        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:
        entity.send_output("Nessuna entità trovata con argomento [white]%s[close]." % arg1)
        return False

    if not argument:
        output  = "[white]%s[close]:\n" % target.code
        output += '''<table class='mud'>'''
        if not target.IS_PLAYER:
            output += '''<tr><td>KeywordsName:</td><td>%s</td></tr>''' % target.keywords_name
            output += '''<tr><td>KeywordsShort:</td><td>%s</td></tr>''' % target.keywords_short
            output += '''<tr><td>KeywordsShortNight:</td><td>%s</td></tr>''' % target.keywords_short_night
        output += '''<tr><td>Name:</td><td>%s</td></tr>''' % target.name
        if target.short:
            output += '''<tr><td>Short:</td><td>%s</td></tr>''' % target.short
        if target.short_night:
            output += '''<tr><td>ShortNight:</td><td>%s</td></tr>''' % target.short_night
        if target.long:
            output += '''<tr><td>Long:</td><td>%s</td></tr>''' % target.long
        if target.long_night:
            output += '''<tr><td>LongNight:</td><td>%s</td></tr>''' % target.long_night
        output += '''<tr><td>Descr:</td><td>%s</td></tr>''' % target.descr
        if target.descr_night:
            output += '''<tr><td valign="top">DescrNight:</td><td>%s</td></tr>''' % target.descr_night
        if target.descr_hearing:
            output += '''<tr><td valign="top">DescrHearing:</td><td>%s</td></tr>''' % target.descr_hearing
        if target.descr_hearing_night:
            output += '''<tr><td valign="top">DescrHearingNight:</td><td>%s</td></tr>''' % target.descr_hearing_night
        if target.descr_smell:
            output += '''<tr><td valign="top">DescrSmell:</td><td>%s</td></tr>''' % target.descr_smell
        if target.descr_smell_night:
            output += '''<tr><td valign="top">DescrSmellNight:</td><td>%s</td></tr>''' % target.descr_smell_night
        if target.descr_touch:
            output += '''<tr><td valign="top">DescrTouch:</td><td>%s</td></tr>''' % target.descr_touch
        if target.descr_touch_night:
            output += '''<tr><td valign="top">DescrTouchNight:</td><td>%s</td></tr>''' % target.descr_touch_night
        if target.descr_taste:
            output += '''<tr><td valign="top">DescrTaste:</td><td>%s</td></tr>''' % target.descr_taste
        if target.descr_taste_night:
            output += '''<tr><td valign="top">DescrTasteNight:</td><td>%s</td></tr>''' % target.descr_taste_night
        if target.descr_sixth:
            output += '''<tr><td valign="top">DescrSixth:</td><td>%s</td></tr>''' % target.descr_sixth
        if target.descr_sixth_night:
            output += '''<tr><td valign="top">DescrSixthNight:</td><td>%s</td></tr>''' % target.descr_sixth_night
        output += '''</table>'''
        if target.IS_PLAYER and not target.game_request:
            entity.send_output("Il giocatore %s è [darkslategray]offline[close]")
        entity.send_output(output, break_line=False)
        return True

    arg2, argument = one_argument(argument)
    attribute = ""
    if is_prefix(arg2, ("KeywordsName", "keywords_name")):
        attribute = "keywords_name"
        attr_descr = "le parole chiavi del nome"
    elif is_prefix(arg2, ("KeywordsShort", "keywords_short")):
        attribute = "keywords_short"
        attr_descr = "le parole chiavi della short"
    elif is_prefix(arg2, ("KeywordsShortNight", "keywords_short_night")):
        attribute = "keywords_short_night"
        attr_descr = "le parole chiavi della short notturna"
    elif is_prefix(arg2, ("Name", "nome")):
        attribute = "name"
        attr_descr = "il nome"
    elif is_prefix(arg2, ("Short", "corta")):
        attribute = "short"
        attr_descr = "la short"
    elif is_prefix(arg2, ("ShortNight", "short_night")):
        attribute = "short_night"
        attr_descr = "la short notturna"
    elif is_prefix(arg2, ("Long", "lunga")):
        attribute = "long"
        attr_descr = "la long"
    elif is_prefix(arg2, ("LongNight", "long_night")):
        attribute = "long_night"
        attr_descr = "la long notturna"
    elif is_prefix(arg2, ("Descr", "descr", "Descrizione", "description")):
        attribute = "descr"
        attr_descr = "la descrizione"
    elif is_prefix(arg2, ("DescrNight", "descr_night")):
        attribute = "descr_night"
        attr_descr = "la descrizione notturna"
    elif is_prefix(arg2, ("DescrHearing", "descr_hearing")):
        attribute = "descr_hearing"
        attr_descr = "la descrizione uditiva"
    elif is_prefix(arg2, ("DescrHearingNight", "descr_hearing_night")):
        attribute = "descr_hearing_night"
        attr_descr = "la descrizione uditiva notturna"
    elif is_prefix(arg2, ("DescrSmell", "descr_smell")):
        attribute = "descr_smell"
        attr_descr = "la descrizione olfattiva"
    elif is_prefix(arg2, ("DescrSmellNight", "descr_smell_night")):
        attribute = "descr_smell_night"
        attr_descr = "la descrizione olfattiva notturna"
    elif is_prefix(arg2, ("DescrTouch", "descr_touch")):
        attribute = "descr_touch"
        attr_descr = "la descrizione tattile"
    elif is_prefix(arg2, ("DescrTouchNight", "descr_touch_night")):
        attribute = "descr_touch_night"
        attr_descr = "la descrizione tattile notturna"
    elif is_prefix(arg2, ("DescrTaste", "descr_taste")):
        attribute = "descr_taste"
        attr_descr = "la descrizione gustativa"
    elif is_prefix(arg2, ("DescrTasteNight", "descr_taste_night")):
        attribute = "descr_taste_night"
        attr_descr = "la descrizione gustativa notturna"
    elif is_prefix(arg2, ("DescrSixth", "descr_sixth")):
        attribute = "descr_sixth"
        attr_descr = "la descrizione intuitiva"
    elif is_prefix(arg2, ("DescrSixthNight", "descr_sixth_night")):
        attribute = "descr_sixth_night"
        attr_descr = "la descrizione intuitiva notturna"

    if not attribute:
        syntax = "L'etichetta da modificare all'entità '%s' è errata: %s" % (target.code, arg2)
        syntax += get_command_syntax(entity, "command_restring")
        entity.send_output(syntax, break_line=False)
        return False

    if not argument:
        syntax = "Il testo da sostituire nell'etichetta è vuoto."
        syntax += get_command_syntax(entity, "command_restring")
        entity.send_output(syntax, break_line=False)
        return False

    if not check_colors(argument):
        entity.send_output("Errore nella colorazione del testo: %s" % argument)
        return False

    if getattr(target, attribute) == argument:
        entity.send_output("Inutile modificare %s di '%s' con un'altra stringa uguale." % (attr_descr, target.code))
        return False

    # Se si sta rinominando un giocatore allora si tiene traccia del vecchio nome
    if target.IS_PLAYER:
        if attribute == "name":
            argument = color_first_upper(argument)
            err_msg_name = get_error_message_name(argument, True, "players")
            if err_msg_name:
                entity.send_output(err_msg_name)
                return False
            if not is_same(argument, target.name):
                target.old_names += " " + target.name
            # (TD) fare anche i messaggi d'avviso per gli altri attributi? da pensare
            target.send_output("\nTi è stato cambiato il nome da %s a %s" % (target.name, argument))
            target.send_prompt()
        elif attribute in ("keywords_name", "keywords_short", "keywords_short_night"):
            entity.send_output("È impossibile modificare %s nei giocatori." % attr_descr)
            return False

    setattr(target, attribute, argument)
    entity.send_output("Hai modificato il testo dell'etichetta %s di '%s' in %s" % (
        to_capitalized_words(attribute), target.code, argument))
    return True
Beispiel #20
0
def command_addexit(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_addexit")
        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 in room.exits:
        if room.exits[direction].destination:
            destination_message = " che porta a %s" % room.exits[
                direction].destination
        else:
            destination_message = ""
        entity.send_output(
            "C'è già un uscita %s%s, non puoi aggiungerne un'altra se non rimuovendola con il comando [limegreen]delexit[close] con il comando [limegreen]modifyexit[close]."
            % (direction.to_dir))
        return False

    # Supporto per la destinazione
    destination = None
    if argument:
        args = multiple_arguments(argument)
        if len(args) not in (3, 4):
            entity.send_output(
                "Sintassi del comando non valida, se si vuole specificare una destinazione servono le relative coordinate ed eventualmente il codice dell'area."
            )
            return False
        if not is_number(args[0]):
            entity.send_output("La coordinata X non è un numero valido: %s" %
                               args[0])
            return False
        if not is_number(args[1]):
            entity.send_output("La coordinata Y non è un numero valido: %s" %
                               args[1])
            return False
        if not is_number(args[2]):
            entity.send_output("La coordinata Z non è un numero valido: %s" %
                               args[2])
            return False
        if len(args) == 4:
            area = get_area_from_argument(args[3])
            if not area:
                entity.send_output("Area non trovata con argomento %s" %
                                   args[3])
                return False
        else:
            area = entity.area
        destination = Destination(int(args[0]), int(args[1]), int(args[2]),
                                  area)

    # Crea la nuova uscita da zero
    exit = Exit(direction)
    if destination:
        exit.destination = destination

    room.exits[direction] = exit
    entity.send_output("E' stata aggiunta l'uscita %s." % direction.to_dir)
    return True
Beispiel #21
0
def command_follow(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("Chi vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_follow")
            entity.send_output(syntax, break_line=False)
        return False

    ag1, argument = one_argument(argument)
    target = entity.find_entity(ag1, location=entity.location)
    if not target:
        entity.act("Non trovi nessun %s da %s qui attorno." % (ag1, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sembra stia cercando qualcuno qui attorno che non c'è.", TO.OTHERS)
        return False

    # (TD) anche qui forse ci vuole lo split
    pass

    # Se entity è sotto charm preferisce rimanere accanto al proprio master
    if entity.master:
        if entity.master == SEX.FEMALE:
            suffix = "alla tua maestra"
        else:
            suffix = "al tuo maestro"
        entity.act("Preferisci rimanere accanto %s $a." % suffix, TO.ENTITY, target, entity.master)
        entity.act("$n tenta di %s $N ma poi cambia idea, come ipnotizzat$o." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n tenta di %s ma poi cambia idea, come ipnotizzat$o." % verbs["you2"], TO.TARGET, target)
        entity.act("$n tenta di ribellarsi %s $a, ma poi cambia idea, è ancora in mano tua." % (
            verbs["gerund"], TO.TARGET, entity.master, target))  # (bb) possibile errore di doppio messaggio
        return False

    # Per smettere di seguire o essere seguiti basta scegliere come obiettivo
    # sé stessi
    if entity == target:
        if entity.guide:
            show_stop_following_messages(entity, target, verbs)
            entity.guide = None
            return True
        else:
            entity.act("Già non stai %s nessuno" % verbs["gerund"], TO.ENTITY)
            entity.act("$n si accorge solo ora che non sta %s nessuno." % verbs["gerund"], TO.OTHERS)
            return False

    # Evita di farsi seguire a vicenda, sarebbe dannoso in aree maze-like
    if entity.have_circle_follow(target):
        entity.act("Cominci a %s $N, che però segue te! Quindi decidi di smettere di farlo." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n e $N cominciano a seguirsi a vicenda, ma smettono quando capiscono che non è una gran idea.", TO.OTHERS, target)
        entity.act("$n comincia a seguirti, tuttavia tu insegui già lui! Dopo un po' decide di smettere di farlo.", TO.TARGET, target)
        return False

    force_return = check_trigger(entity, "before_follow", entity, target, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_followed", entity, target, behavioured)
    if force_return:
        return True

    if entity.guide:
        show_stop_following_messages(entity, target, verbs)
        entity.guide = None

    emote_argument = get_emote_argument(argument)
    entity.act("Cominci a %s $N%s." % (verbs["infinitive"], emote_argument), TO.ENTITY, target)
    if target.can_see(entity):
        # (TD) è che qui più che qualcuno segue $N è proprio o vedi o non vedi,
        # e non un: riconosci o non riconosci, da pensare se inserire un
        # parametro in più per la act per variare un po'
        entity.act("$n comincia a %s $N%s." % (verbs["infinitive"], emote_argument), TO.OTHERS, target)
        entity.act("$n ti comincia a %s%s." % (verbs["infinitive"], emote_argument), TO.TARGET, target)
    else:
        if target.trust > TRUST.PLAYER:
            target.send_to_admin("Anche se non lo puoi vedere sai che %s ha cominciato a %s." % (entity.name, verbs["you2"]))
    entity.guide = target

    force_return = check_trigger(entity, "after_follow", entity, target, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_followed", entity, target, behavioured)
    if force_return:
        return True

    return True
Beispiel #22
0
def dig_an_exit(entity, argument, verbs, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    # behavioured ha valore di verità

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

    location = entity.location

    arg, argument = one_argument(argument);
    direction = get_direction(arg)
    if direction == DIR.NONE:
        entity.act("Non trovi nessuna direzione [white]%s[close] in cui %s." % (arg, verbs["infinitive"]), TO.ENTITY, location)
        entity.act("$n sembra voler %s in una direzione, ma appare spaesato." % verbs["infinitive"], TO.OTHERS, location)
        entity.act("$n sembra voler %s in una direzione, ma appare spaesato." % verbs["you2"], TO.TARGET, location)
        return False

    if not location.IS_ROOM:
        entity.act("Non trovi in un luogo ove poter %s %s." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location)
        entity.act("$n sembra voler %s %s nonostante non si trovi in un luogo con delle uscite." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location)
        entity.act("Non sei un luogo in cui si possa %s %s, eppure $n ci sta provando lo stesso." % (verbs["infinitive"], direction.to_dir), TO.TARGET, location)
        return False

    # (TD) Questo si potrebbe convertire in metodo se dovesse servire nuovamente
    exit = None
    has_secret_door = False
    if direction in location.exits:
        exit = location.exits[direction]
        door = location.get_door(direction)
        if door and door.door_type and DOOR.SECRET in door.door_type.flags and DOOR.CLOSED in door.door_type.flags:
            has_secret_door = True

    if exit and EXIT.DIGGABLE not in exit.flags and not has_secret_door:
        entity.act("Non sapresti proprio come %s %s: c'è già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location)
        entity.act("$n sembra voler %s %s: ma c'è già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location)
        entity.act("$n sembra voler %s %s: ma li hai già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.TARGET, location)
        return False

    entity.act("Cominci a %s %s." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location)
    entity.act("$n comincia a %s %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location)
    entity.act("$n comincia a %s %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location)

    force_return = check_trigger(entity, "before_dig", entity, location, exit, direction, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "before_digged", entity, location, exit, direction, behavioured)
    if force_return:
        return True

    # (TD) Togliere un po' di energie nella scavata
    if exit and not has_secret_door:
        defer_later_function = digging_a_diggable_exit_1
    else:
        defer_later_function = digging_an_inexistent_exit_1
    entity.action_in_progress = ActionInProgress(DIG_SECONDS, defer_later_function, stop_digging_on_exit, entity, location, direction, verbs, behavioured)
    return True
Beispiel #23
0
def command_follow(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("Chi vorresti %s?" % verbs["infinitive"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_follow")
            entity.send_output(syntax, break_line=False)
        return False

    ag1, argument = one_argument(argument)
    target = entity.find_entity(ag1, location=entity.location)
    if not target:
        entity.act(
            "Non trovi nessun %s da %s qui attorno." %
            (ag1, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sembra stia cercando qualcuno qui attorno che non c'è.",
                   TO.OTHERS)
        return False

    # (TD) anche qui forse ci vuole lo split
    pass

    # Se entity è sotto charm preferisce rimanere accanto al proprio master
    if entity.master:
        if entity.master == SEX.FEMALE:
            suffix = "alla tua maestra"
        else:
            suffix = "al tuo maestro"
        entity.act("Preferisci rimanere accanto %s $a." % suffix, TO.ENTITY,
                   target, entity.master)
        entity.act(
            "$n tenta di %s $N ma poi cambia idea, come ipnotizzat$o." %
            verbs["infinitive"], TO.OTHERS, target)
        entity.act(
            "$n tenta di %s ma poi cambia idea, come ipnotizzat$o." %
            verbs["you2"], TO.TARGET, target)
        entity.act(
            "$n tenta di ribellarsi %s $a, ma poi cambia idea, è ancora in mano tua."
            % (verbs["gerund"], TO.TARGET, entity.master,
               target))  # (bb) possibile errore di doppio messaggio
        return False

    # Per smettere di seguire o essere seguiti basta scegliere come obiettivo
    # sé stessi
    if entity == target:
        if entity.guide:
            show_stop_following_messages(entity, target, verbs)
            entity.guide = None
            return True
        else:
            entity.act("Già non stai %s nessuno" % verbs["gerund"], TO.ENTITY)
            entity.act(
                "$n si accorge solo ora che non sta %s nessuno." %
                verbs["gerund"], TO.OTHERS)
            return False

    # Evita di farsi seguire a vicenda, sarebbe dannoso in aree maze-like
    if entity.have_circle_follow(target):
        entity.act(
            "Cominci a %s $N, che però segue te! Quindi decidi di smettere di farlo."
            % verbs["infinitive"], TO.ENTITY, target)
        entity.act(
            "$n e $N cominciano a seguirsi a vicenda, ma smettono quando capiscono che non è una gran idea.",
            TO.OTHERS, target)
        entity.act(
            "$n comincia a seguirti, tuttavia tu insegui già lui! Dopo un po' decide di smettere di farlo.",
            TO.TARGET, target)
        return False

    force_return = check_trigger(entity, "before_follow", entity, target,
                                 behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_followed", entity, target,
                                 behavioured)
    if force_return:
        return True

    if entity.guide:
        show_stop_following_messages(entity, target, verbs)
        entity.guide = None

    emote_argument = get_emote_argument(argument)
    entity.act("Cominci a %s $N%s." % (verbs["infinitive"], emote_argument),
               TO.ENTITY, target)
    if target.can_see(entity):
        # (TD) è che qui più che qualcuno segue $N è proprio o vedi o non vedi,
        # e non un: riconosci o non riconosci, da pensare se inserire un
        # parametro in più per la act per variare un po'
        entity.act(
            "$n comincia a %s $N%s." % (verbs["infinitive"], emote_argument),
            TO.OTHERS, target)
        entity.act(
            "$n ti comincia a %s%s." % (verbs["infinitive"], emote_argument),
            TO.TARGET, target)
    else:
        if target.trust > TRUST.PLAYER:
            target.send_to_admin(
                "Anche se non lo puoi vedere sai che %s ha cominciato a %s." %
                (entity.name, verbs["you2"]))
    entity.guide = target

    force_return = check_trigger(entity, "after_follow", entity, target,
                                 behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_followed", entity, target,
                                 behavioured)
    if force_return:
        return True

    return True
Beispiel #24
0
def skill_kick(entity, argument="", verbs=VERBS, silent=False):
    """
    Skill di combattimento, deve avere un target già prefissato.
    Dà un calcio alla vittima con cui si combatte.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return "failure"

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

    arg, argument = one_argument(argument)
    if arg:
        target = entity.find_entity_extensively(arg)
        if not target:
            entity.send_output("Chi vorresti %s?" % verbs["infinitive"])
            return "failure"
    else:
        target = opponent = entity.get_opponent()

    if not target:
        entity.send_output("Chi vorresti %s?" % verbs["infinitive"])
        return "failure"

    # (TD) gestire le posizioni

    if "kick" not in entity.skills:
        entity.skills["kick"] = 0

    skill_result = check_skill(entity, target, "kick")
    print ">>>>>>> skill kick: skill_result: ", skill_result

    # Ricava quale parte viene colpita
    #arg, argument = one_argument(argument)
    #if not arg:
    #    victim_part = None

    # Ricava se viene utilizzata la gamba destra o sinistra
    #right_leg = True
    #if not argument:
    #    right_leg = entity.hand
    #else:
    #    if is_same(argument, ("destro", "destra", "right")):
    #        right_leg = True
    #    elif is_same(argument, ("sinistro", "sinistra", "left")):
    #        right_leg = False
    #    else:
    #        entity.send_output("Vuoi calciare con la gamba destra o quella sinistra?")
    #        return False

    force_return = check_trigger(entity, "before_kick", entity, target, skill_result)
    if force_return:
        return "failure"
    force_return = check_trigger(target, "before_kicked", entity, target, skill_result)
    if force_return:
        return "failure"

    if not entity.is_fighting(with_him=target):
        start_fight(entity, target)

    if skill_result < config.clumsy_value:
        if not silent:
            entity.act("Tenti di %s il colpo di $N ma metti male la caviglia ed un dolore acuto ti trafigge." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n tenta di %s il colpo di $N ma inciampa facendosi del male." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n si fa del male mentre tenta di %s d'anticipo." % verbs["you2"], TO.TARGET, target)
        # (TD) l'attaccante cade
        kick_damage(entity, target, "clumsy", skill_result)
        execution_result = "clumsy"
        entity.wait(KICK_WAIT * 2)
    elif skill_result < config.failure_value:
        if not silent:
            entity.act("Tenti maldestramente di %s $N rischiando pure di cadere." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n tenta maldestramente di %s $N rischiando di cadere." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n tenta maldestramente di %s rischiando di cadere." % verbs["you2"], TO.TARGET, target)
        kick_damage(entity, target, "failure", skill_result)
        execution_result = "failure"
        entity.wait(KICK_WAIT * 2)
    elif skill_result < config.success_value:
        if not silent:
            entity.act("Riesci a prendere alla sprovvista $N e %s." % verbs["noun"], TO.ENTITY, target)
            entity.act("$n riesce a prendere alla sprovvista$N e %s." % verbs["noun"], TO.OTHERS, target)
            entity.act("$n ti prende alla alla sprovvista e riesce a %s."% verbs["you2"], TO.TARGET, target)
        damage = kick_damage(entity, target, "success", skill_result)
        execution_result = "success"
        entity.wait(KICK_WAIT)
    else:
        if not silent:
            entity.act("Riesci magistralmente a %s $N prendendol$O alla sprovvista." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n riesce magistralmente a %s $N prendendol$O alla sprovvista." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n riesce magistralmente a %s prendendoti alla sprovvista."% verbs["infinitive"], TO.TARGET, target)
        # (TD) il nemico cade
        kick_damage(entity, target, "masterly", skill_result)
        execution_result = "masterly"
        entity.wait(KICK_WAIT)

    force_return = check_trigger(entity, "after_kick", entity, target, skill_result)
    if force_return:
        return execution_result
    force_return = check_trigger(target, "after_kicked", entity, target, skill_result)
    if force_return:
        return execution_result

    return execution_result
Beispiel #25
0
def skill_thundering(entity, argument="", silent=False):
    """
    Skill voce tonante, prende di sorpresa il nemico urlandogli contro
    qualcosa in maniera 'tonante'.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

    execution_success = rpg_channel(entity, argument, CHANNEL.THUNDERING)
    if not execution_success:
        return False

    # (TD) rimane così fino al rifacimento delle skill
    return True

    # La gestione dell'argomento vuoto viene effettuata dalla rpg_channel.
    # Anche se la parte skillosa del comando non viene effettuata il comando
    # è considerato eseguito
    if not argument:
        return True

    arg, argument = one_argument(argument)
    # Qui effettua una ricerca della particella in minuscolo, ci sono più
    # probabilità che non conflitti con la ricerca del nome di un'entità
    if argument and arg[0 : 2] == "a ":
        arg, argument = one_argument(argument)

    # Se il target non si trova allora esce, non eseguendo la parte della skill
    # e considerando il thundering come un comando di canale rpg
    target = entity.find_entity_extensively(arg)
    if not target:
        return True

    percent = check_skill(entity, target, "thundering")
    # (TD) farla utilizzare anche in combattimento, ma ad inizio combattimento
    # ci sono più chance di sorpresa
    if percent < config.clumsy_value:
        if not silent:
            entity.act("\nCerchi di prendere di [yellow]sorpresa[close] $N con la tua [red]voce tonante[close] ma tutto quello che ti esce è una [pink]vocina stridula[close]...", TO.ENTITY, target)
            entity.act("$lui cerca di prendere di [yellow]sorpresa[close] $N con la sua [red]voce tonante[close] ma tutto quello che gli esce è una [pink]vocina stridula[close]...", TO.OTHERS, target)
            entity.act("$lui cerca ti prenderti di [yellow]sorpresa[close] con la sua [red]voce tonante[close] ma tutto quello che gli esce è una [pink]vocina stridula[close]...", TO.TARGET, target)
        return "clumsy"
    elif percent < config.failure_value:
        if not silent:
            entity.act("\nCerchi di prendere di [yellow]sorpresa[close] $N con la tua [red]voce tonante[close] ma [dimgray]fallisci[close]...", TO.ENTITY, target)
            entity.act("$lui cerca ti prenderti di [yellow]sorpresa[close] con la sua [red]voce tonante[close] ma [dimgray]fallisce[close]...", TO.OTHERS, target)
            entity.act("$lui cerca di prendere di [yellow]sorpresa[close] $N con la sua [red]voce tonante[close] ma [dimgray]fallisce[close]..", TO.TARGET, target)
        return "failure"
    elif percent < config.success_value:
        if not silent:
            entity.act("\n[white]Riesci[close] a prendere di [yellow]sorpresa[close] $N con la tua [red]voce tonante[close]!", TO.ENTITY, target)
            entity.act("$lui [white]riesce[close] a prendere di [yellow]sorpresa[close] $N con la sua [red]voce tonante[close]!", TO.OTHERS, target)
            entity.act("$lui ti [white]riesce[close] a prendere di [yellow]sorpresa[close] con la sua [red]voce tonante[close]!", TO.TARGET, target)
        return "success"
    else:
        if not silent:
            entity.act("\n$N [cyan]salta per aria[close] dalla [yellow]sorpresa[close] e rimane [yellow]spaesato[close] dalla tua [red]voce tonante[close]!", TO.ENTITY, target)
            entity.act("$N [cyan]salta per aria[close] dalla [yellow]sorpresa[close] e rimane [yellow]spaesato[close] dalla [red]voce tonante[close] di $lui!", TO.OTHERS, target)
            entity.act("[cyan]Salti per aria[close] dalla [yellow]sorpresa[close] e rimani [yellow]spaesato[close] dalla [red]voce tonante[close] di $lui!", TO.TARGET, target)
        # (TD) Penalità in attesa nell'iniziare il combattimento o del turno
        return "masterly"

    # (TD) se però non è già iniziato non ne ha bisogno (??) cusa l'è che intendevo?
    #start_fight(entity, target)
    return True
Beispiel #26
0
def seed_or_plant(entity, argument, verbs, behavioured, command_name):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

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

    entity = entity.split_entity(1)

    gamescript_suffix = command_name.split("_")[1]
    type_attr_name = gamescript_suffix + "_type"

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

    # (TD) Controllo del mental state deviato

    # Ricerca le entità da seminare o piantare nell'inventario
    arg1, argument = one_argument(argument)
    target = entity.find_entity(arg1, location=entity)
    if not target:
        entity.act("Non hai nessun [white]%s[close] da %s." % (arg1, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n sta cercando inutilmente qualcosa.", TO.OTHERS)
        return False

    arg2 = ""
    location = entity.location
    if argument:
        arg2, argument = one_argument(argument)
        # Rimuove eventuali argomenti facoltativi
        if argument and arg == "in":
            arg2, argument = one_argument(argument)
        # Ricerca dell'entità bersaglio a cui dare l'entità target
        location = entity.find_entity_extensively(arg2)
        if not location:
            entity.act("Non hai trovato nessun [white]%s[close] ove %s $N." % (arg2, verbs["infinitive"]), TO.ENTITY, target)
            entity.act("$n non ha trovato nulla ove %s $N." % (verbs["infinitive"]), TO.OTHERS, target)
            entity.act("$n non ha trovato nulla ove %s." % (verbs["you2"]), TO.TARGET, target)
            return False

    if not arg2:
        arg2 = "da qualche parte"

    # Se l'entità a cui dare si trova nell'inventario allora lo indica
    inventory_message_you = ""
    inventory_message_it = ""
    if location and not location.IS_ROOM and location.location and location.location == entity:
        inventory_message_you = ", nel tuo [yellow]inventario[close],"
        inventory_message_it  = ", nel suo [yellow]inventario[close],"

    # Qui vengono gestite i due casi particolari in cui una delle due entità
    # è stata trovata mentre l'altra no, e quella trovata corrisponde all'entità
    # che ha inviato il comando
    if target and not location and target == entity:
        entity.act("Cerchi di %s [white]te stess$o[close] a [white]%s[close] che non trovi da [gray]nessuna parte[close]." % (verbs["infinitive"], arg2), TO.ENTITY, target)
        entity.act("$n cerca di %s [white]sé stess$o[close] a [white]qualcuno[close] che non sembra trovare da [gray]nessuna parte[close]." % verbs["infinitive"], TO.OTHERS, target)
        return False
    elif not target and location and location == entity:
        entity.act("Cerchi di [orange]passarti[close] da una $hand all'altra [white]%s[close], ma non trovi [gray]nulla del genere[close]." % arg1, TO.ENTITY, location)
        entity.act("$n cerca di [orange]passarsi[close] da una $hand all'altra [white]qualcosa[close] che [gray]non sembra trovare[close].", TO.OTHERS, location)
        return False

    # Gestisce le tre combinazioni di entità non trovate
    if target:
        if not location:
            entity.act("Cerchi di %s $N a [white]%s[close] che non trovi da [gray]nessuna parte[close]." % (verbs["infinitive"], arg2), TO.ENTITY, target)
            entity.act("$n cerca di %s $N a [white]quacuno[close] che non sembra trovare da [gray]nessuna parte[close]." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s a [white]qualcuno[close] che non sembra trovare da [gray]nessuna parte[close]." % verbs["you2"], TO.TARGET, target)
            return False
    else:
        if location:
            entity.act("Cerchi di %s a $N%s un [white]%s[close], ma non trovi [gray]nulla del genere[close]." % (verbs["infinitive"], inventory_message_you, arg1), TO.ENTITY, location)
            entity.act("$n cerca di %s a $N%s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close]." % (verbs["infinitive"], inventory_message_it), TO.OTHERS, location)
            entity.act("$n cerca di %s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close]." % verbs["infinitive"], TO.TARGET, location)
        else:
            entity.act("Cerchi di %s [white]%s[close] a [white]%s[close], ma non trovi [gray]nulla e nessuno[close]." % (verbs["infinitive"], arg1, arg2), TO.ENTITY)
            entity.act("$n cerca di %s [white]qualcosa[close] a [white]quacuno[close], ma [gray]senza molti risultati[close]." % verbs["infinitive"], TO.OTHERS)
        return False

    # Gestisce i tre casi in cui le entità trovate siano uguali a quella che ha
    # inviato il comando
    if target == entity:
        if location == entity:
            entity.act("Cerchi di %s tutt$o [white]te stess$o[close] a... te stess$o!" % verbs["infinitive"], TO.ENTITY)
            entity.act("$n cerca di %s tutt$o [white]sé stess$o[close] a... sé stess$o!" % verbs["infinitive"], TO.OTHERS)
        else:
            entity.act("Cerchi di %s tutt$o [white]te stess$o[close] a $N..." % verbs["infinitive"], TO.ENTITY, location)
            entity.act("$n cerca di %s tutt$o [white]sé stess$o[close] a $N..." % verbs["infinitive"], TO.OTHERS, location)
            entity.act("$n cerca di %s tutt$o [white]sé stess$o[close] a te..." % verbs["infinitive"], TO.TARGET, location)
        return False
    else:
        if location == entity:
            entity.act("Ti [orange]passi[close] $N da una $hand all'altra.", TO.ENTITY, target)
            entity.act("$n si [orange]passa[close] $N da una $hand all'altra.", TO.OTHERS, target)
            entity.act("$n ti [orange]passa[close] da una $hand all'altra.", TO.TARGET, target)
            return False

    # Non si può seminare l'entità in sé stessa
    if target == location:
        entity.act("Cerchi di %s $N a [white]$LUI stess$O[close] senza molti risultati..." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N a [white]$LUI stess$O[close] senza molti risultati..." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s a [white]te stess$O[close] senza molti risultati..." % verbs["you2"], TO.TARGET, target)
        return False

    target_entitype = getattr(target, type_attr_name)

    # Se l'entità è una pianta avvisa che è il caso di utilizzare il comando apposito
    if command_name == "command_seed" and target.plant_type:
        from src.commands.command_plant import VERBS as PLANT_VERBS
        entity.act("Cerchi di %s $N ma faresti prima a %s." % (verbs["infinitive"], PLANT_VERBS["it2"]), TO.ENTITY, target)
        entity.act("$n cerca di %s $N ma farebbe prima a %s." % (verbs["infinitive"], PLANT_VERBS["it2"]), TO.OTHERS, target)
        entity.act("$n cerca di %s ma farebbe prima a %s." % (verbs["you2"], PLANT_VERBS["you2"]), TO.TARGET, target)
        return False

    # Come si può denotare invece è possibile seminare anche se l'entitype
    # non è valido interrando successivamente così l'entità
    if command_name == "command_plant" and not target_entitype:
        entity.act("Cerchi di %s $N che però non sembra essera affatto una pianta." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N che però non sembra affatto essere una pianta." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, ma tu sai di non essere una pianta." % verbs["you2"], TO.TARGET, target)
        return False

    ground = None
    if location.IS_ROOM:
        if (target_entitype and (target_entitype.sectors and location.sector not in target_entitype.sectors
                                 or not target_entitype.sectors and not location.sector.fertile)):
            entity.act("Cerchi di %s $N tuttavia il terreno non sembra essere adatto." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N tuttavia il terreno non sembra essere adatto." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, tuttavia il terreno non sembra essere addato." % verbs["you2"], TO.TARGET, target)
            return False
    elif location.container_type:
        for contains in location.iter_contains():
            if contains.entitype == ENTITYPE.GROUND:
                ground = contains
                break
        else:
            entity.act("Cerchi di %s $N tuttavia non trovi del terreno adatto." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N tuttavia non trova del terreno terreno adatto." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, tuttavia non trova del terreno addato." % verbs["you2"], TO.TARGET, target)
            return False
    elif location.entitype == ENTITYPE.GROUND:
        ground = location
    else:
        entity.act("Cerchi di %s $N tuttavia non trovi del terreno adatto." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s $N tuttavia non trova del terreno terreno adatto." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n cerca di %s, tuttavia non trova del terreno addato." % verbs["you2"], TO.TARGET, target)
        return False

    if ground:
        # Evita di far attecchire piante in un  terreno se questo ha già un seme
        # o una pianta in crescita
        for contains in ground.iter_contains():
            # E' voluto che vi siano potenzialmente più plant_type in uno
            # stesso terreno, ma non più ENTITYPE.PLANT; stesso discorso
            # con l'ENTITYPE.SEED
            if contains.entitype == ENTITYPE.PLANT:
                entity.act("Cerchi di %s $N tuttavia vi è già $a e non riuscirebbe ad attecchire in $A." % verbs["infinitive"], TO.ENTITY, target, contains, ground)
                entity.act("$n cerca di %s $N tuttavia vi è già $a e non riuscirebbe ad attecchire in $A." % verbs["infinitive"], TO.OTHERS, target, contains, ground)
                entity.act("$n cerca di %s, tuttavia vi è già $a e non riuscirebbe ad attecchire in $A." % verbs["you2"], TO.TARGET, target, contains, ground)
                return False
            elif contains.entitype == ENTITYPE.SEED:
                entity.act("Cerchi di %s $N tuttavia noti che qui è già stato %s qualcosa." % (verbs["infinitive"], verbs["infinitive"]), TO.ENTITY, target)
                entity.act("$n cerca di %s $N tuttavia nota che qui è già stato %s qualcosa." % (verbs["infinitive"], verbs["infinitive"]), TO.OTHERS, target)
                entity.act("$n cerca di %s, tuttavia nota che qui è già stato %s qualcosa." % (verbs["you2"], verbs["infinitive"]), TO.TARGET, target)
                return False
    else:
        # Per le staze invece il massimo piantabile è il numero i metri quadri
        # della stanza meno il numero di oggetti già contenuti (visivamente,
        # quindi mucchi di più oggetti valgono uno)
        measured_area = (location.width * location.depth) / 100
        if len(location.get_list_of_entities(entity)) >= measured_area:
            entity.act("Cerchi di %s $N ma non hai spazio ove metterla." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N ma non hai spazio ove metterla." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("$n cerca di %s, ma non hai spazio ove metterla." % verbs["you2"], TO.TARGET, target)
            return False

    force_return = check_trigger(entity, "before_" + gamescript_suffix, entity, target, location, ground, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_" + gamescript_suffix + "ed", entity, target, location, ground, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "before_" + gamescript_suffix + "ing_in_location", entity, target, location, ground, behavioured)
    if force_return:
        return True

    if inventory_message_you and inventory_message_it:
        entity.act("%s $N in $a%s." % (color_first_upper(verbs["you"]), inventory_message_you[ : -1]), TO.ENTITY, target, location)
        entity.act("$n %s $N in $a%s." % (verbs["it"], inventory_message_it[ : -1]), TO.OTHERS, target, location)
        entity.act("$n ti %s in $a%s." % (verbs["it"], inventory_message_it[ : -1]), TO.TARGET, target, location)
        entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, location, target)
    else:
        entity.act("%s $N in $a." % color_first_upper(verbs["you"]), TO.ENTITY, target, location)
        entity.act("$n %s $N in $a." % verbs["it"], TO.OTHERS, target, location)
        entity.act("$n ti %s in $a." % verbs["it"], TO.TARGET, target, location)
        entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, location, target)

    target = target.from_location(1, use_repop=True)
    if ground:
        # Se esiste del ground per la pianta questa attecchisce in esso
        if not ground.container_type:
            # (TD) scelta tecnica di dubbia qualità, da ripensare forse, è certo
            # che se viene cambiata è da rivedere il check nell'iter_variant
            container = Container()
            container.max_weight = target.get_total_weight() * 2
            ground.container_type = container
        target.to_location(ground)
    else:
        target.to_location(location)
    target.flags += FLAG.BURIED
    if target_entitype:
        target.flags += FLAG.GROWING
        target_entitype.start_growth(target, type_attr_name)

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

    force_return = check_trigger(entity, "after_" + gamescript_suffix, entity, target, location, ground, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_" + gamescript_suffix + "ed", entity, target, location, ground, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "after_" + gamescript_suffix + "ing_in_location", entity, target, location, ground, behavioured)
    if force_return:
        return True

    return True
Beispiel #27
0
def command_wear(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di vestirsi di entità nelle varie parti del corpo.
    """
    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_wear")
            entity.send_output(syntax, break_line=False)
        return False

    # (TD) Controllo del mental state deviato
    pass

    # (TD) gestione di all (ti vesti di tutto punto: elenco delle cose indossate)
    pass

    original_argument = argument
    arg, argument = one_argument(argument)
    target = entity.find_entity(arg, location=entity)
    if not target:
        entity.act("Non hai nessun [white]%s[close] nel tuo inventario." % arg, TO.ENTITY)
        entity.act("$n sembra frugare nel suo inventario cercando inutilmente qualcosa.", TO.OTHERS)
        return False

    if target == entity:
        entity.act("Cerchi di %s da sol$o ma... sei sicur$o di quello che stai facendo?" % verbs["you2"], TO.ENTITY)
        entity.act("$n sembra volersi %s da sol$o... Fa finta di non aver visto nulla!" % verbs["infinitive"], TO.OTHERS)
        return False

    chosen_part = None
    if not argument:
        if not target.wear_type:
            entity.act("Non vedi come poter %s $N." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("$n cerca di %s $N ma senza grossi risultati." % verbs["infinitive"], TO.OTHERS, target)
            return False
    else:
        # (TD) Scelta personalizzata della parte da vestire e/o di chi vestire
        #chosen_part = search_part(argument)
        pass

    # (TD) bisognerà fare il supporto body anche per gli oggetti con le proprie parti
    body_parts = entity.get_body_parts()
    if not body_parts and not entity.IS_ITEM:
        log.bug("body_parts non valido per l'entità %s di razza %s" % (entity.code, entity.race))
        return False

    # Ricava la modalità di wear uscendo dal comando se al corpo dell'entità
    # gli mancano delle parti per poter indossare target oppure se l'entità ha
    # già indossato qualcosa
    chosen_mode = None
    already_used_possession = None
    for cycle in ("free", "layarable"):
        for mode in target.wear_type.modes:
            incompatible_part = None
            already_weared_part = None
            # Scorre tra le parti della modalità di wear per controllare discrepanze
            # tra le parti del corpo della razza e quelle dell'entità da indossare
            for part in mode:
                if body_parts and part not in body_parts:
                    incompatible_part = part
                    break
            if incompatible_part:
                continue

            # Supporto friendly per l'hold e il wield, così si possono impugnare o
            # tenere entità anche tramite il comando wear
            if PART.HOLD in mode:
                return command_hold(entity, original_argument)
            if PART.WIELD in mode:
                return command_wield(entity, original_argument)

            # Qui sotto c'è un altro ciclo uguale a quello sopra per dare
            # maggiore priorità alle differenze razziali rispetto alle parti
            # già indossate
            for part in mode:
                already_weared_part, already_weared_possession = check_if_part_is_already_weared(entity, part)
                if already_weared_part:
                    break
            # Se non ha trovato nessuna parte già indossata allora utilizza
            # questa modalità di wear ed esce dal ciclo delle modalità
            if not already_weared_possession or (cycle == "layarable" and already_weared_possession.is_layerable()):
                chosen_mode = mode
                break
        if chosen_mode:
            break

    if incompatible_part:
        # (TT) è stato deciso per ora di nascondere la parte del corpo per cui
        # non si può indossare il vestito
        #entity.act("Il tuo corpo non è adatto a poter indossare $N, ti manca %s." % incompatible_part, TO.ENTITY, target)
        entity.act("Il tuo corpo non è adatto a poter %s $N." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("Il corpo di $n non è adatto a poter %s $N." % verbs["infinitive"], TO.OTHERS, target)
        return False

    if already_weared_possession and not already_weared_possession.is_layerable():
        entity.act("Cerchi di %s $N %s ma hai già indosso $a." % (verbs["infinitive"], already_weared_part.description), TO.ENTITY, target, already_weared_possession)
        entity.act("$n cerca di %s $N %s ma ha già indosso $a." % (verbs["infinitive"], already_weared_part.description), TO.OTHERS, target, already_weared_possession)
        return False

    # (TD) Aggiungere la flag di NO_WEAR (se la location ha la flag NO_WEAR
    # anche il contenuto non potrà indossare, questo è da fare in vista del
    # sistema generico entità-stanze)
    pass

    force_return = check_trigger(entity, "before_wear", entity, target, chosen_part, chosen_mode, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_weared", entity, target, chosen_part, chosen_mode, behavioured)
    if force_return:
        return True

    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.wear_mode.clear()
    for part in chosen_mode:
        target.wear_mode += part
    if already_weared_possession:
        target.under_weared = weakref.ref(already_weared_possession)
        # Forza il posizionamento di target prima di already_weared_possession
        # così che nelle manipolazioni venga prima quella sovrastante
        list_of_target = getattr(entity, target.ACCESS_ATTR)
        index = list_of_target.index(already_weared_possession)
        if index != -1:
            list_of_target.remove(target)
            list_of_target.insert(index, target)

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

    # Poiché l'entità è stata vestita 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()

    part_descriptions = get_part_descriptions(target, "wear", entity, entity)
    # (TD) estendere il verb a tutti i verbi degli act da inizio comando
    send_wear_messages(entity, target, color_first_upper(verbs["you"]), verbs["it"], part_descriptions)

    force_return = check_trigger(entity, "after_wear", entity, target, chosen_part, chosen_mode, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_weared", entity, target, chosen_part, chosen_mode, behavioured)
    if force_return:
        return True

    return True
Beispiel #28
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
Beispiel #29
0
def command_destroy(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    if entity.sended_inputs and is_prefix("romp", 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_destroy")
            entity.send_output(syntax, destroy_line=False)
        return False

    # Solo gli oggetti animati possono utilizzare tale comando
    if entity.IS_ITEM and FLAG.CAN_DAMAGING not in entity.flags:
        entity.act("Non ti è possibile %s nulla di nulla.", TO.ENTITY)
        entity.act("$n sembra vibrare per un attimo... ma forse è stato un abbaglio.", TO.OTHERS)
        return False

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

    target = entity.find_entity_extensively(arg, entity_tables=["items"], inventory_pos="first")
    if not target:
        target = entity.find_entity_extensively(arg, inventory_pos="first")
        if target:
            attack_translation = translate_input(entity, "attack", "en")
            javascript_code = '''javascript:parent.sendInput('%s %s');''' % (attack_translation, target.get_numbered_keyword(looker=entity))
            destroy_noun = verbs["noun"] % grammar_gender(target)
            attack_noun = ATTACK_VERBS["noun"] % grammar_gender(target)
            html_code = '''<a href="%s">%s</a>''' % (javascript_code, attack_noun)
            entity.act("$N non è un oggetto quindi non puoi %s, ma puoi sempre %s." % (destroy_noun, html_code), TO.ENTITY, target)
            entity.act("$n posa uno sguardo indagatore su $N.", TO.OTHERS, target)
            entity.act("$n posa uno sguardo indagatore su di te.", TO.TARGET, target)
        else:
            entity.act("Non riesci a trovare nessun [white]%s[close] da %s" % (arg, verbs["infinitive"]), TO.ENTITY)
            entity.act("$n cerca qualcosa che però non trova.", TO.OTHERS)
        return False

    # (TD) resistenza al comando se charmati

    # (TD) skill di forza bruta

    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 %s" % ["you2"], TO.TARGET, target)
        return False

    # 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_destroy", entity, target, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_broken", entity, target, behavioured)
    if force_return:
        return True

    damage = damage_target(entity, target)
    index, dam_verb_you, dam_verb_it = get_destroy_verbs(damage)

    if target.life <= 0:
        end_destroy(entity, target, verbs, behavioured)
    else:
        messages = {
            "entity" : "%s $N." % dam_verb_you,
            "others" : "$n %s $N." % dam_verb_it,
            "target" : "$n ti %s." % dam_verb_it}
        send_destroy_messages(messages, "start_destroy", entity, target, verbs)
        if index != 0:
            entity.action_in_progress = ActionInProgress(DESTROY_SECONDS, continue_destroy, stop_destroy, entity, target, verbs, behavioured)

    return True
Beispiel #30
0
def command_read(entity, argument="", verbs=VERBS, behavioured=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_read")
            entity.send_output(syntax, break_line=False)
        return False

    arg1, argument = one_argument(argument)
    arg2, argument = one_argument(argument)
    location = None
    if not arg2:
        page_number = 0
    elif is_number(arg2):
        page_number = int(arg2)
    else:
        # Altrimenti cerca la locazione da cui leggere la extra o il readable
        page_number = 0
        if argument and is_number(argument):
            page_number = int(argument)
        location = entity.find_entity_extensively(arg2, inventory_pos="first")
        if not location:
            entity.act("Non riesci a trovare nessun [white]%s[close] da dove cercare di %s qualcosa." % (arg2, verbs["infinitive"]), TO.ENTITY)
            entity.act("$n sembra voler %s da qualcosa che non trova." % verbs["infinitive"], TO.OTHERS)
            return False

    if location:
        target = entity.find_entity(arg1, location=location)
    else:
        target = entity.find_entity_extensively(arg1, inventory_pos="first")
    if not target:
        result = read_extra_from_location(entity, location if location else entity.location, arg1, verbs, behavioured)
        # (TT) non dovrebbero servire queste righe perché ci pensa la fine
        # della read_extra_from_location, tuttavia ho un dubbio sulla
        # sense_at_direction e quindi mantengo le linee per un po' a vedere...
        #if not result:
        #    entity.act("Non riesci a trovare nessun [white]%s[close] da %s." % (arg1, verbs["infinitive"]), TO.ENTITY)
        #    entity.act("$n sembra voler %s qualcosa che non trova." % verbs["infinitive"], TO.OTHERS)
        return result

    if not target.readable_type:
        entity.act("Non trovi modo di poter %s $N" % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n non trova modo di poter %s $N" % verbs["infinitive"], TO.OTHERS, target)
        return False

    if page_number < 0:
        entity.act("Cerchi di %s pagine inesistenti di $N." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n cerca di %s pagine inesistenti di $N" % verbs["infinitive"], TO.OTHERS, target)
        return False

    if page_number > len(target.readable_type.pages) - 1:
        entity.act("Puoi %s solo fino alla %d° pagina di $N." % (verbs["infinitive"], len(target.readable_type.pages)-1), TO.ENTITY, target)
        # E' voluto che qui il messaggio sia uguale a quello sopra, non è un copia e incolla selvaggio
        entity.act("$n cerca di %s pagine inesistenti di $N" % verbs["infinitive"], TO.OTHERS, target)
        return False

    output = target.readable_type.get_pages(entity, target, page_number, location)
    if not output:
        log.bug("Output ricavato dalle pagine per il comando read con entità %s e book %s non valido: %r" % (entity.code, target.code, output))
        return False

    force_return = check_trigger(entity, "before_read", entity, target, output, None, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_readed", entity, target, output, None, behavioured)
    if force_return:
        return True

    from_descr = ""
    if location:
        from_descr = " da %s" % location.get_name(looker=entity)

    # Invia un messaggio adeguato di azione
    previous_same_book  = False
    if entity.sended_inputs and len(entity.sended_inputs) > 2 and len(target.readable_type.pages) > 2 and page_number != 0 and page_number != len(target.readable_type.pages) - 1:
        last_input, last_argument = one_argument(entity.sended_inputs[-2])
        last_input, huh_input, language = multiple_search_on_inputs(entity, last_input)
        last_argument, last_page_argument = one_argument(last_argument)
        last_target = entity.find_entity(last_argument, location=entity)
        if last_input and last_input.command.function == command_read and last_target and last_target == target:
            previous_same_book = True
            if last_page_argument and is_number(last_page_argument):
                last_page_argument = int(last_page_argument)
                if page_number > last_page_argument:
                    entity.act("Sfogli $N%s in avanti." % from_descr, TO.ENTITY, target)
                    entity.act("$n sfoglia $N%s in avanti." % from_descr, TO.OTHERS, target)
                elif page_number < last_page_argument:
                    entity.act("Sfogli $N%s all'indietro." % from_descr, TO.ENTITY, target)
                    entity.act("$n sfoglia $N%s all'indietro." % from_descr, TO.OTHERS, target)
                else:
                    entity.act("Continui a %s $N%s." % (verbs["infinitive"], from_descr), TO.ENTITY, target)
                    entity.act("$n continua a %s $N%s." % (verbs["infinitive"], from_descr), TO.OTHERS, target)
            else:
                entity.act("Continui a %s $N%s." % (verbs["infinitive"], from_descr), TO.ENTITY, target)
                entity.act("$n continua a %s $N%s." % (verbs["infinitive"], from_descr), TO.OTHERS, target)

    # Se non ha trovato che sia stato inviato un comando uguale precedentemente
    # allora invia la messaggistica normale
    if not previous_same_book:
        if len(target.readable_type.pages) > 2:
            if page_number == 0:
                entity.act("%s la copertina di $N%s." % (color_first_upper(verbs["you"]), from_descr), TO.ENTITY, target)
                entity.act("$n %s la copertina di $N%s." % (verbs["it"], from_descr), TO.OTHERS, target)
            elif page_number == 1:
                entity.act("Cominci a %s $N%s." % (verbs["infinitive"], from_descr), TO.ENTITY, target)
                entity.act("$n comincia a %s $N%s." % (verbs["infinitive"], from_descr), TO.OTHERS, target)
            elif page_number == len(target.readable_type.pages) - 1:
                entity.act("%s la retrocopertina di $N%s." % (color_first_upper(verbs["you"]), from_descr), TO.ENTITY, target)
                entity.act("$n %s la retrocopertina di $N%s." % (verbs["it"], from_descr), TO.OTHERS, target)
            else:
                entity.act("%s $N%s." % (color_first_upper(verbs["you"]), from_descr), TO.ENTITY, target)
                entity.act("$n %s $N%s." % (verbs["it"], from_descr), TO.OTHERS, target)
        else:
            entity.act("%s $N%s." % (color_first_upper(verbs["you"]), from_descr), TO.ENTITY, target)
            entity.act("$n %s $N%s." % (verbs["it"], from_descr), TO.OTHERS, target)

    # Visualizza la o le pagine dell'entità leggibile al lettore
    entity.send_output(output)

    # Dona un po' di esperienza ai giocatori che leggono per la prima
    # volta il libro
    if entity.IS_PLAYER:
        if target.prototype.code in entity.readed_books:
            entity.readed_books[target.prototype.code] += 1
        else:
            entity.readed_books[target.prototype.code] = 1
            reason = "per aver letto per la prima volta %s" % target.get_name(looker=entity)
            entity.give_experience(target.level * 10, reason=reason)

    force_return = check_trigger(entity, "after_read", entity, target, output, None, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_readed", entity, target, output, None, behavioured)
    if force_return:
        return True

    return True
Beispiel #31
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
Beispiel #32
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
Beispiel #33
0
def command_buy(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di comprare entità da un commerciante.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

    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_buy")
            entity.send_output(syntax, break_line=False)
        return False

    # Ricava la quantità di entità da comprare
    quantity, argument = quantity_argument(argument)
    arg, argument = one_argument(argument)

    # Cerca specificatamente il negoziante con l'argomento passato
    if argument:
        dealer = entity.find_entity_extensively(argument, quantity=quantity)
        if not dealer:
            entity.act("Non trovi nessun negoziante chiamato [white]%s[close]." % argument, TO.ENTITY)
            entity.act("$n sembra cercare qualcuno da cui %s qualcosa." % verbs["infinitive"], TO.OTHERS)
            return False
        if not dealer.shop:
            entity.act("$N non sembra essere un negoziante da cui %s qualcosa." % verbs["infinitive"], TO.ENTITY, dealer)
            entity.act("$n si accorge che $N non è un negoziante da cui %s qualcosa." % verbs["infinitive"], TO.OTHERS, dealer)
            entity.act("$n si accorge che tu non sei un negoziante da cui %s qualcosa." % verbs["infinitive"], TO.TARGET, dealer)
            return False
    # Altrimenti cerca il primo negoziante che si trova nella locazione del giocatore
    else:
        for dealer in entity.location.iter_contains():
            if dealer.shop:
                break
        else:
            entity.act("Qui non trovi nessun [white]negoziante[close].", TO.ENTITY)
            entity.act("$n non sembra trovare qualcuno da cui %s qualcosa." % verbs["infinitive"], TO.OTHERS)
            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)

    # Ricava il magazzino del negoziante
    storage = dealer.shop.get_storage(dealer)
    if not storage:
        if dealer.shop.proto_storages and dealer.shop.proto_storages[0].IS_MOB:
            from_where = "da chi"
        else:
            from_where = "da dove"
        entity.act("Non puoi %s nulla da $N perché non ha %s prendere la mercanzia!" % (verbs["infinitive"], from_where), TO.ENTITY, dealer)
        entity.act("$n non può %s nulla da $N perché non ha %s prendere la mercanzia!" % (verbs["infinitive"], from_where), TO.OTHERS, dealer)
        entity.act("$n non può %s nulla perché non hai %s prendere la mercanzia!" % (verbs["you2"], from_where), TO.TARGET, dealer)
        return False

    # Cerca l'oggetto voluto nel magazzino del negoziante
    target = dealer.find_entity(arg, location=storage)
    if not target:
        descr = ""
        if SHOP.DISPENSER in dealer.shop.types:
            descr = "tra i prodotti esposti nel distributore"
        else:
            descr = "nella mercanzia esposta"
        entity.act("Non trovi nessun [white]%s[close] %s." % (arg, descr), TO.ENTITY, dealer)
        entity.act("$n non trova tra gli oggetti esposti da $N una [white]cosa[close] in particolare.", TO.OTHERS, dealer)
        entity.act("$n non trova tra i tuoi oggetti esposti una [white]cosa[close] in particolare.", TO.TARGET, dealer)
        return False

    if quantity != 1 and SHOP.DISPENSER in dealer.shop.types:
        entity.act("Non riesci in alcuni modo a %s %d quantità di $a da $N." % verbs["infinitive"], TO.ENTITY, dealer, target)
        entity.act("$n non riesce in alcun modo a %s $a in quantità maggiore di una da $N." % verbs["infinitive"], TO.OTHERS, dealer, target)
        entity.act("$n non riesce in alcun modo a %s $a in quantità maggiore di una da te." % verbs["infinitive"], TO.TARGET, dealer, target)
        entity.act("$n non riesce in alcun modo a %s in quantità maggiore di una da $a." % verbs["you2"], TO.TARGET, target, dealer)
        return False

    # Controlla se in magazzino vi sia la quantità voluta dell'oggetto da comprare
    if quantity == 0:
        quantity = target.quantity
    elif target.quantity < quantity:
        entity.act("Puoi %s solo %d quantità di $N da $a, riprova più tardi." % (verbs["infinitive"], target.quantity), TO.ENTITY, target, dealer)
        entity.act("$n può %s solo %d quantità di $N da $a." % (verbs["infinitive"], target.quantity), TO.OTHERS, target, dealer)
        entity.act("$n può %s da $a solo in %d quantità." % (verbs["you2"], target.quantity), TO.TARGET, target, dealer)
        entity.act("$n può %s $a da te solo in %d quantità." % (verbs["infinitive"], target.quantity), TO.TARGET, dealer, target)
        return False

    buyable = dealer.shop.get_buyable(target)
    if not buyable:
        entity.act("Ti accorgi che $N non è nel listino delle cose possibili da %s." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("$n si accorge che $N non è nel listino delle cose possibili da %s." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n si accorge che non sei nel listino delle cose possibili da %s." % verbs["infinitive"], TO.TARGET, target)
        return False

    price, discount = buyable.get_price(target, quantity=quantity)
    pretty_price = pretty_money_value(price, extended=True)

    # Controlla se il giocatore possa comprare un determinato articolo
    if not can_afford(target.value * quantity, entity, race=dealer.race):
        dealer.shop.send_cannot_afford_messages(entity, target, dealer, verbs, quantity, pretty_price)
        return False

    # Controlla se il giocatore può portare il peso dell'oggetto con sé
    if not entity.can_carry_target(target, quantity=quantity):
        if quantity <= 1:
            entity.act("$N è troppo pesante perché tu possa portarl$O assieme alle tue cose.", TO.ENTITY, target, dealer)
            entity.act("$N è troppo pesante perché $n lo possa portare assieme alle sue cose.", TO.OTHERS, target, dealer)
            entity.act("Sei troppo pesante perché $n ti possa portare assieme alle sue cose.", TO.TARGET, target, dealer)
            # l'act TO.OTHERS fa da 4° messaggio per dealer
        else:
            plural = grammar_gender(target, masculine="i", feminine="e")
            entity.act("%d $N sono troppo pesanti perché tu possa portarl%s assieme alle tue cose." % (quantity, plural), TO.ENTITY, target, dealer)  # (GR) plurare di $N
            entity.act("%d $N sono troppo pesanti perché $n l%s possa portare assieme alle sue cose." % (quantity, plural), TO.OTHERS, target, dealer)  # (GR) plurare di $N
            entity.act("Siete troppo pesanti perché $n vi possa portare assieme alle sue cose.", TO.TARGET, target, dealer)
            # l'act TO.OTHERS fa da 4° messaggio per dealer
        return False

    force_return = check_trigger(entity, "before_buy", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "before_buying", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_bought", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True

    dealer.shop.send_buy_messages(entity, target, dealer, verbs, quantity, pretty_price, discount)

    give_moneys(entity, dealer, price, race=dealer.race)
    target = target.from_location(quantity)
    target.to_location(entity)

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

    force_return = check_trigger(entity, "after_buy", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(dealer, "after_buying", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_bought", entity, dealer, target, quantity, behavioured)
    if force_return:
        return True

    return True
Beispiel #34
0
def interpret(entity, argument, use_check_alias=True, force_position=True, show_input=True, show_prompt=True, behavioured=False):
    """
    Funzione che interpreta gli inputi inviati dalle entità.
    L'argomento use_check_alias a False viene passato dalla find_alias per
    evitare chiamate di alias da altri alias e quindi ricorsioni.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    # Si assicura che colui che esegue l'azione sia un'entità unica e
    # non un mucchio fisico
    entity = entity.split_entity(1)

    if FLAG.CONVERSING in entity.flags and len(argument) == 1 and is_number(argument):
        # (TD)
        return

    arg, argument = one_argument(argument, search_separator=False)
    arg = arg.lower()

    input, huh_input, lang = multiple_search_on_inputs(entity, arg, use_check_alias=use_check_alias, argument=argument)
    # Utilizzo bislacco di lang per indicare che è stato trovato un alias
    # e che questo verrà processato tramite un'altra chiamata all'interpret
    if use_check_alias and lang == "alias":
        return

    # Resetta l'inattività di un player se ha inviato un comando
    if entity.IS_PLAYER:
        entity.inactivity = 0

    # Se non ha trovato nulla invia un messaggio apposito
    if not input:
        if show_input:
            entity.send_output(''' <span class="system">%s %s</span>''' % (remove_colors(arg), argument))
        entity.send_output("Huh?")
        # Se l'input non è stato trovato neanche nell'altra lingua allora
        # esegue il log dell'input, potrebbero esservene alcuni di sensati
        # da utilizzare in futuro come sinonimi
        # Scrive anche gli huh input dei mob così da ricavare gamescript o
        # random_do_inputs errati
        if not huh_input:
            log.huh_inputs(entity, arg)
        # Se serve visualizza il prompt
        if show_input:
            entity.send_prompt()
        return False

    # Poiché alcune words nello stesso input a volte hanno prefisso differente
    # tra loro allora cerca quello più simile possibile per farlo visualizzare
    # all'utente
    founded_input = input.findable_words[0]
    for word in input.findable_words:
        if is_prefix(arg, word):
            founded_input = word
            break

    # Se il giocatore è in stato di wait e l'input è un comando interattivo
    # allora evita di inviarlo subito ma lo mette in coda
    if entity.deferred_wait and CMDFLAG.INTERACT in input.command.flags:
        entity.waiting_inputs.append("%s %s" % (founded_input, argument))
        return False
    else:
        # Altrimenti scrive anche l'input a fianco del prompt
        if show_input:
            entity.send_output(''' <span class="system">%s %s</span>''' % (founded_input, argument))

    # Se il pg si è scollegato dalla pagina di gioco non esegue il comando
    if not entity.location:
        return False

    # Vengono salvate le informazioni sull'ultimo input inviato
    if argument:
        last_input = "%s %s" % (arg, argument)
    else:
        last_input = arg
    engine.last_input_sender = entity
    engine.last_input_sended = last_input
    # Si salva l'ultimo input inviato con successo
    if show_input and entity.IS_PLAYER and CMDFLAG.NO_LAST_INPUT not in input.command.flags:
        entity.last_input = last_input

    if CMDFLAG.GDR in input.command.flags:
        entity.sended_inputs.append("%s %s" % (founded_input, argument))

    if argument:
        argument = html_escape(argument)

    # Gestisce i comandi che devono essere digitati per intero
    command = input.command
    if CMDFLAG.TYPE_ALL in command.flags and not is_same(arg, input.findable_words):
        first_words, other_words = one_argument(input.words, search_separator=False)
        entity.send_output("Se vuoi veramente farlo devi scrivere per intero [limegreen]%s[close]." % first_words)
        execution_result = False
    elif not check_position(entity, command.position, force_position):
        # Se la posizione non è corretta invia il relativo messaggio d'errore
        vowel_of_genre = grammar_gender(entity)
        if entity.position == POSITION.DEAD:
            entity.send_output("Un po' difficile fino a che rimani MORT%s.." % vowel_of_genre.upper())
        elif (entity.position == POSITION.MORTAL
        or    entity.position == POSITION.INCAP):
            entity.send_output("Sei troppo ferit%s per farlo." % vowel_of_genre)
        elif entity.position == POSITION.STUN:
            entity.send_output("Sei troppo intontit%s per farlo." % vowel_of_genre)
        elif entity.position == POSITION.SLEEP:
            entity.send_output("Nei tuoi sogni, o cosa?")
        elif entity.position == POSITION.REST:
            entity.send_output("Nah.. Sei troppo rilassat%s ora.." % vowel_of_genre)
        elif entity.position == POSITION.KNEE:
            entity.send_output("Non puoi farlo da inginocchiat%s" % vowel_of_genre)
        elif entity.position == POSITION.SIT:
            entity.send_output("Non puoi farlo da sedut%s." % vowel_of_genre)
        else:
            log.bug("Manca la posizione %r" % entity.position)
        execution_result = False
    else:
        if command.type == CMDTYPE.SOCIAL:
            check_social(entity, command, argument=argument, behavioured=behavioured)

        if CMDFLAG.PRIVATE not in command.flags and (entity.IS_PLAYER or config.print_entity_inputs) and show_input and show_prompt:
            if entity.IS_PLAYER:
                write_on_file = True
            else:
                write_on_file = False
            log.input("'%s%s%s' digitato da %s in %s" % (
                founded_input,
                " " if argument else "",
                argument,
                entity.code,
                entity.location.get_name()), write_on_file=write_on_file)

        # Per comodità di sviluppo ricarica il modulo relativo al comando ogni
        # volta che lo si digita, così da poter testare le modifiche al codice
        # dei comandi senza aver bisogno di riavviare il gioco tutte le volte
        if config.reload_commands:
            reload(command.module)
            command.import_module_and_function()

        # Se si sta eseguendo un'azione che richiede tempo la interrompe
        if entity.action_in_progress and CMDFLAG.INTERACT in command.flags:
            if entity.action_in_progress.defer_later:
                entity.action_in_progress.stop()
            entity.action_in_progress = None

        # Esegue la funzione del comando cronometrandola
        input.counter_use += 1
        starting_time = time.time()
        execution_result = (command.function)(entity, argument)
        if command.fun_name[ : 8] == "command_" and execution_result != True and execution_result != False:
            log.bug("execution_result non è valido per il comando %s: %r" % (command.fun_name, execution_result))
        if command.fun_name[ : 6] == "skill_" and execution_result != "clumsy" and execution_result != "failure" and execution_result != "success" and execution_result != "magistral":
            log.bug("execution_result non è valido per la skill %s: %r" % (command.fun_name, execution_result))
        execution_time = time.time() - starting_time
        # Comandi che superano il tempo definito nella max_execution_time
        # possono portare a bachi creati dalla deferred impostata nel metodo
        # split_entity (nello stesso metodo c'è un commento con più informazioni)
        # Quindi devono essere il più possibile da evitare, allo stesso tempo
        # sarebbe meglio che il max_execution_time sia relativamente basso.
        if execution_time > config.max_execution_time:
            log.time("Il comando %s è stato eseguito in troppo tempo: %f secondi" % (command.fun_name, execution_time))
        command.timer += execution_time

    # Gestisce i comandi da loggare
    if CMDFLAG.LOG in command.flags:
        log.command("%s %s" % (command.fun_name, argument))

    if FLAG.AFK in entity.flags and command.fun_name != "command_afk":
        command_afk(entity)

    # Infine visualizza il prompt
    if show_prompt:
        entity.send_prompt()

    # Se la lista di input ancora da inviare non è vuota allora crea un
    # "falso wait" per forzarne l'invio. In teoria potrei inviarlo da qui, ma
    # il codice di ritorno execution_result andrebbe perduto, ecco perché
    # si fa uso della wait().
    if not entity.deferred_wait and entity.waiting_inputs:
        entity.wait(0.001)

    # Questa parte è da attivare con l'opzione check_references solo nei
    # server di test perché consuma molta cpu essendo eseguita su migliaia
    # di dati ad ogni invio di input, è una modalità di diagnostica
    # che non bada a spese in termini prestazionali
    if config.check_references and not database.reference_error_found:
        database.check_all_references()

    return execution_result
Beispiel #35
0
def interpret(entity,
              argument,
              use_check_alias=True,
              force_position=True,
              show_input=True,
              show_prompt=True,
              behavioured=False):
    """
    Funzione che interpreta gli inputi inviati dalle entità.
    L'argomento use_check_alias a False viene passato dalla find_alias per
    evitare chiamate di alias da altri alias e quindi ricorsioni.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    # Si assicura che colui che esegue l'azione sia un'entità unica e
    # non un mucchio fisico
    entity = entity.split_entity(1)

    if FLAG.CONVERSING in entity.flags and len(argument) == 1 and is_number(
            argument):
        # (TD)
        return

    arg, argument = one_argument(argument, search_separator=False)
    arg = arg.lower()

    input, huh_input, lang = multiple_search_on_inputs(
        entity, arg, use_check_alias=use_check_alias, argument=argument)
    # Utilizzo bislacco di lang per indicare che è stato trovato un alias
    # e che questo verrà processato tramite un'altra chiamata all'interpret
    if use_check_alias and lang == "alias":
        return

    # Resetta l'inattività di un player se ha inviato un comando
    if entity.IS_PLAYER:
        entity.inactivity = 0

    # Se non ha trovato nulla invia un messaggio apposito
    if not input:
        if show_input:
            entity.send_output(''' <span class="system">%s %s</span>''' %
                               (remove_colors(arg), argument))
        entity.send_output("Huh?")
        # Se l'input non è stato trovato neanche nell'altra lingua allora
        # esegue il log dell'input, potrebbero esservene alcuni di sensati
        # da utilizzare in futuro come sinonimi
        # Scrive anche gli huh input dei mob così da ricavare gamescript o
        # random_do_inputs errati
        if not huh_input:
            log.huh_inputs(entity, arg)
        # Se serve visualizza il prompt
        if show_input:
            entity.send_prompt()
        return False

    # Poiché alcune words nello stesso input a volte hanno prefisso differente
    # tra loro allora cerca quello più simile possibile per farlo visualizzare
    # all'utente
    founded_input = input.findable_words[0]
    for word in input.findable_words:
        if is_prefix(arg, word):
            founded_input = word
            break

    # Se il giocatore è in stato di wait e l'input è un comando interattivo
    # allora evita di inviarlo subito ma lo mette in coda
    if entity.deferred_wait and CMDFLAG.INTERACT in input.command.flags:
        entity.waiting_inputs.append("%s %s" % (founded_input, argument))
        return False
    else:
        # Altrimenti scrive anche l'input a fianco del prompt
        if show_input:
            entity.send_output(''' <span class="system">%s %s</span>''' %
                               (founded_input, argument))

    # Se il pg si è scollegato dalla pagina di gioco non esegue il comando
    if not entity.location:
        return False

    # Vengono salvate le informazioni sull'ultimo input inviato
    if argument:
        last_input = "%s %s" % (arg, argument)
    else:
        last_input = arg
    engine.last_input_sender = entity
    engine.last_input_sended = last_input
    # Si salva l'ultimo input inviato con successo
    if show_input and entity.IS_PLAYER and CMDFLAG.NO_LAST_INPUT not in input.command.flags:
        entity.last_input = last_input

    if CMDFLAG.GDR in input.command.flags:
        entity.sended_inputs.append("%s %s" % (founded_input, argument))

    if argument:
        argument = html_escape(argument)

    # Gestisce i comandi che devono essere digitati per intero
    command = input.command
    if CMDFLAG.TYPE_ALL in command.flags and not is_same(
            arg, input.findable_words):
        first_words, other_words = one_argument(input.words,
                                                search_separator=False)
        entity.send_output(
            "Se vuoi veramente farlo devi scrivere per intero [limegreen]%s[close]."
            % first_words)
        execution_result = False
    elif not check_position(entity, command.position, force_position):
        # Se la posizione non è corretta invia il relativo messaggio d'errore
        vowel_of_genre = grammar_gender(entity)
        if entity.position == POSITION.DEAD:
            entity.send_output("Un po' difficile fino a che rimani MORT%s.." %
                               vowel_of_genre.upper())
        elif (entity.position == POSITION.MORTAL
              or entity.position == POSITION.INCAP):
            entity.send_output("Sei troppo ferit%s per farlo." %
                               vowel_of_genre)
        elif entity.position == POSITION.STUN:
            entity.send_output("Sei troppo intontit%s per farlo." %
                               vowel_of_genre)
        elif entity.position == POSITION.SLEEP:
            entity.send_output("Nei tuoi sogni, o cosa?")
        elif entity.position == POSITION.REST:
            entity.send_output("Nah.. Sei troppo rilassat%s ora.." %
                               vowel_of_genre)
        elif entity.position == POSITION.KNEE:
            entity.send_output("Non puoi farlo da inginocchiat%s" %
                               vowel_of_genre)
        elif entity.position == POSITION.SIT:
            entity.send_output("Non puoi farlo da sedut%s." % vowel_of_genre)
        else:
            log.bug("Manca la posizione %r" % entity.position)
        execution_result = False
    else:
        if command.type == CMDTYPE.SOCIAL:
            check_social(entity,
                         command,
                         argument=argument,
                         behavioured=behavioured)

        if CMDFLAG.PRIVATE not in command.flags and (
                entity.IS_PLAYER
                or config.print_entity_inputs) and show_input and show_prompt:
            if entity.IS_PLAYER:
                write_on_file = True
            else:
                write_on_file = False
            log.input("'%s%s%s' digitato da %s in %s" %
                      (founded_input, " " if argument else "", argument,
                       entity.code, entity.location.get_name()),
                      write_on_file=write_on_file)

        # Per comodità di sviluppo ricarica il modulo relativo al comando ogni
        # volta che lo si digita, così da poter testare le modifiche al codice
        # dei comandi senza aver bisogno di riavviare il gioco tutte le volte
        if config.reload_commands:
            reload(command.module)
            command.import_module_and_function()

        # Se si sta eseguendo un'azione che richiede tempo la interrompe
        if entity.action_in_progress and CMDFLAG.INTERACT in command.flags:
            if entity.action_in_progress.defer_later:
                entity.action_in_progress.stop()
            entity.action_in_progress = None

        # Esegue la funzione del comando cronometrandola
        input.counter_use += 1
        starting_time = time.time()
        execution_result = (command.function)(entity, argument)
        if command.fun_name[:
                            8] == "command_" and execution_result != True and execution_result != False:
            log.bug("execution_result non è valido per il comando %s: %r" %
                    (command.fun_name, execution_result))
        if command.fun_name[:
                            6] == "skill_" and execution_result != "clumsy" and execution_result != "failure" and execution_result != "success" and execution_result != "magistral":
            log.bug("execution_result non è valido per la skill %s: %r" %
                    (command.fun_name, execution_result))
        execution_time = time.time() - starting_time
        # Comandi che superano il tempo definito nella max_execution_time
        # possono portare a bachi creati dalla deferred impostata nel metodo
        # split_entity (nello stesso metodo c'è un commento con più informazioni)
        # Quindi devono essere il più possibile da evitare, allo stesso tempo
        # sarebbe meglio che il max_execution_time sia relativamente basso.
        if execution_time > config.max_execution_time:
            log.time(
                "Il comando %s è stato eseguito in troppo tempo: %f secondi" %
                (command.fun_name, execution_time))
        command.timer += execution_time

    # Gestisce i comandi da loggare
    if CMDFLAG.LOG in command.flags:
        log.command("%s %s" % (command.fun_name, argument))

    if FLAG.AFK in entity.flags and command.fun_name != "command_afk":
        command_afk(entity)

    # Infine visualizza il prompt
    if show_prompt:
        entity.send_prompt()

    # Se la lista di input ancora da inviare non è vuota allora crea un
    # "falso wait" per forzarne l'invio. In teoria potrei inviarlo da qui, ma
    # il codice di ritorno execution_result andrebbe perduto, ecco perché
    # si fa uso della wait().
    if not entity.deferred_wait and entity.waiting_inputs:
        entity.wait(0.001)

    # Questa parte è da attivare con l'opzione check_references solo nei
    # server di test perché consuma molta cpu essendo eseguita su migliaia
    # di dati ad ogni invio di input, è una modalità di diagnostica
    # che non bada a spese in termini prestazionali
    if config.check_references and not database.reference_error_found:
        database.check_all_references()

    return execution_result
Beispiel #36
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
Beispiel #37
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
Beispiel #38
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
Beispiel #39
0
def five_senses_handler(entity, argument, behavioured, command_name, gamescript_suffix2, sense_name, has_sense_method_name, messages):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

    # argument può essere una stringa vuota

    # behavioured ha valore di verità

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

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

    # sense_name può essere una stringa vuota, per il look

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

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

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

    entity = entity.split_entity(1)

    if entity.IS_ACTOR:
        if entity.position < POSITION.SLEEP:
            entity.act(messages["death_position_entity"], TO.ENTITY)
            entity.act(messages["death_position_others"], TO.OTHERS)
            return False
        if entity.position == POSITION.SLEEP:
            entity.act(messages["sleep_position_entity"], TO.ENTITY)
            entity.act(messages["sleep_position_others"], TO.OTHERS)
            return False
        if not getattr(entity, has_sense_method_name)():
            entity.act(messages["not_has_sense_entity"], TO.ENTITY)
            entity.act(messages["not_has_sense_others"], TO.OTHERS)
            return False

    # Se entity è una razza che non può annusare sott'acqua allora esce
    if (sense_name == "smell" and not entity.race.smell_on_water
    and entity.location.IS_ROOM and ROOM.UNDERWATER in entity.location.flags):
        entity.send_output("Stai per annusare quando ti ricordi che qui richieresti di annegare!")
        return False

    # Se non è stato passato nessun argomento allora procede alla ricerca della
    # descrizione sensoriale nella stanza
    if not argument:
        descr = entity.location.get_descr(sense_name, looker=entity)
        if descr and "no_send" not in descr:
            update_sensed_rooms(entity, entity.location, command_name)

            force_return = check_trigger(entity, "before_" + command_name, entity, entity.location, descr, None, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, descr, None, behavioured)
            if force_return:
                return True

            entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            entity.act(messages["room_descr_others"], TO.OTHERS)

            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, descr, None, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, descr, None, behavioured)
            if force_return:
                return True
            return True
        else:
            force_return = check_trigger(entity, "before_" + command_name, entity, entity.location, "", None, behavioured)
            if force_return:
                return False
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, "", None, behavioured)
            if force_return:
                return False

            entity.act(messages["no_argument_entity"], TO.ENTITY)
            entity.act(messages["no_argument_others"], TO.OTHERS)

            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, "", None, behavioured)
            if force_return:
                return False
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, "", None, behavioured)
            if force_return:
                return False
            return False

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

    original_argument = argument
    arg1, argument = one_argument(argument)

    target, target_argument, extra_argument = entity.find_entity_from_args(arg1, argument)
    if ((target and not target.is_secret_door())
    or  (target and target.is_secret_door() and len(target_argument) >= config.min_secret_arg_len)):
        return sense_an_entity(entity, target, extra_argument, command_name, gamescript_suffix2, sense_name, messages, behavioured)

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

    # Cerca un'eventuale extra nella locazione, prima in maniera esatta
    extra = entity.location.extras.get_extra(original_argument, exact=True)
    if extra:
        descr = extra.get_descr(sense_name, looker=entity, parent=entity)
        if descr and "no_send" not in descr:
            update_sensed_rooms(entity, entity.location, command_name)

            force_return = check_trigger(entity, "before_" + command_name, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True

            entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            if EXTRA.NO_LOOK_ACT not in extra.flags:
                if "%s" in messages["room_extra_others"]:
                    word = add_article(extra.keywords.split()[0])
                    entity.act(messages["room_extra_others"] % add_article(word, GRAMMAR.INDETERMINATE), TO.OTHERS)
                else:
                    entity.act(messages["room_extra_others"], TO.OTHERS)

            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            return True

    # Gestisce il look in una direzione, prima in maniera esatta
    if target_argument:
        direction = get_direction(target_argument, exact=True)
        if direction != DIR.NONE:
            return sense_at_direction(entity, direction, extra_argument, True, command_name, gamescript_suffix2, sense_name, messages, behavioured, "to_dir")

    # Cerca un'eventuale extra sensoriale nella stanza, ora in maniera prefissa
    extra = entity.location.extras.get_extra(original_argument, exact=False)
    if extra:
        descr = extra.get_descr(sense_name, looker=entity, parent=entity)
        if descr and "no_send" not in descr:
            update_sensed_rooms(entity, entity.location, command_name)

            force_return = check_trigger(entity, "before_" + command_name, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True

            entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            if EXTRA.NO_LOOK_ACT not in extra.flags:
                if "%s" in messages["room_extra_others"]:
                    word = add_article(extra.keywords.split()[0])
                    entity.act(messages["room_extra_others"] % add_article(word, GRAMMAR.INDETERMINATE), TO.OTHERS)
                else:
                    entity.act(messages["room_extra_others"], TO.OTHERS)

            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, descr, extra, behavioured)
            if force_return:
                return True
            return True

    # Gestisce il look in una direzione, ora in maniera prefissa
    if target_argument:
        direction = get_direction(target_argument, exact=False)
        if direction != DIR.NONE:
            return sense_at_direction(entity, direction, extra_argument, False, command_name, gamescript_suffix2, sense_name, messages, behavioured, "to_dir")

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

    force_return = check_trigger(entity, "before_" + command_name, entity, None, "", extra, behavioured)
    if force_return:
        return False

    if extra:
        word = add_article(extra.keywords.split()[0])
        entity.act(messages["no_found_extra_entity_alt"].replace(" di $N", "") % word, TO.ENTITY)
    else:
        if "%s" in messages["no_found_entity"]:
            entity.act(messages["no_found_entity"] % original_argument, TO.ENTITY)
        else:
            entity.act(messages["no_found_entity"], TO.ENTITY)
    entity.act(messages["no_found_others"], TO.OTHERS)

    force_return = check_trigger(entity, "after_" + command_name, entity, None, "", extra, behavioured)
    if force_return:
        return False

    return False
Beispiel #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
Beispiel #41
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
Beispiel #42
0
def command_restring(entity, argument=""):
    """
    Permette di modificare la short il nome e la descrizione dell'oggetto voluto.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

    if not argument:
        syntax = get_command_syntax(entity, "command_restring")
        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:
        entity.send_output(
            "Nessuna entità trovata con argomento [white]%s[close]." % arg1)
        return False

    if not argument:
        output = "[white]%s[close]:\n" % target.code
        output += '''<table class='mud'>'''
        if not target.IS_PLAYER:
            output += '''<tr><td>KeywordsName:</td><td>%s</td></tr>''' % target.keywords_name
            output += '''<tr><td>KeywordsShort:</td><td>%s</td></tr>''' % target.keywords_short
            output += '''<tr><td>KeywordsShortNight:</td><td>%s</td></tr>''' % target.keywords_short_night
        output += '''<tr><td>Name:</td><td>%s</td></tr>''' % target.name
        if target.short:
            output += '''<tr><td>Short:</td><td>%s</td></tr>''' % target.short
        if target.short_night:
            output += '''<tr><td>ShortNight:</td><td>%s</td></tr>''' % target.short_night
        if target.long:
            output += '''<tr><td>Long:</td><td>%s</td></tr>''' % target.long
        if target.long_night:
            output += '''<tr><td>LongNight:</td><td>%s</td></tr>''' % target.long_night
        output += '''<tr><td>Descr:</td><td>%s</td></tr>''' % target.descr
        if target.descr_night:
            output += '''<tr><td valign="top">DescrNight:</td><td>%s</td></tr>''' % target.descr_night
        if target.descr_hearing:
            output += '''<tr><td valign="top">DescrHearing:</td><td>%s</td></tr>''' % target.descr_hearing
        if target.descr_hearing_night:
            output += '''<tr><td valign="top">DescrHearingNight:</td><td>%s</td></tr>''' % target.descr_hearing_night
        if target.descr_smell:
            output += '''<tr><td valign="top">DescrSmell:</td><td>%s</td></tr>''' % target.descr_smell
        if target.descr_smell_night:
            output += '''<tr><td valign="top">DescrSmellNight:</td><td>%s</td></tr>''' % target.descr_smell_night
        if target.descr_touch:
            output += '''<tr><td valign="top">DescrTouch:</td><td>%s</td></tr>''' % target.descr_touch
        if target.descr_touch_night:
            output += '''<tr><td valign="top">DescrTouchNight:</td><td>%s</td></tr>''' % target.descr_touch_night
        if target.descr_taste:
            output += '''<tr><td valign="top">DescrTaste:</td><td>%s</td></tr>''' % target.descr_taste
        if target.descr_taste_night:
            output += '''<tr><td valign="top">DescrTasteNight:</td><td>%s</td></tr>''' % target.descr_taste_night
        if target.descr_sixth:
            output += '''<tr><td valign="top">DescrSixth:</td><td>%s</td></tr>''' % target.descr_sixth
        if target.descr_sixth_night:
            output += '''<tr><td valign="top">DescrSixthNight:</td><td>%s</td></tr>''' % target.descr_sixth_night
        output += '''</table>'''
        if target.IS_PLAYER and not target.game_request:
            entity.send_output(
                "Il giocatore %s è [darkslategray]offline[close]")
        entity.send_output(output, break_line=False)
        return True

    arg2, argument = one_argument(argument)
    attribute = ""
    if is_prefix(arg2, ("KeywordsName", "keywords_name")):
        attribute = "keywords_name"
        attr_descr = "le parole chiavi del nome"
    elif is_prefix(arg2, ("KeywordsShort", "keywords_short")):
        attribute = "keywords_short"
        attr_descr = "le parole chiavi della short"
    elif is_prefix(arg2, ("KeywordsShortNight", "keywords_short_night")):
        attribute = "keywords_short_night"
        attr_descr = "le parole chiavi della short notturna"
    elif is_prefix(arg2, ("Name", "nome")):
        attribute = "name"
        attr_descr = "il nome"
    elif is_prefix(arg2, ("Short", "corta")):
        attribute = "short"
        attr_descr = "la short"
    elif is_prefix(arg2, ("ShortNight", "short_night")):
        attribute = "short_night"
        attr_descr = "la short notturna"
    elif is_prefix(arg2, ("Long", "lunga")):
        attribute = "long"
        attr_descr = "la long"
    elif is_prefix(arg2, ("LongNight", "long_night")):
        attribute = "long_night"
        attr_descr = "la long notturna"
    elif is_prefix(arg2, ("Descr", "descr", "Descrizione", "description")):
        attribute = "descr"
        attr_descr = "la descrizione"
    elif is_prefix(arg2, ("DescrNight", "descr_night")):
        attribute = "descr_night"
        attr_descr = "la descrizione notturna"
    elif is_prefix(arg2, ("DescrHearing", "descr_hearing")):
        attribute = "descr_hearing"
        attr_descr = "la descrizione uditiva"
    elif is_prefix(arg2, ("DescrHearingNight", "descr_hearing_night")):
        attribute = "descr_hearing_night"
        attr_descr = "la descrizione uditiva notturna"
    elif is_prefix(arg2, ("DescrSmell", "descr_smell")):
        attribute = "descr_smell"
        attr_descr = "la descrizione olfattiva"
    elif is_prefix(arg2, ("DescrSmellNight", "descr_smell_night")):
        attribute = "descr_smell_night"
        attr_descr = "la descrizione olfattiva notturna"
    elif is_prefix(arg2, ("DescrTouch", "descr_touch")):
        attribute = "descr_touch"
        attr_descr = "la descrizione tattile"
    elif is_prefix(arg2, ("DescrTouchNight", "descr_touch_night")):
        attribute = "descr_touch_night"
        attr_descr = "la descrizione tattile notturna"
    elif is_prefix(arg2, ("DescrTaste", "descr_taste")):
        attribute = "descr_taste"
        attr_descr = "la descrizione gustativa"
    elif is_prefix(arg2, ("DescrTasteNight", "descr_taste_night")):
        attribute = "descr_taste_night"
        attr_descr = "la descrizione gustativa notturna"
    elif is_prefix(arg2, ("DescrSixth", "descr_sixth")):
        attribute = "descr_sixth"
        attr_descr = "la descrizione intuitiva"
    elif is_prefix(arg2, ("DescrSixthNight", "descr_sixth_night")):
        attribute = "descr_sixth_night"
        attr_descr = "la descrizione intuitiva notturna"

    if not attribute:
        syntax = "L'etichetta da modificare all'entità '%s' è errata: %s" % (
            target.code, arg2)
        syntax += get_command_syntax(entity, "command_restring")
        entity.send_output(syntax, break_line=False)
        return False

    if not argument:
        syntax = "Il testo da sostituire nell'etichetta è vuoto."
        syntax += get_command_syntax(entity, "command_restring")
        entity.send_output(syntax, break_line=False)
        return False

    if not check_colors(argument):
        entity.send_output("Errore nella colorazione del testo: %s" % argument)
        return False

    if getattr(target, attribute) == argument:
        entity.send_output(
            "Inutile modificare %s di '%s' con un'altra stringa uguale." %
            (attr_descr, target.code))
        return False

    # Se si sta rinominando un giocatore allora si tiene traccia del vecchio nome
    if target.IS_PLAYER:
        if attribute == "name":
            argument = color_first_upper(argument)
            err_msg_name = get_error_message_name(argument, True, "players")
            if err_msg_name:
                entity.send_output(err_msg_name)
                return False
            if not is_same(argument, target.name):
                target.old_names += " " + target.name
            # (TD) fare anche i messaggi d'avviso per gli altri attributi? da pensare
            target.send_output("\nTi è stato cambiato il nome da %s a %s" %
                               (target.name, argument))
            target.send_prompt()
        elif attribute in ("keywords_name", "keywords_short",
                           "keywords_short_night"):
            entity.send_output("È impossibile modificare %s nei giocatori." %
                               attr_descr)
            return False

    setattr(target, attribute, argument)
    entity.send_output(
        "Hai modificato il testo dell'etichetta %s di '%s' in %s" %
        (to_capitalized_words(attribute), target.code, argument))
    return True
Beispiel #43
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
Beispiel #44
0
def dig_an_exit(entity, argument, verbs, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    # behavioured ha valore di verità

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

    location = entity.location

    arg, argument = one_argument(argument)
    direction = get_direction(arg)
    if direction == DIR.NONE:
        entity.act(
            "Non trovi nessuna direzione [white]%s[close] in cui %s." %
            (arg, verbs["infinitive"]), TO.ENTITY, location)
        entity.act(
            "$n sembra voler %s in una direzione, ma appare spaesato." %
            verbs["infinitive"], TO.OTHERS, location)
        entity.act(
            "$n sembra voler %s in una direzione, ma appare spaesato." %
            verbs["you2"], TO.TARGET, location)
        return False

    if not location.IS_ROOM:
        entity.act(
            "Non trovi in un luogo ove poter %s %s." %
            (verbs["infinitive"], direction.to_dir), TO.ENTITY, location)
        entity.act(
            "$n sembra voler %s %s nonostante non si trovi in un luogo con delle uscite."
            % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location)
        entity.act(
            "Non sei un luogo in cui si possa %s %s, eppure $n ci sta provando lo stesso."
            % (verbs["infinitive"], direction.to_dir), TO.TARGET, location)
        return False

    # (TD) Questo si potrebbe convertire in metodo se dovesse servire nuovamente
    exit = None
    has_secret_door = False
    if direction in location.exits:
        exit = location.exits[direction]
        door = location.get_door(direction)
        if door and door.door_type and DOOR.SECRET in door.door_type.flags and DOOR.CLOSED in door.door_type.flags:
            has_secret_door = True

    if exit and EXIT.DIGGABLE not in exit.flags and not has_secret_door:
        entity.act(
            "Non sapresti proprio come %s %s: c'è già un'uscita!" %
            (verbs["infinitive"], direction.to_dir), TO.ENTITY, location)
        entity.act(
            "$n sembra voler %s %s: ma c'è già un'uscita!" %
            (verbs["infinitive"], direction.to_dir), TO.OTHERS, location)
        entity.act(
            "$n sembra voler %s %s: ma li hai già un'uscita!" %
            (verbs["infinitive"], direction.to_dir), TO.TARGET, location)
        return False

    entity.act("Cominci a %s %s." % (verbs["infinitive"], direction.to_dir),
               TO.ENTITY, location)
    entity.act(
        "$n comincia a %s %s." % (verbs["infinitive"], direction.to_dir),
        TO.OTHERS, location)
    entity.act("$n comincia a %s %s." % (verbs["you2"], direction.to_dir),
               TO.TARGET, location)

    force_return = check_trigger(entity, "before_dig", entity, location, exit,
                                 direction, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "before_digged", entity, location,
                                 exit, direction, behavioured)
    if force_return:
        return True

    # (TD) Togliere un po' di energie nella scavata
    if exit and not has_secret_door:
        defer_later_function = digging_a_diggable_exit_1
    else:
        defer_later_function = digging_an_inexistent_exit_1
    entity.action_in_progress = ActionInProgress(DIG_SECONDS,
                                                 defer_later_function,
                                                 stop_digging_on_exit, entity,
                                                 location, direction, verbs,
                                                 behavioured)
    return True
Beispiel #45
0
def rpg_channel(entity, argument, channel, ask=False, exclaim=False, behavioured=False):
    """
    Gestisce i canali rpg, ha le seguenti caratteristiche:
    - supporto per gli smile
    - supporto per i modi di esprimersi con esclamativo e punto di domanda
    - supporto per gli emote
    - gestione del bersaglio che può essere un'entità, il gruppo o sé stessi
    - (TD) parlata da ubriaco
    - (TD) espansione della potenza della voce in altre stanze
    - (TD) espressioni per le stanze attorno, anche per coloro che riconoscono la voce,
           pensare anche alla suddivisione tra social gestuali e 'rumorosi' per gli smile-espressioni around
    - (TD) modulazione della voce a seconda delle dimensioni di chi parla e della sua voice_potence
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    if entity.IS_ROOM:
        return False

    objective = OBJECTIVE_ROOM  # obiettivo del messaggio
    # Linguaggio utilizzato per dire il messaggio
    if entity.IS_ITEM:
        language = LANGUAGE.COMMON
    else:
        language = entity.speaking
    smile = ""            # conterrà l'eventuale espressione di uno smile-social
    emote = ""            # conterrà l'eventuale emote inviato con il messaggio tra due asterischi
    expres_entity = ""    # espressione per chi parla
    expres_room   = ""    # espressione per chi sta ascoltando nella stanza
    expres_objective = "" # espressione per chi riceverà il messaggio

    # Ricava i verbi e il colore relativi al canale
    # Se si sta parlando normalmente la propria lingua vengono utilizzati
    # i verbi razziali per descriverne timbro, flessione o pronuncia
    if channel == CHANNEL.SAY:
        verb_you, verb_it = entity.race.say_verb_you, entity.race.say_verb_it
    else:
        verb_you, verb_it = channel.verb_you, channel.verb_it
    color = get_first_color(channel.name)

    # Se non è stato passato nessun messaggio esce
    if not argument or not remove_colors(argument):
        entity.send_output("Cosa vorresti %s?" % channel)
        return False

    if len(argument) > config.max_google_translate:
        entity.send_output("Non puoi %s un messaggio così logorroico." % channel)
        return False

    # Copia l'argomento originale, in alcuni casi serve recuperarlo poi
    original_argument = argument

    # Controlla se si sta parlando a qualcuno, il controllo sulla particella
    # la esegue in minuscolo, dando per sottinteso che quando uno scrive
    # maiuscolo voglia iniziare un discorso
    target = None
    if argument[0 : 2] == "a ":
        arg, argument = one_argument(argument)
        # Se sta parlando a qualcuno cerca di acquisirlo dal nome successivo
        objective_name, argument = one_argument(argument)
        target = entity.find_entity_extensively(objective_name)
        # con me e self esegue un check senza la is_same volutamente, per evitare
        # ricerche con nome di player che iniziano con Me o Self
        if target == entity or objective_name in ("me", "self"):
            objective = OBJECTIVE_SELF
            # Se si parla da soli lo si fa utilizzando la lingua madre
            language = entity.race.natural_language
        elif target:
            objective = OBJECTIVE_TARGET
            # Se si parla con qualcuno della stessa razza lo si fa utilizzando
            # la lingua preferita dalla razza, è un fattore culturale
            if entity.race == target.race:
                language = entity.race.natural_language
        else:
            # Se non ha trovato nessun 'a <nome bersaglio>' riprende
            # l'argument originale
            argument = original_argument
    # Stessa cosa di sopra ma qui controlla se si stia parlando al gruppo
    elif argument[0 : 3] == "al ":
        arg, argument = one_argument(argument)
        objective_name, argument = one_argument(argument)
        if is_prefix(objective_name, "gruppo"):
            if not entity.group:
                entity.send_output("Non fai parte di nessun gruppo.")
                return False
            # Questa variabile verrà utilizza poi nell'invio del messaggio
            group_members = entity.get_members_here(entity.location)
            if not group_members:
                entity.send_output("Non trovi nessun membro del gruppo vicino a te con cui poter parlare.")
                return False
            objective = OBJECTIVE_GROUP
            # Se si parla in un gruppo in cui tutti sono formati dalla stessa
            # razza si preferirà parlare con la lingua della propria razza
            for group_member in group_members:
                if group_member.race != entity.race:
                    break
            else:
                language = entity.race.natural_language
        else:
            # Se il personaggio non vuole parlare al gruppo recupera
            # il valore originale inviato
            argument = original_argument

    # (TD) Gestisce il caso in cui l'entità si trovi immersa in un liquido
    #if entity.is_immersed():
    #    entity.send_output("Tenti di %s qualcosa ma subito l'acqua ti riempie la gola soffocandoti!" % channel)
    #    entity.points.life -= random.randint(entity.level / 6, entity.level / 4) + 1
    #    return False

    if not entity.location:
        log.bug("entity %s non si trova in una locazione valida: %r (original_argument: %s)" % (
            entity.code, entity.location, original_argument))
        return False

    # Gestisce le stanze che obbligano al silenzio
    if entity.location.IS_ROOM:
        if ROOM.SILENCE in entity.location.flags:
            entity.send_output("Il silenzio del luogo ti blocca la gola impedendoti di %s." % channel)
            return False

        # (TT) Se nella stanza c'è molto casino, tante persone etc etc è difficile
        # parlare piano
        if entity.location.mod_noise > 75 and channel <= CHANNEL.SAY:
            entity.send_output("Non puoi %s con tutta questa confusione!" % channel)
            return False

    # Invia l'appropriato messaggio nel caso in cui trovi argument vuoto
    if not argument:
        send_not_argument_message(entity, objective, channel)
        return False

    # Cerca eventuali smiles nella stringa controllando gli ultimi caratteri
    for social in database["socials"].itervalues():
        if not social.smiles:
            continue
        for single_smile in social.smiles.split():
            if single_smile in argument[-config.chars_for_smile : ]:
                break
        else:
            # Se non trova nessun smile esce dal ciclo dei social e continua
            # col prossimo set di smiles trovato
            continue

        cut_smile = argument.rfind(single_smile)
        # Se argument è formato solo dallo smile invia il corrispondente social
        if cut_smile == 0:
            social_name = social.fun_name[len("social_") : ]
            if objective == OBJECTIVE_TARGET:
                input_to_send = "%s %s" % (social_name, target.name)
            elif objective == OBJECTIVE_SELF:
                input_to_send = "%s %s" % (social_name, entity.name)
            else:
                input_to_send = social_name

            send_input(entity, input_to_send, "en", show_input=False, show_prompt=False)
            return True

        # Altrimenti ne ricava l'espressione dello smile-social e toglie lo
        # smile da argument, se il carattere dopo lo smile era un simbolo di
        # punteggiatura lo attacca alla frase togliendo gli spazi
        first_part  = argument[ : cut_smile]
        second_part = argument[cut_smile + len(single_smile) : ]
        if second_part.strip() and second_part.strip()[0] in "!?.,:;":
            first_part = first_part.rstrip()
            second_part = second_part.lstrip()
        argument = first_part.rstrip() + second_part.rstrip()
        smile = " %s" % social.expression
        break

    # Elabora i punti esclamativi e interrogativi per il canale say.
    # Qui viene utilizzata l'opzione chars_for_smile visto che si sta facendo
    # una cosa simile a sopra, ovvero considerare solo l'ultima parte
    # dell'argomento passato.
    exclamations = argument[-config.chars_for_smile : ].count("!")
    questions    = argument[-config.chars_for_smile : ].count("?")
    if exclamations > questions:
        if channel == CHANNEL.SAY:
            verb_you = "Esclami"
            verb_it  = " esclama"
        exclaim = True
    elif exclamations < questions:
        if channel == CHANNEL.SAY:
            verb_you = "Domandi"
            verb_it  = " domanda"
        ask = True
    # Questo elif sottintende che exclamations e questions siano uguali
    elif exclamations != 0 and questions != 0:
        # Con una stessa quantità di ! e di ? l'ultimo che viene trovato
        # ha maggiore peso rispetto all'altro
        exclamation_pos = argument.rfind("!")
        question_pos = argument.rfind("?")
        if exclamation_pos > question_pos:
            if channel == CHANNEL.SAY:
                verb_you = "Esclami"
                verb_it  = " esclama"
            exclaim = True
        else:
            if channel == CHANNEL.SAY:
                verb_you = "Domandi"
                verb_it  = " domanda"
            ask = True

    # Supporto per piccoli emote separati da * ad inizio argument
    if argument[0] == "*":
        cut_emote = argument[1 : ].find("*")
        if cut_emote != -1:
            emote = " %s" % argument[1 : cut_emote+1].strip()
            if smile:
                emote = " e%s" % emote
            argument = argument[cut_emote+2 : ].strip()

    # Unisce i vari pezzi per formare l'output
    expres_entity = verb_you
    expres_room = verb_it
    expres_target = ""
    if objective == OBJECTIVE_TARGET:
        name = target.get_name(entity)
        expres_entity += " a %s" % name
        expres_room   += " a %s" % name
        expres_target += " ti%s" % verb_it
    elif objective == OBJECTIVE_SELF:
        expres_entity += " a te stess%s" % grammar_gender(entity)
        expres_room   += " a sé stess%s" % grammar_gender(entity)
    elif objective == OBJECTIVE_GROUP:
        members = entity.get_members_here(entity.location)
        if len(members) == 1:
            expres_entity += " a %s" % members[0].name
            expres_room   += " a %s" % members[0].name
            expres_target += " ti%s" % verb_it
        else:
            if len(members) > 5:
                many = "folto "
            else:
                many = ""
            expres_entity += " al gruppo"
            expres_room   += " ad un %sgruppo" % many
            expres_target += "%s al gruppo" % verb_it
    # Aggiunge le eventuali espressioni dello smile e dell'emote
    expres_entity += smile + emote
    expres_room   += smile + emote
    expres_target += smile + emote

    if not argument:
        send_not_argument_message(entity, objective, channel)
        return False

    # Prepara il pezzo riguardante la lingua utilizzata
    language = ""
    if not entity.IS_ITEM and entity.speaking != LANGUAGE.COMMON:
        language = " in lingua %s" % entity.speaking

    # Mischia il testo se si è ubriachi
    original_argument = argument = color_first_upper(argument)
    argument = drunk_speech(argument, entity)

    # Parlando si impara la lingua
    if not entity.IS_ITEM:
        learn_language(entity, channel, entity.speaking)

    # Controlla se vi sono parolacce o parole offrpg e logga i relativi argument
    if entity.IS_PLAYER:
        check_for_badwords(entity, argument)

    # Invia il messaggio a tutti coloro che lo possono sentire
    for location in expand_voice_around(entity, channel):
        if not location:
            log.bug("location per il canale %s e per l'entità %s non è valida: %r" % (channel, entity.code, location))
            continue
        for listener in location.iter_contains(use_reversed=True):
            if listener.position <= POSITION.SLEEP:
                continue

            if listener == entity:
                force_return = check_trigger(entity, "before_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue
                force_return = check_trigger(entity, "before_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue

                # Invia all'entità il suo stesso messaggio
                first_part = (close_color(color) + expres_entity).rstrip()
                message = "%s: '%s'" % (first_part, close_color(argument))
                send_channel_message(entity, message, True)

                force_return = check_trigger(entity, "after_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue
                force_return = check_trigger(entity, "after_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue
            else:
                # Fa ascoltare solo ad un'entità di un eventuale gruppo fisico
                listener = listener.split_entity(1)

                force_return = check_trigger(listener, "before_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue
                force_return = check_trigger(listener, "before_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue

                # Prepara alcune cose a seconda della stanza di provenienza del messaggio
                if entity.location == listener.location:
                    entity_name = entity.get_name(listener)
                    entity_name = color_first_upper(entity_name)
                    from_direction = ""
                elif entity.location.IS_ROOM:
                    # (TD) invia qualcuno a meno che non lo si abbia conosciuto
                    # precedentemente con il sistema di presentazione
                    entity_name = "Qualcuno"
                    from_direction = get_from_direction(listener.location.x, listener.location.y, listener.location.z,
                                                        entity.location.x, entity.location.y, entity.location.z)
                elif entity.location.IS_ACTOR:
                    if entity.location != listener:
                        entity_name = "Qualcuno"  # (TD) come sopra
                    from_direction = " dall'inventario di %s" % entity.location.get_name(listener)
                else:
                    entity_name = "Qualcuno"  # (TD) come sopra
                    from_direction = " da dentro %s" % entity.location.get_name(listener)

                # Prepara la prima parte, quella senza il messaggio
                if objective == OBJECTIVE_ROOM:
                    output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction)
                elif objective == OBJECTIVE_TARGET or OBJECTIVE_SELF:
                    if listener == target:
                        output = "%s%s%s%s" % (entity_name, close_color(color) + expres_target, language, from_direction)
                    else:
                        output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction)
                elif objective == OBJECTIVE_GROUP:
                    if listener in group_members:
                        output = "%s%s%s%s" % (entity_name, close_color(color) + expres_target, language, from_direction)
                    else:
                        output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction)

                output = "<br>%s: '%s'" % (close_color(output).rstrip(), close_color(argument))
                send_channel_message(listener, output, False)
                listener.send_prompt()

                force_return = check_trigger(listener, "after_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue
                force_return = check_trigger(listener, "after_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured)
                if force_return:
                    continue

    return True
Beispiel #46
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
Beispiel #47
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
Beispiel #48
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
Beispiel #49
0
def command_remove(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di vestirsi di entità nelle varie parti del corpo.
    """
    # È 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 di dosso?" % verbs["you2"])
        if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options:
            syntax = get_command_syntax(entity, "command_remove")
            entity.send_output(syntax)
        return False

    # (TD) Controllo del mental state deviato
    pass

    # (TD) gestione di all (ti vesti di tutto punto: elenco delle cose indossate)
    pass

    location = None
    arg, argument = one_argument(argument)
    if argument:
        location = entity.find_entity(argument)
        if not location:
            entity.send_output("Non è stato trovato nessun %s da cui %s %s." % (argument, verbs["infinitive"], arg))
            return False
        target = entity.find_equipped_entity(arg, location)
    else:
        target = entity.find_equipped_entity(arg, entity)

    if not target:
        if is_masculine(arg):
            descr = "indossato"
        else:
            descr = "indossata"
        entity.act("Non hai nessun [white]%s[close] %s." % (arg, descr), TO.ENTITY)
        entity.act("$n sembra cercare qualche cosa che ha addosso.", TO.OTHERS)
        return False

    if target == entity:
        entity.act("Cerchi di %s di dosso ma... sei sicur$o di quello che stai facendo?" % verbs["you2"], TO.ENTITY)
        entity.act("$n sembra volersi %s di dosso... Ma che sta facendo?" % verbs["infinitive"], TO.OTHERS)
        return False

    if location and location != entity and location.IS_ACTOR:
        entity.send_output("Non ti è possibile %s %s da %s." % (verbs["infinitive"], targetget_name(looker=entity), location.get_name(looker=entity)))
        return False

    if FLAG.NO_REMOVE in target.flags:
        if entity.trust > TRUST.MASTER:
            entity.send_output("{Questa sarebbe in realtà un'entità NO_REMOVE}")
        else:
            entity.act("Appena cerchi di %s $N ti accorgi di non poterlo fare." % verbs["infinitive"], TO.ENTITY, target)
            entity.act("Appena $n cerca di %s $N si accorge di non poterlo fare." % verbs["infinitive"], TO.OTHERS, target)
            entity.act("\nAppena $n cerca di %s si accorge di non riuscirci." % verbs["you2"], TO.TARGET, target)
            return False

        # (TT) nel caso si sviluppino stanze no remove qui ci va il chk opportuno

    if target.wear_type:
        upper_weared = target.wear_type.get_upper_weared(target)
        if upper_weared:
            entity.act("Devi %s prima $a di $N." % verbs["you2"], TO.ENTITY, target, upper_weared)
            entity.act("$n cerca di %s $N senza prima essersi %s $a." % (verbs["self"], verbs["participle"]), TO.OTHERS, target, upper_weared)
            entity.act("$n cerca di %s senza prima essersi %s $a." % (verbs["you2"], verbs["participle"]), TO.TARGET, target, upper_weared)
            entity.act("$n cerca di %s $N senza prima %s." % (verbs["self"], verbs["you2"]), TO.TARGET, target, upper_weared)
            return False

    chosen_part = None
    if argument:
        # (TD) rimuovere un'entità da una parte del corpo precisa
        #chosen_part = search_part(argument)
        pass

    if config.reload_commands:
        reload(__import__("src.commands.command_hold", globals(), locals(), [""]))
        reload(__import__("src.commands.command_wield", globals(), locals(), [""]))
        reload(__import__("src.commands.command_wear", globals(), locals(), [""]))
    from src.commands.command_hold  import VERBS as hold_verbs
    from src.commands.command_wield import VERBS as wield_verbs
    from src.commands.command_wear  import VERBS as wear_verbs

    force_return = check_trigger(entity, "before_remove", entity, target, location, chosen_part, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_removed", entity, target, location, chosen_part, behavioured)
    if force_return:
        return True

    # Fare il sistema messaggistica proprio di tutti gli entitype
    # (TD) estendere il sistema di verb dall'inizio del comando
    part_descriptions = get_part_descriptions(target, "remove", entity, entity)
    if PART.HOLD in target.wear_mode or PART.WIELD in target.wear_mode:
        if target.weapon_type:
            if entity == target.location:
                part_descriptions[TO.ENTITY].replace(wield_verbs["participle"] + " ", "")
                part_descriptions[TO.OTHERS].replace(wield_verbs["participle"] + " ", "")
                part_descriptions[TO.TARGET].replace(wield_verbs["participle"] + " ", "")
                send_remove_messages(entity, target, "Smetti d'" + wield_verbs["infinitive_min"], "smette d'" + wield_verbs["infinitive_min"], part_descriptions, True)
            else:
                part_descriptions[TO.ENTITY] = "da $L"
                part_descriptions[TO.OTHERS] = "da $L"
                part_descriptions[TO.TARGET] = "da $L"
                send_remove_messages(entity, target, color_first_upper(verbs["you_min"]), verbs["it_min"], part_descriptions, True)
        else:
            if entity == target.location:
                part_descriptions[TO.ENTITY].replace(hold_verbs["participle"] + " ", "")
                part_descriptions[TO.OTHERS].replace(hold_verbs["participle"] + " ", "")
                part_descriptions[TO.TARGET].replace(hold_verbs["participle"] + " ", "")
                send_remove_messages(entity, target, "Smetti di " + hold_verbs["infinitive_min"], "smette di " + hold_verbs["infinitive_min"], part_descriptions, True)
            else:
                part_descriptions[TO.ENTITY] = "da $L"
                part_descriptions[TO.OTHERS] = "da $L"
                part_descriptions[TO.TARGET] = "da $L"
                send_remove_messages(entity, target, color_first_upper(verbs["you_min"]), verbs["it_min"], part_descriptions, True)
    else:
        if entity == target.location:
            send_remove_messages(entity, target, "Smetti d'" + wear_verbs["infinitive"], "smette d'" + wear_verbs["infinitive"], part_descriptions, False)
        else:
            part_descriptions[TO.ENTITY] = "da $L"
            part_descriptions[TO.OTHERS] = "da $L"
            part_descriptions[TO.TARGET] = "da $L"
            send_remove_messages(entity, target, color_first_upper(verbs["you"]), verbs["it"], part_descriptions, False)
    target.wear_mode.clear()
    target.under_weared = None
    if upper_weared:
        upper_weared.under_weared = None

    # Rimuove tutti gli affect che target stava applicando
    for affect in target.affects:
        affect.remove()

    # Per oggetti rimossi ad altri oggetti li mette per terra, questo perché
    # forza a raccoglierli, facendo scattare eventuali gamescript o altre flag
    if location:
        target = target.from_location(1, use_repop=False)
        target.to_location(location.location)

    # 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_remove", entity, target, location, chosen_part, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_removed", entity, target, location, chosen_part, behavioured)
    if force_return:
        return True

    return True