Beispiel #1
0
    def render_POST(self, request, conn):
        width = 0
        if "width" in request.args:
            width = request.args["width"][0]
            if is_number(width):
                width = int(width)
            else:
                log.bug("resolution width passato dal client con account %s non è un numero valido: %s" % (conn.account.code, width))
                return "0"

        height = 0
        if "height" in request.args:
            height = request.args["height"][0]
            if is_number(height):
                height = int(height)
            else:
                log.bug("resolution height passato dal client con account %s non è un numero valido: %s" % (conn.account.code, height))
                return "0"

        if width != height and (width == 0 or height == 0):
            log.bug("Non sono stati ricavati tutti e due i valori di risoluzione dello schermo del client: width=%d height=%d" % (width, height))
            return "0"

        conn.account.resolution_width  = width
        conn.account.resolution_height = height
Beispiel #2
0
    def get_from_to_numbers(self, request):
        if not request:
            log.bug("request non è un parametro valido: %r" % request)
            return ""

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

        from_number = 0
        if "from_number" in request.args:
            from_number = request.args["from_number"][0]
            if is_number(from_number):
                from_number = int(from_number)
                if from_number < 0:
                    return -1, -1, "Non è stato passato un from_number numerico maggiore o uguale a zero valido: %d" % from_number
            else:
                return -1, -1, "Non è stato passato un from_number valido: %d" % from_number

        to_number = config.news_to_show
        if "to_number" in request.args:
            to_number = request.args["to_number"][0]
            if is_number(to_number):
                to_number = int(to_number)
                if to_number < 0 or to_number < from_number:
                    return -1, -1, "Non è stato passato un to_number numerico maggiore di zero o maggiore e uguale di from_number: %d" % to_number
            else:
                return -1, -1, "Non è stato passato un to_number valido: %d" % to_number

        return from_number, to_number, ""
Beispiel #3
0
    def get_from_to_numbers(self, request):
        if not request:
            log.bug("request non è un parametro valido: %r" % request)
            return ""

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

        from_number = 0
        if "from_number" in request.args:
            from_number = request.args["from_number"][0]
            if is_number(from_number):
                from_number = int(from_number)
                if from_number < 0:
                    return -1, -1, "Non è stato passato un from_number numerico maggiore o uguale a zero valido: %d" % from_number
            else:
                return -1, -1, "Non è stato passato un from_number valido: %d" % from_number

        to_number = config.news_to_show
        if "to_number" in request.args:
            to_number = request.args["to_number"][0]
            if is_number(to_number):
                to_number = int(to_number)
                if to_number < 0 or to_number < from_number:
                    return -1, -1, "Non è stato passato un to_number numerico maggiore di zero o maggiore e uguale di from_number: %d" % to_number
            else:
                return -1, -1, "Non è stato passato un to_number valido: %d" % to_number

        return from_number, to_number, ""
Beispiel #4
0
    def load(self):
        filepath = "persistence/calendar.rpg"
        try:
            file = open(filepath, "r")
        except IOError:
            log.bug("Impossibile aprire il file %s in lettura" % filepath)
            return

        for line in file:
            if not line.strip():
                continue
            if line[0] == "#":
                continue
            break
        else:
            log.bug("Non è stato trovato nessuna riga valida al file %s" %
                    filepath)
            file.close()
            return
        file.close()

        values = line.split()
        if len(values) != 5:
            log.bug(
                "E' stato trovato un numero inatteso di valori al file %s: %d"
                % (filepath, len(values)))
            return

        if is_number(values[0]):
            self.minute = int(values[0])
        else:
            log.bug("minute del file %s non sono un numero valido: %s" %
                    values[0])

        if is_number(values[1]):
            self.hour = int(values[1])
        else:
            log.bug("hour del file %s non sono un numero valido: %s" %
                    values[1])

        if is_number(values[2]):
            self.day = int(values[2])
        else:
            log.bug("day del file %s non sono un numero valido: %s" %
                    values[2])

        self.month = Element(values[3])

        if is_number(values[4]):
            self.year = int(values[4])
        else:
            log.bug("year del file %s non sono un numero valido: %s" %
                    values[4])

        self.get_error_message()
Beispiel #5
0
    def fread(self, file, line):
        if not file:
            log.bug("file non è un parametro valido: %r", file)
            return

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

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

        aggressor_code, victim_code, timer, remaining_tries = line.split(
            None, 3)

        # Può essere normale che non vi sia l'aggressore o la vittima a volte
        # le persistenze vengono rimosse
        table_name = aggressor_code.split("_", 2)[1] + "s"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" %
                    table_name)
            return
        if aggressor_code not in database[table_name]:
            return
        aggressor = database[table_name][aggressor_code]

        if "_" in victim_code:
            table_name = victim_code.split("_", 2)[1] + "s"
        else:
            table_name = "players"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" %
                    table_name)
            return
        if victim_code not in database[table_name]:
            return
        victim = database[table_name][victim_code]

        if not is_number(timer):
            log.bug("timer ricavato per il buyable %s non è un numero: %s" %
                    (line, timer))
            return

        if not is_number(remaining_tries):
            log.bug(
                "remaining_tries ricavato per il buyable %s non è un numero: %s"
                % (line, remaining_tries))
            return

        self.aggressor = weakref.ref(aggressor)
        self.victim = weakref.ref(victim)
        self.timer = int(timer)
        self.remaining_tries = int(remaining_tries)

        aggressiveness_loop.datas.append(self)
Beispiel #6
0
    def apply(self):
        # Ricava l'obiettivo in cui copiare l'self
        if self.type == AFFECT.SELF:
            target = obj
        elif self.type == AFFECT.CONTAINED_BY:
            target = obj.location
        elif self.type == AFFECT.ROOM and obj.location.IS_ROOM:
            target = obj.location
        elif self.type == AFFECT.ENTITY and not obj.location.IS_ROOM:
            target = obj.location
        elif self.type == AFFECT.ITEM and obj.location.IS_ITEM:
            target = obj.location
        elif self.type == AFFECT.ACTOR and obj.location.IS_ACTOR:
            target = obj.location
        elif self.type == AFFECT.MOB and obj.location.IS_MOB:
            target = obj.location
        elif self.type == AFFECT.PLAYER and obj.location.IS_PLAYER:
            target = obj.location
        else:
            return

        # Controlla se ci sono le condizioni per copiare l'self
        if self.conditional and target.race not in self.conditional:
            return

        # Cerca l'attributo da applicare relativo all'etichetta
        apply_attr = from_capitalized_words(self.apply)
        if not hasattr(target, apply_attr):
            log.bug("Non è stato trovato nessun attributo valido dall'etichetta %s per l'self su %s" % (self.apply, obj.code))
            return

        # Infine imposta il valore e si salva il riferimento dell'self
        attr = getattr(target, apply_attr)
        if isinstance(attr, basestring):
            setattr(target, apply_attr, self.modifier)
        else:
            if self.modifier[0] == "+":
                if not is_number(self.modifier[1 : ]):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr + int(self.modifier[1 : ]))
            elif self.modifier[0] == "-":
                if not is_number(self.modifier[1 : ]):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr - int(self.modifier[1 : ]))
            else:
                if not is_number(self.modifier):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, int(self.modifier))

        target.affect_infos.append((self, attr))
Beispiel #7
0
    def load(self):
        filepath = "persistence/calendar.rpg"
        try:
            file = open(filepath, "r")
        except IOError:
            log.bug("Impossibile aprire il file %s in lettura" % filepath)
            return

        for line in file:
            if not line.strip():
                continue
            if line[0] == "#":
                continue
            break
        else:
            log.bug("Non è stato trovato nessuna riga valida al file %s" % filepath)
            file.close()
            return
        file.close()

        values = line.split()
        if len(values) != 5:
            log.bug("E' stato trovato un numero inatteso di valori al file %s: %d" % (filepath, len(values)))
            return

        if is_number(values[0]):
            self.minute = int(values[0])
        else:
            log.bug("minute del file %s non sono un numero valido: %s" % values[0])

        if is_number(values[1]):
            self.hour = int(values[1])
        else:
            log.bug("hour del file %s non sono un numero valido: %s" % values[1])

        if is_number(values[2]):
            self.day = int(values[2])
        else:
            log.bug("day del file %s non sono un numero valido: %s" % values[2])

        self.month = Element(values[3])

        if is_number(values[4]):
            self.year = int(values[4])
        else:
            log.bug("year del file %s non sono un numero valido: %s" % values[4])

        self.get_error_message()
Beispiel #8
0
    def fread(self, file, line):
        if not file:
            log.bug("file non è un parametro valido: %r", file)
            return

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

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

        aggressor_code, victim_code, timer, remaining_tries = line.split(None, 3)

        # Può essere normale che non vi sia l'aggressore o la vittima a volte
        # le persistenze vengono rimosse
        table_name = aggressor_code.split("_", 2)[1] + "s"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" % table_name)
            return
        if aggressor_code not in database[table_name]:
            return
        aggressor = database[table_name][aggressor_code]

        if "_" in victim_code:
            table_name = victim_code.split("_", 2)[1] + "s"
        else:
            table_name = "players"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" % table_name)
            return
        if victim_code not in database[table_name]:
            return
        victim = database[table_name][victim_code]

        if not is_number(timer):
            log.bug("timer ricavato per il buyable %s non è un numero: %s" % (line, timer))
            return

        if not is_number(remaining_tries):
            log.bug("remaining_tries ricavato per il buyable %s non è un numero: %s" % (line, remaining_tries))
            return

        self.aggressor       = weakref.ref(aggressor)
        self.victim          = weakref.ref(victim)
        self.timer           = int(timer)
        self.remaining_tries = int(remaining_tries)

        aggressiveness_loop.datas.append(self)
Beispiel #9
0
    def render_POST(self, request, conn):
        if not conn:
            return ""

        response = {}
        if "refresh_who_counter" in request.args:
            who_players = get_who_players()
            if who_players:
                response["who_counter"] = len(who_players)
            else:
                response["who_counter"] = 0

        if "last_refresh_id" in request.args:
            if is_number(request.args["last_refresh_id"][0]):
                last_refresh_id = int(request.args["last_refresh_id"][0])
                if len(SquarePage.SQUARE_MESSAGES_LIST) > last_refresh_id:
                    square_line = SquarePage.SQUARE_MESSAGES_LIST[last_refresh_id]
                    if "[" in square_line:
                        square_line = convert_colors(square_line)
                    response["last_square_message"] = create_square_message(square_line, conn, last_refresh_id + 1, use_quote=True)
                else:
                    response["last_square_message"] = ""
            else:
                log.bug("last_refresh_id non è un numero: " % request.args["last_refresh_id"][0])

        return pprint.pformat(response, indent=0)
Beispiel #10
0
    def fread_the_line(self, file, line, attr):
        if not file:
            log.bug("file non è un parametro valido: %r" % file)
            return

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

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

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

        values = line.split()

        if len(values) != 4:
            log.fread(
                "Non sono stati ricavati 4 argomenti per il passaggio: %s" %
                line)
            return

        if not is_number(values[0]):
            log.fread("x non è una coordinata valida: %s" % values[0])
            return

        if not is_number(values[1]):
            log.fread("y non è una coordinata valida: %s" % values[1])
            return

        if not is_number(values[2]):
            log.fread("z non è una coordinata valida: %s" % values[2])
            return

        if not values[3]:
            log.fread(
                "proto_room non è una codice di stanza prototipo valido: %r" %
                values[3])
            return

        self.x = int(values[0])
        self.y = int(values[1])
        self.z = int(values[2])
        self.proto_room = values[3]
Beispiel #11
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
Beispiel #12
0
    def fread_the_line(self, file, line, attr):
        if not file:
            log.bug("file non è un parametro valido: %r" % file)
            return

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

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

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

        values = line.split()

        if len(values) != 4:
            log.fread("Non sono stati ricavati 4 argomenti per il passaggio: %s" % line)
            return

        if not is_number(values[0]):
            log.fread("x non è una coordinata valida: %s" % values[0])
            return

        if not is_number(values[1]):
            log.fread("y non è una coordinata valida: %s" % values[1])
            return

        if not is_number(values[2]):
            log.fread("z non è una coordinata valida: %s" % values[2])
            return

        if not values[3]:
            log.fread("proto_room non è una codice di stanza prototipo valido: %r" % values[3])
            return

        self.x = int(values[0])
        self.y = int(values[1])
        self.z = int(values[2])
        self.proto_room = values[3]
Beispiel #13
0
    def render_GET(self, request, conn):
        error_message = ""
        area_code = ""
        coord_z = 0

        if "area_code" in request.args:
            area_code = request.args["area_code"][0]
        if not area_code:
            area_code = sorted(database["areas"].keys())[0]

        area = get_area_from_argument(area_code)
        if area:
            if "coord_z" in request.args:
                coord_z = request.args["coord_z"][0]
                if not coord_z:
                    error_message = "La coordinata Z non è un valore valido: %r" % coord_z
                    coord_z = 0
                if not is_number(coord_z):
                    error_message = "La coordinata Z non è un valore numerico valido: %s" % coord_z
                    coord_z = 0
                coord_z = int(coord_z)
        else:
            error_message = "Non esiste nessun'area con il codice %s" % area_code

        mapping = {
            "area_select_options":
            self.create_area_select_options(area_code),
            "error_message":
            error_message,
            "area_code":
            area.code if area else "",
            "min_coord_z":
            area.get_min_coord("z") if area else 0,
            "coord_z":
            coord_z,
            "max_coord_z":
            area.get_max_coord("z") if area else 0,
            "proto_rooms":
            self.create_proto_datas("proto_rooms", area) if area else "",
            "proto_items":
            self.create_proto_datas("proto_items", area) if area else "",
            "proto_mobs":
            self.create_proto_datas("proto_mobs", area) if area else "",
            "cells":
            self.create_cells(area, coord_z) if area else "",
            "legend_icons":
            self.create_legend_icons(),
            "area_labels":
            self.create_area_labels(area) if area else ""
        }
        return self.PAGE_TEMPLATE.safe_substitute(mapping)
Beispiel #14
0
    def fread(self, file, line):
        if not file:
            log.bug("file non è un parametro valido: %r", file)
            return

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

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

        entity_code, ingested_code, timer = line.split(None, 2)

        # Può essere normale che non vi sia l'entità, a volte le persistenze vengono rimosse
        if "_" in entity_code:
            table_name = entity_code.split("_", 2)[1] + "s"
        else:
            table_name = "players"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" %
                    table_name)
            return
        if entity_code not in database[table_name]:
            return
        entity = database[table_name][entity_code]

        table_name = ingested_code.split("_", 2)[1] + "s"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" %
                    table_name)
            return
        if ingested_code not in database[table_name]:
            return
        ingested = database[table_name][ingested_code]

        if not is_number(timer):
            log.bug("timer ricavato per il supply %s non è un numero: %s" %
                    (line, timer))
            return

        self.entity = weakref.ref(entity)
        self.ingested = weakref.ref(ingested)
        self.timer = int(timer)

        digestion_loop.datas.append(self)
Beispiel #15
0
    def fread(self, file, line):
        if not file:
            log.bug("file non è un parametro valido: %r", file)
            return

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

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

        entity_code, ingested_code, timer = line.split(None, 2)

        # Può essere normale che non vi sia l'entità, a volte le persistenze vengono rimosse
        if "_" in entity_code:
            table_name = entity_code.split("_", 2)[1] + "s"
        else:
            table_name = "players"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" % table_name)
            return
        if entity_code not in database[table_name]:
            return
        entity = database[table_name][entity_code]

        table_name = ingested_code.split("_", 2)[1] + "s"
        if not table_name in database:
            log.bug("Non esiste nessuna tabella dal nome %s nel database" % table_name)
            return
        if ingested_code not in database[table_name]:
            return
        ingested = database[table_name][ingested_code]

        if not is_number(timer):
            log.bug("timer ricavato per il supply %s non è un numero: %s" % (line, timer))
            return

        self.entity   = weakref.ref(entity)
        self.ingested = weakref.ref(ingested)
        self.timer    = int(timer)

        digestion_loop.datas.append(self)
Beispiel #16
0
    def render_GET(self, request, conn):
        error_message = ""
        area_code = ""
        coord_z = 0

        if "area_code" in request.args:
            area_code = request.args["area_code"][0]
        if not area_code:
            area_code = sorted(database["areas"].keys())[0]

        area = get_area_from_argument(area_code)
        if area:
            if "coord_z" in request.args:
                coord_z = request.args["coord_z"][0]
                if not coord_z:
                    error_message = "La coordinata Z non è un valore valido: %r" % coord_z
                    coord_z = 0
                if not is_number(coord_z):
                    error_message = "La coordinata Z non è un valore numerico valido: %s" % coord_z
                    coord_z = 0
                coord_z = int(coord_z)
        else:
            error_message = "Non esiste nessun'area con il codice %s" % area_code

        mapping = {"area_select_options" : self.create_area_select_options(area_code),
                   "error_message"       : error_message,
                   "area_code"           : area.code if area else "",
                   "min_coord_z"         : area.get_min_coord("z") if area else 0,
                   "coord_z"             : coord_z,
                   "max_coord_z"         : area.get_max_coord("z") if area else 0,
                   "proto_rooms"         : self.create_proto_datas("proto_rooms", area) if area else "",
                   "proto_items"         : self.create_proto_datas("proto_items", area) if area else "",
                   "proto_mobs"          : self.create_proto_datas("proto_mobs", area) if area else "",
                   "cells"               : self.create_cells(area, coord_z) if area else "",
                   "legend_icons"        : self.create_legend_icons(),
                   "area_labels"         : self.create_area_labels(area) if area else ""}
        return self.PAGE_TEMPLATE.safe_substitute(mapping)
Beispiel #17
0
    def render_POST(self, request, conn):
        error_message = ""
        if "minutes" not in request.args:
            return '''<br><span style="color:red">La richiesta di shutdown non è valida</span><br>'''

        minutes = request.args["minutes"][0]
        if not is_number(minutes):
            return '''<br><span style="color:red">Il valore relativo ai minuti è risultato errato: %s</span><br>''' % minutes

        database.avoid_backup_on_shutdown = False
        database.avoid_save_on_shutdown = False
        database.only_player_persistence = False
        if "avoid_backup" in request.args and request.args["avoid_backup"][0] == "1":
            database.avoid_backup_on_shutdown = True
        if "avoid_save" in request.args and request.args["avoid_save"][0] == "1":
            database.avoid_save_on_shutdown = True
        if "only_player_persistence" in request.args and request.args["only_player_persistence"][0] == "1":
            database.only_player_persistence = True

        # Il tutto viene poi gestito dal loop principale
        engine.seconds_to_shutdown = int(minutes) * 60
        javascript = '''<script>current_interval = setInterval(refreshSecondsToShut, 1000);</script>'''
        return '''Lo Shutdown di %s avverà tra <span name="seconds_to_shutdown">%d</span> secondi.%s''' % (
            config.game_name, engine.seconds_to_shutdown, javascript)
Beispiel #18
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
Beispiel #19
0
    def render_POST(self, request, conn):
        """
        Quando la pagina di gioco viene chiusa viene chiusa anche la connessione
        di gioco e, quindi, fatto uscire dal gioco il player.
        C'è da notare che se il browser-client crasha questa chiamata
        probabilmente non viene fatta e quindi l'uscita del player dal gioco
        viene eseguita tramite il contatore di idle.
        """
        # Se è stato passato l'argomento apposito allora esegue la
        # distribuzione dei talenti sui punti e sulle skill
        distribute = "0"
        if "distribute" in request.args:
            distribute = request.args["distribute"][0]
        if distribute == "1":
            if "initial_talents" not in request.args:
                return "Punti di talento iniziali non sono stati passati."
            if "talents" not in request.args:
                return "Punti di talento non sono stati passati."
            if "initial_life" not in request.args:
                return "Punti di vita iniziali non sono stati passati."
            if "initial_mana" not in request.args:
                return "Punti di mana iniziali non sono stati passati."
            if "initial_vigour" not in request.args:
                return "Punti di vigore iniziali non sono stati passati."
            if "life_points" not in request.args:
                return "Punti di vita non sono stati passati."
            if "mana_points" not in request.args:
                return "Punti di mana non sono stati passati."
            if "vigour_points" not in request.args:
                return "Punti di vigore non sono stati passati."

            initial_talents = request.args["initial_talents"][0]
            talents = request.args["talents"][0]
            initial_life = request.args["initial_life"][0]
            initial_mana = request.args["initial_mana"][0]
            initial_vigour = request.args["initial_vigour"][0]
            life_points = request.args["life_points"][0]
            mana_points = request.args["mana_points"][0]
            vigour_points = request.args["vigour_points"][0]

            if not is_number(initial_talents):
                return "Punti di talento iniziali non sono un numero: %s" % initial_talents
            if not is_number(talents):
                return "Punti di talento non sono un numero: %s" % talents
            if not is_number(initial_life):
                return "Punti di vita iniziali non sono un numero: %s" % initial_life
            if not is_number(initial_mana):
                return "Punti di mana iniziali non sono un numero: %s" % initial_mana
            if not is_number(initial_vigour):
                return "Punti di vigore iniziali non sono un numero: %s" % initial_vigour
            if not is_number(life_points):
                return "Punti di vita non sono un numero: %s" % life_points
            if not is_number(mana_points):
                return "Punti di mana non sono un numero: %s" % mana_points
            if not is_number(vigour_points):
                return "Punti di vigore non sono un numero: %s" % vigour_points

            initial_talents = int(initial_talents)
            talents = int(talents)
            initial_life = int(initial_life)
            initial_mana = int(initial_mana)
            initial_vigour = int(initial_vigour)
            life_points = int(life_points)
            mana_points = int(mana_points)
            vigour_points = int(vigour_points)

            distributed_talents = initial_talents - talents
            if distributed_talents == 0:
                return "Non è stato distribuito nessun talento"

            total_initial = initial_life + initial_mana + initial_vigour
            total_points = life_points + mana_points + vigour_points
            if distributed_talents != total_points - total_initial:
                return "C'è stato un errore nella distribuzione dei talenti"

            if not conn.player:
                log.bug(
                    "Impossibile distribuire i talenti ad una connessione senza player valido: %r (conn: %s)"
                    % (conn.player, conn.get_id()))
                return

            conn.player.talents = talents
            conn.player.max_life = life_points
            conn.player.max_mana = mana_points
            conn.player.max_vigour = vigour_points

            return ""

        # Se è stato passato l'argomento apposito aggiorna il pannello
        # della tab relativa i talenti
        refresh_talents = "0"
        if "refresh_talents" in request.args:
            refresh_talents = request.args["refresh_talents"][0]
        if refresh_talents == "1":
            return self.create_talents_body(conn)

        # Se è stato passato l'argomento apposito chiude la connessione
        close_connection = "0"
        if "close_connection" in request.args:
            close_connection = request.args["close_connection"][0]
        if close_connection == "1":
            conn.close_game_request()
Beispiel #20
0
def command_get(entity, argument="", verbs=VERBS, behavioured=False):
    # È possibile se il comando è stato deferrato
    if not entity:
        return False

    entity = entity.split_entity(1)

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

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

    original_argument = argument

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return True
Beispiel #21
0
    def render_POST(self, request, conn):
        """
        Quando la pagina di gioco viene chiusa viene chiusa anche la connessione
        di gioco e, quindi, fatto uscire dal gioco il player.
        C'è da notare che se il browser-client crasha questa chiamata
        probabilmente non viene fatta e quindi l'uscita del player dal gioco
        viene eseguita tramite il contatore di idle.
        """
        # Se è stato passato l'argomento apposito allora esegue la
        # distribuzione dei talenti sui punti e sulle skill
        distribute = "0"
        if "distribute" in request.args:
            distribute = request.args["distribute"][0]
        if distribute == "1":
            if "initial_talents" not in request.args:
                return "Punti di talento iniziali non sono stati passati."
            if "talents" not in request.args:
                return "Punti di talento non sono stati passati."
            if "initial_life" not in request.args:
                return "Punti di vita iniziali non sono stati passati."
            if "initial_mana" not in request.args:
                return "Punti di mana iniziali non sono stati passati."
            if "initial_vigour" not in request.args:
                return "Punti di vigore iniziali non sono stati passati."
            if "life_points" not in request.args:
                return "Punti di vita non sono stati passati."
            if "mana_points" not in request.args:
                return "Punti di mana non sono stati passati."
            if "vigour_points" not in request.args:
                return "Punti di vigore non sono stati passati."

            initial_talents = request.args["initial_talents"][0]
            talents   = request.args["talents"][0]
            initial_life    = request.args["initial_life"][0]
            initial_mana    = request.args["initial_mana"][0]
            initial_vigour  = request.args["initial_vigour"][0]
            life_points     = request.args["life_points"][0]
            mana_points     = request.args["mana_points"][0]
            vigour_points   = request.args["vigour_points"][0]

            if not is_number(initial_talents):
                return "Punti di talento iniziali non sono un numero: %s" % initial_talents
            if not is_number(talents):
                return "Punti di talento non sono un numero: %s" % talents
            if not is_number(initial_life):
                return "Punti di vita iniziali non sono un numero: %s" % initial_life
            if not is_number(initial_mana):
                return "Punti di mana iniziali non sono un numero: %s" % initial_mana
            if not is_number(initial_vigour):
                return "Punti di vigore iniziali non sono un numero: %s" % initial_vigour
            if not is_number(life_points):
                return "Punti di vita non sono un numero: %s" % life_points
            if not is_number(mana_points):
                return "Punti di mana non sono un numero: %s" % mana_points
            if not is_number(vigour_points):
                return "Punti di vigore non sono un numero: %s" % vigour_points

            initial_talents = int(initial_talents)
            talents         = int(talents)
            initial_life    = int(initial_life)
            initial_mana    = int(initial_mana)
            initial_vigour  = int(initial_vigour)
            life_points     = int(life_points)
            mana_points     = int(mana_points)
            vigour_points   = int(vigour_points)

            distributed_talents = initial_talents - talents
            if distributed_talents == 0:
                return "Non è stato distribuito nessun talento"

            total_initial = initial_life + initial_mana + initial_vigour
            total_points  = life_points + mana_points + vigour_points
            if distributed_talents != total_points - total_initial:
                return "C'è stato un errore nella distribuzione dei talenti"

            if not conn.player:
                log.bug("Impossibile distribuire i talenti ad una connessione senza player valido: %r (conn: %s)" % (conn.player, conn.get_id()))
                return

            conn.player.talents = talents
            conn.player.max_life      = life_points
            conn.player.max_mana      = mana_points
            conn.player.max_vigour    = vigour_points

            return ""

        # Se è stato passato l'argomento apposito aggiorna il pannello
        # della tab relativa i talenti
        refresh_talents = "0"
        if "refresh_talents" in request.args:
            refresh_talents = request.args["refresh_talents"][0]
        if refresh_talents == "1":
            return self.create_talents_body(conn)

        # Se è stato passato l'argomento apposito chiude la connessione
        close_connection = "0"
        if "close_connection" in request.args:
            close_connection = request.args["close_connection"][0]
        if close_connection == "1":
            conn.close_game_request()
Beispiel #22
0
    def remove(self, target=None, affect_info=None):
        """
        Da notare che non esegue controlli condizionali e sulla duration.
        """
        if not target:
            # Ricava l'obiettivo in cui copiare l'self
            if self.type == AFFECT.SELF:
                target = obj
            elif self.type == AFFECT.CONTAINED_BY:
                target = obj.location
            elif self.type == AFFECT.ROOM and obj.location.IS_ROOM:
                target = obj.location
            elif self.type == AFFECT.ENTITY and not obj.location.IS_ROOM:
                target = obj.location
            elif self.type == AFFECT.ITEM and obj.location.IS_ITEM:
                target = obj.location
            elif self.type == AFFECT.ACTOR and obj.location.IS_ACTOR:
                target = obj.location
            elif self.type == AFFECT.MOB and obj.location.IS_MOB:
                target = obj.location
            elif self.type == AFFECT.PLAYER and obj.location.IS_PLAYER:
                target = obj.location
            else:
                return

        # Cerca l'self su target riguardante questo, se non lo trova
        # significa che l'entità per qualche motivo non lo ha più addosso
        if not affect_info:
            for affect_info in target.affect_infos:
                if affect_info[0] == self:
                    break
            else:
                log.bug("Per qualche motivo bacoso %s non ha il riferimento all'self con apply %s e modifier %s di %s" % (
                    target.code, self.apply, self.modifier, obj.code))
                return

        # Cerca l'attributo da applicare relativo all'etichetta
        apply_attr = from_capitalized_words(self.apply)
        if not hasattr(target, apply_attr):
            log.bug("Non è stato trovato nessun attributo valido dall'etichetta %s per l'self su %s" % (self.apply, obj.code))
            return

        # Infine rimuove il valore eventualmente dall'attributo salvato
        # precedentemente
        attr = getattr(target, apply_attr)
        if isinstance(attr, basestring):
            setattr(target, apply_attr, affect_info[1])
        else:
            if self.modifier[0] == "+":
                if not is_number(self.modifier[1 : ]):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr + int(self.modifier[1 : ]))
            elif self.modifier[0] == "-":
                if not is_number(self.modifier[1 : ]):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr - int(self.modifier[1 : ]))
            else:
                if not is_number(self.modifier):
                    log.bug("modifier per un self su di %s non è un numero: %s" % (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, affect_info[1])

        target.affect_infos.remove(affect_info)
Beispiel #23
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
Beispiel #24
0
    def apply(self):
        # Ricava l'obiettivo in cui copiare l'self
        if self.type == AFFECT.SELF:
            target = obj
        elif self.type == AFFECT.CONTAINED_BY:
            target = obj.location
        elif self.type == AFFECT.ROOM and obj.location.IS_ROOM:
            target = obj.location
        elif self.type == AFFECT.ENTITY and not obj.location.IS_ROOM:
            target = obj.location
        elif self.type == AFFECT.ITEM and obj.location.IS_ITEM:
            target = obj.location
        elif self.type == AFFECT.ACTOR and obj.location.IS_ACTOR:
            target = obj.location
        elif self.type == AFFECT.MOB and obj.location.IS_MOB:
            target = obj.location
        elif self.type == AFFECT.PLAYER and obj.location.IS_PLAYER:
            target = obj.location
        else:
            return

        # Controlla se ci sono le condizioni per copiare l'self
        if self.conditional and target.race not in self.conditional:
            return

        # Cerca l'attributo da applicare relativo all'etichetta
        apply_attr = from_capitalized_words(self.apply)
        if not hasattr(target, apply_attr):
            log.bug(
                "Non è stato trovato nessun attributo valido dall'etichetta %s per l'self su %s"
                % (self.apply, obj.code))
            return

        # Infine imposta il valore e si salva il riferimento dell'self
        attr = getattr(target, apply_attr)
        if isinstance(attr, basestring):
            setattr(target, apply_attr, self.modifier)
        else:
            if self.modifier[0] == "+":
                if not is_number(self.modifier[1:]):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr + int(self.modifier[1:]))
            elif self.modifier[0] == "-":
                if not is_number(self.modifier[1:]):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr - int(self.modifier[1:]))
            else:
                if not is_number(self.modifier):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, int(self.modifier))

        target.affect_infos.append((self, attr))
Beispiel #25
0
    def remove(self, target=None, affect_info=None):
        """
        Da notare che non esegue controlli condizionali e sulla duration.
        """
        if not target:
            # Ricava l'obiettivo in cui copiare l'self
            if self.type == AFFECT.SELF:
                target = obj
            elif self.type == AFFECT.CONTAINED_BY:
                target = obj.location
            elif self.type == AFFECT.ROOM and obj.location.IS_ROOM:
                target = obj.location
            elif self.type == AFFECT.ENTITY and not obj.location.IS_ROOM:
                target = obj.location
            elif self.type == AFFECT.ITEM and obj.location.IS_ITEM:
                target = obj.location
            elif self.type == AFFECT.ACTOR and obj.location.IS_ACTOR:
                target = obj.location
            elif self.type == AFFECT.MOB and obj.location.IS_MOB:
                target = obj.location
            elif self.type == AFFECT.PLAYER and obj.location.IS_PLAYER:
                target = obj.location
            else:
                return

        # Cerca l'self su target riguardante questo, se non lo trova
        # significa che l'entità per qualche motivo non lo ha più addosso
        if not affect_info:
            for affect_info in target.affect_infos:
                if affect_info[0] == self:
                    break
            else:
                log.bug(
                    "Per qualche motivo bacoso %s non ha il riferimento all'self con apply %s e modifier %s di %s"
                    % (target.code, self.apply, self.modifier, obj.code))
                return

        # Cerca l'attributo da applicare relativo all'etichetta
        apply_attr = from_capitalized_words(self.apply)
        if not hasattr(target, apply_attr):
            log.bug(
                "Non è stato trovato nessun attributo valido dall'etichetta %s per l'self su %s"
                % (self.apply, obj.code))
            return

        # Infine rimuove il valore eventualmente dall'attributo salvato
        # precedentemente
        attr = getattr(target, apply_attr)
        if isinstance(attr, basestring):
            setattr(target, apply_attr, affect_info[1])
        else:
            if self.modifier[0] == "+":
                if not is_number(self.modifier[1:]):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr + int(self.modifier[1:]))
            elif self.modifier[0] == "-":
                if not is_number(self.modifier[1:]):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, attr - int(self.modifier[1:]))
            else:
                if not is_number(self.modifier):
                    log.bug(
                        "modifier per un self su di %s non è un numero: %s" %
                        (obj.code, self.modifier))
                    return
                setattr(target, apply_attr, affect_info[1])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if argument:
        argument = html_escape(argument)

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

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

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

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

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

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

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

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

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

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

    return execution_result
Beispiel #27
0
    def parse_miml_check(self, check, looker=None):
        if not check:
            log.bug("check non è un parametro valido: %r" % check)
            return False

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

        check_parts = check.split()

        if check_parts[0][0:4] == "self":
            check_entity = self
        elif check_parts[0][0:8] == "location":
            if self.IS_ROOM:
                check_entity = self
            else:
                check_entity = self.location
        elif check_parts[0][0:17] == "previous_location":
            if self.IS_ROOM:
                check_entity = self
            else:
                check_entity = self.previous_location
        elif check_parts[0][0:6] == "looker":
            if not looker:
                log.bug(
                    "looker non valido (%r) anche se il check lo necessita: %s"
                    % (looker, check))
                return False
            check_entity = looker
        elif check_parts[0][0:6] == "season":
            if check_parts[1] == "is":
                if calendar.season == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if calendar.season != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        else:
            log.bug("entità da utilizzare per i check è sconosciuta: %s" %
                    check_parts[0])
            return False

        # (TD) no, dovrò splittare con or o and ed utilizzare le builtin any o all
        #for element_code in check_parts[2].split("|"):
        #    pass

        # Miml relativo alla razza dell'entità controllata
        if check_parts[2][0:5] == "RACE.":
            if check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.race == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.race != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo alla sessualità dell'entità controllata
        elif check_parts[2][0:4] == "SEX.":
            if check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.sex == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.sex != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo ai contenitori
        elif check_parts[2][0:10] == "CONTAINER.":
            if check_entity.IS_ROOM or not check_entity.container_type:
                return False

            if check_parts[1] == "is":
                if Element(
                        check_parts[2]) in check_entity.container_type.flags:
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if Element(check_parts[2]
                           ) not in check_entity.container_type.flags:
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo al settore di una stanza
        elif check_parts[2][0:7] == "SECTOR.":
            if not check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.sector == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.sector != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo alle flags di una stanza
        elif check_parts[2][0:5] == "ROOM.":
            if not check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if Element(check_parts[2]) in check_entity.flags:
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if Element(check_parts[2]) not in check_entity.flags:
                    return True
                else:
                    return False
            else:
                log.bug(
                    "Operatore di check sconosciuto: %s per l'elemento con codice %s"
                    % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo all'inventario portato
        elif check_parts[0][-14:] == ".inventory_qty":
            check_qty = 0
            if is_number(check_parts[2]):
                check_qty = int(check_parts[2])
            else:
                log.bug(
                    "la parte destra dell'opeartore del check miml %s non è un numbero valido"
                    % (check))

            qty = 0
            for content in check_entity.iter_contains():
                if len(content.wear_mode
                       ) == 0 and FLAG.INGESTED not in content.flags:
                    qty += 1

            if check_parts[1] == "==" and qty == check_qty:
                return True
            elif check_parts[1] == "!=" and qty != check_qty:
                return True
            elif check_parts[1] == ">" and qty > check_qty:
                return True
            elif check_parts[1] == ">=" and qty >= check_qty:
                return True
            elif check_parts[1] == "<" and qty < check_qty:
                return True
            elif check_parts[1] == "<=" and qty <= check_qty:
                return True
            else:
                return False
        # Miml relativo all'equipaggiamento portato
        elif check_parts[0][-14:] == ".equipment_qty":
            check_qty = 0
            if is_number(check_parts[2]):
                check_qty = int(check_parts[2])
            else:
                log.bug(
                    "la parte destra dell'opeartore del check miml %s non è un numbero valido"
                    % check)

            qty = 0
            for content in check_entity.iter_contains():
                if len(content.wear_mode
                       ) != 0 and FLAG.INGESTED not in content.flags:
                    qty += 1

            if check_parts[1] == "==" and qty == check_qty:
                return True
            elif check_parts[1] == "!=" and qty != check_qty:
                return True
            elif check_parts[1] == ">" and qty > check_qty:
                return True
            elif check_parts[1] == ">=" and qty >= check_qty:
                return True
            elif check_parts[1] == "<" and qty < check_qty:
                return True
            elif check_parts[1] == "<=" and qty <= check_qty:
                return True
            else:
                return False
        # Miml relativo alle exits, wall e direzioni
        elif get_direction_miml(check_parts[0]) != DIR.NONE:
            if not check_entity.IS_ROOM:
                return False

            direction = get_direction_miml(check_parts[0])
            if direction in check_entity.exits:
                if check_parts[1] == "is":
                    if check_parts[2] == "Exit":
                        return True
                    elif check_parts[2] == "Wall":
                        # Il check qui ci vuole comunque perché una direzione può
                        # avere sia uscita che muro, idem per il ramo 'is not'
                        if direction in check_entity.walls:
                            return True
                        else:
                            return False
                    elif check_parts[2] == "Door":
                        if check_entity.exits[
                                direction].door and check_entity.exits[
                                    direction].door.door_type:
                            return True
                        else:
                            return False
                    elif check_parts[2][:5] == "EXIT.":
                        if Element(check_parts[2]
                                   ) in check_entity.exits[direction].flags:
                            return True
                        else:
                            return False
                    elif check_parts[2][:5] == "DOOR.":
                        if check_entity.exits[
                                direction].door and check_entity.exits[
                                    direction].door.door_type and Element(
                                        check_parts[2]) in check_entity.exits[
                                            direction].door.door_type.flags:
                            return True
                        else:
                            return False
                elif check_parts[1] == "is not":
                    if check_parts[2] == "Exit":
                        return False
                    elif check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return False
                        else:
                            return True
                    elif check_parts[2] == "Door":
                        if check_entity.exits[
                                direction].door and check_entity.exits[
                                    direction].door.door_type:
                            return False
                        else:
                            return True
                    elif check_parts[2][:5] == "EXIT.":
                        if Element(check_parts[2]
                                   ) in check_entity.exits[direction].flags:
                            return False
                        else:
                            return True
                    elif check_parts[2][:5] == "DOOR.":
                        if check_entity.exits[
                                direction].door and check_entity.exits[
                                    direction].door.door_type and Element(
                                        check_parts[2]) in check_entity.exits[
                                            direction].door.door_type.flags:
                            return False
                        else:
                            return True
                else:
                    log.bug(
                        "Operatore di check sconosciuto: %s per il check %s" %
                        (check_parts[1], check))
                    return False

            if direction in check_entity.walls:
                if check_parts[1] == "is":
                    if check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return True
                        else:
                            return False
                elif check_parts[1] == "is not":
                    if check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return False
                        else:
                            return True

            return False

        # Tutti gli altri casi vengono gestiti come errore di sintassi
        log.bug("check del miml dalla sintassi errata: %s" % check)
        return False
Beispiel #28
0
    def parse_miml_check(self, check, looker=None):
        if not check:
            log.bug("check non è un parametro valido: %r" % check)
            return False

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

        check_parts = check.split()

        if check_parts[0][0 : 4] == "self":
            check_entity = self
        elif check_parts[0][0 : 8] == "location":
            if self.IS_ROOM:
                check_entity = self
            else:
                check_entity = self.location
        elif check_parts[0][0 : 17] == "previous_location":
            if self.IS_ROOM:
                check_entity = self
            else:
                check_entity = self.previous_location
        elif check_parts[0][0 : 6] == "looker":
            if not looker:
                log.bug("looker non valido (%r) anche se il check lo necessita: %s" % (looker, check))
                return False
            check_entity = looker
        elif check_parts[0][0 : 6] == "season":
            if check_parts[1] == "is":
                if calendar.season == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if calendar.season != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        else:
            log.bug("entità da utilizzare per i check è sconosciuta: %s" % check_parts[0])
            return False

        # (TD) no, dovrò splittare con or o and ed utilizzare le builtin any o all
        #for element_code in check_parts[2].split("|"):
        #    pass

        # Miml relativo alla razza dell'entità controllata
        if check_parts[2][0 : 5] == "RACE.":
            if check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.race == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.race != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo alla sessualità dell'entità controllata
        elif check_parts[2][0 : 4] == "SEX.":
            if check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.sex == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.sex != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo ai contenitori
        elif check_parts[2][0 : 10] == "CONTAINER.":
            if check_entity.IS_ROOM or not check_entity.container_type:
                return False

            if check_parts[1] == "is":
                if Element(check_parts[2]) in check_entity.container_type.flags:
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if Element(check_parts[2]) not in check_entity.container_type.flags:
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo al settore di una stanza
        elif check_parts[2][0 : 7] == "SECTOR.":
            if not check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if check_entity.sector == Element(check_parts[2]):
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if check_entity.sector != Element(check_parts[2]):
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo alle flags di una stanza
        elif check_parts[2][0 : 5] == "ROOM.":
            if not check_entity.IS_ROOM:
                return False

            if check_parts[1] == "is":
                if Element(check_parts[2]) in check_entity.flags:
                    return True
                else:
                    return False
            elif check_parts[1] == "is not":
                if Element(check_parts[2]) not in check_entity.flags:
                    return True
                else:
                    return False
            else:
                log.bug("Operatore di check sconosciuto: %s per l'elemento con codice %s" % (check_parts[1], check_parts[2]))
                return False
        # Miml relativo all'inventario portato
        elif check_parts[0][-14 : ] == ".inventory_qty":
            check_qty = 0
            if is_number(check_parts[2]):
                check_qty = int(check_parts[2])
            else:
                log.bug("la parte destra dell'opeartore del check miml %s non è un numbero valido" % (check))

            qty = 0
            for content in check_entity.iter_contains():
                if len(content.wear_mode) == 0 and FLAG.INGESTED not in content.flags:
                    qty += 1

            if check_parts[1] == "==" and qty == check_qty:
                return True
            elif check_parts[1] == "!=" and qty != check_qty:
                return True
            elif check_parts[1] == ">" and qty > check_qty:
                return True
            elif check_parts[1] == ">=" and qty >= check_qty:
                return True
            elif check_parts[1] == "<" and qty < check_qty:
                return True
            elif check_parts[1] == "<=" and qty <= check_qty:
                return True
            else:
                return False
        # Miml relativo all'equipaggiamento portato
        elif check_parts[0][-14 : ] == ".equipment_qty":
            check_qty = 0
            if is_number(check_parts[2]):
                check_qty = int(check_parts[2])
            else:
                log.bug("la parte destra dell'opeartore del check miml %s non è un numbero valido" % check)

            qty = 0
            for content in check_entity.iter_contains():
                if len(content.wear_mode) != 0 and FLAG.INGESTED not in content.flags:
                    qty += 1

            if check_parts[1] == "==" and qty == check_qty:
                return True
            elif check_parts[1] == "!=" and qty != check_qty:
                return True
            elif check_parts[1] == ">" and qty > check_qty:
                return True
            elif check_parts[1] == ">=" and qty >= check_qty:
                return True
            elif check_parts[1] == "<" and qty < check_qty:
                return True
            elif check_parts[1] == "<=" and qty <= check_qty:
                return True
            else:
                return False
        # Miml relativo alle exits, wall e direzioni
        elif get_direction_miml(check_parts[0]) != DIR.NONE:
            if not check_entity.IS_ROOM:
                return False

            direction = get_direction_miml(check_parts[0])
            if direction in check_entity.exits:
                if check_parts[1] == "is":
                    if check_parts[2] == "Exit":
                        return True
                    elif check_parts[2] == "Wall":
                        # Il check qui ci vuole comunque perché una direzione può
                        # avere sia uscita che muro, idem per il ramo 'is not'
                        if direction in check_entity.walls:
                            return True
                        else:
                            return False
                    elif check_parts[2] == "Door":
                        if check_entity.exits[direction].door and check_entity.exits[direction].door.door_type:
                            return True
                        else:
                            return False
                    elif check_parts[2][ : 5] == "EXIT.":
                        if Element(check_parts[2]) in check_entity.exits[direction].flags:
                            return True
                        else:
                            return False
                    elif check_parts[2][ : 5] == "DOOR.":
                        if check_entity.exits[direction].door and check_entity.exits[direction].door.door_type and Element(check_parts[2]) in check_entity.exits[direction].door.door_type.flags:
                            return True
                        else:
                            return False
                elif check_parts[1] == "is not":
                    if check_parts[2] == "Exit":
                        return False
                    elif check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return False
                        else:
                            return True
                    elif check_parts[2] == "Door":
                        if check_entity.exits[direction].door and check_entity.exits[direction].door.door_type:
                            return False
                        else:
                            return True
                    elif check_parts[2][ : 5] == "EXIT.":
                        if Element(check_parts[2]) in check_entity.exits[direction].flags:
                            return False
                        else:
                            return True
                    elif check_parts[2][ : 5] == "DOOR.":
                        if check_entity.exits[direction].door and check_entity.exits[direction].door.door_type and Element(check_parts[2]) in check_entity.exits[direction].door.door_type.flags:
                            return False
                        else:
                            return True
                else:
                    log.bug("Operatore di check sconosciuto: %s per il check %s" % (check_parts[1], check))
                    return False

            if direction in check_entity.walls:
                if check_parts[1] == "is":
                    if check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return True
                        else:
                            return False
                elif check_parts[1] == "is not":
                    if check_parts[2] == "Wall":
                        if direction in check_entity.walls:
                            return False
                        else:
                            return True

            return False

        # Tutti gli altri casi vengono gestiti come errore di sintassi
        log.bug("check del miml dalla sintassi errata: %s" % check)
        return False
Beispiel #29
0
def command_addexit(entity, argument=""):
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return False

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

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

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

    room = entity.location

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

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

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

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

    room.exits[direction] = exit
    entity.send_output("E' stata aggiunta l'uscita %s." % direction.to_dir)
    return True
Beispiel #30
0
def interpret(entity,
              argument,
              use_check_alias=True,
              force_position=True,
              show_input=True,
              show_prompt=True,
              behavioured=False):
    """
    Funzione che interpreta gli inputi inviati dalle entità.
    L'argomento use_check_alias a False viene passato dalla find_alias per
    evitare chiamate di alias da altri alias e quindi ricorsioni.
    """
    if not entity:
        log.bug("entity non è un parametro valido: %r" % entity)
        return

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

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

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

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

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

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

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

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

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

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

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

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

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

    if argument:
        argument = html_escape(argument)

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

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

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

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

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

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

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

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

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

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

    return execution_result
Beispiel #31
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