def defer_random_time(min_time, max_time, function, *args): """ Funzione che viene utilizzata quando si vogliono eseguire dei comandi dopo un certo tot di tempo. """ if min_time < 0: log.bug("min_time non è un parametro valido perchè minore di 0: %d" % min_time) return if max_time < min_time: log.bug("max_time non è un parametro valido perchè minore di min_time %d: %d" % (min_time, max_time)) return # ------------------------------------------------------------------------- if config.time_warp: time = 1 else: if min_time == max_time: time = min_time else: time = random.randint(min_time, max_time) key = get_key() _before_defer(key, function, *args) return task.deferLater(reactor, time, _after_defer, key, function, *args)
def get_browser_from_ua(user_agent): if not user_agent: log.bug("user_agent non è un parametro valido: r" % user_agent) return "" # ------------------------------------------------------------------------- if "MSIE " in user_agent: version = user_agent.split("MSIE")[1].split(".")[0] return "IE_" + version.strip() elif "Firefox/" in user_agent: version = user_agent.split("Firefox/")[1].split(".")[0] return "FIREFOX_" + version.strip() elif "Chrome/" in user_agent: version = user_agent.split("Chrome/")[1].split(".")[0] return "CHROME_" + version.strip() elif "Safari/" in user_agent: version = user_agent.split("Version/")[1].split(".")[0] return "SAFARI_" + version.strip() elif "Opera/" in user_agent: version = user_agent.split("Version/")[1].split(".")[0] return "OPERA_" + version.strip() elif "Iceweasel/" in user_agent: version = user_agent.split("Iceweasel/")[1].split(".")[0] return "FIREFOX_" + version.strip() elif "Kindle" in user_agent: versione = user_agent.split("Kindle/")[1].split(".")[0] return "KINDLE_" + version.strip() elif "Links (2" in user_agent: return "LINKS_2" elif "ELinks/0" in user_agent: return "ELINKS_0" return "???"
def command_score(entity, argument="", behavioured=False): """ Permette di visualizzare il proprio stato. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- if argument and entity.trust >= TRUST.MASTER: target = entity.find_entity(argument, entity_tables=["players", "mobs"]) if not target: entity.send_output("Non è stato trovato nessun giocatore o mob con argomento [white]%s[close]" % argument) return False target = target.split_entity(1) else: target = entity.split_entity(1) output = get_score_output(entity, target) if not output: log.bug("Inatteso output non valido con entity %s e target %s: %r" % (entity.code, target.code, output)) return False entity.send_output(output) return True
def blooming(pianta, room, age, fortuna): if pianta.code not in database["items"]: return fiore = Item("karpuram_item_mirtillo-rosso-04-fiore") if not fiore: log.bug("impossibile creare fiore: %r" % fiore) return location=pianta.location pianta.act("Nelle scorse ore $N ha aperto i fiori", TO.OTHERS, pianta) pianta.act("Nelle scorse ore $N ha aperto i fiori", TO.ENTITY, pianta) pianta.extract(1) fiore.inject(location) fiore.act("$N rifulge di tutto il suo splendore.", TO.OTHERS, fiore) fiore.act("$N rifulge di tutto il suo splendore.", TO.ENTITY, fiore) fortuna = fortuna -1 if random.randint(1, fortuna) == 1: reactor.callLater(random.randint( FLOWER_WAIT_MIN , FLOWER_WAIT_MAX ), desiccation, fiore, room, age ) return reactor.callLater(random.randint( FLOWER_WAIT_MIN , FLOWER_WAIT_MAX ),fructification , fiore, room, age, fortuna)
def marciume(seed, room): if seed.code not in database["items"]: return frutto_marcio = Item("karpuram_item_mirtillo-rosso-00-frutto-marcio") if not frutto_marcio: log.bug("impossibile creare frutto_marcio: %r" % frutto_marcio) return if room != seed.location: # log da rimuovere log.bug("room di drop diversa da room attuale") return location=seed.location seed.act("$N appare tutto molliccio...", TO.OTHERS, seed) seed.act("$N appare tutto molliccio...", TO.ENTITY, seed) seed.extract() frutto_marcio.inject(location) frutto_marcio.act("... è $N buono solo come concime.", TO.OTHERS, frutto_marcio) frutto_marcio.act("... è $N buono solo come concime.", TO.ENTITY, frutto_marcio)
def get_syntax_template_handler(entity, command_name): """ Esiste per essere chiamata anche dal comando command_skills e command_socials """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" if not command_name: log.bug("command_name non è un parametro valido: %r" % command_name) return "" # ------------------------------------------------------------------------- syntax = "" syntax += "%s\n" % command_name syntax += "%s italiano\n" % command_name syntax += "%s inglese\n" % command_name syntax += "%s traduzione\n" % command_name if command_name == "commands": syntax += "%s tipi\n" % command_name if entity.trust >= TRUST.MASTER: syntax += "%s fiducia\n" % command_name syntax += "%s <comando cercato>\n" % command_name return syntax
def command_mgoto(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_mgoto") entity.send_output(syntax, break_line=False) return False target, room, last_message = goto_entity_handler(entity, argument, "mobs") if not target or not room: return False if entity.location.IS_ROOM: old_coords = "%d %d %d" % (entity.location.x, entity.location.y, entity.location.z) else: old_coords = "$l" old_area_code = entity.location.area.code goto_message(entity, room, "mgoto") entity = entity.from_location(1, use_repop=True) entity.to_location(room, use_look=True) entity.act("$n arriva tramite un goto da %s %s" % (old_coords, old_area_code), TO.ADMINS) entity.send_output(put_final_dot(last_message)) return True
def get_error_message(self): """ Ritorna un messaggio di errore se qualcosa nel comando è sbagliata, altrimenti se tutto è a posto ritorna una stringa vuota. """ if not self.fun_name: msg = "il nome della funzione non è valido" elif (not self.fun_name.startswith("command_") and not self.fun_name.startswith("skill_") and not self.fun_name.startswith("social_")): msg = "il nome della funzione non inizia per command_, skill_ o social_" elif self.type.get_error_message(CMDTYPE, "type") != "": msg = self.type.get_error_message(CMDTYPE, "type") elif self.trust.get_error_message(TRUST, "trust") != "": msg = self.trust.get_error_message(TRUST, "trust") elif self.position.get_error_message(POSITION, "position") != "": msg = self.position.get_error_message(POSITION, "position") elif self.flags.get_error_message(CMDFLAG, "flags") != "": msg = self.flags.get_error_message(CMDFLAG, "flags") elif self.no_races.get_error_message(RACE, "no_races") != "": msg = self.no_races.get_error_message(RACE, "no_races") # Ignora i minihelp vuoti relativi ai comandi-social elif not self.mini_help and not self.fun_name.startswith("social_"): msg = "la stringa di mini help è vuota" elif self.timer < 0.0: msg = "il timer non può essere negativo: %f" % self.timer elif not self.module: msg = "modulo non importato" elif not self.function: msg = "funzione non importata" else: return "" # Se arriva qui significa che ha un messaggio da inviare log.bug("(Command: fun_name %s) %s" % (self.fun_name, msg)) return msg
def check_aggressiveness(aggressor, victim=None): """ Controlla se un'entità possa attaccarne un'altra se questa ultima viene passata come parametro, altrimenti viene cercata una possibile vittima. """ if not aggressor: log.bug("aggressor non è un parametro valido: %r" % aggressor) return # ------------------------------------------------------------------------- if FLAG.AGGRESSIVE not in aggressor.flags: log.bug("Inattesa chiamata senza che l'entità sia aggressiva: %s (victim: %s)" % (aggressor.code, victim.code if victim else "None")) return # Se non è stata passata una vittima ne cerca una if victim: if not aggressor.can_aggress(victim): return else: victims = [] for en in aggressor.location.iter_contains(): if aggressor.can_aggress(en): victims.append(en) if not victims: return victim = random.choice(victims) if aggressor.aggressivenesses: aggressiveness_loop.add(aggressor, victim) else: start_fight(aggressor, victim)
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)
def sense_messages_to_others_equipped(entity, target, messages, message_key, equipped_target): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not target: log.bug("target non è un parametro valido: %r" % target) return if not messages: log.bug("messages non è un parametro valido: %r" % messages) return if not message_key: log.bug("message_key non è un parametro valido: %r" % message_key) return if not equipped_target: log.bug("equipped_target non è un parametro valido: %r" % equipped_target) return # ------------------------------------------------------------------------- if target == entity: entity.act(messages[message_key + "_self"], TO.OTHERS) else: entity.act(messages[message_key + "_others"], TO.OTHERS, target) entity.act(messages[message_key + "_target"], TO.TARGET, target)
def nifty_value_search(dictionary, argument): if not dictionary: log.bug("dictionary non è un parametro valido: %r" % dictionary) return if not argument: log.bug("argument non è un parametro valido: %r" % argument) return # ------------------------------------------------------------------------- try: return dictionary[argument] except KeyError: # Se non ha trovato nulla allora prova a trovare in maniera # intelligente una chiave simile all'argomento passato pass argument = argument.lower() for key in dictionary: if is_same(argument, key): return dictionary[key] for key in dictionary: if is_prefix(argument, key): return dictionary[key] return None
def check_if_part_is_already_weared(entity, part): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return None, None if not part: log.bug("part non è un parametro valido: %r" % part) return None, None # ------------------------------------------------------------------------- # Dà prima la precedenza alle entità layerate così da ritornare l'entità # più esterna nella stratificazione dei vestiti for possession in entity.iter_contains(): if not possession.under_weared or not possession.under_weared(): continue if FLAG.INGESTED in possession.flags: continue for location in possession.wear_mode: if location == part: return part, possession for possession in entity.iter_contains(): if FLAG.INGESTED in possession.flags: continue for location in possession.wear_mode: if location == part: return part, possession return None, None
def command_title(entity, argument=""): """ Permette al giocatore d'inserire un proprio title al personaggio. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- if not argument: syntax = get_command_syntax(entity, "command_title") entity.send_output(syntax, break_line=False) return False if not entity.IS_PLAYER: entity.send_output("Non ti è possibile impostare un titolo.") return if is_same(argument, "cancella") or is_same(argument, "delete"): entity.title = "" entity.send_output("Il tuo titolo è stato cancellato.") return True color_qty = count_colors(argument) # (TD) In futuro non farlo dipendente dal livello ma da qualche achievement o quest if color_qty > entity.level / 2: entity.send_output("Devi crescere di livello se vuoi colorare maggiormente il tuo titolo.") return False entity.title = close_color(argument) entity.send_output("Il tuo titolo è stato modificato in: '%s'" % entity.title) return True
def __init__(self, direction=DIR.NONE): if not direction: log.bug("direction non è un parametro valido: %r" % direction) return # --------------------------------------------------------------------- self.comment = "" # Eventuale commento all'uscita self.direction = Element(direction) # Tipologia della direzione self.descr = "" # Descrizione di quello che si vede guardando la direzione self.descr_night = "" # Descrizione notturna di quello che si vede guardando la direzione self.descr_hearing = "" # Descrizione uditiva self.descr_hearing_night = "" # Descrizione uditiva notturna self.descr_smell = "" # Descrizione odorosa self.descr_smell_night = "" # Descrizione odorosa notturna self.descr_touch = "" # Descrizione tattile self.descr_touch_night = "" # Descrizione tattile notturna self.descr_taste = "" # Descrizione del sapore self.descr_taste_night = "" # Descrizione del sapore notturna self.descr_sixth = "" # Descrizione del sesto senso self.descr_sixth_night = "" # Descrizione del sesto senso notturna self.icon = "" # Icona rappresentante l'uscita di giorno self.icon_night = "" # Icona rappresentante l'uscita di notte self.extras = Extras() # Descrizioni extra dell'uscita self.flags = Flags(EXIT.NONE) # Flags dell'uscita self.destination = None # Stanza a cui l'uscita porta se questa differente rispetto alla direzione presa self.door = None # Oggetto porta se serve aprirla (se non viene indicata questa viene caricata dal limbo una porta di default) (TD) qui vorrei aggiungere anche una variabile finestra.. ma poi come gestire finestre e porte multiple? e il key_code nel qual caso una finestra sia chiudibile (cmq per ora continuo così.. in effetti potrei considerare il fatto di voler inserire più porte o finestre in una uscita come una eccezione e gestirla tramite gamescripts) self.entity_message = "" # Messaggio di movimento per colui che si sta spostando self.others_in_message = "" # Messaggio di movimento per gli altri della stanza di partenza self.others_out_message = "" # Messaggio di movimento per gli altri della stanza di arrivo
def look_for_caterpillar(dust, show_act=True): if not dust: log.bug("dust non è un parametro valido: %r" % dust) return caterpillar = dust.find_entity("bruco", dust.location, ["mobs"]) if not caterpillar: if show_act: dust.act("My name is $n: niente bruchi" % dust, TO.OTHERS) dust.act("My name is $n: niente bruchi" % dust, TO.ENTITY) defer(60, look_for_caterpillar, dust) return if show_act: dust.act("My name is $n, ho visto un bruco: %r" % caterpillar, TO.OTHERS) dust.act("My name is $n, ho visto un bruco: %r" % caterpillar, TO.ENTITY) command_say(caterpillar, "sa la vist cus'è?") #defer(60, look_for_caterpillar, dust) # il bruco potrebbe essere soggetto a script che lo potrebbero mutare senza # avvisaglie quindi tolgo di mezzo il bruco per sostituirlo con un altro # che so non essere afflitto da script location = caterpillar.location caterpillar.extract(1) new_caterpillar = Mob(PROTO_CATERPILLAR_CODE) new_caterpillar.inject(location) new_caterpillar.act("$n cambia aspetto in modo repentino.", TO.OTHERS) dust_eating(dust, new_caterpillar)
def send_input(entity, argument, lang="", show_input=True, show_prompt=True): """ Invia un input preoccupandosi di convertirlo prima nella lingua corretta per essere trovata dall'interprete. E' importante che l'argomento lang sia corrispondente alla lingua dell'input in argument. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" if not argument: log.bug("argument non è un parametro valido: %r" % argument) return "" if lang != "it" and lang != "en" and lang != "": log.bug("lang non è un parametro valido: %r" % lang) return "" if show_input != True and show_input != False: log.bug("show_input non è un parametro valido: %r" % show_input) return "" if show_prompt != True and show_prompt != False: log.bug("show_prompt non è un parametro valido: %r" % show_prompt) return "" # ------------------------------------------------------------------------- args = argument.split() args[0] = translate_input(entity, args[0], lang) argument = " ".join(args) # Invia il comando ottenuto all'interprete interpret(entity, argument, show_input=show_input, show_prompt=show_prompt)
def number_argument(argument): """ Se l'argomento passato è una stringa di questo tipo: 2.spada ritorna 2 e spada. Non esegue controlli sul numero ricavato. """ if not argument: log.bug("argument non è un parametro valido: %r" % argument) return -1, "" # ------------------------------------------------------------------------- number = 1 original_argument = argument if "." in argument: number, argument = argument.split(".", 1) if not number or not is_number(number) or not argument: return 1, original_argument # Se il numero è minore di zero, allora non lo considera e ritorna # tutto l'argomento number = int(number) if number < 1: return 1, original_argument return number, argument
def dice(argument, for_debug=None): if not argument: log.bug("argument non è un parametro valido: %r" % argument) return 0 # ------------------------------------------------------------------------- argument = argument.lower() if "d" in argument: dice_qty, dice_size = argument.split("d", 1) else: log.bug("Non è stata passata un'espressione dice valida: %s (for_debug=%s)" % (argument, for_debug)) return 0 addend = "" if "+" in dice_size: dice_size, addend = dice_size.rsplit("+", 1) elif "-" in dice_size: dice_size, addend = dice_size.rsplit("-", 1) addend = "-" + addend dice_qty = int(dice_qty) dice_size = int(dice_size) addend = int(addend) result = 0 while dice_qty > 0: result += random.randint(1, dice_size) dice_qty -= 1 return result + addend
def html_escape(text): """ Funzioncina che serve a convertire i caratteri <, > e & nelle rispettive entità html. """ if not text: log.bug("text non è un parametro valido: %r" % text) return "" # ------------------------------------------------------------------------- # La & deve essere la prima ad essere sostituita if "&" in text: text = text.replace("&", "&") if "<" in text: text = text.replace("<", "<") if ">" in text: text = text.replace(">", ">") if '"' in text: text = text.replace('"', """) if "'" in text: text = text.replace("'", "'") #if "/" in text: # text = text.replace("/", "/") #if "+" in text: # text = text.replace("+", "+") #if ":" in text: # text = text.replace(":", ":") #if ";" in text: # text = text.replace(";", ";") return text
def reverse_one_argument(argument, search_separator=True): """ Come la one_argument, ma esegue la ricerca partendo dal fondo. """ if not argument: if argument != "": log.bug("argument non è un parametro valido: %r" % argument) return "", "" # ------------------------------------------------------------------------- separator = " " end = len(argument) if search_separator and argument[-1] == '"': separator = '"' end = len(argument) - 1 elif search_separator and argument[-1] == "'": separator = "'" end = len(argument) - 1 elif argument[-1] == " ": log.bug("argument finisce con uno spazio: %s" % argument) end = len(argument) - 1 length = 0 for c in reversed(argument[ : end]): if c == separator: break length += 1 return argument[ : end-length].strip(), argument[end-length : end].strip()
def interpret_or_echo(entity, argument, looker=None, behavioured=False): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not argument: log.bug("argument non è un parametro valido: %r" % argument) return # ------------------------------------------------------------------------- if MIML_SEPARATOR in argument: argument = entity.parse_miml(argument) if not argument: return if "$" in argument: argument = looker.replace_act_tags(argument, target=entity) if "$" in argument: argument = looker.replace_act_tags_name(argument, looker=looker, target=entity) original_argument = argument arg, argument = one_argument(argument) input, huh_input, lang = multiple_search_on_inputs(entity, arg, exact=True) if input: interpret(entity, original_argument, use_check_alias=False, show_input=False, show_prompt=False, behavioured=behavioured) else: entity.location.echo(original_argument)
def check_position(entity, position, force_position=True): """ Controlla che la posizione del comando passata sia adatta a quella che l'entità ha in questo momento. Viene passata force_position a False quando bisogna evitare ricorsioni. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not position: log.bug("position non è un parametro valido: %r" % position) return False # ------------------------------------------------------------------------- # Se un mob non può eseguire il comando allora cerca di mettersi # nella posizione adatta ad eseguirlo if force_position and not entity.IS_PLAYER and entity.position < position: if position == POSITION.SLEEP: command_sleep(entity, argument) elif position == POSITION.REST: command_rest(entity, argument) elif position == POSITION.KNEE: command_knee(entity, argument) elif position == POSITION.SIT: command_sit(entity, argument) elif position == POSITION.STAND: command_stand(entity, argument) # Se la posizione dell'entità è corretta allora può eseguire il comando if entity.position >= position: return True return False
def _get_already_deferred_arg(deferred_params, arg): if not deferred_params: log.bug("deferred_params non è un parametro valido: %r" % deferred_params) return False, None if not arg: log.bug("arg non è un parametro valido: %r" % arg) return False, None # ------------------------------------------------------------------------- for deferred_entities in deferred_params: for deferred_entity in deferred_entities: if not deferred_entity(): return False, None if deferred_entity() == arg: #if arg.prototype.code == "ikea_item_uovo-gallina": # f = open("gallina.txt", "a") # buf = "impostata la deferred_entity alla _after_defer: %r / %r, %r / %r, %d / %d, %r / %r, %r / %r\n" % ( # arg.code, deferred_entities[-1].code, arg.location, deferred_entities[-1].location, arg.quantity, deferred_entities[-1].quantity, # FLAG.EXTRACTED in arg.flags, FLAG.EXTRACTED in deferred_entities[-1].flags, FLAG.WEAKLY_EXTRACTED in arg.flags, FLAG.WEAKLY_EXTRACTED in deferred_entities[-1].flags) # f.write(buf) # print buf # import traceback # traceback.print_stack(file=f) # f.close() return True, arg return False, None
def get_formatted_equipment_list(entity, target, show_header=True, show_footer=True): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" if not target: log.bug("target non è un parametro valido: %r" % target) return "" # ------------------------------------------------------------------------- output = get_equipment_list(entity, target) if show_header: if target == entity: if output: output = ["[red]Stai utilizzando[close]:\n"] + output else: output.append("Non stai utilizzando nulla, sei %s!\n" % entity.skin_colorize("nud$o")) else: if output: output = ["%s [red]sta utilizzando[close]:\n" % color_first_upper(target.get_name(entity))] + output else: output.append("%s non sta utilizzando nulla, è %s!\n" % ( color_first_upper(target.get_name(looker=entity)), target.skin_colorize("nud%s" % grammar_gender(target)))) if show_footer: carry_equip_descr = get_weight_descr(target.get_equipped_weight()) output.append(create_demi_line(entity)) output.append("Stai indossando un peso totale di %s." % carry_equip_descr) return "".join(output)
def pretty_list(list_to_convert): """ Ritorna una frase descrivendo un elenco, separato da virgole o dalla congiunzione 'e', partendo da una lista di stringhe. """ if not list_to_convert: log.bug("list_to_convert non è un parametro valido: %r" % list_to_convert) return # ------------------------------------------------------------------------- if len(list_to_convert) == 1: return str(list_to_convert[0]) arguments = [] for argument in list_to_convert: argument = str(argument).strip() if len(list_to_convert) >= 2 and argument == str(list_to_convert[-1]): arguments.append(" e " + argument) else: if argument == str(list_to_convert[0]): arguments.append(argument) else: arguments.append(", " + argument) return "".join(arguments)
def __init__(self, direction=DIR.NONE): if not direction: log.bug("direction non è un parametro valido: %r" % direction) return # --------------------------------------------------------------------- self.comment = "" # Eventuale commento al muro self.direction = Element(direction) # Tipologia della direzione self.maked_by = None # Oggetto di base utilizzato nella costruzione del muro (di solito un mattone o una pietra) self.depth = 0 # Profondità della parete, assieme al tipo di materiale in quella direzione ne fanno la forza, che serve nel caso si voglia romperlo, picconarlo, sfondarlo o farlo saltare in aria! self.height = 0 # Altezza del muro, se differente dall'altezza della stanza self.descr = "" # Descrizione dell'uscita che viene a formarsi quando il muro viene sfondato self.descr_night = "" # Descrizione notturna dell'uscita che viene a formarsi quando il muro viene sfondato self.descr_hearing = "" # Descrizione uditiva self.descr_hearing_night = "" # Descrizione uditiva notturna self.descr_smell = "" # Descrizione odorosa self.descr_smell_night = "" # Descrizione odorosa notturna self.descr_touch = "" # Descrizione tattile self.descr_touch_night = "" # Descrizione tattile notturna self.descr_taste = "" # Descrizione del sapore self.descr_taste_night = "" # Descrizione del sapore notturna self.descr_sixth = "" # Descrizione del sesto senso self.descr_sixth_night = "" # Descrizione del sesto senso notturna self.extras = Extras() # Elenco delle extra che si possono guardare o leggere sul muro
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- syntax = "" syntax += "restring <nome o codice entità>\n" syntax += "restring <nome o codice entità> KeywordsName <nuove chiavi>\n" syntax += "restring <nome o codice entità> KeywordsShort <nuove chiavi>\n" syntax += "restring <nome o codice entità> KeywordsShortNight <nuove chiavi>\n" syntax += "restring <nome o codice entità> Name <nuovo nome>\n" syntax += "restring <nome o codice entità> Short <nuova short>\n" syntax += "restring <nome o codice entità> ShortNight <nuova short>\n" syntax += "restring <nome o codice entità> Long <nuova long>\n" syntax += "restring <nome o codice entità> LongNight <nuova long>\n" syntax += "restring <nome o codice entità> Descr <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrNight <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrHearing <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrHearingNight <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrSmell <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrSmellNight <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrTouch <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrTouchNight <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrTaste <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrTasteNight <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrSixth <nuova descrizione>\n" syntax += "restring <nome o codice entità> DescrSixthNight <nuova descrizione>\n" return syntax
def can_aggress(aggressor, victim): """ Funzione con le regole di aggressivibilità di un'entità rispetto ad un'altra. I giocatori sono sempre aggredibili, mentre per le altre entità vengono utilizzate regole di legge della natura semplificate. """ if not aggressor: log.bug("aggressor non è un parametro valido: %r" % aggressor) return if not victim: log.bug("victim non è un parametro valido: %r" % victim) return # ------------------------------------------------------------------------- # I giocatori vengono attaccati solo se di livello relativamente uguale o # basso rispetto all'aggressore if victim.IS_PLAYER and victim.level <= aggressor.level+1: return True # Attacca per cibo if FLAG.CARNIVOROUS in aggressor.flags and FLAG.HERBIVORE in victim.flags: return True # Attacca per territorio if FLAG.CARNIVOROUS in aggressor.flags and FLAG.CARNIVOROUS in victim.flags: return True return False
def renew(fruttificato, room, age, fortuna): if fruttificato.code not in database["items"]: return pianta = Item("karpuram_item_mirtillo-rosso-03-pianta") if not pianta: log.bug("impossibile creare pianta: %r" % pianta) return age = age +1 location=fruttificato.location fruttificato.act("quel che un tempo doveva esser $N, ora ...", TO.OTHERS, fruttificato) fruttificato.act("quel che un tempo doveva esser $N, ora ...", TO.ENTITY, fruttificato) fruttificato.extract(1) pianta.inject(location) pianta.act("... è $N che fruttificherà più avanti", TO.OTHERS, pianta) pianta.act("... è $N che fruttificherà più avanti", TO.ENTITY, pianta) fortuna = fortuna -1 if random.randint(1, fortuna) == 1: reactor.callLater(random.randint(10,20), desiccation, pianta, room, age ) return reactor.callLater(random.randint(10,20), blooming, pianta, room, age, fortuna)
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "typo <errore testuale trovato>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "comment <commento che si vuole esprimere>\n"
def __str__(self): if self.synonym: return self.synonym elif self.enum_element: return self.enum_element.name log.bug("enum_element errato per %r con synonym %r" % (self, self.synonym)) return "<error>"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "hold <nome oggetto o creatura>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "idea <idea avuta che si vuole segnalare>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return get_syntax_template_handler(entity, "socials")
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "thunder <nome bersaglio> <messaggio da tuonare al bersaglio>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "unlock <porta o contenitore da aprire>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "chat <messaggio da inviare in off-gdr>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "hissing <nome bersaglio> <messaggio da sibilare al bersaglio>"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "gtell <messaggio off-gdr da dire al gruppo>\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "exit <entità da cui vuoi uscire>\n"
def hair_colorize(self, argument): if not argument: log.bug("argument non è un parametro valido: %r" % argument) return "" # --------------------------------------------------------------------- return "[black]%s[close]" % argument
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "spare\n"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "wield <nome arma o oggetto>\n"
def command_iinvoke(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- return invoke_handler(entity, argument, "command_iinvoke", "items")
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "money <oggetto o creatura da comprare> (commerciante se più di uno nella stanza)\n"
def command_comment(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- return send_note(entity, argument, "command_comment", "comment", "commento", "commenti", Comment, GRAMMAR.MASCULINE)
def pretty_money_value(value, extended=False, entity=None): if value < 0: log.bug("Il parametro value non è una quantità valida: %r" % value) return "" # ------------------------------------------------------------------------- # (TD) Se entity è stato passato allora fa vedere con che monete paga il negoziante if entity: return "" # Nel qual caso arrivi qui con un prezzo di 0 if value == 0: if extended: return "0 monete di [copper]rame[close]" else: return "0 di [copper]rame[close]" mithril, gold, silver, copper = compute_currencies(value) if mithril > 0: if extended: mithril = "%d monet%s di [white]mithril[close]" % (mithril, "a" if mithril == 1 else "e") else: mithril = "%d di [white]mithril[close]" % mithril else: mithril = "" if gold > 0: if extended: gold = "%d monet%s d'[gold]oro[close]" % (gold, "a" if gold == 1 else "e") else: gold = "%d d'[gold]oro[close]" % gold else: gold = "" if silver > 0: if extended: silver = "%d monet%s d'[lightgray]argento[close]" % (silver, "a" if silver == 1 else "e") else: silver = "%d d'[lightgray]argento[close]" % silver else: silver = "" if copper > 0: if extended: copper = "%d monet%s di [copper]rame[close]" % (copper, "a" if copper == 1 else "e") else: copper = "%d di [copper]rame[close]" % copper else: copper = "" descr = "" for coin in (mithril, gold, silver, copper): if coin: descr += "%s, " % coin descr = descr.rstrip(", ") if "," in descr: descr = descr[::-1].replace(",", "e ", 1)[::-1] return descr
def is_masculine(argument): """ Ritorna vero se l'argomento passato è una parola maschile. """ if not argument: log.bug("argument non è un parametro valido: %r" % argument) return False # ------------------------------------------------------------------------- # Bisogna avere per forza un dizionario che indichi le eccezioni non # ricavabili dalla funzione for entry_word in vocabulary: if is_same( argument, (entry_word.masculine_singular, entry_word.masculine_plural)): return True elif is_same( argument, (entry_word.feminine_singular, entry_word.feminine_plural)): return False word = grammar_cleaner(argument) # Di solito le parole con la 'a' finale non sono maschili if word[-1] == "a": # Le parole che finiscono in "essa" non sono maschili if is_suffix("essa", word): return False # Le tipologie di derivazione greca che finiscono in "ma" sono maschili if is_same(word, ("diploma", "dramma", "poema", "teorema", "problema")): return True # Altre parole maschili if is_same(word, ("duca", "nulla", "papa", "pigiama", "poeta", "profeta", "vaglia")): return True return False elif word[-1] == "e": # Se la parole finisce in "tore" è maschile if is_suffix("tore", word): return True # Se finisce in "sore" la maggior parte delle volte è maschile if is_suffix("sore", word): return True # Quelle che finiscono in trice sono femminili if is_suffix("trice", word): return False return True elif word[-1] == "i": return True elif word[-1] == "o": return True elif word[-1] == "u": return True return False
def skill_counter(entity, target, verbs=VERBS, silent=False): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "failure" if not target: log.bug("target non è un parametro valido: %r" % target) return "failure" # ------------------------------------------------------------------------- if "counter" not in entity.skills: entity.skills["counter"] = 0 if entity.skills["counter"] <= 0: return "failure" skill_result = check_skill(entity, target, "counter") if skill_result < config.clumsy_value: if not silent: entity.act( "\nTenti maldestramente di %s di $N ma ti ingarbugli e perdi il ritmo dell'attacco." % verbs["infinitive"], TO.ENTITY, target) entity.act( "$n tenta maldestramente di %s di $N ma si ingarbuglia e perde il ritmo dell'attacco." % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n tenta maldestramente di %s ma si ingarbuglia e perde il ritmo dell'attacco." % verbs["you2"], TO.TARGET, target) return "clumsy" elif skill_result < config.failure_value: # Nessun messaggio se v'è il fallimento return "failure" elif skill_result < config.success_value: if not silent: entity.act( "\nRiesci ad anticipare il ritmo del colpo di $N e %s." % verbs["noun"], TO.ENTITY, target) entity.act( "$n riesce ad anticipare il ritmo del colpo di $N e %s." % verbs["noun"], TO.OTHERS, target) entity.act( "$n riesce ad anticipare il ritmo del tuo colpo e %s." % verbs["you2"], TO.TARGET, target) return "success" else: if not silent: entity.act( "\nRiesci magistralmente a %s il colpo di $N prendendol$O alla sprovvista." % verbs["infinitive"], TO.ENTITY, target) entity.act( "$n riesce magistralmente a %s il colpo di $N prendendol$O alla sprovvista." % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n riesce magistralmente a %s il tuo colpo prendendoti alla sprovvista." % verbs["infinitive"], TO.TARGET, target) return "masterly"
def get_syntax_template(entity): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return "" # ------------------------------------------------------------------------- return "speak\n" return "speak <colui con cui vuoi dialogare>\n"
def command_snoopers(entity, argument=""): """ Permette di visualizzare tutto l'output di uno o più entità. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- target = None if argument: target = entity.find_entity(argument, entity_tables=["players"], avoid_equipment=False) if not target: entity.send_output( "Non trovi nessun amministratore con argomento [white]%s[close]" % argument) return False if target.trust < TRUST.MASTER: entity.send_output("Il giocatore %s non è un amministratore." % target.name) return False syntax = get_command_syntax(entity, "command_snoopers") entity.send_output(syntax, break_line=False) return False snooped_by = {} players_founded = False players = database["players"].values() for admin in players: if admin.trust < TRUST.MASTER or admin.trust > entity.trust: continue if target and admin != target: continue snooped_by[admin] = [] for player in players + database["mobs"].values( ) + database["items"].values(): if admin in player.snoopers: snooped_by[admin].append(player) players_founded = True lines = [] for admin, snooped_players in snooped_by.iteritems(): if not snooped_players: continue lines.append("Entità snoopate da %s:" % admin.name) for snooped_player in snooped_players: lines.append(snooped_player.name) if players_founded: entity.send_output("\n".join(lines)) else: entity.send_output("Nessun giocatore snoopato dagli amministratori.") return True
def command_restore(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- if not argument: if entity.life >= entity.max_life: syntax = get_command_syntax(entity, "command_restore") entity.send_output(syntax, break_line=False) return False else: argument = entity.code target = entity.find_entity_extensively(argument) if not target: entity.send_output( "Nessuna entità trovata con argomento [white]%s[close]." % argument) return False if target.IS_PLAYER and entity.trust < TRUST.IMPLEMENTOR: entity.send_output( "Non ti è possibile ripristinare i punti dei personaggi.") return False # Ripristino prima di inviare il messaggio cosicché il prompt visualizza # correttamente il tutto target.life = target.max_life target.mana = target.max_mana target.vigour = target.max_vigour if target.IS_ACTOR: target.thirst = 0 target.hunger = 0 target.sleep = 0 target.drunkness = 0 target.adrenaline = 0 target.mind = 0 target.emotion = 0 target.bloodthirst = 0 if entity == target: entity.act("Ti invii un flusso d'energia per ripristinarti!", TO.ENTITY, target) entity.act("$n si invia un flusso d'energia per ripristinarsi!", TO.OTHERS, target) else: entity.act("Invii un flusso d'energia su di $N che lo ripristina!", TO.ENTITY, target) entity.act("$n invia un flusso d'energia su di $N che lo ripristina!", TO.OTHERS, target) target.act( "$n ti invia un flusso d'energia su di te che ti ripristina!", TO.TARGET, target) return True
def command_typo(entity, argument): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- return send_note(entity, argument, "command_typo", "typo", "typo", "typo", Typo, GRAMMAR.MASCULINE)
def __repr__(self): if self.enum_element: if self.synonym: return "%s %s" % (repr(self.enum_element), self.synonym) else: return "%s" % repr(self.enum_element) else: log.bug("enum_element errato per %r con synonym %r" % (self, self.synonym)) return "<errore!> %s" % self.synonym
def command_idea(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- return send_note(entity, argument, "command_idea", "idea", "idea", "idee", Idea, GRAMMAR.FEMININE)
def command_aliases(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- entity.send_output('''Puoi modificare gli alias in <a href="/aliases.html", target="aliases">questa pagina</a>.''') return True
def command_rinvoke(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- entity.send_output("Non ancora funzionante, ma chissà se un giorno...") return False
def command_colors(entity, argument=""): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # ------------------------------------------------------------------------- entity.send_output('''Una lista dei colori si può vedere alla pagina <a href="/builder_pages/colors.htm", target="colors">questa pagina</a>.''') return True