示例#1
0
    def get_extra(self, argument, exact=False):
        """
        Cerca un'extra particolare tramite l'argomento passato, esegue la ricerca
        in maniera esatta oppure anche in maniera prefissa.
        Questa funzione è da chiamare dai metodi get_extra delle stanze e delle
        entità.
        """
        if not argument:
            log.bug("argument non è un parametro valido: %s" % argument)
            return None

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

        for extra in self:
            if is_same(multiple_arguments(extra.keywords), argument):
                return extra

        # Se viene passato un argomento lungo un solo carattere allora non viene
        # eseguita la ricerca prefissa, questo per evitare che i player eseguano
        # un brute force per trovare eventuali extra nascoste (look a, look b,
        # look c, look d...)
        if not exact and len(argument) >= config.min_secret_arg_len:
            for extra in self:
                if is_prefix(argument, multiple_arguments(extra.keywords)):
                    return extra

        return None
def before_listen_rpg_channel(caldarrostaio, player, target, phrase, ask, exclaim, behavioured):
    if not player.IS_PLAYER:
        return

    # Mi assicuro che si stia parlando rivolgendosi al caldarrostaio
    if target != caldarrostaio:
        return

    if is_infix("menù", phrase):
        to_say = "a %s Car$o, io vendo solo caldarroste." % player.code
        defer_random_time(1, 2, command_say, caldarrostaio, to_say)
        return

    proto_cibi = []
    for proto_code in PROTO_FOODS_CODES:
        table_name = "proto_" + proto_code.split("_")[1] + "s"  # E con questo hai scoperto come mai i codici prototipo delle entità devono avere l'identificativo della tipologia tra due underscore
        proto_entity = database[table_name][proto_code]
        for keyword in multiple_arguments(proto_entity.get_keywords_attr()):
            #print ">>> Keyword <<<", proto_entity.code, keyword
            if is_infix(keyword, phrase):
                proto_cibi.append(proto_entity)

    if not proto_cibi:
        to_say = "a %s Ma io vendo solo castagne!" % player.code
        command_say(caldarrostaio, to_say)
        return

    to_say = "a %s Castagne in arrivo!" % player.code
    defer_random_time(1, 2, command_say, caldarrostaio, to_say)

    proto_pietanza = random.choice(proto_cibi)
    castagne = proto_pietanza.CONSTRUCTOR(proto_pietanza.code)
    defer_random_time(5, 7, caldarrostaio_act, caldarrostaio, player, castagne)
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

    if is_infix("menù", phrase):
        to_say = "a %s Il nostro menù di oggi lo potete leggere anche da qui, è lì sul bancone." % 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)

    player_code = player.get_numbered_keyword(looker=locandiera)

    if not proto_cibi:
        to_say = "a %s Non abbiam nessun cibo di quel tipo..." % player_code
        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, first_color_upper(pietanza.get_name(looker=locandiera)))
    defer_random_time(1, 2, command_say, locandiera, to_say)
    defer_random_time(5, 7, locandiera_act, locandiera, player, pietanza)
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

    if is_infix("menù", phrase):
        to_say = "a %s Il nostro menù di oggi lo potete leggere anche da qui, è lì sul bancone." % 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)

    player_code = player.get_numbered_keyword(looker=locandiera)

    if not proto_cibi:
        to_say = "a %s Non abbiam nessun cibo di quel tipo..." % player_code
        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, first_color_upper(pietanza.get_name(looker=locandiera)))
    defer_random_time(1, 2, command_say, locandiera, to_say)
    defer_random_time(5, 7, locandiera_act, locandiera, player, pietanza)
def before_listen_rpg_channel(listener, speaker, target, phrase, ask, exclaim, behavioured):
    # Con una probabilità dell'10%
    if random.randint(1, 10) != 1:
        return

    # Continua solo se sta per parlare l'unicorno rosa
    if speaker.prototype.code != "mfdonald_mob_unicorno-rosa":
        return

    # Spezza la frase detta in più parole (o gruppi di parole tra virgolette)
    words = multiple_arguments(phrase)

    # Controlla se vi sia almeno una parola che inizi nella maniera voluta
    # tra quelle dette (occhio che lo script si attiva anche se l'unicorno dice
    # parole come 'ringhia', per evitare questo bisognerebbe utilizzare la
    # funzione is_same sempre dal modulo utility)
    if not is_prefix(("drin", "ring"), words):
        return

    # Aggiungendo casualmente qualche punto esclamativo a quello che viene detto
    to_say = "Ring!%s Ring!%s" % (random_marks(0, 3), random_marks(0, 3))
    command_say(listener, to_say)

    # Avendo anticipato l'unicorno rosa blocca quello che stava per dire
    return True
示例#6
0
def before_listen_rpg_channel(listener, speaker, target, phrase, ask, exclaim,
                              behavioured):
    # Con una probabilità dell'10%
    if random.randint(1, 10) != 1:
        return

    # Continua solo se sta per parlare l'unicorno rosa
    if speaker.prototype.code != "mfdonald_mob_unicorno-rosa":
        return

    # Spezza la frase detta in più parole (o gruppi di parole tra virgolette)
    words = multiple_arguments(phrase)

    # Controlla se vi sia almeno una parola che inizi nella maniera voluta
    # tra quelle dette (occhio che lo script si attiva anche se l'unicorno dice
    # parole come 'ringhia', per evitare questo bisognerebbe utilizzare la
    # funzione is_same sempre dal modulo utility)
    if not is_prefix(("drin", "ring"), words):
        return

    # Aggiungendo casualmente qualche punto esclamativo a quello che viene detto
    to_say = "Ring!%s Ring!%s" % (random_marks(0, 3), random_marks(0, 3))
    command_say(listener, to_say)

    # Avendo anticipato l'unicorno rosa blocca quello che stava per dire
    return True
示例#7
0
def _find_entities_handler_for_admin(entity,
                                     argument,
                                     list_to_search,
                                     compare_function,
                                     avoid_inventory=False,
                                     avoid_equipment=True,
                                     avoid_doors=False):
    """
    Per velocizzare la find_entity, che con parametro location passato a Null
    può arrivare a rallentamenti notevoli, è stata creata questa copia dalla
    _find_entity_handler con un check aggiuntivo che riguarda solo gli admin.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return []

    if not argument:
        log.bug("argument non è un parametro valido: %r" %
                argument)  # (TT) questo test potrebbe non servire
        return []

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return []

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

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

    entities = []

    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" %
                    (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)) or is_same(
                argument, target.code):
            entities.append(target)

    return entities
示例#8
0
def get_room_from_coords(entity, argument):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return None, False

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

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

    in_room = entity.get_in_room()
    if not in_room:
        log.bug("L'entità %s non si trova in nessuna stanza valida: %r" % (entity.get_name, in_room))
        return None, True

    args = multiple_arguments(argument)
    if len(args) == 2:
        if not is_number(args[0]) or not is_number(args[1]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = in_room.z
        area = in_room.area
    elif len(args) == 3:
        if not is_number(args[0]) or not is_number(args[1]) or not is_number(args[2]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = int(args[2])
        area = in_room.area
    elif len(args) == 4:
        if not is_number(args[0]) or not is_number(args[1]) or not is_number(args[2]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = int(args[2])
        area = nifty_value_search(database["areas"], args[3])
        if not area:
            entity.send_output("Codice d'area simile a [green]%s[close] inesistente." % args[3])
            return None, False
    else:
        return None, True

    coords = "%d %d %d" % (coord_x, coord_y, coord_z)
    if coords in area.rooms:
        return area.rooms[coords], False
    else:
        if area.wild:
            room = create_wild_room(area, coords)
            return room, False
        else:
            entity.send_output("Coordinate [green]%s[close] non trovate nell'area [white]%s[close]." % (coords, area.name))
            return None, False
示例#9
0
def _find_entity_handler(entity,
                         argument,
                         list_to_search,
                         number,
                         compare_function,
                         avoid_inventory=False,
                         avoid_equipment=True,
                         avoid_doors=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return None

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

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return None

    if number <= 0:
        log.bug("number non è un parametro valido: %r" % number)
        return None

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

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

    counter = 0
    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" %
                    (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)):
            if counter + target.quantity >= number:
                return target
            counter += target.quantity

    return None
示例#10
0
def _find_entity_handler_for_admin(entity, argument, list_to_search, number, compare_function, avoid_inventory=False, avoid_equipment=True, avoid_doors=False):
    """
    Per velocizzare la find_entity, che con parametro location passato a Null
    può arrivare a rallentamenti notevoli, è stata creata questa copia dalla
    _find_entity_handler con un check aggiuntivo che riguarda solo gli admin.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return None

    if not argument:
        log.bug("argument non è un parametro valido: %r" % argument)  # (TT) questo test potrebbe non servire
        return None

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return None

    if number <= 0:
        log.bug("number non è un parametro valido: %r" % number)
        return None

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

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

    counter = 0
    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" % (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)) or is_same(argument, target.code) or is_prefix(argument + "#", target.code):
            if counter + target.quantity >= number:
                return target
            counter += target.quantity

    return None
def before_giving(player, pesce, gatto, direction, behavioured):
    if not player.IS_PLAYER:
        player.act("$N ti soffia e fa come per graffiarti, non sei una compagnia desiderabile.", TO.ENTITY, gatto)
        player.act("$N, con il pelo ritto sulla schiena, scaccia $n in malomodo.", TO.OTHERS, gatto)
        player.act("$n ti si avvicina un po' troppo per i tuoi gusti e lo scacci senza troppi complimenti.", TO.TARGET, gatto)
        return True

    pesce_keywords = multiple_arguments(pesce.get_keywords_attr(looker=gatto))
    if is_same(pesce_keywords, ("agrumi", "agrume", "arance", "arancia", "limone", "limoni", "bergamotto", "mandarino", "mandarini", "pompelmo", "pompelmi", "cedro", "cedri", "mandarancio", "mandaranci", "lime")):
        num_rand = random.randint(1, 100)
        if num_rand < 75:
            player.act("$N ti attacca in un raptus di furia assassina!", TO.ENTITY, gatto)
            player.act("Apparentemente senza ragione $N attacca $n.", TO.OTHERS, gatto)
            player.act("Quel pazzo di $n ha tentato di darti un agrume, la dovrà pagare!", TO.TARGET, gatto)
            player.life -= give_damage(player)
            return True
        else:
            player.act("$N sguaina le unghie e tenta di attaccarti ma fortunatamente manca il colpo.", TO.ENTITY, gatto)
            player.act("$N fa uno scatto verso $n come per attaccarlo ma la zampata non va a buon fine.", TO.OTHERS, gatto)
            player.act("Tenti di attacare $n ma non ci riesci", TO.TARGET, gatto)
            return True

    if not pesce.entitype == ENTITYPE.FOOD or not is_same(pesce_keywords, ("pesce", "pesci")):
        player.act("$N storce i baffi schizzinoso.", TO.ENTITY, gatto)
        player.act("$n tenta inutilmente di dare qualcosa a $N che lo snobba schizzinoso.", TO.OTHERS, gatto)
        player.act("$n tenta di propinarti qualcosa che anche un cane rifiuterebbe.", TO.TARGET, gatto)
        return True

    if pesce.weight > PESO_MASSIMO:
        player.act("$N ti guarda perplesso dopo aver valutato il peso di ciò che gli vorresti dare.", TO.ENTITY, gatto)
        player.act("Noti uno strano gioco di sguardi tra $N e $n.", TO.OTHERS, gatto)
        player.act("$n cerca di darti qualcosa di veramente troppo pesante per te.", TO.TARGET, gatto)
        return True

    for content in gatto.iter_contains(use_reversed=True):
        if FLAG.INGESTED in content.flags:
            if content.entitype == ENTITYPE.FOOD:
                player.act("$N rifiuta il cibo che gli offri, d'evessere sazio!", TO.ENTITY, gatto)
                player.act("$n vorrebbe dare qualcosa a $N che però non sembra interessato..", TO.OTHERS, gatto)
                player.act("$n vorrebbe ingozzarti, la tua dignità di impedisce di far la figura del maiale all'ingrasso..", TO.TARGET, gatto)
                return True
            else:
                content.extract(1)
                return True

    palla = Item(PROTO_FUR_CODE)
    defer_random_time(1, 3, puke_hairs, gatto, player, palla)
    defer_random_time(4, 5, fish_eat, player, gatto, pesce)
示例#12
0
def _find_entities_handler(entity, argument, list_to_search, compare_function,
                           avoid_inventory, avoid_equipment, avoid_doors):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return []

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

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return []

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

    # avoid_inventory e avoid_equipment e avoid_doors hanno valore di verità

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

    entities = []

    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if not avoid_equipment and target.under_weared and target.under_weared(
        ):
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" %
                    (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)):
            entities.append(target)

    return entities
示例#13
0
def _find_entity_handler(entity, argument, list_to_search, number, compare_function, avoid_inventory=False, avoid_equipment=True, avoid_doors=False):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return None

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

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return None

    if number <= 0:
        log.bug("number non è un parametro valido: %r" % number)
        return None

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

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

    counter = 0
    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" % (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)):
            if counter + target.quantity >= number:
                return target
            counter += target.quantity

    return None
示例#14
0
def _find_entities_handler(entity, argument, list_to_search, compare_function, avoid_inventory, avoid_equipment, avoid_doors):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return []

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

    if not list_to_search and list_to_search != []:
        log.bug("list_to_search non è valido: %r" % list_to_search)
        return []

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

    # avoid_inventory e avoid_equipment e avoid_doors hanno valore di verità

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

    entities = []

    for target in list_to_search:
        if avoid_inventory and len(target.wear_mode) == 0:
            continue
        if avoid_equipment and len(target.wear_mode) != 0:
            continue
        if not avoid_equipment and target.under_weared and target.under_weared():
            continue
        if avoid_doors and target.door_type and target.is_hinged():
            continue
        if not entity.can_see(target):
            continue

        keywords = target.get_keywords_attr(entity)
        if not keywords:
            log.bug("target %s senza keywords valide: %s" % (target.code, keywords))
            continue

        if compare_function(argument, multiple_arguments(keywords)):
            entities.append(target)

    return entities
def after_listen_rpg_channel(listener, speaker, target, phrase, ask, exclaim, behavioured):
    words = multiple_arguments(phrase)
    if not is_prefix(("drin", "ring"), words):
        return

    if speaker.prototype.code != "mfdonald_mob_unicorno-rosa":
        return

    # Aggiunge casualmente un prefisso, qualche o finale e punti esclamativi
    # e di domanda finali, risponde all'unicorno rosa
    prefix = ""
    if random.randint(1, 10) == 1:
        prefix = "Ha%s " % ("." * random.randint(2, 4))
    to_say = "a %s %sHall%s?%s" % (speaker.get_numbered_keyword(looker=listener), prefix, "o" * random.randint(1, 3), random_marks(1, 1))
    # Attende qualche secondo.. dopotutto deve raggiungere il telefono!
    # Attenzione ad inserire un numero di secondi troppo alto, altrimenti
    # l'unicorno rosa potrebbe dire più spesso ring ring di quanto l'unicorno
    # azzurro possa rispondere, riempiendo così la ram di callback :P
    # Comunque in questo caso non abbiamo assolutamente questo problema
    defer_random_time(1, 3, command_say, listener, to_say)
示例#16
0
def after_listen_rpg_channel(listener, speaker, target, phrase, ask, exclaim,
                             behavioured):
    words = multiple_arguments(phrase)
    if not is_prefix(("drin", "ring"), words):
        return

    if speaker.prototype.code != "mfdonald_mob_unicorno-rosa":
        return

    # Aggiunge casualmente un prefisso, qualche o finale e punti esclamativi
    # e di domanda finali, risponde all'unicorno rosa
    prefix = ""
    if random.randint(1, 10) == 1:
        prefix = "Ha%s " % ("." * random.randint(2, 4))
    to_say = "a %s %sHall%s?%s" % (speaker.get_numbered_keyword(
        looker=listener), prefix, "o" * random.randint(1, 3), random_marks(
            1, 1))
    # Attende qualche secondo.. dopotutto deve raggiungere il telefono!
    # Attenzione ad inserire un numero di secondi troppo alto, altrimenti
    # l'unicorno rosa potrebbe dire più spesso ring ring di quanto l'unicorno
    # azzurro possa rispondere, riempiendo così la ram di callback :P
    # Comunque in questo caso non abbiamo assolutamente questo problema
    defer_random_time(1, 3, command_say, listener, to_say)
示例#17
0
def before_listen_rpg_channel(caldarrostaio, player, target, phrase, ask,
                              exclaim, behavioured):
    if not player.IS_PLAYER:
        return

    # Mi assicuro che si stia parlando rivolgendosi al caldarrostaio
    if target != caldarrostaio:
        return

    if is_infix("menù", phrase):
        to_say = "a %s Car$o, io vendo solo caldarroste." % player.code
        defer_random_time(1, 2, command_say, caldarrostaio, to_say)
        return

    proto_cibi = []
    for proto_code in PROTO_FOODS_CODES:
        table_name = "proto_" + proto_code.split(
            "_"
        )[1] + "s"  # E con questo hai scoperto come mai i codici prototipo delle entità devono avere l'identificativo della tipologia tra due underscore
        proto_entity = database[table_name][proto_code]
        for keyword in multiple_arguments(proto_entity.get_keywords_attr()):
            #print ">>> Keyword <<<", proto_entity.code, keyword
            if is_infix(keyword, phrase):
                proto_cibi.append(proto_entity)

    if not proto_cibi:
        to_say = "a %s Ma io vendo solo castagne!" % player.code
        command_say(caldarrostaio, to_say)
        return

    to_say = "a %s Castagne in arrivo!" % player.code
    defer_random_time(1, 2, command_say, caldarrostaio, to_say)

    proto_pietanza = random.choice(proto_cibi)
    castagne = proto_pietanza.CONSTRUCTOR(proto_pietanza.code)
    defer_random_time(5, 7, caldarrostaio_act, caldarrostaio, player, castagne)
示例#18
0
def command_addexit(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

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

    room = entity.location

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

    if direction in room.exits:
        if room.exits[direction].destination:
            destination_message = " che porta a %s" % room.exits[
                direction].destination
        else:
            destination_message = ""
        entity.send_output(
            "C'è già un uscita %s%s, non puoi aggiungerne un'altra se non rimuovendola con il comando [limegreen]delexit[close] con il comando [limegreen]modifyexit[close]."
            % (direction.to_dir))
        return False

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

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

    room.exits[direction] = exit
    entity.send_output("E' stata aggiunta l'uscita %s." % direction.to_dir)
    return True
示例#19
0
def get_room_from_coords(entity, argument):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return None, False

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

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

    in_room = entity.get_in_room()
    if not in_room:
        log.bug("L'entità %s non si trova in nessuna stanza valida: %r" %
                (entity.get_name, in_room))
        return None, True

    args = multiple_arguments(argument)
    if len(args) == 2:
        if not is_number(args[0]) or not is_number(args[1]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = in_room.z
        area = in_room.area
    elif len(args) == 3:
        if not is_number(args[0]) or not is_number(args[1]) or not is_number(
                args[2]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = int(args[2])
        area = in_room.area
    elif len(args) == 4:
        if not is_number(args[0]) or not is_number(args[1]) or not is_number(
                args[2]):
            return None, True
        coord_x = int(args[0])
        coord_y = int(args[1])
        coord_z = int(args[2])
        area = nifty_value_search(database["areas"], args[3])
        if not area:
            entity.send_output(
                "Codice d'area simile a [green]%s[close] inesistente." %
                args[3])
            return None, False
    else:
        return None, True

    coords = "%d %d %d" % (coord_x, coord_y, coord_z)
    if coords in area.rooms:
        return area.rooms[coords], False
    else:
        if area.wild:
            room = create_wild_room(area, coords)
            return room, False
        else:
            entity.send_output(
                "Coordinate [green]%s[close] non trovate nell'area [white]%s[close]."
                % (coords, area.name))
            return None, False
示例#20
0
文件: help.py 项目: Onirik79/aaritmud
def get_help(entity, argument):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    # Se argument è formato da più parole erroneamente separate da più spazi
    # allora li converte in un'unico spazio
    if "  " in argument:
        argument = " ".join(argument.split())

    # Cerca prima tra gli help della propria lingua in maniera esatta
    if entity.IS_PLAYER or OPTION.ITALIAN in entity.account.options:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_same(argument, multiple_arguments(help.italian_keywords)):
                return help
    else:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_same(argument, multiple_arguments(help.english_keywords)):
                return help

    # Cerca poi tra gli help della propria lingua in maniera prefissa
    if entity.IS_PLAYER or OPTION.ITALIAN in entity.account.options:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_prefix(argument, multiple_arguments(help.italian_keywords)):
                return help
    else:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_prefix(argument, multiple_arguments(help.english_keywords)):
                return help

    # Cerca poi tra gli help della lingua secondaria in maniera esatta
    if entity.IS_PLAYER or OPTION.ITALIAN in entity.account.options:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_same(argument, multiple_arguments(help.english_keywords)):
                return help
    else:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_same(argument, multiple_arguments(help.italian_keywords)):
                return help

    # Cerca poi tra gli help della lingua secondaria in maniera prefissa
    if entity.IS_PLAYER or OPTION.ITALIAN in entity.account.options:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_prefix(argument, multiple_arguments(help.english_keywords)):
                return help
    else:
        for help in database["helps"].itervalues():
            if not help.text and help.admin_text and entity.trust == TRUST.PLAYER:
                continue
            if is_prefix(argument, multiple_arguments(help.italian_keywords)):
                return help

    return None
def before_giving(player, pesce, gatto, direction, behavioured):
    if not player.IS_PLAYER:
        player.act(
            "$N ti soffia e fa come per graffiarti, non sei una compagnia desiderabile.",
            TO.ENTITY, gatto)
        player.act(
            "$N, con il pelo ritto sulla schiena, scaccia $n in malomodo.",
            TO.OTHERS, gatto)
        player.act(
            "$n ti si avvicina un po' troppo per i tuoi gusti e lo scacci senza troppi complimenti.",
            TO.TARGET, gatto)
        return True

    pesce_keywords = multiple_arguments(pesce.get_keywords_attr(looker=gatto))
    if is_same(pesce_keywords,
               ("agrumi", "agrume", "arance", "arancia", "limone", "limoni",
                "bergamotto", "mandarino", "mandarini", "pompelmo", "pompelmi",
                "cedro", "cedri", "mandarancio", "mandaranci", "lime")):
        num_rand = random.randint(1, 100)
        if num_rand < 75:
            player.act("$N ti attacca in un raptus di furia assassina!",
                       TO.ENTITY, gatto)
            player.act("Apparentemente senza ragione $N attacca $n.",
                       TO.OTHERS, gatto)
            player.act(
                "Quel pazzo di $n ha tentato di darti un agrume, la dovrà pagare!",
                TO.TARGET, gatto)
            player.life -= give_damage(player)
            return True
        else:
            player.act(
                "$N sguaina le unghie e tenta di attaccarti ma fortunatamente manca il colpo.",
                TO.ENTITY, gatto)
            player.act(
                "$N fa uno scatto verso $n come per attaccarlo ma la zampata non va a buon fine.",
                TO.OTHERS, gatto)
            player.act("Tenti di attacare $n ma non ci riesci", TO.TARGET,
                       gatto)
            return True

    if not pesce.entitype == ENTITYPE.FOOD or not is_same(
            pesce_keywords, ("pesce", "pesci")):
        player.act("$N storce i baffi schizzinoso.", TO.ENTITY, gatto)
        player.act(
            "$n tenta inutilmente di dare qualcosa a $N che lo snobba schizzinoso.",
            TO.OTHERS, gatto)
        player.act(
            "$n tenta di propinarti qualcosa che anche un cane rifiuterebbe.",
            TO.TARGET, gatto)
        return True

    if pesce.weight > PESO_MASSIMO:
        player.act(
            "$N ti guarda perplesso dopo aver valutato il peso di ciò che gli vorresti dare.",
            TO.ENTITY, gatto)
        player.act("Noti uno strano gioco di sguardi tra $N e $n.", TO.OTHERS,
                   gatto)
        player.act(
            "$n cerca di darti qualcosa di veramente troppo pesante per te.",
            TO.TARGET, gatto)
        return True

    for content in gatto.iter_contains(use_reversed=True):
        if FLAG.INGESTED in content.flags:
            if content.entitype == ENTITYPE.FOOD:
                player.act(
                    "$N rifiuta il cibo che gli offri, d'evessere sazio!",
                    TO.ENTITY, gatto)
                player.act(
                    "$n vorrebbe dare qualcosa a $N che però non sembra interessato..",
                    TO.OTHERS, gatto)
                player.act(
                    "$n vorrebbe ingozzarti, la tua dignità di impedisce di far la figura del maiale all'ingrasso..",
                    TO.TARGET, gatto)
                return True
            else:
                content.extract(1)
                return True

    palla = Item(PROTO_FUR_CODE)
    defer_random_time(1, 3, puke_hairs, gatto, player, palla)
    defer_random_time(4, 5, fish_eat, player, gatto, pesce)
示例#22
0
def command_timemachine(entity, argument):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

    minute = calendar.minute
    hour = calendar.hour
    day = calendar.day
    month = calendar.month
    year = calendar.year

    args = multiple_arguments(argument)

    # Permette di digitare il comando anche così: 'time machine'
    if is_same(args[0], "machine"):
        args = args[1:]

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

    if is_number(args[0]):
        minute = int(args[0])
    else:
        entity.send_output(
            "Il primo argomento, relativo ai [white]minuti[close], dev'essere numerico e non: [green]%s[close]"
            % args[0])
        return False
    if minute < 0 or minute > config.minutes_in_hour - 1:
        entity.send_output("I minuti devono essere tra 0 e %d." %
                           (config.minutes_in_hour - 1))
        return False

    if len(args) > 1:
        if is_number(args[1]):
            hour = int(args[1])
        else:
            entity.send_output(
                "Il secondo argomento, relativo all'[white]ora[close], dev'essere numerico e non: [green]%s[close]"
                % args[1])
            return False
        if hour < 0 or hour > config.hours_in_day - 1:
            entity.send_output("L'ora dev'essere tra 0 e %d." %
                               (config.hours_in_day - 1))
            return False

    if len(args) > 2:
        if is_number(args[2]):
            day = int(args[2])
        else:
            entity.send_output(
                "Il terzo argomento, relativo al [white]giorno[close], dev'essere numerico e non: [green]%s[close]"
                % args[2])
            return False
        if day < 1 or day > config.days_in_month:
            entity.send_output("Il numero del giorno dev'essere tra 1 e %d." %
                               config.days_in_month)
            return False

    if len(args) > 3:
        if is_number(args[3]):
            month = int(args[3])
        else:
            entity.send_output(
                "Il quarto argomento, relativo al [white]mese[close], dev'essere numerico e non: [green]%s[close]"
                % args[3])
            return False
        if month < 1 or month > config.months_in_year:
            entity.send_output("Il numero del mese dev'essere tra 1 e %d." %
                               config.months_in_year)
            return False
        month = MONTH.elements[month - 1]

    if len(args) > 4:
        if is_number(args[4]):
            year = int(args[4])
        else:
            entity.send_output(
                "Il quinto argomento, relativo all'[white]anno[close], dev'essere numerico e non: [green]%s[close]"
                % args[4])
            return False

    if (minute == calendar.minute and hour == calendar.hour
            and day == calendar.day and month == calendar.month
            and year == calendar.year):
        entity.send_output(
            "La data da impostare è la stessa di quella corrente!")
        return False

    stop_all_reset_events()

    calendar.minute = minute
    calendar.hour = hour
    calendar.day = day
    calendar.month = month
    calendar.year = year
    article = "le"
    if hour == 1:
        article = "la"
    entity.send_output(
        "La nuova data impostata è: %s [white]%d[close] e [white]%d[close] del giorno [white]%d[close] del mese %s nell'anno [white]%d[close]"
        % (article, hour, minute, day, month, year))

    # Ora che è cambiata la data reinizializza tutti i reset
    defer_all_reset_events()
    return True