Exemple #1
0
def send_follow_others_come_message(walker, entity, direction, fleeing, running):
    # walker può essere None

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

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

    # fleeing e running hanno valore di verità

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

    if walker and walker.follow_others_come_message:
        message = walker.follow_others_come_message
        if "%verb" in message:
            if message.startswith("%verb"):
                message = message.replace("%verb", color_first_upper(entity.come_verb_it(fleeing, running)))
            else:
                message = message.replace("%verb", entity.come_verb_it(fleeing, running).lower())
        if "%direction" in message:
            if message.startswith("%direction"):
                message = message.replace("%direction", color_first_upper(direction.from_dir))
            else:
                message = message.replace("%direction", direction.from_dir.lower())
    else:
        message = "$n %s %s seguendo $N." % (entity.come_verb_it(fleeing, running), direction.reverse_dir.from_dir)

    entity.act(put_final_dot(message), TO.OTHERS, entity.guide)
Exemple #2
0
    def get_descr(self, type="", looker=None, parent=None):
        """
        Ritorna la descrizione dell'extra.
        """
        if type:
            type = "_" + type

        if calendar.is_night():
            descr_night = getattr(self, "descr%s_night" % type)
            if descr_night:
                return put_final_dot(color_first_upper(descr_night))
            elif EXTRA.DAY_ONLY in self.flags:
                return ""

        # Non c'è bisogno di implementare la EXTRA.DAY_ONLY perché
        # concettualmente già funziona così, l'ho aggiunta perché i builder
        # si trovano meglio a inserirla esplicitamente in alcuni casi

        descr = getattr(self, "descr%s" % type)

        if MIML_SEPARATOR in descr:
            if parent:
                descr = parent.parse_miml(descr, looker)
            else:
                log.bug(
                    "Anche se il parametro è opzionale è inteso come dovuto: %r"
                    % parent)

        if descr:
            return put_final_dot(color_first_upper(descr))
        else:
            # Può accadere quando il type è una stringa indicante un senso
            # differente da quello della vista
            return ""
def get_formatted_equipment_list(entity, target, show_header=True, show_footer=True):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return ""

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

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

    output = get_equipment_list(entity, target)

    if show_header:
        if target == entity:
            if output:
                output = ["[red]Stai utilizzando[close]:\n"] + output
            else:
                output.append("Non stai utilizzando nulla, sei %s!\n" % entity.skin_colorize("nud$o"))
        else:
            if output:
                output = ["%s [red]sta utilizzando[close]:\n" % color_first_upper(target.get_name(entity))] + output
            else:
                output.append("%s non sta utilizzando nulla, è %s!\n" % (
                    color_first_upper(target.get_name(looker=entity)),
                    target.skin_colorize("nud%s" % grammar_gender(target))))

    if show_footer:
        carry_equip_descr = get_weight_descr(target.get_equipped_weight())
        output.append(create_demi_line(entity))
        output.append("Stai indossando un peso totale di %s." % carry_equip_descr)

    return "".join(output)
Exemple #4
0
    def send_messages(self, entity, target, verbs):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if self.entity_message:
            message = self.entity_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you"])
                else:
                    message = message % verbs["you"].lower()
        else:
            sating_descr = ""
            if entity.IS_ITEM or entity.hunger <= 0:
                sating_descr = ", saziandoti."
            if entity == target:
                message = "Ti %s%s" % (verbs["you"].lower(), sating_descr)
            else:
                message = "%s $N%s" % (color_first_upper(
                    verbs["you"]), sating_descr)
        entity.act(message, TO.ENTITY, target)

        if self.others_message:
            message = self.others_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it"])
                else:
                    message = message % verbs["it"].lower()
        else:
            if entity == target:
                message = "$n si %s!" % verbs["it"]
            else:
                message = "$n %s $N" % verbs["it"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            message = ""
            if self.target_message:
                message = self.target_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["it"])
                    else:
                        message = message % verbs["it"].lower()
            else:
                message = "$n ti %s" % verbs["it"].lower()
            entity.act(message, TO.TARGET, target)
Exemple #5
0
    def send_messages(self, entity, target, verbs):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if self.entity_message:
            message = self.entity_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you"])
                else:
                    message = message % verbs["you"].lower()
        else:
            sating_descr = ""
            if entity.IS_ITEM or entity.hunger <= 0:
                sating_descr = ", saziandoti."
            if entity == target:
                message = "Ti %s%s" % (verbs["you"].lower(), sating_descr)
            else:
                message = "%s $N%s" % (color_first_upper(verbs["you"]), sating_descr)
        entity.act(message, TO.ENTITY, target)

        if self.others_message:
            message = self.others_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it"])
                else:
                    message = message % verbs["it"].lower()
        else:
            if entity == target:
                message = "$n si %s!" % verbs["it"]
            else:
                message = "$n %s $N" % verbs["it"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            message = ""
            if self.target_message:
                message = self.target_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["it"])
                    else:
                        message = message % verbs["it"].lower()
            else:
                message = "$n ti %s" % verbs["it"].lower()
            entity.act(message, TO.TARGET, target)
Exemple #6
0
    def send_eatkey_messages(self,
                             entity,
                             target,
                             key,
                             direction=None,
                             destination_room=None):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_eatkey_message:
            message = self.entity_unlock_message
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$N ti si polverizza in mano"
        entity.act(message, TO.ENTITY, key, destination_room)

        if self.others_eatkey_message:
            message = self.entity_unlock_message
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$N si polverizza fra le mani di $n"
        entity.act(message, TO.OTHERS, key, destination_room)

        if entity != target:
            if self.target_eatkey_message:
                message = self.entity_unlock_message
                if "%dir" in message:
                    if message.startswith("%dir"):
                        message = message % color_first_upper(
                            direction.to_dir2)
                    else:
                        message = message % direction.to_dir2.lower()
            else:
                message = "Tu che sei $N ti polverizzi"
            entity.act(message, TO.TARGET, key, destination_room)
Exemple #7
0
    def send_no_room_messages(self, entity, target, verbs):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_no_room_message:
            message = "\n" + self.entity_no_room_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["infinitive"])
                else:
                    message = message % verbs["infinitive"].lower()
        else:
            message = "\nProvi ad %s in $N ma qualcosa non funziona..." % verbs[
                "infinitive"]
        entity.act(message, TO.ENTITY, target)

        if self.others_no_room_message:
            message = self.others_no_room_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["infinitive"])
                else:
                    message = message % verbs["infinitive"].lower()
        else:
            message = "$n prova ad %s dentro $N ma qualcosa non funziona..." % verbs[
                "infinitive"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            if self.target_no_room_message:
                message = self.target_no_room_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(
                            verbs["infinitive"])
                    else:
                        message = message % verbs["infinitive"].lower()
            else:
                message = "$n prova ad %s dentro te ma non hai il collegamento di destinazione." % verbs[
                    "infinitive"]
            entity.act(message, TO.TARGET, target)
def before_giving(player, arma, fabbro, direction, behavioured):
    # Solo per i giocatori
    if not player.IS_PLAYER:
        player.act("$N non accetta che tu gli dia alcunché.", TO.ENTITY, fabbro)
        player.act("$n cerca inutilmente di dare qualcosa a $n.", TO.OTHERS, fabbro)
        player.act("$n cerca di darti robaccia ma tu non accetti.", TO.TARGET, fabbro)
        return True

    arma_name = arma.get_name(looker=fabbro)

    # Solo se l'oggetto è un'arma
    if not arma.weapon_type:
        to_say = "a %s Non mi pare proprio che %s sia un'arma." % (player.code, arma_name)
        command_say(fabbro, to_say)
        return True

    if arma.life >= arma.max_life:
        to_say = "a %s Si vede ad occhio che %s non ha bisogno di riparazioni!" % (player.code, arma_name)
        command_say(fabbro, to_say)
        return True

    to_say = "a %s %s ha proprio bisogno di una sistemata." % (player.code, color_first_upper(arma_name))
    command_say(fabbro, to_say)

    # (TD) farei una defer con messaggio di act con il lavorio sull'arma
    arma.life = arma.max_life
    to_say = "a %s Ecco fatto, ora %s è a posto!" % (player.code, arma_name)
    command_say(fabbro, to_say)
    return True
Exemple #9
0
def before_giving(player, arma, fabbro, direction, behavioured):
    # Solo per i giocatori
    if not player.IS_PLAYER:
        player.act("$N non accetta che tu gli dia alcunché.", TO.ENTITY,
                   fabbro)
        player.act("$n cerca inutilmente di dare qualcosa a $n.", TO.OTHERS,
                   fabbro)
        player.act("$n cerca di darti robaccia ma tu non accetti.", TO.TARGET,
                   fabbro)
        return True

    arma_name = arma.get_name(looker=fabbro)

    # Solo se l'oggetto è un'arma
    if not arma.weapon_type:
        to_say = "a %s Non mi pare proprio che %s sia un'arma." % (player.code,
                                                                   arma_name)
        command_say(fabbro, to_say)
        return True

    if arma.life >= arma.max_life:
        to_say = "a %s Si vede ad occhio che %s non ha bisogno di riparazioni!" % (
            player.code, arma_name)
        command_say(fabbro, to_say)
        return True

    to_say = "a %s %s ha proprio bisogno di una sistemata." % (
        player.code, color_first_upper(arma_name))
    command_say(fabbro, to_say)

    # (TD) farei una defer con messaggio di act con il lavorio sull'arma
    arma.life = arma.max_life
    to_say = "a %s Ecco fatto, ora %s è a posto!" % (player.code, arma_name)
    command_say(fabbro, to_say)
    return True
def before_listen_rpg_channel(locandiera, player, target, phrase, ask, exclaim, behavioured):
    # Mi assicuro che si stia parlando rivolgendosi alla locandiera
    if target != locandiera:
        return

    player_code = player.get_numbered_keyword(looker=locandiera)

    if is_infix("menù", phrase):
        to_say = "a %s Il nostro menù di oggi lo potete vedere qui." % player_code
        defer_if_possible(1, 2, locandiera, player, command_say, locandiera, to_say)
        return

    proto_cibi = []
    for proto_code in PROTO_FOODS_CODES:
        table_name = "proto_" + proto_code.split("_")[1] + "s"
        proto_entity = database[table_name][proto_code]

        for keyword in multiple_arguments(proto_entity.get_keywords_attr(looker=locandiera)):
            if is_infix(keyword, phrase):
                proto_cibi.append(proto_entity)

    if not proto_cibi:
        to_say = "a %s Non credo di poterla accontentare..." % player_code
        defer_if_possible(1, 2, locandiera, player, command_say, locandiera, to_say)
        return

    proto_pietanza = random.choice(proto_cibi)
    pietanza = proto_pietanza.CONSTRUCTOR(proto_pietanza.code)

    to_say = "a %s Ottimo! %s in arrivo." % (player_code, color_first_upper(pietanza.get_name(looker=player)))
    defer_if_possible(1, 2, locandiera, player, command_say, locandiera, to_say)
    defer_random_time(6, 8, locandiera_act, locandiera, pietanza, player)
Exemple #11
0
    def show_exit_messages(self, entity, target, verbs, fleeing):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_exit_message:
            message = "\n" + self.entity_exit_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you2"])
                else:
                    message = message % verbs["you2"].lower()
        else:
            message = "\n%s in $l." % verbs["you2"]
        entity.act(message, TO.ENTITY, target)

        if self.others_exit_message:
            message = self.others_exit_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it2"])
                else:
                    message = message % verbs["it2"].lower()
        else:
            message = "$n %s da chissà dove..." % verbs["it2"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            if self.target_exit_message:
                message = self.target_exit_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(
                            verbs["destination2"])
                    else:
                        message = message % verbs["destination2"].lower()
            else:
                message = "$n %s da te in $l." % verbs["destination2"]
            entity.act(message, TO.TARGET, target, entity.location,
                       entity.previous_location())
Exemple #12
0
    def send_no_room_messages(self, entity, target, verbs):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_no_room_message:
            message = "\n" + self.entity_no_room_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["infinitive"])
                else:
                    message = message % verbs["infinitive"].lower()
        else:
            message = "\nProvi ad %s in $N ma qualcosa non funziona..." % verbs["infinitive"]
        entity.act(message, TO.ENTITY, target)

        if self.others_no_room_message:
            message = self.others_no_room_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["infinitive"])
                else:
                    message = message % verbs["infinitive"].lower()
        else:
            message = "$n prova ad %s dentro $N ma qualcosa non funziona..." % verbs["infinitive"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            if self.target_no_room_message:
                message = self.target_no_room_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["infinitive"])
                    else:
                        message = message % verbs["infinitive"].lower()
            else:
                message = "$n prova ad %s dentro te ma non hai il collegamento di destinazione." % verbs["infinitive"]
            entity.act(message, TO.TARGET, target)
Exemple #13
0
    def show_exit_messages(self, entity, target, verbs, fleeing):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_exit_message:
            message = "\n" + self.entity_exit_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you2"])
                else:
                    message = message % verbs["you2"].lower()
        else:
            message = "\n%s in $l." % verbs["you2"]
        entity.act(message, TO.ENTITY, target)

        if self.others_exit_message:
            message = self.others_exit_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it2"])
                else:
                    message = message % verbs["it2"].lower()
        else:
            message = "$n %s da chissà dove..." % verbs["it2"]
        entity.act(message, TO.OTHERS, target)

        if entity != target:
            if self.target_exit_message:
                message = self.target_exit_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["destination2"])
                    else:
                        message = message % verbs["destination2"].lower()
            else:
                message = "$n %s da te in $l." % verbs["destination2"]
            entity.act(message, TO.TARGET, target, entity.location, entity.previous_location())
Exemple #14
0
    def send_eatkey_messages(self, entity, target, key, direction=None, destination_room=None):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        if self.entity_eatkey_message:
            message = self.entity_unlock_message
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$N ti si polverizza in mano"
        entity.act(message, TO.ENTITY, key, destination_room)

        if self.others_eatkey_message:
            message = self.entity_unlock_message
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$N si polverizza fra le mani di $n"
        entity.act(message, TO.OTHERS, key, destination_room)

        if entity != target:
            if self.target_eatkey_message:
                message = self.entity_unlock_message
                if "%dir" in message:
                    if message.startswith("%dir"):
                        message = message % color_first_upper(direction.to_dir2)
                    else:
                        message = message % direction.to_dir2.lower()
            else:
                message = "Tu che sei $N ti polverizzi"
            entity.act(message, TO.TARGET, key, destination_room)
Exemple #15
0
def end_destroy(entity, target, verbs, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    # behavioured ha valore di verità

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

    if target.quantity <= 1:
        messages = {
            "entity" : "%s $N." % color_first_upper(verbs["you"]),
            "others" : "$n %s $N." % verbs["it"],
            "target" : "$n ti %s." % verbs["it"]}
    else:
        messages = {
            "entity" : "%s $N, per un quantitativo di %d." % (color_first_upper(verbs["you"]), target.quantity),
            "others" : "$n %s $N, per un quantitativo di %d." % (verbs["it"], target.quantity),
            "target" : "$n ti %s, per un quantitativo di %d." % (verbs["it"], target.quantity)}
    send_destroy_messages(messages, "end_destroy", entity, target, verbs)

    target.dies(opponent=entity, quantity=target.quantity)

    # Il comando dona 1 punto xp per ogni oggetto distrutto, poca roba, ma
    # magari serve ad incoraggiare la pulizia da parte dei giocatori di entità
    # ormai inutili
    if entity.IS_PLAYER:
        reason = "per aver distrutto con successo %s" % target.get_name(looker=entity)
        entity.give_experience(1, reason=reason)

    force_return = check_trigger(entity, "after_destroy", entity, target, behavioured)
    if force_return:
        return
    force_return = check_trigger(target, "after_broken", entity, target, behavioured)
    if force_return:
        return
def get_formatted_equipment_list(entity,
                                 target,
                                 show_header=True,
                                 show_footer=True):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return ""

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

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

    output = get_equipment_list(entity, target)

    if show_header:
        if target == entity:
            if output:
                output = ["[red]Stai utilizzando[close]:\n"] + output
            else:
                output.append("Non stai utilizzando nulla, sei %s!\n" %
                              entity.skin_colorize("nud$o"))
        else:
            if output:
                output = [
                    "%s [red]sta utilizzando[close]:\n" %
                    color_first_upper(target.get_name(entity))
                ] + output
            else:
                output.append(
                    "%s non sta utilizzando nulla, è %s!\n" %
                    (color_first_upper(target.get_name(looker=entity)),
                     target.skin_colorize("nud%s" % grammar_gender(target))))

    if show_footer:
        carry_equip_descr = get_weight_descr(target.get_equipped_weight())
        output.append(create_demi_line(entity))
        output.append("Stai indossando un peso totale di %s." %
                      carry_equip_descr)

    return "".join(output)
Exemple #17
0
def send_destroy_messages(messages, message_type, entity, target, verbs, new_line=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

    # new_line ha valore di verità

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

    for to in (TO.ENTITY, TO.OTHERS, TO.TARGET):
        to_mini_code = to.get_mini_code()
        attr_name = message_type + "_" + to_mini_code
        if target.destroy and getattr(target.destroy, attr_name):
            message = getattr(target.destroy, attr_name)
            if "%verb_you2" in message:
                message = message.replace("%verb_you2", verbs["you2"])
            if "%verb_you" in message:
                # Questo replace deve trovarsi dopo quello di verb_you2
                message = message.replace("%verb_you", verbs["you"])
            if "%verb_it" in message:
                message = message.replace("%verb_it", verbs["it"])
            if "%verb" in message:
                message = message.replace("%verb", verbs["infinitive"])
        else:
            message = messages[to_mini_code]

        if new_line:
            entity.act("\n" + color_first_upper(message), to, target)
        else:
            entity.act(color_first_upper(message), to, target)
    if new_line:
        entity.send_prompt()
Exemple #18
0
def send_follow_entity_come_message(walker, entity, direction, fleeing, running, follower_names):
    # walker può essere None

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

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

    # fleeing e running hanno valore di verità

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

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

    if walker and walker.follow_entity_come_message:
        message = walker.follow_entity_come_message
        if "%verb" in message:
            if message.startswith("%verb"):
                message = message.replace("%verb", color_first_upper(entity.go_verb_it(fleeing, running)))
            else:
                message = message.replace("%verb", entity.go_verb_it(fleeing, running).lower())
        if "%direction" in message:
            if message.startswith("%direction"):
                message = message.replace("%direction", color_first_upper(direction.from_dir))
            else:
                message = message.replace("%direction", direction.from_dir.lower())
        if "%followers" in message:
            message = message.replace("%followers", pretty_list(follower_names))
    else:
        message = "Vieni seguit$o da %s." % pretty_list(follower_names)

    entity.act("\n" + put_final_dot(message), TO.ENTITY, entity.guide)
Exemple #19
0
def command_emote(entity, argument="", behavioured=False):
    """
    Permette di inviare liberamente dei messaggi per poter esprimere sentimenti
    o gesti.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

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

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

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

    argument = put_final_dot(argument)

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

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

    return True
Exemple #20
0
def before_listen_rpg_channel(locandiera, player, target, phrase, ask, exclaim,
                              behavioured):
    # Mi assicuro che si stia parlando rivolgendosi alla locandiera
    if target != locandiera:
        return

    player_code = player.get_numbered_keyword(looker=locandiera)

    if is_infix("menù", phrase):
        to_say = "a %s Il nostro menù di oggi lo potete vedere qui." % player_code
        defer_if_possible(1, 2, locandiera, player, command_say, locandiera,
                          to_say)
        return

    proto_cibi = []
    for proto_code in PROTO_FOODS_CODES:
        table_name = "proto_" + proto_code.split("_")[1] + "s"
        proto_entity = database[table_name][proto_code]

        for keyword in multiple_arguments(
                proto_entity.get_keywords_attr(looker=locandiera)):
            if is_infix(keyword, phrase):
                proto_cibi.append(proto_entity)

    if not proto_cibi:
        to_say = "a %s Non credo di poterla accontentare..." % player_code
        defer_if_possible(1, 2, locandiera, player, command_say, locandiera,
                          to_say)
        return

    proto_pietanza = random.choice(proto_cibi)
    pietanza = proto_pietanza.CONSTRUCTOR(proto_pietanza.code)

    to_say = "a %s Ottimo! %s in arrivo." % (
        player_code, color_first_upper(pietanza.get_name(looker=player)))
    defer_if_possible(1, 2, locandiera, player, command_say, locandiera,
                      to_say)
    defer_random_time(6, 8, locandiera_act, locandiera, pietanza, player)
Exemple #21
0
def send_not_argument_message(entity, objective, channel):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

    if objective < OBJECTIVE_ROOM or objective > OBJECTIVE_GROUP:
        log.bug("objective non è un parametro valido: %r" % objective)
        return

    if not channel or channel == CHANNEL.NONE:
        log.bug("channel non è un parametro valido: %r" % channel)
        return

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

    channel_verb = color_first_upper(str(channel))

    if objective == OBJECTIVE_ROOM:
        entity.send_output("%s che cosa?" % channel_verb)
    elif objective == OBJECTIVE_TARGET:
        entity.send_output("%s a %s che cosa?" % (channel_verb, target.get_name(looker=entity)))
    elif objective == OBJECTIVE_SELF:
        entity.send_output("%s al gruppo che cosa?" % channel_verb)
Exemple #22
0
def send_not_argument_message(entity, objective, channel):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

    if objective < OBJECTIVE_ROOM or objective > OBJECTIVE_GROUP:
        log.bug("objective non è un parametro valido: %r" % objective)
        return

    if not channel or channel == CHANNEL.NONE:
        log.bug("channel non è un parametro valido: %r" % channel)
        return

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

    channel_verb = color_first_upper(str(channel))

    if objective == OBJECTIVE_ROOM:
        entity.send_output("%s che cosa?" % channel_verb)
    elif objective == OBJECTIVE_TARGET:
        entity.send_output("%s a %s che cosa?" %
                           (channel_verb, target.get_name(looker=entity)))
    elif objective == OBJECTIVE_SELF:
        entity.send_output("%s al gruppo che cosa?" % channel_verb)
Exemple #23
0
    def send_offer_messages(self, entity, target, dealer, verbs, quantity, pretty_price):
        if not entity:
            log.bug("entity non è un parametro valido: %r", entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

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

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_offer_message:
            message = self.entity_offer_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        elif quantity <= 1:
            message = "$N ti %s %s per $N." % (verbs["it"], pretty_price)
        else:
            message = "$N ti %s %s per %d unità di $N." % (verbs["it"], pretty_price, quantity)
        entity.act(message, TO.ENTITY, target, dealer)

        if self.others_offer_message:
            message = self.entity_offer_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        elif quantity <= 1:
            message = "$N %s %s a $n per $N." % (verbs["it"], pretty_price)
        else:
            message = "$N %s %s a $n per %d unità di $N." % (verbs["it"], pretty_price, quantity)
        entity.act(message, TO.OTHERS, target, dealer)

        if target != entity:
            if self.target_offer_message:
                message = self.entity_offer_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message.replace("%verb", color_first_upper(verbs["you"]))
                    else:
                        message = message.replace("%verb", verbs["you"].lower())
                if "%quantity" in message:
                    message = message.replace("%quantity", quantity_descr)
                if "%price" in message:
                    message = message.replace("%price", pretty_price)
            elif quantity <= 1:
                message = "%s a $n %s per $N." % (color_first_upper(verbs["you"]), pretty_price)
            else:
                message = "%s a $n %s per %d unità di $N." % (color_first_upper(verbs["you"], quantity), pretty_price)
            entity.act(message, TO.TARGET, target, dealer)

        if dealer != entity:
            if self.dealer_offer_message:
                message = self.entity_offer_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message.replace("%verb", color_first_upper(verbs["it"]))
                    else:
                        message = message.replace("%verb", verbs["it"].lower())
                if "%quantity" in message:
                    message = message.replace("%quantity", quantity_descr)
                if "%price" in message:
                    message = message.replace("%price", pretty_price)
            elif quantity <= 1:
                message = "$a %s a $n %s per te." % (verbs["it"], pretty_price)
            else:
                message = "$a %s a $n %s per %d unità di te." % (verbs["it"], pretty_price, quantity)
            entity.act(message, TO.TARGET, dealer, target)
Exemple #24
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
Exemple #25
0
def command_wield(entity, argument="", verbs=VERBS, behavioured=False, command_name="wield"):
    """
    Permette di prendere un oggetto nella mano secondaria o, se quest'ultima
    è occupata, in quella primaria.
    """
    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

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

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

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

    entity = entity.split_entity(1)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return True
Exemple #26
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
Exemple #27
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
Exemple #28
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
Exemple #29
0
    def send_enter_messages(self, entity, target, verbs, fleeing):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        # (TD) Se l'entità conosce target fare visualizzare questo messaggio,
        # altrimenti fare visualizzare un postfisso: 'andando chissà dove'
        if fleeing:
            verb = "Fuggi"
        else:
            verb = color_first_upper(verbs["you"])
        if self.entity_enter_message:
            message = "\n" + self.entity_enter_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verb)
                else:
                    message = message % verb.lower()
        else:
            if entity == target:
                message = "[royalblue]%s[close] in te stess$o.\n" % verb
            else:
                message = "[royalblue]%s[close] in $N.\n" % verb
        entity.act(message, TO.ENTITY, target, entity.location, entity.previous_location())

        if fleeing:
            verb = "fugge"
        else:
            verb = verbs["it"].lower()
        if self.others_enter_message:
            message = self.others_enter_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verb)
                else:
                    message = message % verb.lower()
        else:
            if entity == target:
                message = "$n [royalblue]%s[close] in sé stess$o andando chissà dove..." % verb
            else:
                message = "$n [royalblue]%s[close] in $N andando chissà dove..." % verb
        entity.act(message, TO.OTHERS, target, entity.location, entity.previous_location())

        if entity != target:
            if fleeing:
                verb = "fugge"
            else:
                verb = verbs["it"].lower()
            if self.target_enter_message:
                message = self.target_enter_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verb)
                    else:
                        message = message % verb.lower()
            else:
                message = "$n [royalblue]%s[close] in te." % verb
            entity.act(message, TO.TARGET, target, entity.location, entity.previous_location())
Exemple #30
0
def command_wield(entity,
                  argument="",
                  verbs=VERBS,
                  behavioured=False,
                  command_name="wield"):
    """
    Permette di prendere un oggetto nella mano secondaria o, se quest'ultima
    è occupata, in quella primaria.
    """
    if not verbs:
        log.bug("verbs non è un parametro valido: %r" % verbs)
        return False

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

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

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

    entity = entity.split_entity(1)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return True
Exemple #31
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
Exemple #32
0
    def send_cannot_afford_messages(self, entity, purchase, dealer, verbs, quantity, pretty_price):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

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

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_cannot_afford_message:
            message = self.entity_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb", verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "Non hai abbastanza soldi per poter %s %s$N da $a: costa %s." % (verbs["infinitive"], quantity_descr, pretty_price)
        entity.act(message, TO.ENTITY, purchase, dealer)

        if self.others_cannot_afford_message:
            message = self.others_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb", verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non sembra avere abbastanza soldi per poter %s %s$N." % (verbs["infinitive"], quantity_descr)
        entity.act(message, TO.OTHERS, purchase, dealer)

        if self.target_cannot_afford_message:
            message = self.target_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb", verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non ha abbastanza soldi per poterti %s da $a." % verbs["infinitive"]
        entity.act(message, TO.TARGET, purchase, dealer)

        if self.dealer_cannot_afford_message:
            message = self.dealer_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb", verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non ha abbastanza soldi per poter %s %s$a da te." % (verbs["infinitive"], quantity_descr)
        entity.act(message, TO.TARGET, dealer, purchase)
Exemple #33
0
    def send_cannot_afford_messages(self, entity, purchase, dealer, verbs,
                                    quantity, pretty_price):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

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

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_cannot_afford_message:
            message = self.entity_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace(
                        "%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb",
                                              verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "Non hai abbastanza soldi per poter %s %s$N da $a: costa %s." % (
                verbs["infinitive"], quantity_descr, pretty_price)
        entity.act(message, TO.ENTITY, purchase, dealer)

        if self.others_cannot_afford_message:
            message = self.others_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace(
                        "%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb",
                                              verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non sembra avere abbastanza soldi per poter %s %s$N." % (
                verbs["infinitive"], quantity_descr)
        entity.act(message, TO.OTHERS, purchase, dealer)

        if self.target_cannot_afford_message:
            message = self.target_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace(
                        "%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb",
                                              verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non ha abbastanza soldi per poterti %s da $a." % verbs[
                "infinitive"]
        entity.act(message, TO.TARGET, purchase, dealer)

        if self.dealer_cannot_afford_message:
            message = self.dealer_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace(
                        "%verb", color_first_upper(verbs["infinitive"]))
                else:
                    message = message.replace("%verb",
                                              verbs["infinitive"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            message = "$n non ha abbastanza soldi per poter %s %s$a da te." % (
                verbs["infinitive"], quantity_descr)
        entity.act(message, TO.TARGET, dealer, purchase)
Exemple #34
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
Exemple #35
0
def digging_a_location_2(entity, location, verbs, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

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

    targets = []
    for target in location.iter_contains():
        if FLAG.BURIED in target.flags:
            targets.append(target)

    # C'è una possibilità su cento che venga trovato qualcosa di interessante
    # (TD) magari la probabilità aumentarla facendola sulla base della skill scava
    # (TD) magari aggiungere un affect per invalidare tentativi robotizzati di scavaggio continuo
    if not targets and random.randint(1, 100) < DIG_PROBABILITY:
        codes = database["areas"]["rip"].proto_items.keys()
        codes += database.randomizable_codes
        codes += database.race_money_codes
        codes += database.seed_codes

        code = random.choice(codes)
        if code.split("_")[1] == "item":
            targets = [Item(code)]
        else:
            targets = [Mob(code)]

        # Per le monete viene impostata anche una quantità casuale.
        # Qui in sostanza viene detto che si possono trovare da 1 a 1000 monete
        # di rame e al massimo solo 1 moneta di mithril, valori intermedi sono
        # inversamente proporzionali al valore della moneta stessa
        if targets[0].money_type:
            copper_value = min(targets[0].money_type.copper_value, 1000)
            targets[0].quantity = random.randint(1, int(1000 / copper_value))

        # (TD) Bisognerebbe inserire un affect nella locazione che impedisca di
        # scavare ancora lì per tot tempo
        targets[0].inject(location)

    # L'esperienza per aver scavato la prima volta nella stanza viene data
    # a prescindere che sia stato trovata un'entità o meno
    if entity.IS_PLAYER and location.IS_ROOM:
        if location.prototype.code in entity.digged_rooms:
            entity.digged_rooms[location.prototype.code] += 1
        else:
            entity.digged_rooms[location.prototype.code] = 1
            reason = "per aver scavato %s" % location.get_name(looker=entity)
            entity.give_experience(location.area.level, reason=reason)

    if not targets:
        entity.act("\n%s ma non trovi proprio nulla di interessante." % color_first_upper(verbs["you"]), TO.ENTITY, location)
        entity.act("$n %s una buca in $N senza trovare nulla di interessante." % verbs["it"], TO.OTHERS, location)
        entity.act("$n ti %s una buca senza trovare nulla di interessante." % verbs["it"], TO.TARGET, location)
        entity.send_prompt()
        entity.action_in_progress = None
        return

    target = random.choice(targets)
    target = target.split_entity(random.randint(1, target.quantity))

    entity.action_in_progress = None

    entity.act("\nFinisci di %s scoprendo $N!" % verbs["infinitive"], TO.ENTITY, target)
    entity.act("$n termina di %s dopo che ha scoperto qualcosa." % verbs["infinitive"], TO.OTHERS, target)
    entity.act("$n termina di %s dopo che ti ha scoperto nel terreno." % verbs["infinitive"], TO.TARGET, target)
    entity.act("$n termina di %s dopo che ha scoperto $a dentro di te." % verbs["infinitive"], TO.TARGET, location, target)
    entity.send_prompt()

    target.flags -= FLAG.BURIED
    # Se era un seme o una pianta allora ne ferma la crescita 
    if target.seed_type:
        target.seed_type.stop_growth()
    if target.plant_type:
        target.plant_type.stop_growth()

    # (TD) imparare un po' la skill scava dai propri successi

    force_return = check_trigger(entity, "after_dig", entity, location, target, DIR.NONE, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "after_digged", entity, location, target, DIR.NONE, behavioured)
    if force_return:
        return True
Exemple #36
0
    def create_page(self,
                    request,
                    conn,
                    age=0,
                    height=0,
                    weight=0,
                    hair_color=COLOR.NONE,
                    hair_type=HAIRTYPE.NONE,
                    hair_length=0,
                    eye_color=COLOR.NONE,
                    skin_color=COLOR.NONE,
                    hand=HAND.NONE,
                    name="",
                    err_msg_age="",
                    err_msg_height="",
                    err_msg_weight="",
                    err_msg_haircolor="",
                    err_msg_hairtype="",
                    err_msg_hairlength="",
                    err_msg_eyecolor="",
                    err_msg_skin_color="",
                    err_msg_hand="",
                    err_msg_name=""):
        # Prepara il form con i dati per la creazione di un nuovo personaggio
        form = []
        row = create_form_row(form)
        row.label = '''Età'''
        row.field = '''<input type="text" name="age" maxlength="3" size="6" value="%s" />''' % age
        row.message = err_msg_age

        row = create_form_row(form)
        row.label = '''Altezza (cm)'''
        row.field = '''<input type="text" name="height" maxlength="3" size="6" value="%s" />''' % height
        row.message = err_msg_height

        if conn.new_player.race.weight_low > 1000:
            row = create_form_row(form)
            row.label = '''Peso (kg)'''
            row.field = '''<input type="text" name="weight" maxlength="3" size="6" value="%s" />''' % weight
            row.message = err_msg_weight

        if conn.new_player.race.have_hair:
            row = create_form_row(form)
            row.label = '''Colore dei capelli'''
            row.field = create_listdrop_of_colors("hair_color", hair_color)
            row.message = err_msg_haircolor

            row = create_form_row(form)
            row.label = '''Tipo di capelli'''
            row.field = create_listdrop_of_elements("hair_type", hair_type)
            row.message = err_msg_hairtype

            row = create_form_row(form)
            row.label = '''Lunghezza dei capelli (cm)'''
            row.field = '''<input type="text" name="hair_length" maxlength="3" size="6" value="%s" />''' % hair_length
            row.message = err_msg_hairlength

        row = create_form_row(form)
        row.label = '''Colore degli occhi'''
        row.field = create_listdrop_of_colors("eye_color", eye_color)
        row.message = err_msg_eyecolor

        row = create_form_row(form)
        row.label = '''Colore della %s''' % "pelle/pelo"
        row.field = create_listdrop_of_colors("skin_color", skin_color)
        row.message = err_msg_skin_color

        row = create_form_row(form)
        row.label = '''%s principale''' % color_first_upper(
            str(conn.new_player.race.hand))
        row.field = create_listdrop_of_elements("hand", hand)
        row.message = err_msg_hand

        # (TD) utilizzo della mano destra o sinistra

        row = create_form_row(form)
        # (TD) dire che i nomi si possono colorare
        # (BB) fino a che non si risolve il problema degli accenti, o non si utilizza python 3.0 questa storia degli accenti la possiamo dimenticare
        #row.label   = '''Nome %s''' % create_tooltip(conn, "Puoi inserirvi un numero contenuto di vocali accentate.")
        row.label = '''Nome'''
        row.field = '''<input type="text" name="name" maxlength="%s" value="%s" onkeydown="$(this.parentNode).prev().text('');" />''' % (
            config.max_len_name, name)
        row.message = err_msg_name

        row = create_form_row(form)
        row.label = '''<input type="submit" value="Continua..." onclick="document.getElementById('form_create_player_2').submit();" />'''

        # Crea la pagina html
        return create_form(form, "form_create_player_2", "create_player2.html",
                           "Crea un nuovo Personaggio")
Exemple #37
0
    def send_buy_messages(self, entity, purchase, dealer, verbs, quantity, pretty_price, discount):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

        if discount < 0:
            log.bug("discount non è un parametro valido: %d" % discount)
            return

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

        is_dispenser = SHOP.DISPENSER in dealer.shop.types

        discount_descr = ""
        if discount > 0:
            discount_descr = " scontato"

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_buy_message:
            message = self.entity_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["you"]))
                else:
                    message = message.replace("%verb", verbs["you"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "%s %s$N da $a inserendovi %s." % (color_first_upper(verbs["you"]), quantity_descr, pretty_price)
            else:
                message = "%s %s$N da $a pagandol$O %s%s." % (color_first_upper(verbs["you"]), quantity_descr, pretty_price, discount_descr)
        entity.act(message, TO.ENTITY, purchase, dealer)

        if self.others_buy_message:
            message = self.others_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n %s %s$N da $a inserendovi %s." % (verbs["it"], quantity_descr, pretty_price)
            else:
                message = "$n %s %s$N da $a pagandol$O %s%s." % (verbs["it"], quantity_descr, pretty_price, discount_descr)
        entity.act(message, TO.OTHERS, purchase, dealer)

        if self.target_buy_message:
            message = self.target_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n ti %s da $a inserendovi %s." % (verbs["it"], pretty_price)
            else:
                message = "$n ti %s da $a pagandoti %s%s." % (verbs["it"], pretty_price, discount_descr)
        entity.act(message, TO.TARGET, purchase, dealer)

        if self.dealer_buy_message:
            message = self.dealer_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb", color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n ti %s %s$N inserendoti %s." % (verbs["it"], quantity_descr, pretty_price)
            else:
                message = "$n ti %s %s$N pagandol$O %s%s." % (verbs["it"], quantity_descr, pretty_price, discount_descr)
        entity.act(message, TO.TARGET, dealer, purchase)
Exemple #38
0
    def send_enter_messages(self, entity, target, verbs, fleeing):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

        # (TD) Se l'entità conosce target fare visualizzare questo messaggio,
        # altrimenti fare visualizzare un postfisso: 'andando chissà dove'
        if fleeing:
            verb = "Fuggi"
        else:
            verb = color_first_upper(verbs["you"])
        if self.entity_enter_message:
            message = "\n" + self.entity_enter_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verb)
                else:
                    message = message % verb.lower()
        else:
            if entity == target:
                message = "[royalblue]%s[close] in te stess$o.\n" % verb
            else:
                message = "[royalblue]%s[close] in $N.\n" % verb
        entity.act(message, TO.ENTITY, target, entity.location,
                   entity.previous_location())

        if fleeing:
            verb = "fugge"
        else:
            verb = verbs["it"].lower()
        if self.others_enter_message:
            message = self.others_enter_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verb)
                else:
                    message = message % verb.lower()
        else:
            if entity == target:
                message = "$n [royalblue]%s[close] in sé stess$o andando chissà dove..." % verb
            else:
                message = "$n [royalblue]%s[close] in $N andando chissà dove..." % verb
        entity.act(message, TO.OTHERS, target, entity.location,
                   entity.previous_location())

        if entity != target:
            if fleeing:
                verb = "fugge"
            else:
                verb = verbs["it"].lower()
            if self.target_enter_message:
                message = self.target_enter_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verb)
                    else:
                        message = message % verb.lower()
            else:
                message = "$n [royalblue]%s[close] in te." % verb
            entity.act(message, TO.TARGET, target, entity.location,
                       entity.previous_location())
Exemple #39
0
    def render_POST(self, request, conn):
        if not conn.new_player:
            return '''Per qualche errore sul server il personaggio non è stato creato, oppure è stato già creato, controlla la pagina con <a href="players.html">i tuoi personaggi</a>.'''

        # Ricava gli argomenti del form dalla richiesta
        age = 0
        if "age" in request.args:
            age = request.args["age"][0]

        height = 0
        if "height" in request.args:
            height = request.args["height"][0]

        weight = 0
        if conn.new_player.race.weight_low > 1000:
            if "weight" in request.args:
                weight = request.args["weight"][0]
        else:
            weight = random.randint(conn.new_player.race.weight_low,
                                    conn.new_player.race.weight_high)

        hair_color = None
        hair_type = None
        hair_length = 0
        if conn.new_player.race.have_hair:
            if "hair_color" in request.args:
                hair_color = Element(request.args["hair_color"][0])

            if "hair_type" in request.args:
                hair_type = Element(request.args["hair_type"][0])

            if "hair_length" in request.args:
                hair_length = request.args["hair_length"][0]

        eye_color = ""
        if "eye_color" in request.args:
            eye_color = Element(request.args["eye_color"][0])

        skin_color = ""
        if "skin_color" in request.args:
            skin_color = Element(request.args["skin_color"][0])

        hand = ""
        if "hand" in request.args:
            hand = Element(request.args["hand"][0])

        name = ""
        if "name" in request.args:
            name = request.args["name"][0]

        # Controlla la validità degli argomenti inseriti nel form
        err_msg_age = ""
        try:
            age = int(age)
        except ValueError:
            err_msg_age = "L'età deve essere un numero che indica gli anni vissuti dal tuo personaggio"
        else:
            if age < conn.new_player.race.age_adolescence or age > conn.new_player.race.age_old:
                err_msg_age = "I limiti dell'età, relativamente alla razza da te scelta, sono tra %d e %d." % (
                    conn.new_player.race.age_adolescence,
                    conn.new_player.race.age_old)

        err_msg_height = ""
        try:
            height = int(height)
        except ValueError:
            err_msg_height = "L'altezza deve essere un numero in centimetri"
        else:
            if height < conn.new_player.race.height_low or height > conn.new_player.race.height_high:
                err_msg_height = "I limiti dell'altezza, relativamente alla razza da te scelta, sono tra %d e %d" % (
                    conn.new_player.race.height_low,
                    conn.new_player.race.height_high)

        err_msg_weight = ""
        if conn.new_player.race.weight_low > 1000:
            try:
                weight = int(weight)
            except ValueError:
                err_msg_weight = "Il peso deve essere un numero in chili"
            else:
                if weight < conn.new_player.race.weight_low / 1000 or weight > conn.new_player.race.weight_high / 1000:
                    err_msg_weight = "I limiti del peso, relativamente alla razza da te scelta, sono tra %d e %d" % (
                        conn.new_player.race.weight_low / 1000,
                        conn.new_player.race.weight_high / 1000)

        err_msg_haircolor = ""
        err_msg_hairtype = ""
        err_msg_hairlength = ""
        if conn.new_player.race.have_hair:
            if not hair_color:
                err_msg_haircolor = "Scegli il colore di capelli che vuoi dare al tuo personaggio."
                hair_color = COLOR.NONE

            if not hair_type:
                err_msg_hairtype = "Scegli il tipo di tagli di capelli che vuoi per il tuo personaggio."
                hair_type = HAIRTYPE.NONE

            try:
                hair_length = int(hair_length)
            except ValueError:
                err_msg_hairlength = "La lunghezza dei capelli deve essere un numero in centimentri."
            else:
                if hair_length < 0 or hair_length >= conn.new_player.race.height_low:
                    err_msg_hairlength = "La lunghezza dei capelli deve essere un numero tra lo 0 e %d" % (
                        conn.new_player.race.height_low / 2)

        err_msg_eyecolor = ""
        if not eye_color:
            err_msg_eyecolor = "Scegli il colore degli occhi che vuoi dare al tuo personaggio"
            eye_color = COLOR.NONE

        err_msg_skin_color = ""
        if not skin_color:
            err_msg_skin_color = "Scegli il colore della pelle che vuoi dare al tuo personaggio"
            skin_color = COLOR.NONE

        err_msg_hand = ""
        if not hand:
            err_msg_hand = "Scegli qual'è la %s principale del tuo futuro personaggio" % conn.new_player.race.hand
            hand = HAND.NONE

        err_msg_name = ""
        if name:
            name = color_first_upper(name)
            err_msg_name = get_error_message_name(name, False, "players")
        else:
            err_msg_name = "Inserisci il nome del personaggio che vuoi interpretare."

        # Se non ci sono stati errori allora inserisce i dati scelti dal
        # giocatore nell'oggetto personaggio che sta creando e continua
        # la creazione
        if (not err_msg_age and not err_msg_height and not err_msg_weight
                and not err_msg_haircolor and not err_msg_hairtype
                and not err_msg_hairlength and not err_msg_eyecolor
                and not err_msg_skin_color and not err_msg_hand
                and not err_msg_name):
            conn.new_player.age = age
            conn.new_player.birth_month = conn.new_player.constellation.month
            conn.new_player.birth_day = random.randint(1, config.days_in_month)
            conn.new_player.height = height
            if conn.new_player.race.weight_low > 1000:
                conn.new_player.weight = weight * 1000
            else:
                conn.new_player.weight = weight
            conn.new_player.hair_color = hair_color
            conn.new_player.hair_type = hair_type
            conn.new_player.hair_length = hair_length
            conn.new_player.eye_color = eye_color
            conn.new_player.skin_color = skin_color
            conn.new_player.hand = hand
            conn.new_player.name = name
            conn.new_player.code = remove_colors(name)

            # Se vi era un giocatore connesso al gioco allora lo sconnette
            # per poi connettersi con quello nuovo
            if conn.player and conn.player.game_request:
                conn.player.send_output(
                    "\n\nConnessione chiusa per la creazione di un nuovo personaggio."
                )
                conn.player.game_request.finish()

            # Se ha terminato di distribuire tutti i punti allora procede alla
            # creazione e all'inserimento in gioco del nuovo personaggio
            conn.account.player = conn.new_player
            conn.account.players[conn.new_player.code] = conn.new_player
            conn.player = conn.new_player
            conn.player.account = conn.account
            database["players"][conn.new_player.code] = conn.new_player
            conn.new_player = None

            # Se c'è solo il nuovo personaggio nel database allora gli dona
            # il massimo dei permessi
            if len(database["players"]) == 1:
                conn.player.trust = TRUST.IMPLEMENTOR

            # Internet Explorer non riesce a gestire qualche cosa e non si connette
            # direttamente in gioco
            if conn.get_browser().startswith("IE"):
                request.redirect("chaplayersml")
            else:
                request.redirect("game_interface.html?pg_code=%s" %
                                 conn.player.code)
            request.finish()
            return server.NOT_DONE_YET

        return self.create_page(request, conn, age, height, weight, hair_color,
                                hair_type, hair_length, eye_color, skin_color,
                                hand, name, err_msg_age, err_msg_height,
                                err_msg_weight, err_msg_haircolor,
                                err_msg_hairtype, err_msg_hairlength,
                                err_msg_eyecolor, err_msg_skin_color,
                                err_msg_hand, err_msg_name)
Exemple #40
0
    def send_unbolt_messages(self,
                             entity,
                             target,
                             verbs,
                             direction=None,
                             destination_room=None):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if self.entity_unbolt_message:
            message = self.entity_unbolt_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you"])
                else:
                    message = message % verbs["you"].lower()
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "%s $N." % color_first_upper(verbs["you"])
        entity.act(message, TO.ENTITY, target, destination_room)

        if self.others_unbolt_message:
            message = self.others_unbolt_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it"])
                else:
                    message = message % verbs["it"].lower()
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$n %s $N." % verbs["it"].lower()
        entity.act(message, TO.OTHERS, target, destination_room)

        if entity != target:
            if self.target_unbolt_message:
                message = self.target_unbolt_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["it"])
                    else:
                        message = message % verbs["it"].lower()
                if "%dir" in message:
                    if message.startswith("%dir"):
                        message = message % color_first_upper(
                            direction.to_dir2)
                    else:
                        message = message % direction.to_dir2.lower()
            else:
                message = "$n ti %s." % verbs["it"].lower()
            entity.act(message, TO.TARGET, target, destination_room)
Exemple #41
0
def sense_an_entity(entity, target, extra_argument, command_name, gamescript_suffix2, sense_name, messages, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

    # extra_argument può essere una stringa vuota

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

    if not 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 extra_argument:
        # Cerca una extra sensoriale, prima in maniera esatta e poi prefissa
        extra = target.extras.get_extra(extra_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_entities(entity, target, command_name)

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

                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
                word = add_article(extra.keywords.split()[0], GRAMMAR.INDETERMINATE)
                sense_messages_to_others(entity, target, messages, behavioured, "entity_extra", word, extra)

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

        extra = target.extras.get_extra(extra_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_entities(entity, target, command_name)

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

                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
                word = add_article(extra.keywords.split()[0], GRAMMAR.INDETERMINATE)
                sense_messages_to_others(entity, target, messages, behavioured, "entity_extra", word, extra)
                force_return = check_trigger(entity, "after_" + command_name, entity, target, descr, extra, behavioured)

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

        avoid_inventory = True
        if target.is_sensable_inside(sense_name):
            avoid_inventory = False

        # Oltre alle extra cerca anche tra gli oggetti equipaggiati di target
        equipped_target = entity.find_entity(extra_argument, location=target, avoid_inventory=avoid_inventory, avoid_equipment=False)
        if equipped_target:
            descr = equipped_target.get_descr(sense_name, looker=entity)
            if descr and "no_send" not in descr:
                update_sensed_entities(entity, equipped_target, command_name)

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

                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
                sense_messages_to_others_equipped(entity, equipped_target, messages, "entity_equip", target)

                force_return = check_trigger(entity, "after_" + command_name, entity, equipped_target, descr, extra, behavioured)
                if force_return:
                    return True
                force_return = check_trigger(equipped_target, "after_" + gamescript_suffix2, entity, equipped_target, descr, extra, behavioured)
                if force_return:
                    return True
                return True
            else:
                force_return = check_trigger(entity, "before_" + command_name, entity, equipped_target, target, "", behavioured)
                if force_return:
                    return False
                force_return = check_trigger(equipped_target, "before_" + gamescript_suffix2, entity, equipped_target, "", target, behavioured)
                if force_return:
                    return False

                sense_messages_to_others_equipped(entity, equipped_target, messages, "entity_equip", target)
                entity.act(messages["entity_equip_auto"], TO.ENTITY, target, equipped_target)

                force_return = check_trigger(entity, "after_" + command_name, entity, equipped_target, "", target, behavioured)
                if force_return:
                    return False
                force_return = check_trigger(equipped_target, "after_" + gamescript_suffix2, entity, equipped_target, "", target, behavioured)
                if force_return:
                    return False
                return False

        # (TD) Qui inoltre dovrò cercare tra le parti del corpo

        # Se la keyword si trova però in un'altro senso allora invia un
        # messaggio leggermente differente, coma a dare per scontato che
        # vi sia effettivamente un'altra keywords
        force_return = check_trigger(entity, "before_" + command_name, entity, target, "", extra, behavioured)
        if force_return:
            return False
        force_return = check_trigger(target, "before_" + gamescript_suffix2, entity, target, "", extra, behavioured)
        if force_return:
            return False

        if extra:
            if entity == target:
                if "%s" in messages["no_found_extra_entity_alt_auto"]:
                    entity.act(messages["no_found_extra_entity_alt_auto"] % extra_argument, TO.ENTITY)
                else:
                    entity.act(messages["no_found_extra_entity_alt_auto"], TO.ENTITY)
            else:
                if "%s" in messages["no_found_extra_entity_alt"]:
                    entity.act(messages["no_found_extra_entity_alt"] % extra_argument, TO.ENTITY, target)
                else:
                    entity.act(messages["no_found_extra_entity_alt"], TO.ENTITY, target)
        else:
            if entity == target:
                if "%s" in messages["no_found_extra_entity_auto"]:
                    entity.act(messages["no_found_extra_entity_auto"] % extra_argument, TO.ENTITY)
                else:
                    entity.act(messages["no_found_extra_entity_auto"], TO.ENTITY)
            else:
                if "%s" in messages["no_found_extra_entity"]:
                    entity.act(messages["no_found_extra_entity"] % extra_argument, TO.ENTITY, target)
                else:
                    entity.act(messages["no_found_extra_entity"], TO.ENTITY, target)
        if entity == target:
            entity.act(messages["no_found_extra_others_auto"], TO.OTHERS)
        else:
            entity.act(messages["no_found_extra_others"], TO.OTHERS, target)
        if entity != target:
            entity.act(messages["no_found_extra_target"], TO.TARGET, target)

        force_return = check_trigger(entity, "after_" + command_name, entity, target, "", extra, behavioured)
        if force_return:
            return False
        force_return = check_trigger(target, "after_" + gamescript_suffix2, entity, target, "", extra, behavioured)
        if force_return:
            return False
        return False
    else:
        # Se si sta toccando un oggetto ne si può ricavare il peso totale invece
        # della sola tara come avviene invece nel look
        if target.IS_ITEM and sense_name == "touch":
            weight_descr = get_weight_descr(target.get_total_weight())
            if entity == target:
                weight_descr = "Pesi in totale %s" % weight_descr
            else:
                name = target.get_name(entity)
                weight_descr = "%s pesa in totale %s" % (color_first_upper(name), weight_descr)

        descr = target.get_descr(sense_name, looker=entity)
        if descr and "no_send" not in descr:
            update_sensed_entities(entity, target, command_name)

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

            if target.IS_ITEM and sense_name == "touch":
                entity.send_output('''<div style="width:66%%">%s</div>''' % descr + weight_descr + "\n", break_line=False)
            else:
                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            sense_messages_to_others(entity, target, messages, behavioured, "entity_descr", "")
            force_return = check_trigger(entity, "after_" + command_name, entity, target, descr, None, behavioured)
            if force_return:
                return True
            force_return = check_trigger(target, "after_" + gamescript_suffix2, entity, target, descr, None, behavioured)
            if force_return:
                return True
            return True
        else:
            force_return = check_trigger(entity, "before_" + command_name, entity, target, "", None, behavioured)
            if force_return:
                return False
            force_return = check_trigger(target, "before_" + gamescript_suffix2, entity, target, "", None, behavioured)
            if force_return:
                return False

            if entity == target:
                entity.act(messages["no_found_descr_entity_auto"], TO.ENTITY)
            elif target.IS_ITEM and sense_name == "touch":
                entity.act(messages["no_found_descr_entity"] + "\n" + weight_descr, TO.ENTITY, target)
            else:
                entity.act(messages["no_found_descr_entity"], TO.ENTITY, target)
            if entity == target:
                entity.act(messages["no_found_descr_others_auto"], TO.OTHERS)
            else:
                entity.act(messages["no_found_descr_target"], TO.TARGET, target)
                entity.act(messages["no_found_descr_others"], TO.OTHERS, target)

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

    log.bug("Raggiungimento inaspettato del codice")
    return False
Exemple #42
0
def command_drop(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di abbandonare oggetti per terra oppure posarli in un luogo preciso.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

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

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

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

    # (TD) Controllo del mental state deviato

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

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

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

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

    # (TD) posare monete

    # (TD) argomento all, ultima cosa da supportare

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

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

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

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

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

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

    return True
Exemple #43
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
Exemple #44
0
    def send_unbolt_messages(self, entity, target, verbs, direction=None, destination_room=None):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if self.entity_unbolt_message:
            message = self.entity_unbolt_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["you"])
                else:
                    message = message % verbs["you"].lower()
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "%s $N." % color_first_upper(verbs["you"])
        entity.act(message, TO.ENTITY, target, destination_room)

        if self.others_unbolt_message:
            message = self.others_unbolt_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message % color_first_upper(verbs["it"])
                else:
                    message = message % verbs["it"].lower()
            if "%dir" in message:
                if message.startswith("%dir"):
                    message = message % color_first_upper(direction.to_dir2)
                else:
                    message = message % direction.to_dir2.lower()
        else:
            message = "$n %s $N." % verbs["it"].lower()
        entity.act(message, TO.OTHERS, target, destination_room)

        if entity != target:
            if self.target_unbolt_message:
                message = self.target_unbolt_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message % color_first_upper(verbs["it"])
                    else:
                        message = message % verbs["it"].lower()
                if "%dir" in message:
                    if message.startswith("%dir"):
                        message = message % color_first_upper(direction.to_dir2)
                    else:
                        message = message % direction.to_dir2.lower()
            else:
                message = "$n ti %s." % verbs["it"].lower()
            entity.act(message, TO.TARGET, target, destination_room)
Exemple #45
0
def kill_handler(entity, argument, command_name, entity_tables, attack=False, destroy=False, verbs=VERBS, behavioured=False):
    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 not entity_tables:
        log.bug("entity_tables non è un parametro valido: %r" % entity_tables)
        return False

    # behavioured ha valore di verità

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

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Chi o che cosa vorresti %s?" % verbs["infinitive"])
        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 sul mental state

    # Cerca la vittima da attaccare
    target = entity.find_entity(argument, location=entity.location, entity_tables=entity_tables, avoid_equipment=True)
    if not target:
        entity.act("Non trovi nessun [white]%s[close] da %s" % (argument, verbs["infinitive"]), TO.ENTITY)
        entity.act("$n non trova nessuno su cui poter sfogare la propria [red]brama di sangue[close].", TO.OTHERS)
        return False

    if entity.IS_ITEM:
        entity.act("Non ti è possibile %s perché sei un oggetto inanimato." % verbs["infinitive"], TO.ENTITY, target)
        entity.act("Non è possibile per $n poter %s $N %s perché è un oggetto inanimato." % verbs["infinitive"], TO.OTHERS, target)
        entity.act("Non è possibile per $n poterti %s perché è un oggetto inanimato." % verbs["infinitive"], TO.TARGET, target)
        return False

    if target == entity:
        entity.act("Non ti puoi %s da sol$o!" % verbs["infinitive"], TO.ENTITY)
        entity.act("$n sembra volersi %s da sol$o..." % verbs["infinitive"], TO.OTHERS)
        return False

    if entity.trust > TRUST.PLAYER and target.trust > TRUST.PLAYER:
        entity.act("Cerca di risolvere la cosa in maniera pacifica...", TO.ENTITY)
        return False

    if entity.is_fighting(with_him=target):
        entity.act("Stai già %s $N!" % verbs["gerund"], TO.ENTITY, target)
        entity.act("$n non riesce a %s $N più di così!" % verbs["infinitive"], TO.OTHERS, target)
        entity.act("$n non riesce a %s più di così!" % verbs["infinitive"], TO.TARGET, target)
        return False

    if target.IS_ITEM and target.life <= 0:
        from src.commands import command_destroy
        entity.act("Non puoi %s $N più di così." % command_destroy.VERBS["infinitive"], TO.ENTITY, target)
        entity.act("$n non riesce a %s $N più di così." % command_destroy.VERBS["infinitive"], TO.OTHERS, target)
        entity.act("$n non riesce a %s più di così." % command_destroy.VERBS["you2"], TO.TARGET, target)
        return False

    force_return = check_trigger(entity, "before_kill", entity, target, attack, destroy, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_killed", entity, target, attack, destroy, behavioured)
    if force_return:
        return True

    # Avvia il combattimento!
    entity.act("%s $N." % color_first_upper(ATTACK_VERBS["you"]), TO.ENTITY, target)
    entity.act("$n %s $N." % ATTACK_VERBS["it"], TO.OTHERS, target)
    entity.act("$n ti %s." % ATTACK_VERBS["it"], TO.TARGET, target)
    start_fight(entity, target)

    force_return = check_trigger(entity, "after_kill", entity, target, attack, destroy, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_killed", entity, target, attack, destroy, behavioured)
    if force_return:
        return True

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

    entity = entity.split_entity(1)

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

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

    original_argument = argument

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return True
Exemple #47
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
Exemple #48
0
def sense_at_direction(entity, direction, argument, exact, command_name, gamescript_suffix2, sense_name, messages, behavioured, from_or_to, readable=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

    # argument può essere una stringa vuota

    # exact 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

    if not sense_name and sense_name != "":
        log.bug("sense_name non è un parametro valido: %r" % sense_name)
        return False

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

    if from_or_to not in ("from_dir", "to_dir"):
        log.bug("from_or_to non è un parametro valido: %r" % from_or_to)
        return False

    # readable ha valore di verità

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

    if not readable:
        if not entity.location.IS_ROOM:
            force_return = check_trigger(entity, "before_" + sense_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

            if "%s" in messages["direction_entity"]:
                entity.act(messages["direction_entity"] % getattr(direction, from_or_to), TO.ENTITY)
            else:
                entity.act(messages["direction_entity"], TO.ENTITY)
            if "%s" in messages["direction_others"]:
                entity.act(messages["direction_others"] % direction.to_dir, TO.OTHERS)
            else:
                entity.act(messages["direction_others"], TO.OTHERS)

            force_return = check_trigger(entity, "after_" + sense_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

    # (TD) dovrebbe far vedere anche altre cose, a seconda della tipologia
    # dell'uscita (segreta e non) e se l'eventuale porta è stata sfondata

    # (TD) Se la stanza di arrivo è buia le cose cambiano, da pensare, anche
    # relativamente alla descr_night

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

    if direction in entity.location.walls:
        wall = entity.location.walls[direction]
        # (TD) pensare se accorpare tutti questi pezzetti di codice simile sotto
        show_to_others = True
        if argument:
            descr = ""
            extra = wall.extras.get_extra(argument, entity, parent=entity)
            if readable and EXTRA.READABLE not in extra.flags:
                extra = None
            if extra:
                descr = extra.get_descr(sense_name, looker=entity, parent=entity)
                if EXTRA.NO_LOOK_ACT in extra.flags:
                    show_to_others = False
        elif not readable:
            descr = wall.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_" + "read" if readable else sense_name, entity, entity.location, descr, wall, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "before_" + "readed" if readable else sense_name, entity, entity.location, descr, wall, behavioured)
            if force_return:
                return True

            entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            if "%s" in messages["direction_wall_others"]:
                entity.act(messages["direction_wall_others"] % direction.to_dir, TO.OTHERS)
            else:
                entity.act(messages["direction_wall_others"], TO.OTHERS)
            force_return = check_trigger(entity, "after_" + "read" if readable else sense_name, entity, entity.location, descr, wall, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "after_" + "readed" if readable else sense_name, entity, entity.location, descr, wall, behavioured)
            if force_return:
                return True
            return True

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

    door = entity.location.get_door(direction)
    if door and DOOR.CLOSED in door.door_type.flags:
        if DOOR.SECRET in door.door_type.flags:
            if "%s" in messages["direction_entity"]:
                entity.act(messages["direction_entity"] % getattr(direction, from_or_to), TO.ENTITY)
            else:
                entity.act(messages["direction_entity"], TO.ENTITY)
            if "%s" in messages["direction_others"]:
                entity.act(messages["direction_others"] % direction.to_dir, TO.OTHERS)
            else:
                entity.act(messages["direction_others"], TO.OTHERS)
            return False
        else:
            show_to_others = True
            if argument:
                descr = ""
                extra = door.extras.get_extra(argument, exact=exact)
                if readable and EXTRA.READABLE not in extra.flags:
                    extra = None
                if extra:
                    descr = extra.get_descr(sense_name, looker=entity, parent=entity)
                    if EXTRA.NO_LOOK_ACT in extra.flags:
                        show_to_others = False
            elif not readable:
                descr = door.get_descr(sense_name, looker=entity)
            if descr and "no_send" not in descr:
                update_sensed_entities(entity, door, command_name)

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

                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
                if "%s" in messages["direction_target_others"]:
                    entity.act(messages["direction_target_others"] % direction.to_dir, TO.OTHERS, door)
                else:
                    entity.act(messages["direction_target_others"], TO.OTHERS, door)
                force_return = check_trigger(entity, "after_" + command_name, entity, door, descr, None, behavioured)
                if force_return:
                    return True
                force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, door, descr, None, behavioured)
                if force_return:
                    return True
                return True

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

    exit = None
    if direction in entity.location.exits:
        exit = entity.location.exits[direction]

    if exit and EXIT.DIGGABLE not in exit.flags:
        show_to_others = True
        if argument:
            descr = ""
            extra = exit.extras.get_extra(argument, exact=exact)
            if readable and EXTRA.READABLE not in extra.flags:
                extra = None
            if extra:
                descr = extra.get_descr(sense_name, looker=entity, parent=entity)
                if EXTRA.NO_LOOK_ACT in extra.flags:
                    show_to_others = False
        elif not readable:
            descr = exit.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, exit, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, descr, exit, behavioured)
            if force_return:
                return True

            entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
            if "%s" in messages["direction_exit_others"]:
                entity.act(messages["direction_exit_others"] % direction.to_dir, TO.OTHERS)
            else:
                entity.act(messages["direction_exit_others"], TO.OTHERS)
            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, descr, exit, behavioured)
            if force_return:
                return True
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, descr, exit, behavioured)
            if force_return:
                return True
            return True
    else:
        if "%s" in messages["direction_entity"]:
            entity.act(messages["direction_entity"] % getattr(direction, from_or_to), TO.ENTITY)
        else:
            entity.act(messages["direction_entity"], TO.ENTITY)
        if "%s" in messages["direction_others"]:
            entity.act(messages["direction_others"] % direction.to_dir, TO.OTHERS)
        else:
            entity.act(messages["direction_others"], TO.OTHERS)
        return False

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

    # Se c'era una extra da guardare e non ha trovato nulla nell'uscita o nel
    # wall allora prova a guardare tra le extra dell'eventuale porta aperta
    if argument and door and DOOR.CLOSED not in door.door_type.flags:
        # Qui poiché la porta è aperta non è più da considerarsi segreta
        extra = door.extras.get_extra(argument, exact=exact)
        if readable and EXTRA.READABLE not in extra.flags:
            extra = None
        if extra:
            descr = extra.get_descr(sense_name, looker=entity, parent=entity)
            if descr and "no_send" not in descr:
                update_sensed_entities(entity, door, command_name)

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

                entity.send_output('''<div style="width:66%%">%s</div>''' % descr, break_line=False)
                if "%s" in messages["direction_target_others"]:
                    entity.act(messages["direction_target_others"] % direction.to_dir, TO.OTHERS, door)
                else:
                    entity.act(messages["direction_target_others"], TO.OTHERS, door)
                force_return = check_trigger(entity, "after_" + command_name, entity, door, descr, None, behavioured)
                if force_return:
                    return True
                force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, door, descr, None, behavioured)
                if force_return:
                    return True
                return True

    if readable:
        return False
    else:
        destination_room = entity.location.get_destination_room(direction)
        if not destination_room:
            force_return = check_trigger(entity, "before_" + command_name, entity, entity.location, "", str(direction), behavioured)
            if force_return:
                return False
            force_return = check_trigger(entity.location, "before_" + gamescript_suffix2, entity, entity.location, "", str(direction), behavioured)
            if force_return:
                return False

            if "%s" in messages["direction_entity"]:
                entity.act(messages["direction_entity"] % getattr(direction, from_or_to), TO.ENTITY)
            else:
                entity.act(messages["direction_entity"] % getattr(direction, from_or_to), TO.ENTITY)
            if "%s" in messages["direction_others"]:
                entity.act(messages["direction_others"] % direction.to_dir, TO.OTHERS)
            else:
                entity.act(messages["direction_others"], TO.OTHERS)
            force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, "", str(direction), behavioured)
            if force_return:
                return False
            force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, "", str(direction), behavioured)
            if force_return:
                return False
            return False

        # Fa visualizzare il nome della stanza
        # (TD) non farlo vedere se la stanza non è visibile, buia o che
        # sarà bene unire questa ricerca del nome della stanza con la stessa
        # che viene visualizza nell'elenco delle uscite della stanza
        descr = color_first_upper(put_final_dot(destination_room.get_name(entity)))

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

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

        force_return = check_trigger(entity, "after_" + command_name, entity, entity.location, descr, destination_room, behavioured)
        if force_return:
            return True
        force_return = check_trigger(entity.location, "after_" + gamescript_suffix2, entity, entity.location, descr, destination_room, behavioured)
        if force_return:
            return True
        return True
Exemple #49
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
Exemple #50
0
def digging_a_location_2(entity, location, verbs, behavioured):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

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

    targets = []
    for target in location.iter_contains():
        if FLAG.BURIED in target.flags:
            targets.append(target)

    # C'è una possibilità su cento che venga trovato qualcosa di interessante
    # (TD) magari la probabilità aumentarla facendola sulla base della skill scava
    # (TD) magari aggiungere un affect per invalidare tentativi robotizzati di scavaggio continuo
    if not targets and random.randint(1, 100) < DIG_PROBABILITY:
        codes = database["areas"]["rip"].proto_items.keys()
        codes += database.randomizable_codes
        codes += database.race_money_codes
        codes += database.seed_codes

        code = random.choice(codes)
        if code.split("_")[1] == "item":
            targets = [Item(code)]
        else:
            targets = [Mob(code)]

        # Per le monete viene impostata anche una quantità casuale.
        # Qui in sostanza viene detto che si possono trovare da 1 a 1000 monete
        # di rame e al massimo solo 1 moneta di mithril, valori intermedi sono
        # inversamente proporzionali al valore della moneta stessa
        if targets[0].money_type:
            copper_value = min(targets[0].money_type.copper_value, 1000)
            targets[0].quantity = random.randint(1, int(1000 / copper_value))

        # (TD) Bisognerebbe inserire un affect nella locazione che impedisca di
        # scavare ancora lì per tot tempo
        targets[0].inject(location)

    # L'esperienza per aver scavato la prima volta nella stanza viene data
    # a prescindere che sia stato trovata un'entità o meno
    if entity.IS_PLAYER and location.IS_ROOM:
        if location.prototype.code in entity.digged_rooms:
            entity.digged_rooms[location.prototype.code] += 1
        else:
            entity.digged_rooms[location.prototype.code] = 1
            reason = "per aver scavato %s" % location.get_name(looker=entity)
            entity.give_experience(location.area.level, reason=reason)

    if not targets:
        entity.act(
            "\n%s ma non trovi proprio nulla di interessante." %
            color_first_upper(verbs["you"]), TO.ENTITY, location)
        entity.act(
            "$n %s una buca in $N senza trovare nulla di interessante." %
            verbs["it"], TO.OTHERS, location)
        entity.act(
            "$n ti %s una buca senza trovare nulla di interessante." %
            verbs["it"], TO.TARGET, location)
        entity.send_prompt()
        entity.action_in_progress = None
        return

    target = random.choice(targets)
    target = target.split_entity(random.randint(1, target.quantity))

    entity.action_in_progress = None

    entity.act("\nFinisci di %s scoprendo $N!" % verbs["infinitive"],
               TO.ENTITY, target)
    entity.act(
        "$n termina di %s dopo che ha scoperto qualcosa." %
        verbs["infinitive"], TO.OTHERS, target)
    entity.act(
        "$n termina di %s dopo che ti ha scoperto nel terreno." %
        verbs["infinitive"], TO.TARGET, target)
    entity.act(
        "$n termina di %s dopo che ha scoperto $a dentro di te." %
        verbs["infinitive"], TO.TARGET, location, target)
    entity.send_prompt()

    target.flags -= FLAG.BURIED
    # Se era un seme o una pianta allora ne ferma la crescita
    if target.seed_type:
        target.seed_type.stop_growth()
    if target.plant_type:
        target.plant_type.stop_growth()

    # (TD) imparare un po' la skill scava dai propri successi

    force_return = check_trigger(entity, "after_dig", entity, location, target,
                                 DIR.NONE, behavioured)
    if force_return:
        return True
    force_return = check_trigger(location, "after_digged", entity, location,
                                 target, DIR.NONE, behavioured)
    if force_return:
        return True
Exemple #51
0
def kill_handler(entity,
                 argument,
                 command_name,
                 entity_tables,
                 attack=False,
                 destroy=False,
                 verbs=VERBS,
                 behavioured=False):
    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 not entity_tables:
        log.bug("entity_tables non è un parametro valido: %r" % entity_tables)
        return False

    # behavioured ha valore di verità

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

    entity = entity.split_entity(1)

    if not argument:
        entity.send_output("Chi o che cosa vorresti %s?" % verbs["infinitive"])
        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 sul mental state

    # Cerca la vittima da attaccare
    target = entity.find_entity(argument,
                                location=entity.location,
                                entity_tables=entity_tables,
                                avoid_equipment=True)
    if not target:
        entity.act(
            "Non trovi nessun [white]%s[close] da %s" %
            (argument, verbs["infinitive"]), TO.ENTITY)
        entity.act(
            "$n non trova nessuno su cui poter sfogare la propria [red]brama di sangue[close].",
            TO.OTHERS)
        return False

    if entity.IS_ITEM:
        entity.act(
            "Non ti è possibile %s perché sei un oggetto inanimato." %
            verbs["infinitive"], TO.ENTITY, target)
        entity.act(
            "Non è possibile per $n poter %s $N %s perché è un oggetto inanimato."
            % verbs["infinitive"], TO.OTHERS, target)
        entity.act(
            "Non è possibile per $n poterti %s perché è un oggetto inanimato."
            % verbs["infinitive"], TO.TARGET, target)
        return False

    if target == entity:
        entity.act("Non ti puoi %s da sol$o!" % verbs["infinitive"], TO.ENTITY)
        entity.act("$n sembra volersi %s da sol$o..." % verbs["infinitive"],
                   TO.OTHERS)
        return False

    if entity.trust > TRUST.PLAYER and target.trust > TRUST.PLAYER:
        entity.act("Cerca di risolvere la cosa in maniera pacifica...",
                   TO.ENTITY)
        return False

    if entity.is_fighting(with_him=target):
        entity.act("Stai già %s $N!" % verbs["gerund"], TO.ENTITY, target)
        entity.act("$n non riesce a %s $N più di così!" % verbs["infinitive"],
                   TO.OTHERS, target)
        entity.act("$n non riesce a %s più di così!" % verbs["infinitive"],
                   TO.TARGET, target)
        return False

    if target.IS_ITEM and target.life <= 0:
        from src.commands import command_destroy
        entity.act(
            "Non puoi %s $N più di così." %
            command_destroy.VERBS["infinitive"], TO.ENTITY, target)
        entity.act(
            "$n non riesce a %s $N più di così." %
            command_destroy.VERBS["infinitive"], TO.OTHERS, target)
        entity.act(
            "$n non riesce a %s più di così." % command_destroy.VERBS["you2"],
            TO.TARGET, target)
        return False

    force_return = check_trigger(entity, "before_kill", entity, target, attack,
                                 destroy, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "before_killed", entity, target,
                                 attack, destroy, behavioured)
    if force_return:
        return True

    # Avvia il combattimento!
    entity.act("%s $N." % color_first_upper(ATTACK_VERBS["you"]), TO.ENTITY,
               target)
    entity.act("$n %s $N." % ATTACK_VERBS["it"], TO.OTHERS, target)
    entity.act("$n ti %s." % ATTACK_VERBS["it"], TO.TARGET, target)
    start_fight(entity, target)

    force_return = check_trigger(entity, "after_kill", entity, target, attack,
                                 destroy, behavioured)
    if force_return:
        return True
    force_return = check_trigger(target, "after_killed", entity, target,
                                 attack, destroy, behavioured)
    if force_return:
        return True

    return True
Exemple #52
0
    def send_buy_messages(self, entity, purchase, dealer, verbs, quantity,
                          pretty_price, discount):
        if not entity:
            log.bug("entity non è un parametro valido: %r" % entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

        if discount < 0:
            log.bug("discount non è un parametro valido: %d" % discount)
            return

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

        is_dispenser = SHOP.DISPENSER in dealer.shop.types

        discount_descr = ""
        if discount > 0:
            discount_descr = " scontato"

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_buy_message:
            message = self.entity_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["you"]))
                else:
                    message = message.replace("%verb", verbs["you"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "%s %s$N da $a inserendovi %s." % (color_first_upper(
                    verbs["you"]), quantity_descr, pretty_price)
            else:
                message = "%s %s$N da $a pagandol$O %s%s." % (
                    color_first_upper(verbs["you"]), quantity_descr,
                    pretty_price, discount_descr)
        entity.act(message, TO.ENTITY, purchase, dealer)

        if self.others_buy_message:
            message = self.others_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n %s %s$N da $a inserendovi %s." % (
                    verbs["it"], quantity_descr, pretty_price)
            else:
                message = "$n %s %s$N da $a pagandol$O %s%s." % (
                    verbs["it"], quantity_descr, pretty_price, discount_descr)
        entity.act(message, TO.OTHERS, purchase, dealer)

        if self.target_buy_message:
            message = self.target_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n ti %s da $a inserendovi %s." % (verbs["it"],
                                                              pretty_price)
            else:
                message = "$n ti %s da $a pagandoti %s%s." % (
                    verbs["it"], pretty_price, discount_descr)
        entity.act(message, TO.TARGET, purchase, dealer)

        if self.dealer_buy_message:
            message = self.dealer_buy_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        else:
            if is_dispenser:
                message = "$n ti %s %s$N inserendoti %s." % (
                    verbs["it"], quantity_descr, pretty_price)
            else:
                message = "$n ti %s %s$N pagandol$O %s%s." % (
                    verbs["it"], quantity_descr, pretty_price, discount_descr)
        entity.act(message, TO.TARGET, dealer, purchase)
Exemple #53
0
def command_drop(entity, argument="", verbs=VERBS, behavioured=False):
    """
    Permette di abbandonare oggetti per terra oppure posarli in un luogo preciso.
    """
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

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

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

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

    # (TD) Controllo del mental state deviato

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

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

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

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

    # (TD) posare monete

    # (TD) argomento all, ultima cosa da supportare

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

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

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

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

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

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

    return True
Exemple #54
0
    def send_offer_messages(self, entity, target, dealer, verbs, quantity,
                            pretty_price):
        if not entity:
            log.bug("entity non è un parametro valido: %r", entity)
            return

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

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

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

        if quantity < 0:
            log.bug("quantity non è un parametro valido: %d" % quantity)
            return

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

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

        quantity_descr = ""
        if quantity > 1:
            quantity_descr = "%d " % quantity

        if self.entity_offer_message:
            message = self.entity_offer_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        elif quantity <= 1:
            message = "$N ti %s %s per $N." % (verbs["it"], pretty_price)
        else:
            message = "$N ti %s %s per %d unità di $N." % (
                verbs["it"], pretty_price, quantity)
        entity.act(message, TO.ENTITY, target, dealer)

        if self.others_offer_message:
            message = self.entity_offer_message
            if "%verb" in message:
                if message.startswith("%verb"):
                    message = message.replace("%verb",
                                              color_first_upper(verbs["it"]))
                else:
                    message = message.replace("%verb", verbs["it"].lower())
            if "%quantity" in message:
                message = message.replace("%quantity", quantity_descr)
            if "%price" in message:
                message = message.replace("%price", pretty_price)
        elif quantity <= 1:
            message = "$N %s %s a $n per $N." % (verbs["it"], pretty_price)
        else:
            message = "$N %s %s a $n per %d unità di $N." % (
                verbs["it"], pretty_price, quantity)
        entity.act(message, TO.OTHERS, target, dealer)

        if target != entity:
            if self.target_offer_message:
                message = self.entity_offer_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message.replace(
                            "%verb", color_first_upper(verbs["you"]))
                    else:
                        message = message.replace("%verb",
                                                  verbs["you"].lower())
                if "%quantity" in message:
                    message = message.replace("%quantity", quantity_descr)
                if "%price" in message:
                    message = message.replace("%price", pretty_price)
            elif quantity <= 1:
                message = "%s a $n %s per $N." % (color_first_upper(
                    verbs["you"]), pretty_price)
            else:
                message = "%s a $n %s per %d unità di $N." % (
                    color_first_upper(verbs["you"], quantity), pretty_price)
            entity.act(message, TO.TARGET, target, dealer)

        if dealer != entity:
            if self.dealer_offer_message:
                message = self.entity_offer_message
                if "%verb" in message:
                    if message.startswith("%verb"):
                        message = message.replace(
                            "%verb", color_first_upper(verbs["it"]))
                    else:
                        message = message.replace("%verb", verbs["it"].lower())
                if "%quantity" in message:
                    message = message.replace("%quantity", quantity_descr)
                if "%price" in message:
                    message = message.replace("%price", pretty_price)
            elif quantity <= 1:
                message = "$a %s a $n %s per te." % (verbs["it"], pretty_price)
            else:
                message = "$a %s a $n %s per %d unità di te." % (
                    verbs["it"], pretty_price, quantity)
            entity.act(message, TO.TARGET, dealer, target)
Exemple #55
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