예제 #1
0
    def send_statement(self, speaker, listener):
        if not speaker:
            log.bug("speaker non è un parametro valido: %s" % speaker)
            return

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

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

    # (TD) import interno per essere sicuro di non avere le lista vuota
    # non ancora inizializzate
        from src.interpret import inputs_command_en, inputs_skill_en, inputs_social_en

        for action in self.actions:
            arg, argument = one_argument(action)
            input = action.find_input(
                arg, True,
                inputs_command_en + inputs_skill_en + inputs_social_en)
            if input:
                if self.__class__.__name__ == "ListenerStatement":
                    interpret(listener, action, use_check_alias=False)
                else:
                    interpret(speaker, action, use_check_alias=False)
            else:
                listener.send_output(action)

        statements = self.listener_statements or self.speaker_statements
        for counter, statement in enumerate(statements):
            listener.send_output('''%d] %s''' %
                                 (counter + 1, self.choice_text))
예제 #2
0
파일: dialog.py 프로젝트: Carlovan/aaritmud
    def send_statement(self, speaker, listener):
        if not speaker:
            log.bug("speaker non è un parametro valido: %s" % speaker)
            return

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

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

        # (TD) import interno per essere sicuro di non avere le lista vuota
        # non ancora inizializzate
        from src.interpret import inputs_command_en, inputs_skill_en, inputs_social_en

        for action in self.actions:
            arg, argument = one_argument(action)
            input = action.find_input(arg, True, inputs_command_en + inputs_skill_en + inputs_social_en)
            if input:
                if self.__class__.__name__ == "ListenerStatement":
                    interpret(listener, action, use_check_alias=False)
                else:
                    interpret(speaker, action, use_check_alias=False)
            else:
                listener.send_output(action)

        statements = self.listener_statements or self.speaker_statements
        for counter, statement in enumerate(statements):
            listener.send_output('''%d] %s''' % (counter + 1, self.choice_text))
def before_touched(entity, cespuglio, detail, descr, behavioured):
    # Il valore di cespuglio.quantity è ad uno anche se è parte di un gruppo fisico.

    if not cespuglio.specials or 'ancestors' not in cespuglio.specials:
        print "#### ROMIL - TOUCH - specials NON presenti"
        # (TD) da gestire, ricreare i genotipi
        # Se un trust alto icrea il cespuglio accanto agli altri,
        # crasha tutto in fase di fecondazione
        return

    # (TD) dopo 2 o 3 volte che si tocca dovrebbe perdere la sua efficacia
    command_emote(cespuglio,
                  "comincia ad oscillare spargendo un po' di polline.")
    interpret(entity, "sneeze", show_input=False, show_prompt=False)
    if not cespuglio.location.IS_ROOM:
        # (TD) In vaso sarà un dramma da gestire
        return

    room = cespuglio.location
    cespugli = []

    for item in room.iter_contains(use_reversed=True):
        if item.IS_ITEM and item.prototype.code == cespuglio.prototype.code:
            for x in xrange(item.quantity):
                if 'genotipo' in splitted_cespuglio.__dict__ and splitted_cespuglio.genotipo.gameti_propri != []:
                    # evito inutili ripetizioni nel caso qualcuno tocchi più volte
                    continue
                # Splitto i cespugli e in ciascuno metto un metodo Genotipo in cui
                # carico il genoma e ricavo i due gameti
                splitted_cespuglio = item.split_entity(1)
                splitted_cespuglio.genotipo = Genotipo()
                splitted_cespuglio.genotipo.importa_specials(
                    splitted_cespuglio)
                # ora metto una lista con i due gameti per ciascun cespuglio
                splitted_cespuglio.genotipo.gameti_propri = splitted_cespuglio.genotipo.get_gameti(
                )
                cespugli.append(splitted_cespuglio)

    print "numero cespugli che han generato i loro gameti: ", len(cespugli)
    # per ogni cespuglio metto nell'apposita lista del Genotipo la lista di tutti gli alleli degli altri cespugli
    for item in cespugli:
        for en in cespugli:
            if item != en:
                if not item.specials and 'already_touched' not in item.specials:
                    item.genotipo.gameti_altrui += en.genotipo.gameti_propri

    print 'cespugli: ', cespugli
    print 'cespugli[0]', cespugli[0]
    print 'cespugli[0].genotipo', cespugli[0].genotipo
    print 'cespugli[0].genotipo.gameti_propri', cespugli[
        0].genotipo.gameti_propri
    cespuglio.specials['already_touched'] = True
    return True
def before_touched(entity, cespuglio, detail, descr, behavioured):
    # Il valore di cespuglio.quantity è ad uno anche se è parte di un gruppo fisico.

    if not cespuglio.specials or 'ancestors' not in cespuglio.specials:
        print "#### ROMIL - TOUCH - specials NON presenti"
        # (TD) da gestire, ricreare i genotipi
        # Se un trust alto icrea il cespuglio accanto agli altri,
        # crasha tutto in fase di fecondazione
        return

    # (TD) dopo 2 o 3 volte che si tocca dovrebbe perdere la sua efficacia
    command_emote(cespuglio, "comincia ad oscillare spargendo un po' di polline.")
    interpret(entity, "sneeze", show_input=False, show_prompt=False)
    if not cespuglio.location.IS_ROOM:
        # (TD) In vaso sarà un dramma da gestire
        return

    room = cespuglio.location
    cespugli = []
    
    for item in room.iter_contains(use_reversed=True):
        if item.IS_ITEM and item.prototype.code == cespuglio.prototype.code:
            for x in xrange(item.quantity):
                if 'genotipo' in splitted_cespuglio.__dict__ and splitted_cespuglio.genotipo.gameti_propri != []:
                    # evito inutili ripetizioni nel caso qualcuno tocchi più volte
                    continue
                # Splitto i cespugli e in ciascuno metto un metodo Genotipo in cui
                # carico il genoma e ricavo i due gameti
                splitted_cespuglio = item.split_entity(1)
                splitted_cespuglio.genotipo = Genotipo()
                splitted_cespuglio.genotipo.importa_specials(splitted_cespuglio)
                # ora metto una lista con i due gameti per ciascun cespuglio 
                splitted_cespuglio.genotipo.gameti_propri = splitted_cespuglio.genotipo.get_gameti()
                cespugli.append(splitted_cespuglio)

    print "numero cespugli che han generato i loro gameti: ", len(cespugli)   
    # per ogni cespuglio metto nell'apposita lista del Genotipo la lista di tutti gli alleli degli altri cespugli
    for item in cespugli:
        for en in cespugli:
            if item != en:
                if not item.specials and 'already_touched' not in item.specials:
                    item.genotipo.gameti_altrui += en.genotipo.gameti_propri

    print 'cespugli: ',  cespugli
    print 'cespugli[0]', cespugli[0]
    print 'cespugli[0].genotipo', cespugli[0].genotipo
    print 'cespugli[0].genotipo.gameti_propri', cespugli[0].genotipo.gameti_propri
    cespuglio.specials['already_touched'] = True
    return True
예제 #5
0
    def check_alias(self, arg, argument):
        """
        Controlla se argument sia un alias di un pg, se sì lo ritorna.
        """
        if not arg:
            log.bug("arg non è un parametro valido: %r" % arg)
            return

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

        if arg not in self.aliases:
            return False

        alias = self.aliases[arg]
        argument = argument or ""
        interpret(self.player, "%s %s" % (alias.action, argument), use_check_alias=False)
        return True
예제 #6
0
파일: social.py 프로젝트: Onirik79/aaritmud
    def send_with_same_intention(self, sender, receiver=None):
        """
        Invia un social a caso con la stessa intenzione.
        Se receiver non è valido allora invia il social senza argomento.
        """
        if not sender:
            log.bug("sender non è un parametro valido: %r" % sender)
            return

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

        # Il più delle volte invia lo stesso social in questione, altrimenti ne
        # cerca uno con intenzione simile
        if random.randint(0, 5) != 0:
            social_input = self.get_input_argument()
            if receiver:
                receiver_numbered_keyword = receiver.get_numbered_keyword(looker=sender)
                argument = "%s %s" % (social_input, receiver_numbered_keyword)
            else:
                argument = social_input
            interpret(sender, argument)
            return

        # Se il mud è stato appena creato potrebbe non avere ancora i social
        if not database["socials"]:
            return

        # Crea una lista con tutti i social con l'intenzione voluta
        socials = []
        for social in database["socials"].itervalues():
            if social.intention == self.intention:
                socials.append(social)

        # Potrebbe benissimo essere che non esistano ancora abbastanza social
        # per averne uno con quell'intenzione
        if not socials:
            return

        # Invia un social scelto a caso tra quelli voluti
        social = random.choice(socials)
        argument = social.fun_name.split("_")[1]
        if receiver:
            argument += " %s" % receiver.get_numbered_keyword(looker=sender)

        interpret(sender, argument)
예제 #7
0
    def check_alias(self, arg, argument):
        """
        Controlla se argument sia un alias di un pg, se sì lo ritorna.
        """
        if not arg:
            log.bug("arg non è un parametro valido: %r" % arg)
            return

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

        if arg not in self.aliases:
            return False

        alias = self.aliases[arg]
        argument = argument or ""
        interpret(self.player,
                  "%s %s" % (alias.action, argument),
                  use_check_alias=False)
        return True
예제 #8
0
파일: social.py 프로젝트: Onirik79/aaritmud
    def send_to(self, sender, receiver=None):
        """
        Se receiver non è valido allora invia il social senza argomento.
        """
        # E' possibile che non siano valide per via della defer che
        # chiama questo metodo
        if not sender:
            return
        if not receiver:
            return

        modifier = 0
        if sender.position > POSITION.SLEEP and not is_affected(sender, "charm") and sender.is_original():
            # Modificatore comportamentale per i mob, un valore tra -10 e 10
            if receiver and sender.race in receiver.reputations:
                modifier = receiver.reputations[sender.race] / 10  # (TD)
            if self.intention == INTENTION.FRIENDLY:
                modifier += 5
            elif self.intention == INTENTION.AGGRESSIVE:
                modifier -= 5

        # Caso peggiorativo
        if receiver and modifier <= -10:
            if random.randint(0, 5) == 0:
                interpret(sender, "say a %s Te la sei proprio [red]andata a cercare[close]!" % receiver.get_numbered_keyword(looker=sender))
            start_fight(receiver, sender)
        # Casi non buoni
        elif modifier <= -5 and self.intention == INTENTION.AGGRESSIVE:
            self.send_with_same_intention(sender, receiver)
        # Casi neutrali
        elif -5 < modifier < 5 and self.intention == INTENTION.NEUTRAL:
            # Qui è voluto che capitino casi buffi, come ad esempio se si
            # annuisce potrebbe darsi che di risposti ci si becchi una vomitata.
            # Se si vuole un mud full-rpg forse è bene ritornare al posto di
            # questa riga sottostante
            self.send_with_same_intention(sender, receiver)
        # Casi migliorativi
        elif modifier >= 5 and self.intention == INTENTION.FRIENDLY:
            self.send_with_same_intention(sender, receiver)
from src.parse import parse_into_tree
from src.interpret import interpret
from src.format_pico import print_to_file

# these should be command line argument
INPUT_FILE = "input/theorem.out"
OUT_FILE = "theorem.cnf"

tree = parse_into_tree(INPUT_FILE)
clauses, var_len = interpret(tree)
print_to_file(OUT_FILE, clauses, var_len)
예제 #10
0
def command_force(entity, argument=""):
    """
    Forza l'esecuzione di un comando da parte di un'altra entità.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return True