def execute(self): """ Anche ai giocatori offline esegue la digestione. """ if not self.is_valid(): return entity = self.entity() ingested = self.ingested() force_return = check_trigger(entity, "before_digestion", self) if force_return: return force_return = check_trigger(ingested, "before_digested", self) if force_return: return entity.act("Dall'aria che sale dal tuo stomaco sembra che tu abbia appena digerito $N.", TO.ENTITY, ingested) # Per galanteria viene inviato solo una volta ogni tanto if random.randint(0, 100) == 0: entity.act("A $n scappa un rutto! Sembra che abbia appena digerito qualcosa.", TO.OTHERS, ingested) entity.act("Sembra che $n ti abbia appena digerito, è giunto il momento di andare sempre più giù...", TO.TARGET, ingested) ingested.extract(ingested.quantity, use_repop=True) force_return = check_trigger(entity, "after_digestion", self) if force_return: return force_return = check_trigger(ingested, "after_digested", self) if force_return: return
def dies(self, opponent=None, auto_loot=False, teleport_corpse=False, quantity=1): force_return = check_trigger(self, "before_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "before_dies", self, opponent) if force_return: return self.life = 0 # Se l'entità era già stata rotta allora stavolta la fa sparire if self.code.startswith("rip_item_broken-"): remains, use_repop = None, True else: remains, use_repop = self.make_remains(auto_loot) force_return = check_trigger(self, "after_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "after_dies", self, opponent) if force_return: return self.extract(quantity, use_repop=use_repop)
def __init__(self, code=""): super(Mob, self).__init__() BehaviourUpdaterSuperclass.__init__(self) self.code = "" self.prototype = None if code: self.reinit_code(code) copy_existing_attributes(self.prototype, self, except_these_attrs=["code"]) self.after_copy_existing_attributes() # Eventuale inizializzazione dei punti if self.max_life == 0: self.max_life = config.starting_points if self.max_mana == 0: self.max_mana = config.starting_points if self.max_vigour == 0: self.max_vigour = config.starting_points if self.life == 0: self.life = self.max_life if self.mana == 0: self.mana = self.max_mana if self.vigour == 0: self.vigour = self.max_vigour if self.hand == HAND.NONE: self.hand = self.hand.randomize() # Variabili proprie di una istanza di mob: self.area = None self.attack = 1 self.defense = 1 self.speaking = Element( LANGUAGE.COMMON ) # Indica con quale linguaggio sta attualmente parlando il mob self.style = Element( STYLE.NONE) # Style di combattimento che sta utilizzando self.experience = 0 # Esperienza accumulata prima di poter livellare self.mount = None # Indica quale mob o pg sta cavalcando self.mounted_by = None # Indica da quali mob o pg è cavalcato self.specials = { } # E' una lista di variabili speciali, possono essere utilizzate come delle flags, vengono aggiunte di solito nei gamescript self.reply = None # Entità a cui si può replicare # self.tracking = Track() # Serve quando il mob inizia a tracciare e cacciare una preda fuggita self.last_fight_time = None self.last_death_time = None # Contatori di statistica self.defeat_from_mob_counter = 0 # Conteggio delle sconfitte self.defeat_from_item_counter = 0 # Conteggio delle sconfitte self.defeat_from_player_counter = 0 # Conteggio delle sconfitte self.death_from_player_counter = 0 # Conteggio delle sconfitte self.mob_defeated_counter = 0 # Conteggio delle vittorie sui mob self.item_defeated_counter = 0 # Conteggio degli oggetti distrutti self.player_defeated_counter = 0 # Conteggio delle vittorie sui giocatori self.player_killed_counter = 0 # Conteggio delle volte che viene ucciso un giocatore check_trigger(self, "on_init", self)
def digging_an_inexistent_exit_2(entity, location, direction, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not location: log.bug("location non è un parametro valido: %r" % location) return if not direction or direction == DIR.NONE: log.bug("direction non è un paramtro valido: %r" % direction) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # ------------------------------------------------------------------------- entity.action_in_progress = None entity.act("\nSmetti di %s %s, non hai trovato niente. Tanta fatica per nulla!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act("$n smette di %s, sembra non aver trovato niente %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act("$n smette di %s, sembra non aver trovato niente %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location) entity.send_prompt() # (TD) imparare un po' la skill scava, ma poco force_return = check_trigger(entity, "after_dig", entity, location, None, direction, behavioured) if force_return: return True force_return = check_trigger(location, "after_digged", entity, location, None, direction, behavioured) if force_return: return True
def command_equipment(entity, argument="", behavioured=False): """ Permette di visualizzare il proprio equipaggiamento. """ # Normale se questo comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: target = entity else: target = entity.find_entity_extensively(argument) if not target: entity.act("Non vedi nessun [white]%s[close] qui attorno." % argument, TO.ENTITY) entity.act("$n cerca qualcuno qui attorno.", TO.OTHERS) return False force_return = check_trigger(entity, "before_equipment", entity, None if entity == target else target, behavioured) if force_return: return True entity.send_output(get_formatted_equipment_list(entity, target)) force_return = check_trigger(entity, "after_equipment", entity, None if entity == target else target, behavioured) if force_return: return True return True
def dies(self, opponent=None, auto_loot=False, teleport_corpse=False): force_return = check_trigger(self, "before_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "before_dies", self, opponent) if force_return: return #self.send_output('''<script>$("#output").vibrate();</script>''') # (bb) if not self.location: log.always("%s è mort%s." % (self.get_name(), grammar_gender(self)), log_stack=False) else: log.always("%s è mort%s a %s" % (self.get_name(), grammar_gender(self), self.location.get_name()), log_stack=False) self.life = 1 remains, use_repop = self.make_remains(auto_loot) remains.corpse_type.was_player = True if teleport_corpse: self.recall(also_entities=[remains]) else: self.recall() self.flags -= FLAG.BEATEN if self.action_in_progress and self.action_in_progress.defer_later: self.action_in_progress.stop() self.action_in_progress = None force_return = check_trigger(self, "after_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "after_dies", self, opponent) if force_return: return
def command_inventory(entity, argument="", behavioured=False): """ Permette di visualizzare il proprio inventario. """ # Normale se questo comando è stato deferrato if not entity: return False entity = entity.split_entity(1) # (TD) I trigger di inventory funzionano cmq con il target perché in futuro # ci sarà la skill apposita per visualizzare l'inventario anche se adesso # è solo lato admin if not argument or entity.trust <= TRUST.PLAYER: target = entity else: target = entity.find_entity_extensively(argument) if not target: entity.act("Non vedi nessun [white]%s[close] qui attorno." % argument, TO.ENTITY) entity.act("$n sembra stia cercando qualcuno qui attorno che però non c'è.", TO.OTHERS) return False force_return = check_trigger(entity, "before_inventory", entity, None if entity == target else target, behavioured) if force_return: return True entity.send_output(get_formatted_inventory_list(entity, target), break_line=False) force_return = check_trigger(entity, "after_inventory", entity, None if entity == target else target, behavioured) if force_return: return True return True
def digging_a_diggable_exit_2(entity, location, direction, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not location: log.bug("location non è un parametro valido: %r" % location) return if not direction or direction == DIR.NONE: log.bug("direction non è un paramtro valido: %r" % direction) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # ------------------------------------------------------------------------- # (TD) Bisognerà fare i check se l'uscita esista ancora entity.action_in_progress = None entity.act( "\nSmetti di %s quando i tuoi sforzi rivelano l'esistenza di un passaggio %s!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act( "$n smette di %s quando scopre un passaggio %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act( "$n smette di %s quando scopre un passaggio %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location) entity.send_prompt() location.exits[direction].flags -= EXIT.DIGGABLE reverse_exit = location.get_reverse_exit(direction) if reverse_exit: reverse_exit.flags -= EXIT.DIGGABLE # Rimuove l'eventuale flag di secret alle eventuali due porte ai lati normal_door = location.get_door(direction, reverse_search=False) if normal_door and normal_door.door_type and DOOR.SECRET in normal_door.door_type.flags: normal_door.door_type.flags -= DOOR.SECRET reverse_door = location.get_door(direction, direct_search=True) if reverse_door and reverse_door.door_type and DOOR.SECRET in reverse_door.door_type.flags: reverse_door.door_type.flags -= DOOR.SECRET # (TD) imparare un po' la skill scava dai propri successi force_return = check_trigger(entity, "after_dig", entity, location, None, direction, behavioured) if force_return: return True force_return = check_trigger(location, "after_digged", entity, location, None, direction, behavioured) if force_return: return True
def flee_with_portal(entity, messages, opponent=None): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not messages: log.bug("messages non è un parametro valido: %r" % messages) return False # ------------------------------------------------------------------------- portals = [] for en in entity.location.iter_contains(): if FLAG.NO_LOOK_LIST in en.flags and en.entitype == ENTITYPE.PORTAL and en.portal_type: portals.append(en) if not portals: entity.act(messages["entity"], TO.ENTITY, opponent) entity.act(messages["others"], TO.OTHERS, opponent) if "target" in messages: entity.act(messages["target"], TO.TARGET, opponent) return False if random.randint(0, 1) == 0: entity.act( "Non riesci a cogliere l'attimo giusto per la %s!" % verbs["noun"], TO.ENTITY, opponent) entity.act( "$n non riesce a cogliere l'attimo giusto per la sua %s!" % verbs["noun"], TO.OTHERS, opponent) entity.act( "$n non riesce a cogliere l'attimo giusto per la sua %s!" % verbs["noun"], TO.TARGET, opponent) entity.wait(FLEE_WAIT) return False opponent = entity.get_opponent() portal = random.choice(portals) force_return = check_trigger(entity, "before_flee", entity, opponent, None, portal, behavioured) if force_return: return True execution_result = command_enter( entity, portal.get_numbered_keyword(looker="entity"), fleeing=True) xp_loss_and_stop_fight(entity, opponent, verbs) entity.wait(FLEE_WAIT) force_return = check_trigger(entity, "after_flee", entity, opponent, None, portal, behavioured) if force_return: return True return execution_result
def command_sleep(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Stai già %s, più di così non puoi!" % verbs["gerund"]) entity.act("$n russa profondamente.", TO.OTHERS) return False force_return = check_trigger(entity, "before_sleep", entity, behavioured) if force_return: return True elif entity.position == POSITION.REST: #if entity.adrenaline > (ADRENALINE_LIMIT + random.randint(0, 0.2 * ADRENALINE_LIMIT)): # entity.act("Difficile %s con tutta questa eccitazione in corpo." % verbs["infinitive"], TO.ENTITY) # entity.act("$n socchiude gli occhi cercando di %s, ma è troppo irrequieto." % verbs["infinitive"], TO.OTHERS) # return False entity.act("È tempo di riposare le stanche membra.", TO.ENTITY) entity.act("$n chiude gli occhi e s'assopisce lentamente.", TO.OTHERS) elif entity.position == POSITION.SIT: #if entity.adrenaline > (ADRENALINE_LIMIT + random.randint(0, 0.3/2 * ADRENALINE_LIMIT)): # entity.act("Difficile %s con tutta questa eccitazione in corpo." % verbs["infinitive"], TO.ENTITY) # entity.act("$n socchiude gli occhi cercando di %s, ma è troppo irrequieto." % verbs["infinitive"], TO.OTHERS) # return False entity.act("È tempo di distendersi e riposare le stanche membra.", TO.ENTITY) entity.act("$n si distende, chiude gli occhi e s'assopisce lentamente.", TO.OTHERS) elif entity.position == POSITION.KNEE: #if entity.adrenaline > (ADRENALINE_LIMIT + random.randint(0, 0.2 * ADRENALINE_LIMIT)): # entity.act("Difficile %s con tutta questa eccitazione in corpo." % verbs["infinitive"], TO.ENTITY) # entity.act("$n socchiude gli occhi cercando di %s, ma è troppo irrequieto." % verbs["infinitive"], TO.OTHERS) # return False entity.act("Appoggi i palmi per terra, ti metti più comodo, chiudi gli occhi e scivoli nel sonno.", TO.ENTITY) entity.act("$n appoggia i palmi per terra, si distende, chiude gli occhi e s'assopisce lentamente.", TO.OTHERS) elif entity.position == POSITION.STAND: #if entity.adrenaline > (ADRENALINE_LIMIT + random.randint(0, 0.5 * ADRENALINE_LIMIT)): # entity.act("Difficile %s con tutta questa eccitazione in corpo." % verbs["infinitive"], TO.ENTITY) # entity.act("$n socchiude gli occhi cercando di %s, ma è troppo irrequieto" % verbs["infinitive"], TO.OTHERS) # return False entity.act("Ti metti più comodo, chiudi gli occhi e ti lasci scivolare nel sonno.", TO.ENTITY) entity.act("$n si distende, chiude gli occhi e s'assopisce lentamente.", TO.OTHERS) entity.position = POSITION.SLEEP force_return = check_trigger(entity, "after_sleep", entity, behavioured) if force_return: return True return True
def execute(self): if not self.is_valid(): return aggressor = self.aggressor() victim = self.victim() if not aggressor.aggressivenesses: log.bug("aggressor %s non possiede messaggi di aggressivenesses da inviare: %r" % (aggressor, aggressor.aggressivenesses)) return if aggressor.location != victim.location: return if config.reload_commands: reload(__import__("src.commands.command_kill", globals(), locals(), [""])) from src.commands.command_kill import command_kill force_return = check_trigger(aggressor, "before_express_aggressiveness", self) if force_return: return force_return = check_trigger(victim, "before_undergoes_aggressiveness", self) if force_return: return # Attacca solamente se il numero di tentativi di avvertimento sono # terminati oppure per caso ma viene sempre inviato almeno un avvertimento if (aggressor.IS_MOB and self.remaining_tries < len(aggressor.aggressivenesses) and (self.remaining_tries == 0 or random.randint(0, self.remaining_tries) == 0)): command_kill(aggressor, victim.get_numbered_keyword(looker=aggressor)) else: # Se non vi fosse questo check gli oggetti continuerebbero ad inviare # il messaggio di minaccia per sempre, questo perché non possono # uccidere ed entrare nella condizione superiore if self.remaining_tries > 0: argument = random.choice(aggressor.aggressivenesses) if not argument: log.bug("aggressivenesses di %s possiede del testo non valido: %r" % (aggressor, argument)) return interpret_or_echo(aggressor, argument, looker=victim) self.timer = self.get_timer() self.remaining_tries -= 1 force_return = check_trigger(aggressor, "after_express_aggressiveness", self) if force_return: return force_return = check_trigger(victim, "after_undergoes_aggressiveness", self) if force_return: return
def digging_a_diggable_exit_2(entity, location, direction, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not location: log.bug("location non è un parametro valido: %r" % location) return if not direction or direction == DIR.NONE: log.bug("direction non è un paramtro valido: %r" % direction) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # ------------------------------------------------------------------------- # (TD) Bisognerà fare i check se l'uscita esista ancora entity.action_in_progress = None entity.act("\nSmetti di %s quando i tuoi sforzi rivelano l'esistenza di un passaggio %s!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act("$n smette di %s quando scopre un passaggio %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act("$n smette di %s quando scopre un passaggio %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location) entity.send_prompt() location.exits[direction].flags -= EXIT.DIGGABLE reverse_exit = location.get_reverse_exit(direction) if reverse_exit: reverse_exit.flags -= EXIT.DIGGABLE # Rimuove l'eventuale flag di secret alle eventuali due porte ai lati normal_door = location.get_door(direction, reverse_search=False) if normal_door and normal_door.door_type and DOOR.SECRET in normal_door.door_type.flags: normal_door.door_type.flags -= DOOR.SECRET reverse_door = location.get_door(direction, direct_search=True) if reverse_door and reverse_door.door_type and DOOR.SECRET in reverse_door.door_type.flags: reverse_door.door_type.flags -= DOOR.SECRET # (TD) imparare un po' la skill scava dai propri successi force_return = check_trigger(entity, "after_dig", entity, location, None, direction, behavioured) if force_return: return True force_return = check_trigger(location, "after_digged", entity, location, None, direction, behavioured) if force_return: return True
def command_rest(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti accomodi a %s, ma solo nei tuoi sogni!" % verbs["infinitive"]) entity.act("$ si stiracchia nel sonno.", TO.OTHERS) return False elif entity.position == POSITION.REST: entity.act("Ti allunghi cercando una posizione più comoda per te", TO.ENTITY) entity.act( "$n allunga alla grandissima cercando una posizione più comoda." % verbs["infinitive"], TO.ENTITY) return False force_return = check_trigger(entity, "before_rest", entity, behavioured) if force_return: return True if entity.position == POSITION.SIT: entity.act( "Stuf$o di stare sedut$o ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act("$n si mette a %s." % verbs["infinitive"], TO.OTHERS) elif entity.position == POSITION.STAND: entity.act("Ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act("$n mette a %s." % verbs["infinitive"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act( "Alzi un ginocchio dopo l'altro e ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act( "$n alza un ginocchio dopo l'altro e si mette a %s." % verbs["infinitive"], TO.OTHERS) entity.position = POSITION.REST force_return = check_trigger(entity, "after_rest", entity, behavioured) if force_return: return True return True
def command_stand(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti %s in piedi ma solo nei tuoi sogni!" % verbs["you"]) entity.act("$n si gira nel sonno ed ora sta supino.") return False elif entity.position == POSITION.STAND: entity.act("Sei già in piedi.", TO.ENTITY) entity.act( "$n si allunga sulle punte dei $feet come se volesse stare più in piedi di così.", TO.OTHERS) return False force_return = check_trigger(entity, "before_stand", entity, behavioured) if force_return: return True # (TD) da gestire forse anche il combattimento con ritardi sullo stand if entity.position == POSITION.REST: entity.act("Smetti di riposare e ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act("$n smette di riposare e si %s in piedi." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.SIT: entity.act("Ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act("$n si %s in piedi." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act( "Un ginocchio dopo l'altro e ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act( "Un ginocchio dopo l'altro e $n si %s in piedi." % verbs["it"], TO.OTHERS) entity.position = POSITION.STAND force_return = check_trigger(entity, "after_stand", entity, behavioured) if force_return: return True return True
def __init__(self, code=""): super(Item, self).__init__() BehaviourUpdaterSuperclass.__init__(self) self.code = "" self.prototype = None if code: self.reinit_code(code) copy_existing_attributes(self.prototype, self, except_these_attrs=["code"]) self.after_copy_existing_attributes() # Variabili proprie di una istanza di oggetto: self.area = None self.experience = 0 # Esperienza accumulata prima di poter livellare self.specials = {} # E' una lista di variabili speciali, possono essere utilizzate come delle flags, vengono aggiunte di solito nei gamescript check_trigger(self, "on_init", self)
def flee_with_portal(entity, messages, opponent=None): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not messages: log.bug("messages non è un parametro valido: %r" % messages) return False # ------------------------------------------------------------------------- portals = [] for en in entity.location.iter_contains(): if FLAG.NO_LOOK_LIST in en.flags and en.entitype == ENTITYPE.PORTAL and en.portal_type: portals.append(en) if not portals: entity.act(messages["entity"], TO.ENTITY, opponent) entity.act(messages["others"], TO.OTHERS, opponent) if "target" in messages: entity.act(messages["target"], TO.TARGET, opponent) return False if random.randint(0, 1) == 0: entity.act("Non riesci a cogliere l'attimo giusto per la %s!" % verbs["noun"], TO.ENTITY, opponent) entity.act("$n non riesce a cogliere l'attimo giusto per la sua %s!" % verbs["noun"], TO.OTHERS, opponent) entity.act("$n non riesce a cogliere l'attimo giusto per la sua %s!" % verbs["noun"], TO.TARGET, opponent) entity.wait(FLEE_WAIT) return False opponent = entity.get_opponent() portal = random.choice(portals) force_return = check_trigger(entity, "before_flee", entity, opponent, None, portal, behavioured) if force_return: return True execution_result = command_enter(entity, portal.get_numbered_keyword(looker="entity"), fleeing=True) xp_loss_and_stop_fight(entity, opponent, verbs) entity.wait(FLEE_WAIT) force_return = check_trigger(entity, "after_flee", entity, opponent, None, portal, behavioured) if force_return: return True return execution_result
def end_destroy(entity, target, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not target: log.bug("target non è un parametro valido: %r" % target) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # behavioured ha valore di verità # ------------------------------------------------------------------------- if target.quantity <= 1: messages = { "entity" : "%s $N." % color_first_upper(verbs["you"]), "others" : "$n %s $N." % verbs["it"], "target" : "$n ti %s." % verbs["it"]} else: messages = { "entity" : "%s $N, per un quantitativo di %d." % (color_first_upper(verbs["you"]), target.quantity), "others" : "$n %s $N, per un quantitativo di %d." % (verbs["it"], target.quantity), "target" : "$n ti %s, per un quantitativo di %d." % (verbs["it"], target.quantity)} send_destroy_messages(messages, "end_destroy", entity, target, verbs) target.dies(opponent=entity, quantity=target.quantity) # Il comando dona 1 punto xp per ogni oggetto distrutto, poca roba, ma # magari serve ad incoraggiare la pulizia da parte dei giocatori di entità # ormai inutili if entity.IS_PLAYER: reason = "per aver distrutto con successo %s" % target.get_name(looker=entity) entity.give_experience(1, reason=reason) force_return = check_trigger(entity, "after_destroy", entity, target, behavioured) if force_return: return force_return = check_trigger(target, "after_broken", entity, target, behavioured) if force_return: return
def digging_an_inexistent_exit_2(entity, location, direction, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not location: log.bug("location non è un parametro valido: %r" % location) return if not direction or direction == DIR.NONE: log.bug("direction non è un paramtro valido: %r" % direction) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # ------------------------------------------------------------------------- entity.action_in_progress = None entity.act( "\nSmetti di %s %s, non hai trovato niente. Tanta fatica per nulla!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act( "$n smette di %s, sembra non aver trovato niente %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act( "$n smette di %s, sembra non aver trovato niente %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location) entity.send_prompt() # (TD) imparare un po' la skill scava, ma poco force_return = check_trigger(entity, "after_dig", entity, location, None, direction, behavioured) if force_return: return True force_return = check_trigger(location, "after_digged", entity, location, None, direction, behavioured) if force_return: return True
def command_emote(entity, argument="", behavioured=False): """ Permette di inviare liberamente dei messaggi per poter esprimere sentimenti o gesti. """ # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) force_return = check_trigger(entity, "before_emote", entity, argument, behavioured) if force_return: return True if not argument: entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_emote") entity.send_output(syntax, break_line=False) return False if len(argument) > config.max_google_translate: entity.act("Non puoi %s in maniera così prolissa." % verbs["you2"]) entity.act("Non riesce ad %s adeguatamente e si impappina." % verbs["it2"]) return False argument = put_final_dot(argument) # Mostra a tutti ciò che il giocatore vuole esprimere if "$n" in argument: argument = color_first_upper(argument) entity.act(argument.replace("$n", entity.name), TO.ENTITY) entity.act(argument, TO.OTHERS) else: entity.act("%s %s" % (entity.name, argument), TO.ENTITY) entity.act("$n %s" % argument, TO.OTHERS) force_return = check_trigger(entity, "after_emote", entity, argument, behavioured) if force_return: return True return True
def command_sit(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti %s, ma solo nei tuoi sogni!" % verbs["you"]) entity.act("$n si rannicchia nel sonno.", TO.OTHERS) return False elif entity.position == POSITION.SIT: entity.act( "Sposti a destra e a sinistra il bacino cercando una posizione da %s più comoda." % verbs["noun"], TO.ENTITY) entity.act( "$n sposta a destra e a sinistra il bacino cercando una posizione da %s più comoda." % verbs["noun"], TO.OTHERS) return False force_return = check_trigger(entity, "before_sit", entity, behavioured) if force_return: return True if entity.position == POSITION.REST: entity.act("Smetti di riposare e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n smette di riposare e si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.STAND: entity.act("Ti %s." % verbs["you"], TO.ENTITY) entity.act("$n si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act("Alzi un ginocchio dopo l'altro e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n alza un ginocchio dopo l'altro e si %s." % verbs["it"], TO.OTHERS) entity.position = POSITION.SIT force_return = check_trigger(entity, "after_sit", entity, behavioured) if force_return: return True return True
def command_inventory(entity, argument="", behavioured=False): """ Permette di visualizzare il proprio inventario. """ # Normale se questo comando è stato deferrato if not entity: return False entity = entity.split_entity(1) # (TD) I trigger di inventory funzionano cmq con il target perché in futuro # ci sarà la skill apposita per visualizzare l'inventario anche se adesso # è solo lato admin if not argument or entity.trust <= TRUST.PLAYER: target = entity else: target = entity.find_entity_extensively(argument) if not target: entity.act( "Non vedi nessun [white]%s[close] qui attorno." % argument, TO.ENTITY) entity.act( "$n sembra stia cercando qualcuno qui attorno che però non c'è.", TO.OTHERS) return False force_return = check_trigger(entity, "before_inventory", entity, None if entity == target else target, behavioured) if force_return: return True entity.send_output(get_formatted_inventory_list(entity, target), break_line=False) force_return = check_trigger(entity, "after_inventory", entity, None if entity == target else target, behavioured) if force_return: return True return True
def __init__(self, code=""): super(Item, self).__init__() BehaviourUpdaterSuperclass.__init__(self) self.code = "" self.prototype = None if code: self.reinit_code(code) copy_existing_attributes(self.prototype, self, except_these_attrs=["code"]) self.after_copy_existing_attributes() # Variabili proprie di una istanza di oggetto: self.area = None self.experience = 0 # Esperienza accumulata prima di poter livellare self.specials = { } # E' una lista di variabili speciali, possono essere utilizzate come delle flags, vengono aggiunte di solito nei gamescript check_trigger(self, "on_init", self)
def command_stand(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti %s in piedi ma solo nei tuoi sogni!" % verbs["you"]) entity.act("$n si gira nel sonno ed ora sta supino.") return False elif entity.position == POSITION.STAND: entity.act("Sei già in piedi.", TO.ENTITY) entity.act("$n si allunga sulle punte dei $feet come se volesse stare più in piedi di così.", TO.OTHERS) return False force_return = check_trigger(entity, "before_stand", entity, behavioured) if force_return: return True # (TD) da gestire forse anche il combattimento con ritardi sullo stand if entity.position == POSITION.REST: entity.act("Smetti di riposare e ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act("$n smette di riposare e si %s in piedi." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.SIT: entity.act("Ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act("$n si %s in piedi." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act("Un ginocchio dopo l'altro e ti %s in piedi." % verbs["you"], TO.ENTITY) entity.act("Un ginocchio dopo l'altro e $n si %s in piedi." % verbs["it"], TO.OTHERS) entity.position = POSITION.STAND force_return = check_trigger(entity, "after_stand", entity, behavioured) if force_return: return True return True
def command_knee(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti %s, ma solo nei tuoi sogni!" % verbs["you"]) entity.act("$n si agita spostandosi su di un lato.", TO.OTHERS) return False elif entity.position == POSITION.KNEE: entity.act("Sposti di un poco le ginocchia cercando una posizione più comoda.", TO.ENTITY) entity.act("$n sposta di un poco le ginocchia cercando una posizione più comoda.", TO.OTHERS) return False force_return = check_trigger(entity, "before_knee", entity, behavioured) if force_return: return True if entity.position == POSITION.REST: entity.act("Smetti di riposare e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n smette di riposare e si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.STAND: entity.act("Ti %s." % verbs["you"], TO.ENTITY) entity.act("$n si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.SIT: entity.act("Scivoli lentamente in avanti e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n scivola lentamente in avanti e si %s." % verbs["it"], TO.OTHERS) entity.position = POSITION.KNEE force_return = check_trigger(entity, "before_knee", entity, behavioured) if force_return: return True return True
def command_sit(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti %s, ma solo nei tuoi sogni!" % verbs["you"]) entity.act("$n si rannicchia nel sonno.", TO.OTHERS) return False elif entity.position == POSITION.SIT: entity.act("Sposti a destra e a sinistra il bacino cercando una posizione da %s più comoda." % verbs["noun"], TO.ENTITY) entity.act("$n sposta a destra e a sinistra il bacino cercando una posizione da %s più comoda." % verbs["noun"], TO.OTHERS) return False force_return = check_trigger(entity, "before_sit", entity, behavioured) if force_return: return True if entity.position == POSITION.REST: entity.act("Smetti di riposare e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n smette di riposare e si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.STAND: entity.act("Ti %s." % verbs["you"], TO.ENTITY) entity.act("$n si %s." % verbs["it"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act("Alzi un ginocchio dopo l'altro e ti %s." % verbs["you"], TO.ENTITY) entity.act("$n alza un ginocchio dopo l'altro e si %s." % verbs["it"], TO.OTHERS) entity.position = POSITION.SIT force_return = check_trigger(entity, "after_sit", entity, behavioured) if force_return: return True return True
def command_rest(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.position == POSITION.SLEEP: entity.send_output("Ti accomodi a %s, ma solo nei tuoi sogni!" % verbs["infinitive"]) entity.act("$ si stiracchia nel sonno.", TO.OTHERS) return False elif entity.position == POSITION.REST: entity.act("Ti allunghi cercando una posizione più comoda per te", TO.ENTITY) entity.act("$n allunga alla grandissima cercando una posizione più comoda." % verbs["infinitive"], TO.ENTITY) return False force_return = check_trigger(entity, "before_rest", entity, behavioured) if force_return: return True if entity.position == POSITION.SIT: entity.act("Stuf$o di stare sedut$o ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act("$n si mette a %s." % verbs["infinitive"], TO.OTHERS) elif entity.position == POSITION.STAND: entity.act("Ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act("$n mette a %s." % verbs["infinitive"], TO.OTHERS) elif entity.position == POSITION.KNEE: entity.act("Alzi un ginocchio dopo l'altro e ti metti a %s." % verbs["infinitive"], TO.ENTITY) entity.act("$n alza un ginocchio dopo l'altro e si mette a %s." % verbs["infinitive"], TO.OTHERS) entity.position = POSITION.REST force_return = check_trigger(entity, "after_rest", entity, behavioured) if force_return: return True return True
def command_equipment(entity, argument="", behavioured=False): """ Permette di visualizzare il proprio equipaggiamento. """ # Normale se questo comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: target = entity else: target = entity.find_entity_extensively(argument) if not target: entity.act( "Non vedi nessun [white]%s[close] qui attorno." % argument, TO.ENTITY) entity.act("$n cerca qualcuno qui attorno.", TO.OTHERS) return False force_return = check_trigger(entity, "before_equipment", entity, None if entity == target else target, behavioured) if force_return: return True entity.send_output(get_formatted_equipment_list(entity, target)) force_return = check_trigger(entity, "after_equipment", entity, None if entity == target else target, behavioured) if force_return: return True return True
def dies(self, opponent=None, auto_loot=False, teleport_corpse=False): force_return = check_trigger(self, "before_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "before_dies", self, opponent) if force_return: return remains, use_repop = self.make_remains(auto_loot) # Attenzione che l'utilizzo di tali trigger potrebbero essere pericolosi # visto che sotto c'è un'extract force_return = check_trigger(self, "after_die", self, opponent) if force_return: return if opponent: force_return = check_trigger(opponent, "after_dies", self, opponent) if force_return: return self.extract(1, use_repop=use_repop)
def command_split(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: entity.send_output("Che [white]cosa[close] vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_split") entity.send_output(syntax) return False force_return = check_trigger(entity, "before_split", entity, target1, target2) if force_return: return True force_return = check_trigger(entity, "after_split", entity, target1, target2) if force_return: return True return True
def execute(self): """ Anche ai giocatori offline esegue la digestione. """ if not self.is_valid(): return entity = self.entity() ingested = self.ingested() force_return = check_trigger(entity, "before_digestion", self) if force_return: return force_return = check_trigger(ingested, "before_digested", self) if force_return: return entity.act( "Dall'aria che sale dal tuo stomaco sembra che tu abbia appena digerito $N.", TO.ENTITY, ingested) # Per galanteria viene inviato solo una volta ogni tanto if random.randint(0, 100) == 0: entity.act( "A $n scappa un rutto! Sembra che abbia appena digerito qualcosa.", TO.OTHERS, ingested) entity.act( "Sembra che $n ti abbia appena digerito, è giunto il momento di andare sempre più giù...", TO.TARGET, ingested) ingested.extract(ingested.quantity, use_repop=True) force_return = check_trigger(entity, "after_digestion", self) if force_return: return force_return = check_trigger(ingested, "after_digested", self) if force_return: return
def next_stage(self, old_entity, type_attr_name): if not old_entity: log.bug("old_entity non è parametro valido: %r" % old_entity) return if type_attr_name not in ("plant_type", "seed_type"): log.bug("type_attr_name non è parametro valido: %r" % type_attr_name) return # --------------------------------------------------------------------- # Pulisce la deferred relativa a questo metodo in qualsiasi caso self.deferred_stage = None entitype = getattr(old_entity, type_attr_name) if not entitype: log.bug("%s dell'entità precedente non valido: %r" % (type_attr_name, entitype)) return # (TD) deve scegliere quale delle tre entità worse, normal o better # in maniera non casuale ma basandosi su effettivi fattori ambientali entitypes = [] for entitype_name in ("worse_entity", "normal_entity", "better_entity"): if getattr(entitype, entitype_name): entitypes.append(entitype_name) if not entitypes: log.bug("Nessuna tipologia d'entità da utilizzare come prossimo stadio: %r" % entitypes) return choised_attr = random.choice(entitypes) # Se la vita della pianta è terminata e finalmente si trova un'entità # di pianta morta, allora la utilizza if entitype.remaining_life == 0 and entitype.dead_entity: choised_attr = "dead_entity" # --------------------------------------------------------------------- # Crea la nuova pianta a seconda delle scelte di cui sopra choised_entity = getattr(entitype, choised_attr) if not choised_entity: log.bug("Impossibile continuare con la crescita della pianta da %s per la scelta %s" % ( old_entity.code, choised_attr)) return if choised_entity.max_global_quantity > 0 and choised_entity.current_global_quantity >= choised_entity.max_global_quantity: return new_entity = choised_entity.CONSTRUCTOR(choised_entity.code) # Passa alcune caratteristiche della vecchia entità nella nuova # prima di distruggerla if new_entity.plant_type: new_entity.flags += FLAG.GROWING new_entity.plant_type.remaining_life = entitype.remaining_life new_entity.plant_type.worse_counter = entitype.worse_counter new_entity.plant_type.normal_counter = entitype.normal_counter new_entity.plant_type.better_counter = entitype.better_counter quality_attr = choised_attr.split("_")[0] + "_counter" setattr(new_entity.plant_type, quality_attr, getattr(new_entity.plant_type, quality_attr) + 1) # Inserisce la nuova entità in gioco new_entity.inject(old_entity.location) # --------------------------------------------------------------------- # Lista delle entità che cambieranno locazione nel ciclo sottostante # e che vengono passate nel trigger on_next_stage per comodità, vengono # salvati solo le entità frutta, seme e cibo entities = [] # Controlla come deve comportarsi con il contenuto della vecchia entità: # se passarlo alla nuova, oppure distruggerlo, oppure ancora farlo # cadere a terra flower_counter = 0 for content in old_entity.iter_contains(use_reversed=True): if content.entitype == ENTITYPE.FLOWER: flower_counter += 1 continue elif content.entitype in (ENTITYPE.FRUIT, ENTITYPE.SEED, ENTITYPE.FOOD): content = content.from_location(content.quantity, use_repop=False) in_room = content.get_in_room() container_carrier = content.get_container_carrier() # Più la pianta è grande e maggiore è la probabilità che il suo # contenuto cada nella stanza invece che nel vaso if in_room and container_carrier and random.randint(0, max(1, math.log(new_entity.get_weight()) - math.log(container_carrier.get_weight()))) == 0: content.to_location(in_room) entities.append(content) elif in_room and random.randint(0, max(1, math.log(new_entity.get_weight()))) == 0: content.to_location(in_room) entities.append(content) elif container_carrier: content.to_location(container_carrier) entities.append(content) else: content.to_location(old_entity.location) entities.append(content) # Tutte le entità inserite a terra attivano un timer per # rimuoverle e non creare inutili mucchi di semi content.start_purification(entitype.decomposition_rpg_hours, decomposition=True) else: # (BB) qui se passavano delle entità di tipo food invece di # ENTITYPE.FRUIT bacava i riferimenti, probabilmente il # problema c'è ancora, per questo l'elif sopra accetta # anche food content = content.from_location(content.quantity, use_repop=False) content.to_location(new_entity) # --------------------------------------------------------------------- # Si salva tutti i semi per sapere se entità da inserire nella pianta # sia solo di tipo seme oppure se eventuali semi sono mischiati ad # altre tipo di entità, ciò serve perché in tal caso i semi vengono # inseriti nelle altre tipologie di entità (frutti o fiori chessia) seeds = [] for proto_code, quantity in entitype.contents.iteritems(): prototype = database.get_proto_entity(proto_code) if not prototype: continue if prototype.entitype == ENTITYPE.SEED: seeds.append([prototype, quantity]) if len(seeds) == len(entitype.contents): seeds = [] # Ogni volta che la pianta produce dei semi diminuisce le proprie # risorse vitali if seeds and new_entity.plant_type.remaining_life > 0: new_entity.plant_type.remaining_life -= 1 # Crea l'eventuale contenuto voluto per la nuova entità for proto_code, quantity in entitype.contents.iteritems(): prototype = database.get_proto_entity(proto_code) if not prototype: continue # Se il prototipo è un seme da inserire in un frutto o simile allora lo salta for seed in seeds: if prototype == seed[0]: break else: add_content(prototype, quantity, choised_attr, flower_counter, new_entity, seeds) # Crea, se è il caso, una tipologia di contenitore alla nuova entità # per permettere ai giocatori ad interagire con la pianta if not new_entity.container_type and new_entity.entitype == ENTITYPE.PLANT: container = Container() container.max_weight = new_entity.get_carried_weight() * 2 new_entity.container_type = container # Avvisa dell'avvenuta crescita della pianta if new_entity.plant_type: message = "%s cresce: %s" else: message = "%s finisce di crescere: %s" log.plant(message % (old_entity.prototype.code, new_entity.prototype.code)) # Supporto gamescript, se viene forzato il ritorno non esegue # l'eventuale stadio successivo force_return = check_trigger(old_entity, "on_next_stage", old_entity, new_entity, choised_attr, entities) if force_return: return True # Ora si può rimuovere la vecchia pianta # (la si può estrarre completamente perché se possiede del contenuto non # viene raggruppata fisicamente, altrimenti si può rimuovere il gruppetto # senza problemi perché senza contenuto) old_entity.extract(old_entity.quantity, use_repop=False) # Prepara il lancio per il prossimo stage if choised_attr != "dead_entity" and new_entity.plant_type: new_entity.plant_type.start_growth(new_entity, "plant_type")
def digging_a_location_2(entity, location, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not location: log.bug("location non è un parametro valido: %r" % location) return if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return # ------------------------------------------------------------------------- targets = [] for target in location.iter_contains(): if FLAG.BURIED in target.flags: targets.append(target) # C'è una possibilità su cento che venga trovato qualcosa di interessante # (TD) magari la probabilità aumentarla facendola sulla base della skill scava # (TD) magari aggiungere un affect per invalidare tentativi robotizzati di scavaggio continuo if not targets and random.randint(1, 100) < DIG_PROBABILITY: codes = database["areas"]["rip"].proto_items.keys() codes += database.randomizable_codes codes += database.race_money_codes codes += database.seed_codes code = random.choice(codes) if code.split("_")[1] == "item": targets = [Item(code)] else: targets = [Mob(code)] # Per le monete viene impostata anche una quantità casuale. # Qui in sostanza viene detto che si possono trovare da 1 a 1000 monete # di rame e al massimo solo 1 moneta di mithril, valori intermedi sono # inversamente proporzionali al valore della moneta stessa if targets[0].money_type: copper_value = min(targets[0].money_type.copper_value, 1000) targets[0].quantity = random.randint(1, int(1000 / copper_value)) # (TD) Bisognerebbe inserire un affect nella locazione che impedisca di # scavare ancora lì per tot tempo targets[0].inject(location) # L'esperienza per aver scavato la prima volta nella stanza viene data # a prescindere che sia stato trovata un'entità o meno if entity.IS_PLAYER and location.IS_ROOM: if location.prototype.code in entity.digged_rooms: entity.digged_rooms[location.prototype.code] += 1 else: entity.digged_rooms[location.prototype.code] = 1 reason = "per aver scavato %s" % location.get_name(looker=entity) entity.give_experience(location.area.level, reason=reason) if not targets: entity.act( "\n%s ma non trovi proprio nulla di interessante." % color_first_upper(verbs["you"]), TO.ENTITY, location) entity.act( "$n %s una buca in $N senza trovare nulla di interessante." % verbs["it"], TO.OTHERS, location) entity.act( "$n ti %s una buca senza trovare nulla di interessante." % verbs["it"], TO.TARGET, location) entity.send_prompt() entity.action_in_progress = None return target = random.choice(targets) target = target.split_entity(random.randint(1, target.quantity)) entity.action_in_progress = None entity.act("\nFinisci di %s scoprendo $N!" % verbs["infinitive"], TO.ENTITY, target) entity.act( "$n termina di %s dopo che ha scoperto qualcosa." % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n termina di %s dopo che ti ha scoperto nel terreno." % verbs["infinitive"], TO.TARGET, target) entity.act( "$n termina di %s dopo che ha scoperto $a dentro di te." % verbs["infinitive"], TO.TARGET, location, target) entity.send_prompt() target.flags -= FLAG.BURIED # Se era un seme o una pianta allora ne ferma la crescita if target.seed_type: target.seed_type.stop_growth() if target.plant_type: target.plant_type.stop_growth() # (TD) imparare un po' la skill scava dai propri successi force_return = check_trigger(entity, "after_dig", entity, location, target, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(location, "after_digged", entity, location, target, DIR.NONE, behavioured) if force_return: return True
def dig_an_exit(entity, argument, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not argument: log.bug("argument non è un parametro valido: %r" % argument) return False if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return False # behavioured ha valore di verità # ------------------------------------------------------------------------- location = entity.location arg, argument = one_argument(argument) direction = get_direction(arg) if direction == DIR.NONE: entity.act( "Non trovi nessuna direzione [white]%s[close] in cui %s." % (arg, verbs["infinitive"]), TO.ENTITY, location) entity.act( "$n sembra voler %s in una direzione, ma appare spaesato." % verbs["infinitive"], TO.OTHERS, location) entity.act( "$n sembra voler %s in una direzione, ma appare spaesato." % verbs["you2"], TO.TARGET, location) return False if not location.IS_ROOM: entity.act( "Non trovi in un luogo ove poter %s %s." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act( "$n sembra voler %s %s nonostante non si trovi in un luogo con delle uscite." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act( "Non sei un luogo in cui si possa %s %s, eppure $n ci sta provando lo stesso." % (verbs["infinitive"], direction.to_dir), TO.TARGET, location) return False # (TD) Questo si potrebbe convertire in metodo se dovesse servire nuovamente exit = None has_secret_door = False if direction in location.exits: exit = location.exits[direction] door = location.get_door(direction) if door and door.door_type and DOOR.SECRET in door.door_type.flags and DOOR.CLOSED in door.door_type.flags: has_secret_door = True if exit and EXIT.DIGGABLE not in exit.flags and not has_secret_door: entity.act( "Non sapresti proprio come %s %s: c'è già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act( "$n sembra voler %s %s: ma c'è già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act( "$n sembra voler %s %s: ma li hai già un'uscita!" % (verbs["infinitive"], direction.to_dir), TO.TARGET, location) return False entity.act("Cominci a %s %s." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, location) entity.act( "$n comincia a %s %s." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, location) entity.act("$n comincia a %s %s." % (verbs["you2"], direction.to_dir), TO.TARGET, location) force_return = check_trigger(entity, "before_dig", entity, location, exit, direction, behavioured) if force_return: return True force_return = check_trigger(location, "before_digged", entity, location, exit, direction, behavioured) if force_return: return True # (TD) Togliere un po' di energie nella scavata if exit and not has_secret_door: defer_later_function = digging_a_diggable_exit_1 else: defer_later_function = digging_an_inexistent_exit_1 entity.action_in_progress = ActionInProgress(DIG_SECONDS, defer_later_function, stop_digging_on_exit, entity, location, direction, verbs, behavioured) return True
def command_use(entity, argument="", verbs=VERBS, behavioured=False): """ Permette di usare un'entità, tenterà di usare il comando relativo all'entità e al suo stato. """ # È 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_use") entity.send_output(syntax, break_line=False) return False original_argument = argument arg, argument = one_argument(argument) target_for_eat_drink = entity.find_entity(arg, location=entity) target_for_open_close = entity.find_entity_extensively(arg, inventory_pos="last") target_for_enter = entity.find_entity_extensively(arg) target_for_read = entity.find_entity_extensively(arg, inventory_pos="first") target_for_remove = entity.find_equipped_entity(arg, entity) target = target_for_eat_drink or target_for_open_close or target_for_enter or target_for_read or target_for_remove if not target: entity.act("Non trovi nessun [white]%s[close] da %s." % (arg, verbs["infinitive"]), TO.ENTITY) entity.act("$n sembra cercare qualcosa che non riesce proprio a trovare.", TO.ENTITY) return False # È voluto che i trigger di use scattino anche su entità che non hanno una # struttura di entitype valida, questo per dare la possibilità di inserire # trigger su entità qualsiasi in maniera tale da poterle utilizzare per far # scattare una qualsiasi cosa usandoli. # Ricordo che se in un trigger viene ritornato un valore True il normale # flusso di codice viene fermato, ecco cosa serve il force_return. force_return = check_trigger(entity, "before_use", entity, target, argument, behavioured) if force_return: return True force_return = check_trigger(target, "before_used", entity, target, argument, behavioured) if force_return: return True # ------------------------------------------------------------------------- if target_for_open_close and target_for_open_close.entitype == ENTITYPE.CONTAINER and CONTAINER.CLOSABLE in target_for_open_close.container_type.flags: if CONTAINER.BOLTED in target_for_open_close.container_type.flags: return command_unbolt(entity, original_argument, behavioured=behavioured) elif CONTAINER.LOCKED in target_for_open_close.container_type.flags: return command_unlock(entity, original_argument, behavioured=behavioured) elif CONTAINER.CLOSED in target_for_open_close.container_type.flags: return command_open(entity, original_argument, behavioured=behavioured) else: return command_close(entity, original_argument, behavioured=behavioured) elif target_for_open_close and target_for_open_close.entitype == ENTITYPE.DOOR and DOOR.CLOSABLE in target_for_open_close.door_type.flags: if DOOR.BOLTED in target_for_open_close.door_type.flags: return command_unbolt(entity, original_argument, behavioured=behavioured) elif DOOR.LOCKED in target_for_open_close.door_type.flags: return command_unlock(entity, original_argument, behavioured=behavioured) elif DOOR.CLOSED in target_for_open_close.door_type.flags: return command_open(entity, original_argument, behavioured=behavioured) else: return command_close(entity, original_argument, behavioured=behavioured) elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.DRINK: return command_drink(entity, original_argument, behavioured=behavioured) elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.FOOD: return command_eat(entity, original_argument, behavioured=behavioured) # La ricerca del seme nel comando seme è uguale a quella del cibo e delle # bevande, ecco perchè viene utilizzato comunque target_for_eat_drink elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.SEED: return command_seed(entity, original_argument, behavioured=behavioured) # La ricerca della pianta è uguale a quella del seme più sotto elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.PLANT: return command_plant(entity, original_argument, behavioured=behavioured) elif target_for_enter and target_for_enter.entitype == ENTITYPE.PORTAL: return command_enter(entity, original_argument, behavioured=behavioured) # C'è da notare relativamente al read che con il comando use non è possibile # leggere entità dentro altre entità, poco male direi... elif target_for_read and target_for_read.entitype == ENTITYPE.READABLE: return command_read(entity, original_argument, behavioured=behavioured) # Stesse considerazioni dette per il tipo seed elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.WEAR: return command_wear(entity, original_argument, behavioured=behavioured) # Stesse considerazioni dette per il tipo seed elif target_for_eat_drink and target_for_eat_drink.entitype == ENTITYPE.WEAPON: return command_wield(entity, original_argument, behavioured=behavioured) elif target_for_remove and target_for_remove.entitype == ENTITYPE.WEAR: return command_remove(entity, original_argument, behavioured=behavioured) #elif target.entitype == ENTITYPE.CORPSE: #elif target.entitype == ENTITYPE.FISHING: #elif target.entitype == ENTITYPE.FLOWER: #elif target.entitype == ENTITYPE.FRUIT: #elif target.entitype == ENTITYPE.GROUND: #elif target.entitype == ENTITYPE.INSTRUMENT: #elif target.entitype == ENTITYPE.KEY: #elif target.entitype == ENTITYPE.KEYRING: #elif target.entitype == ENTITYPE.MENHIR: #elif target.entitype == ENTITYPE.MONEY: # ------------------------------------------------------------------------- entity.act("Non sai proprio come poter %s $N." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n non sa proprio come poter %s $N." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n non sa proprio come poter %s." % verbs["you2"], TO.TARGET, target) # Per saperne di più sul perché questi trigger si trovato a questo livello # è bene leggersi il commento in alto relativo agli altri trigger che vale # anche per questa coppia force_return = check_trigger(entity, "after_use", entity, target, argument, behavioured) if force_return: return True force_return = check_trigger(target, "after_used", entity, target, argument, behavioured) if force_return: return True return False
def execute(self): if not self.is_valid(): return aggressor = self.aggressor() victim = self.victim() if not aggressor.aggressivenesses: log.bug( "aggressor %s non possiede messaggi di aggressivenesses da inviare: %r" % (aggressor, aggressor.aggressivenesses)) return if aggressor.location != victim.location: return if config.reload_commands: reload( __import__("src.commands.command_kill", globals(), locals(), [""])) from src.commands.command_kill import command_kill force_return = check_trigger(aggressor, "before_express_aggressiveness", self) if force_return: return force_return = check_trigger(victim, "before_undergoes_aggressiveness", self) if force_return: return # Attacca solamente se il numero di tentativi di avvertimento sono # terminati oppure per caso ma viene sempre inviato almeno un avvertimento if (aggressor.IS_MOB and self.remaining_tries < len(aggressor.aggressivenesses) and (self.remaining_tries == 0 or random.randint(0, self.remaining_tries) == 0)): command_kill(aggressor, victim.get_numbered_keyword(looker=aggressor)) else: # Se non vi fosse questo check gli oggetti continuerebbero ad inviare # il messaggio di minaccia per sempre, questo perché non possono # uccidere ed entrare nella condizione superiore if self.remaining_tries > 0: argument = random.choice(aggressor.aggressivenesses) if not argument: log.bug( "aggressivenesses di %s possiede del testo non valido: %r" % (aggressor, argument)) return interpret_or_echo(aggressor, argument, looker=victim) self.timer = self.get_timer() self.remaining_tries -= 1 force_return = check_trigger(aggressor, "after_express_aggressiveness", self) if force_return: return force_return = check_trigger(victim, "after_undergoes_aggressiveness", self) if force_return: return
def rpg_channel(entity, argument, channel, ask=False, exclaim=False, behavioured=False): """ Gestisce i canali rpg, ha le seguenti caratteristiche: - supporto per gli smile - supporto per i modi di esprimersi con esclamativo e punto di domanda - supporto per gli emote - gestione del bersaglio che può essere un'entità, il gruppo o sé stessi - (TD) parlata da ubriaco - (TD) espansione della potenza della voce in altre stanze - (TD) espressioni per le stanze attorno, anche per coloro che riconoscono la voce, pensare anche alla suddivisione tra social gestuali e 'rumorosi' per gli smile-espressioni around - (TD) modulazione della voce a seconda delle dimensioni di chi parla e della sua voice_potence """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not channel: log.bug("channel non è un parametro valido: %r" % channel) return False # ------------------------------------------------------------------------- if entity.IS_ROOM: return False objective = OBJECTIVE_ROOM # obiettivo del messaggio # Linguaggio utilizzato per dire il messaggio if entity.IS_ITEM: language = LANGUAGE.COMMON else: language = entity.speaking smile = "" # conterrà l'eventuale espressione di uno smile-social emote = "" # conterrà l'eventuale emote inviato con il messaggio tra due asterischi expres_entity = "" # espressione per chi parla expres_room = "" # espressione per chi sta ascoltando nella stanza expres_objective = "" # espressione per chi riceverà il messaggio # Ricava i verbi e il colore relativi al canale # Se si sta parlando normalmente la propria lingua vengono utilizzati # i verbi razziali per descriverne timbro, flessione o pronuncia if channel == CHANNEL.SAY: verb_you, verb_it = entity.race.say_verb_you, entity.race.say_verb_it else: verb_you, verb_it = channel.verb_you, channel.verb_it color = get_first_color(channel.name) # Se non è stato passato nessun messaggio esce if not argument or not remove_colors(argument): entity.send_output("Cosa vorresti %s?" % channel) return False if len(argument) > config.max_google_translate: entity.send_output("Non puoi %s un messaggio così logorroico." % channel) return False # Copia l'argomento originale, in alcuni casi serve recuperarlo poi original_argument = argument # Controlla se si sta parlando a qualcuno, il controllo sulla particella # la esegue in minuscolo, dando per sottinteso che quando uno scrive # maiuscolo voglia iniziare un discorso target = None if argument[0:2] == "a ": arg, argument = one_argument(argument) # Se sta parlando a qualcuno cerca di acquisirlo dal nome successivo objective_name, argument = one_argument(argument) target = entity.find_entity_extensively(objective_name) # con me e self esegue un check senza la is_same volutamente, per evitare # ricerche con nome di player che iniziano con Me o Self if target == entity or objective_name in ("me", "self"): objective = OBJECTIVE_SELF # Se si parla da soli lo si fa utilizzando la lingua madre language = entity.race.natural_language elif target: objective = OBJECTIVE_TARGET # Se si parla con qualcuno della stessa razza lo si fa utilizzando # la lingua preferita dalla razza, è un fattore culturale if entity.race == target.race: language = entity.race.natural_language else: # Se non ha trovato nessun 'a <nome bersaglio>' riprende # l'argument originale argument = original_argument # Stessa cosa di sopra ma qui controlla se si stia parlando al gruppo elif argument[0:3] == "al ": arg, argument = one_argument(argument) objective_name, argument = one_argument(argument) if is_prefix(objective_name, "gruppo"): if not entity.group: entity.send_output("Non fai parte di nessun gruppo.") return False # Questa variabile verrà utilizza poi nell'invio del messaggio group_members = entity.get_members_here(entity.location) if not group_members: entity.send_output( "Non trovi nessun membro del gruppo vicino a te con cui poter parlare." ) return False objective = OBJECTIVE_GROUP # Se si parla in un gruppo in cui tutti sono formati dalla stessa # razza si preferirà parlare con la lingua della propria razza for group_member in group_members: if group_member.race != entity.race: break else: language = entity.race.natural_language else: # Se il personaggio non vuole parlare al gruppo recupera # il valore originale inviato argument = original_argument # (TD) Gestisce il caso in cui l'entità si trovi immersa in un liquido #if entity.is_immersed(): # entity.send_output("Tenti di %s qualcosa ma subito l'acqua ti riempie la gola soffocandoti!" % channel) # entity.points.life -= random.randint(entity.level / 6, entity.level / 4) + 1 # return False if not entity.location: log.bug( "entity %s non si trova in una locazione valida: %r (original_argument: %s)" % (entity.code, entity.location, original_argument)) return False # Gestisce le stanze che obbligano al silenzio if entity.location.IS_ROOM: if ROOM.SILENCE in entity.location.flags: entity.send_output( "Il silenzio del luogo ti blocca la gola impedendoti di %s." % channel) return False # (TT) Se nella stanza c'è molto casino, tante persone etc etc è difficile # parlare piano if entity.location.mod_noise > 75 and channel <= CHANNEL.SAY: entity.send_output("Non puoi %s con tutta questa confusione!" % channel) return False # Invia l'appropriato messaggio nel caso in cui trovi argument vuoto if not argument: send_not_argument_message(entity, objective, channel) return False # Cerca eventuali smiles nella stringa controllando gli ultimi caratteri for social in database["socials"].itervalues(): if not social.smiles: continue for single_smile in social.smiles.split(): if single_smile in argument[-config.chars_for_smile:]: break else: # Se non trova nessun smile esce dal ciclo dei social e continua # col prossimo set di smiles trovato continue cut_smile = argument.rfind(single_smile) # Se argument è formato solo dallo smile invia il corrispondente social if cut_smile == 0: social_name = social.fun_name[len("social_"):] if objective == OBJECTIVE_TARGET: input_to_send = "%s %s" % (social_name, target.name) elif objective == OBJECTIVE_SELF: input_to_send = "%s %s" % (social_name, entity.name) else: input_to_send = social_name send_input(entity, input_to_send, "en", show_input=False, show_prompt=False) return True # Altrimenti ne ricava l'espressione dello smile-social e toglie lo # smile da argument, se il carattere dopo lo smile era un simbolo di # punteggiatura lo attacca alla frase togliendo gli spazi first_part = argument[:cut_smile] second_part = argument[cut_smile + len(single_smile):] if second_part.strip() and second_part.strip()[0] in "!?.,:;": first_part = first_part.rstrip() second_part = second_part.lstrip() argument = first_part.rstrip() + second_part.rstrip() smile = " %s" % social.expression break # Elabora i punti esclamativi e interrogativi per il canale say. # Qui viene utilizzata l'opzione chars_for_smile visto che si sta facendo # una cosa simile a sopra, ovvero considerare solo l'ultima parte # dell'argomento passato. exclamations = argument[-config.chars_for_smile:].count("!") questions = argument[-config.chars_for_smile:].count("?") if exclamations > questions: if channel == CHANNEL.SAY: verb_you = "Esclami" verb_it = " esclama" exclaim = True elif exclamations < questions: if channel == CHANNEL.SAY: verb_you = "Domandi" verb_it = " domanda" ask = True # Questo elif sottintende che exclamations e questions siano uguali elif exclamations != 0 and questions != 0: # Con una stessa quantità di ! e di ? l'ultimo che viene trovato # ha maggiore peso rispetto all'altro exclamation_pos = argument.rfind("!") question_pos = argument.rfind("?") if exclamation_pos > question_pos: if channel == CHANNEL.SAY: verb_you = "Esclami" verb_it = " esclama" exclaim = True else: if channel == CHANNEL.SAY: verb_you = "Domandi" verb_it = " domanda" ask = True # Supporto per piccoli emote separati da * ad inizio argument if argument[0] == "*": cut_emote = argument[1:].find("*") if cut_emote != -1: emote = " %s" % argument[1:cut_emote + 1].strip() if smile: emote = " e%s" % emote argument = argument[cut_emote + 2:].strip() # Unisce i vari pezzi per formare l'output expres_entity = verb_you expres_room = verb_it expres_target = "" if objective == OBJECTIVE_TARGET: name = target.get_name(entity) expres_entity += " a %s" % name expres_room += " a %s" % name expres_target += " ti%s" % verb_it elif objective == OBJECTIVE_SELF: expres_entity += " a te stess%s" % grammar_gender(entity) expres_room += " a sé stess%s" % grammar_gender(entity) elif objective == OBJECTIVE_GROUP: members = entity.get_members_here(entity.location) if len(members) == 1: expres_entity += " a %s" % members[0].name expres_room += " a %s" % members[0].name expres_target += " ti%s" % verb_it else: if len(members) > 5: many = "folto " else: many = "" expres_entity += " al gruppo" expres_room += " ad un %sgruppo" % many expres_target += "%s al gruppo" % verb_it # Aggiunge le eventuali espressioni dello smile e dell'emote expres_entity += smile + emote expres_room += smile + emote expres_target += smile + emote if not argument: send_not_argument_message(entity, objective, channel) return False # Prepara il pezzo riguardante la lingua utilizzata language = "" if not entity.IS_ITEM and entity.speaking != LANGUAGE.COMMON: language = " in lingua %s" % entity.speaking # Mischia il testo se si è ubriachi original_argument = argument = color_first_upper(argument) argument = drunk_speech(argument, entity) # Parlando si impara la lingua if not entity.IS_ITEM: learn_language(entity, channel, entity.speaking) # Controlla se vi sono parolacce o parole offrpg e logga i relativi argument if entity.IS_PLAYER: check_for_badwords(entity, argument) # Invia il messaggio a tutti coloro che lo possono sentire for location in expand_voice_around(entity, channel): if not location: log.bug( "location per il canale %s e per l'entità %s non è valida: %r" % (channel, entity.code, location)) continue for listener in location.iter_contains(use_reversed=True): if listener.position <= POSITION.SLEEP: continue if listener == entity: force_return = check_trigger(entity, "before_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger( entity, "before_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue # Invia all'entità il suo stesso messaggio first_part = (close_color(color) + expres_entity).rstrip() message = "%s: '%s'" % (first_part, close_color(argument)) send_channel_message(entity, message, True) force_return = check_trigger(entity, "after_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger(entity, "after_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue else: # Fa ascoltare solo ad un'entità di un eventuale gruppo fisico listener = listener.split_entity(1) force_return = check_trigger(listener, "before_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger( listener, "before_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue # Prepara alcune cose a seconda della stanza di provenienza del messaggio if entity.location == listener.location: entity_name = entity.get_name(listener) entity_name = color_first_upper(entity_name) from_direction = "" elif entity.location.IS_ROOM: # (TD) invia qualcuno a meno che non lo si abbia conosciuto # precedentemente con il sistema di presentazione entity_name = "Qualcuno" from_direction = get_from_direction( listener.location.x, listener.location.y, listener.location.z, entity.location.x, entity.location.y, entity.location.z) elif entity.location.IS_ACTOR: if entity.location != listener: entity_name = "Qualcuno" # (TD) come sopra from_direction = " dall'inventario di %s" % entity.location.get_name( listener) else: entity_name = "Qualcuno" # (TD) come sopra from_direction = " da dentro %s" % entity.location.get_name( listener) # Prepara la prima parte, quella senza il messaggio if objective == OBJECTIVE_ROOM: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction) elif objective == OBJECTIVE_TARGET or OBJECTIVE_SELF: if listener == target: output = "%s%s%s%s" % ( entity_name, close_color(color) + expres_target, language, from_direction) else: output = "%s%s%s%s" % ( entity_name, close_color(color) + expres_room, language, from_direction) elif objective == OBJECTIVE_GROUP: if listener in group_members: output = "%s%s%s%s" % ( entity_name, close_color(color) + expres_target, language, from_direction) else: output = "%s%s%s%s" % ( entity_name, close_color(color) + expres_room, language, from_direction) output = "<br>%s: '%s'" % (close_color(output).rstrip(), close_color(argument)) send_channel_message(listener, output, False) listener.send_prompt() force_return = check_trigger(listener, "after_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger( listener, "after_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue return True
def dig_a_location(entity, verbs, behavioured): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return False # behavioured ha valore di verità # ------------------------------------------------------------------------- location = entity.location if location.IS_ROOM: sector = add_article(str(location.sector), location.sector.genre, location.sector.number, GRAMMAR.PREPOSITION_IN) if location.sector.dig_difficulty >= 100: entity.act( "Ti è impossibile poter %s %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act( "$n cerca di %s %s ma gli è impossibile." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n cerca di %s ma gli è impossibile." % verbs["you2"], TO.TARGET, location) return False elif location.sector.dig_difficulty >= 80: entity.act( "Cominci a %s con molta difficoltà %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act( "$n comincia a %s con molta difficoltà %s." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n comincia a %s con molta difficoltà." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS + 2 elif location.sector.dig_difficulty >= 60: entity.act( "Cominci a %s con difficoltà %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act( "$n comincia a %s con difficoltà %s." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n comincia a %s con difficoltà." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS + 1 elif location.sector.dig_difficulty >= 40: entity.act( "Cominci a %s con fatica %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act( "$n comincia a %s con fatica %s." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n comincia a %s con fatica." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS + 0.5 elif location.sector.dig_difficulty >= 20: entity.act("Cominci a %s %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act("$n comincia a %s %s." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n comincia a %s." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS else: entity.act( "Cominci a %s facilmente %s." % (verbs["infinitive"], sector), TO.ENTITY, location) entity.act( "$n comincia a %s facilmente %s." % (verbs["infinitive"], sector), TO.OTHERS, location) entity.act("$n comincia a %s facilmente." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS - 0.5 else: entity.act("Cominci a %s qui." % verbs["infinitive"], TO.ENTITY, location) entity.act("$n comincia a %s qui." % verbs["infinitive"], TO.OTHERS, location) entity.act("$n comincia a %s." % verbs["you"], TO.TARGET, location) seconds = DIG_SECONDS force_return = check_trigger(entity, "before_dig", entity, location, location, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(location, "before_digged", entity, location, location, DIR.NONE, behavioured) if force_return: return True entity.action_in_progress = ActionInProgress(seconds, digging_a_location_1, stop_digging_on_location, entity, location, verbs, behavioured) return True
def give_or_put(entity, argument, verbs, behavioured, entity_tables, noflag, noroom, gamescript_suffix1, gamescript_suffix2, gamescript_suffix3, preposition): if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False # argument può essere una stringa vuota if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return False if not entity_tables: log.bug("entity_tables non è un parametro valido: %r" % entity_tables) return False if noflag not in (FLAG.NO_PUT, FLAG.NO_GIVE): log.bug("noflag non è un parametro valido: %r" % noflag) return False if noroom not in (ROOM.NO_PUT, ROOM.NO_GIVE): log.bug("noroom non è un parametro valido: %r" % noroom) return False if gamescript_suffix1 not in ("put", "give"): log.bug("gamescript_suffix1 non è un parametro valido: %r" % gamescript_suffix1) return False if gamescript_suffix2 not in ("putted", "gave"): log.bug("gamescript_suffix2 non è un parametro valido: %r" % gamescript_suffix2) return False if gamescript_suffix3 not in ("putting", "giving"): log.bug("gamescript_suffix3 non è un parametro valido: %r" % gamescript_suffix3) return False if preposition not in ("in", "a"): log.bug("gamescript_suffix non è un parametro valido: %r" % gamescript_suffix) return False # ------------------------------------------------------------------------- entity = entity.split_entity(1) if not argument: entity.send_output( "Che [white]cosa[close] vorresti %s %s [white]%s[close]?" % (verbs["infinitive"], preposition, "qualcuno" if preposition == "a" else "qualcosa")) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_put") entity.send_output(syntax) return False # Ricava l'eventuale quantità d'oggetti da posare quantity, argument = quantity_argument(argument) arg1, argument = one_argument(argument) # (TD) Controllo del mental state deviato # Ricerca nell'inventario dell'entità quella da dare o mettere target = entity.find_entity(arg1, quantity=quantity, location=entity) arg2 = "" receiver = None if argument: arg2, argument = one_argument(argument) # Rimuove eventuali argomenti facoltativi if argument and arg2 == "a": arg2, argument = one_argument(argument) # Ricerca dell'entità bersaglio a cui dare l'entità target receiver = entity.find_entity_extensively(arg2, entity_tables=entity_tables) # Controlla se si vuole inserire una porta sui cardini di un'uscita direction = get_direction(arg2) if target and not receiver and direction != DIR.NONE: if not entity.location.IS_ROOM: entity.act( "Vorresti %s $N sui cardini di un'eventuale uscita %s, ma non ti trovi in una stanza." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, target) entity.act( "$n vorrebbe %s $N sui cardini di un'eventuale uscita %s, ma non vi trovate in una stanza." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, target) entity.act( "$n ti vorrebbe %s sui cardini di un'eventuale uscita %s, ma non vi trovate in una stanza." % (verbs["infinitive"], direction.to_dir), TO.TARGET, target) return False if not direction in entity.location.exits: entity.act( "Vorresti %s $N sui cardini di un'eventuale uscita %s, ma questa non esiste." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, target) entity.act( "$n vorrebbe %s $N sui cardini di un'eventuale uscita %s, ma questa non esiste." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, target) entity.act( "$n ti vorrebbe %s sui cardini di un'eventuale uscita %s, ma questa non esiste." % (verbs["infinitive"], direction.to_dir), TO.TARGET, target) return False exit_door = entity.location.exits[direction].door if exit_door: entity.act( "Vorresti %s $N sui cardini dell'uscita %s, ma questa possiede già $a." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, target, exit_door) entity.act( "$n vorrebbe %s $N sui cardini dell'uscita %s, ma questa possiede già $a." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, target, exit_door) entity.act( "$n ti vorrebbe %s sui cardini dell'uscita %s, ma questa possiede già $a." % (verbs["infinitive"], direction.to_dir), TO.TARGET, target, exit_door) return False if not target.door_type: entity.act( "Vorresti %s sui cardini dell'uscita %s $N, ma quest'ultim$O non è una porta." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, target, exit_door) entity.act( "$n vorrebbe %s sui cardini dell'uscita %s $N, ma quest'ultim$O non è una porta." % (verbs["infinitive"], direction.to_dir), TO.OTHERS, target, exit_door) entity.act( "$n ti vorrebbe %s sui cardini dell'uscita %s, ma non sei una porta." % (verbs["infinitive"], direction.to_dir), TO.TARGET, target, exit_door) return False if quantity > 1: entity.act( "Vorresti %s sui cardini dell'uscita %s $N, ma è possibile inserirne solo un$O." % (verbs["infinitive"], direction.to_dir), TO.ENTITY, target, exit_door) entity.act( "$n vorrebbe %s sui cardini dell'uscita %s $N, ma è possibile inserirne solo un$O" % (verbs["infinitive"], direction.to_dir), TO.OTHERS, target, exit_door) entity.act( "$n ti vorrebbe %s sui cardini dell'uscita %s, ma è possibile inserirti solo in un'unità." % (verbs["infinitive"], direction.to_dir), TO.TARGET, target, exit_door) return False force_return = check_trigger(entity, "before_" + gamescript_suffix1, entity, target, None, direction, behavioured) if force_return: return True force_return = check_trigger(target, "before_" + gamescript_suffix2, entity, target, None, direction, behavioured) if force_return: return True force_return = check_trigger(receiver, "before_" + gamescript_suffix3, entity, target, None, direction, behavioured) if force_return: return True entity.act( "%s $N sui cardini dell'uscita %s." % (verbs["you"], direction.to_dir), TO.ENTITY, target) entity.act( "$n %s $N sui cardini dell'uscita %s." % (verbs["it"], direction.to_dir), TO.OTHERS, target) entity.act( "$n ti %s sui cardini dell'uscita %s." % (verbs["it"], direction.to_dir), TO.TARGET, target) target = target.from_location(1) target.to_location(entity.location) entity.location.exits[direction].door = target force_return = check_trigger(entity, "after_" + gamescript_suffix1, entity, target, None, direction, behavioured) if force_return: return True force_return = check_trigger(target, "after_" + gamescript_suffix2, entity, target, None, direction, behavioured) if force_return: return True force_return = check_trigger(receiver, "after_" + gamescript_suffix3, entity, target, None, direction, behavioured) if force_return: return True return True # ------------------------------------------------------------------------- if not arg2: arg2 = "qualcuno" if preposition == "a" else "qualcosa" # Se l'entità a cui dare si trova nell'inventario allora lo indica on_message_you = "" on_message_it = "" if receiver and receiver.location and receiver.location == entity: if receiver and len(receiver.wear_mode) > 0: on_message_you = " che stai [khaki]indossando[close]" on_message_it = " che sta [khaki]indossando[close]" else: on_message_you = " nel tuo [yellow]inventario[close]" on_message_it = " nel suo [yellow]inventario[close]" # Gestisce le varie combinazioni di entità non trovate e/o uguali # all'entità che ha digitato il comando if target: if not receiver: entity.act( "Cerchi di %s $N %s [white]%s[close] che non trovi da nessuna parte." % (verbs["infinitive"], preposition, arg2), TO.ENTITY, target) entity.act( "$n cerca di %s $N %s [white]%s[close] che non sembra trovare da nessuna parte." % (verbs["infinitive"], preposition, arg2), TO.OTHERS, target) entity.act( "$n cerca di %s %s [white]%s[close] che non sembra trovare da nessuna parte." % (verbs["you2"], preposition, arg2), TO.TARGET, target) return False elif receiver == entity: entity.act( "Cerchi di %s $N %s te stess$o, ma è già tu$O!" % (verbs["infinitive"], preposition), TO.ENTITY, target) entity.act( "$n cerca di %s $N %s se stess$o, ma è già su$O." % (verbs["infinitive"], preposition), TO.OTHERS, target) entity.act( "$n cerca di %s $N %s se stess$o, ma è già su$O." % (verbs["infinitive"], preposition), TO.TARGET, target) return False elif receiver == target: entity.act( "Cerchi di %s $N %s se stess$o, ma ciò è impossibile!" % (verbs["infinitive"], preposition), TO.ENTITY, target) entity.act( "$n cerca di %s $N %s se stess$o, ma ciò è impossibile." % (verbs["infinitive"], preposition), TO.OTHERS, target) entity.act( "$n cerca di %s $N %s te stess$o, ciò è impossibile." % (verbs["infinitive"], preposition), TO.TARGET, target) return False elif not target: if not receiver: entity.act( "Cerchi di %s [white]%s[close] %s [white]%s[close], ma non trovi nulla e nessuno nel tuo inventario." % (verbs["infinitive"], arg1, preposition, arg2), TO.ENTITY) entity.act( "$n cerca di %s [white]qualcosa[close] %s [white]quacuno[close], ma senza molti risultati nel suo inventario." % (verbs["infinitive"], preposition), TO.OTHERS) return False elif receiver == entity: if entity.IS_ITEM: entity.act( "Cerchi di [orange]passarti [white]%s[close], ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]." % arg1, TO.ENTITY, receiver) entity.act( "$n cerca di [orange]passarsi [white]qualcosa[close] che [gray]non sembra trovare[close] nel suo [yellow]inventario[close].", TO.OTHERS, receiver) else: entity.act( "Cerchi di [orange]passarti[close] da una $hand all'altra [white]%s[close], ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]." % arg1, TO.ENTITY, receiver) entity.act( "$n cerca di [orange]passarsi[close] da una $hand all'altra [white]qualcosa[close] che [gray]non sembra trovare[close] nel suo [yellow]inventario[close].", TO.OTHERS, receiver) return False else: if on_message_you and on_message_it: entity.act( "Cerchi di %s un [white]%s[close] %s $N%s, ma non trovi [gray]nulla del genere[close]." % (verbs["infinitive"], arg1, preposition, on_message_you), TO.ENTITY, receiver) entity.act( "$n cerca di %s [white]qualcosa[close] %s $N%s, ma non sembra trovare [gray]nulla del genere[close]." % (verbs["infinitive"], preposition, on_message_it), TO.OTHERS, receiver) entity.act( "$n cerca di %s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close]." % (verbs["infinitive"]), TO.TARGET, receiver) else: entity.act( "Cerchi di %s un [white]%s[close] %s $N, ma non trovi [gray]nulla del genere[close] nel tuo [yellow]inventario[close]." % (verbs["infinitive"], arg1, preposition), TO.ENTITY, receiver) entity.act( "$n cerca di %s [white]qualcosa[close] %s $N, ma non sembra trovare [gray]nulla del genere[close] nel suo [yellow]inventario[close]." % (verbs["infinitive"], preposition[2:]), TO.OTHERS, receiver) entity.act( "$n cerca di %s [white]qualcosa[close], ma non sembra trovare [gray]nulla del genere[close] nel suo [yellow]inventario[close]." % (verbs["infinitive"]), TO.TARGET, receiver) return False if quantity == 0: quantity = target.quantity elif target.quantity < quantity: entity.act( "Non puoi %s $N perché ne possiedi solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target) entity.act( "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target) return False if receiver.container_type and CONTAINER.CLOSED in receiver.container_type.flags: entity.act( "Cerchi di %s $a %s $N ma l$O trovi chius$O." % (verbs["infinitive"], preposition), TO.ENTITY, receiver, target) entity.act( "$n cerca di %s $a %s $N ma l$O trova chius$O." % (verbs["infinitive"], preposition), TO.OTHERS, receiver, target) return False # Se l'obiettivo a cui dare l'entità è un oggetto e non è un contenitore # allora solo gli admin possono eseguire l'azione if receiver.IS_ITEM and not receiver.container_type: if entity.trust > TRUST.PLAYER: entity.send_to_admin( "Il ricevitore non è un contenitore ma tu puoi eseguire comunque l'azione" ) else: entity.act( "Cerchi di %s $N %s $a, ma quest'ultimo non ti sembra un contenitore." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "$n cerca di %s $N %s $a, ma non riesce a trovare modo per farlo non essendo un contenitore." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "$n cerca di %s %s $a, ma non sembra riuscirvi visto che quest'ultimo non è un contenitore." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "$n cerca di %s $a, ma avrà ben poca fortuna visto che non sei un contenitore." % verbs["you"], TO.TARGET, receiver, target) return False # Se l'entità che ha inviato il comando ha la noflag viene evitata # l'azione if noflag in entity.flags: if entity.trust > TRUST.PLAYER: entity.send_to_admin("Tu avresti in realtà la flag NO_GIVE") else: entity.act( "Cerchi di %s $N %s $a, ma qualche [blueroyal]forza misteriosa[close] ti blocca l'azione." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "$n cerca di %s $N %s $a, ma sembra essere bloccat$n da una [royalblue]forza misteriosa[close]." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "$n cerca di %s %s $a, ma sembra essere essere bloccat$o da una [royalblue]forza misteriosa[close]." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "$n cerca di %s $a, ma sembre essere bloccat$o da una [royalblue]forza misteriosa[close]." % verbs["you"], TO.TARGET, receiver, target) return False # Se l'oggetto da dare ha la flag NO_GIVE allora evita di farsi if noflag in target.flags: if entity.trust > TRUST.PLAYER: entity.send_to_admin( "L'entità da dare avrebbe in realtà la flag NO_GIVE") else: if entity.IS_ITEM: entity.act( "Appena cerchi di %s $N %s $a te lo ritrovi, con un [cyan]balzo[close] addosso." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "Appena $n cerca di %s $N %s $a se lo ritrova, con un [cyan]balzo[close] addosso." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "Appena $n cerca di %s %s $a gli [cyan]rimbalzi[close] addosso." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "Appena $n cerca di %s $a se lo ritrova, con un [cyan]balzo[close] addosso." % verbs["you2"], TO.TARGET, receiver, target) else: entity.act( "Appena cerchi di %s $N %s $a te lo ritrovi, con un [cyan]balzo[close], in $hand." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "Appena $n cerca di %s $N %s $a se lo ritrova, con un [cyan]balzo[close], in $hand." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "Appena $n cerca di %s %s $a gli [cyan]rimbalzi[close] in $hand." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "Appena $n cerca di %s $a se lo ritrova, con un [cyan]balzo[close], in $hand." % verbs["you2"], TO.TARGET, receiver, target) return False # Se l'entità a cui dare l'oggetto ha la flag NO_GIVE allora non lo accetta if noflag in receiver.flags: if entity.trust > TRUST.PLAYER: entity.send_to_admin( "L'entità a cui dare avrebbe in realtà la flag NO_GIVE") else: if entity.IS_ITEM: entity.act( "Cerchi di %s $N %s $a, ma questi te l$O ridà." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "$n cerca di %s $N %s $a, ma questi gliel$O ridà." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "$n cerca di %s %s $a, ma questi gliel$O ridà." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "$n cerca di %s $a, ma gliel%s ridai." % (verbs["you2"], grammar_gender(target)), TO.TARGET, receiver, target) else: entity.act( "Cerchi di %s $N %s $a, ma questi te l$O ridà in $hand." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "$n cerca di %s $N %s $a, ma questi gliel$O ridà in $hand." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "$n cerca di %s %s $a, ma questi gliel$O ridà in $hand." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "$n cerca di %s $a, ma gliel%s ridai in $hand." % (verbs["you2"], grammar_gender(target)), TO.TARGET, receiver, target) return False # Se la stanza ha la flag NO_GIVE non permette di dare oggetti if entity.location.IS_ROOM and noroom in entity.location.flags: if entity.trust > TRUST.PLAYER: entity.send_to_admin( "Questa stanza avrebbe in realtà la flag di NO_GIVE") else: if entity.IS_ITEM: entity.act( "Appena cerchi di %s $N %s $a%s te l$O ritrovi addosso come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!" % (verbs["infinitive"], preposition, on_message_you), TO.ENTITY, target, receiver) entity.act( "Appena $n cerca di %s %s $a%s $N se l$O ritrova addosso come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!" % (verbs["infinitive"], preposition, on_message_it), TO.OTHERS, target, receiver) entity.act( "Appena $n cerca di %s %s $a%s gli ritorni addosso grazie ad una [royalblue]forza misteriosa[close] del luogo!" % (verbs["you2"], preposition, on_message_it), TO.TARGET, target, receiver) entity.act( "Appena $n cerca di %s $a gli ritorna addosso grazie ad una [royalblue]forza misteriosa[close] del luogo!" % (verbs["you2"]), TO.TARGET, receiver, target) else: entity.act( "Appena cerchi di %s $N %s $a%s te l$O ritrovi in $hand come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!" % (verbs["infinitive"], preposition, on_message_you), TO.ENTITY, target, receiver) entity.act( "Appena $n cerca di %s %s $a%s $N se l$O ritrova in $hand come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!" % (verbs["infinitive"], preposition, on_message_it), TO.OTHERS, target, receiver) entity.act( "Appena $n cerca di %s %s $a%s gli ritorni in $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!" % (verbs["you2"], preposition, on_message_it), TO.TARGET, target, receiver) entity.act( "Appena $n cerca di %s $a gli ritorna in $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!" % (verbs["you2"]), TO.TARGET, receiver, target) return False # (TD) dare monete # (TD) gestione dell'argomento all, ultima cosa da supportare # Se il peso dell'entità da dare supera quello sopportabile dall'obiettivo # a cui darlo allora avverte e evita l'azione # (TD) size e carry_number come il get? if not receiver.can_carry_target(target, quantity=quantity): if receiver.trust > TRUST.PLAYER: receiver.send_to_admin( "Riesci comunque a %s %s anche se è troppo pesante per te." % (verbs["infinitive"], target.get_name(entity))) elif entity.trust > TRUST.PLAYER and not receiver.IS_PLAYER: entity.send_to_admin( "Riesci comunque a %s %s anche se è troppo pesante per %s." % (verbs["infinitive"], target.get_name(entity), receiver.get_name(entity))) else: entity.act( "Non riesci %s %s $N a $a, non può portare con sé tutto quel peso." % (verbs["infinitive"], preposition), TO.ENTITY, target, receiver) entity.act( "$n non riesce a %s $N %s $a, non può portare con sé tutto quel peso." % (verbs["infinitive"], preposition), TO.OTHERS, target, receiver) entity.act( "$n non riesce a %s %s $a, non può portare con sé tutto il tuo peso." % (verbs["you2"], preposition), TO.TARGET, target, receiver) entity.act( "$n non riesce a %s $a, non puoi portare con te tutto quel peso." % verbs["you2"], TO.TARGET, receiver, target) return False force_return = check_trigger(entity, "before_" + gamescript_suffix1, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(target, "before_" + gamescript_suffix2, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(receiver, "before_" + gamescript_suffix3, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True if on_message_you and on_message_it: entity.act( "%s $N %s $a%s." % (color_first_upper(verbs["you"]), preposition, on_message_you), TO.ENTITY, target, receiver) entity.act( "$n %s $N %s $a%s." % (verbs["it"], preposition, on_message_it), TO.OTHERS, target, receiver) entity.act( "$n ti %s %s $a%s." % (verbs["it"], preposition, on_message_it), TO.TARGET, target, receiver) entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, receiver, target) else: entity.act( "%s $N %s $a." % (color_first_upper(verbs["you"]), preposition), TO.ENTITY, target, receiver) entity.act("$n %s $N %s $a." % (verbs["it"], preposition), TO.OTHERS, target, receiver) entity.act("$n ti %s %s $a." % (verbs["it"], preposition), TO.TARGET, target, receiver) entity.act("$n ti %s $a." % verbs["it"], TO.TARGET, receiver, target) target = target.from_location(quantity, use_repop=True) target.to_location(receiver) force_return = check_trigger(entity, "after_" + gamescript_suffix1, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(target, "after_" + gamescript_suffix2, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True force_return = check_trigger(receiver, "after_" + gamescript_suffix3, entity, target, receiver, DIR.NONE, behavioured) if force_return: return True return True
def command_lock(entity, argument="", verbs=VERBS, behavioured=False, container_only=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_lock) entity.send_output(entity, "command_lock", break_line=False) return False target = entity.find_entity_extensively(argument, inventory_pos="last") if not target: entity.act("Cerchi di %s %s che però non riesci a trovare." % (verbs["infinitive"], argument), TO.ENTITY) entity.act("$n cerca qualcosa che non sembra riuscire a trovare.", TO.OTHERS) return False # Nel caso che la porta, nel lato della stanza in cui entity si trova, sia # già chiusa NON prova a controllare l'eventuale porta dall'altro lato, come # invece succede col comando open, perché sarebbe impossibile da raggiungere if not target.door_type and not target.container_type: if entity == target: entity.act("Cerchi di %s te stess$o, senza molto successo..." % verbs["infinitive"], TO.ENTITY) entity.act("$n cerca di %s sé stess$o, senza molto successo..." % verbs["infinitive"], TO.OTHERS) else: entity.act("Cerchi di %s $N, ma non trovi modo di farlo." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra trovare modo di farlo." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra trovare modo di farlo." % verbs["you2"], TO.TARGET, target) return False if container_only and not target.container_type and target.door_type: entity.act("Cerchi di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra essere un contenitore." % verbs["you2"], TO.TARGET, target) return False if container_only: entitype_priority = "container" else: entitype_priority = target.get_open_close_priority() if entitype_priority != "door" and entitype_priority != "container": log.bug("entitype_priority è un valore errato: %s" % entitype_priority) return False if entitype_priority == "door": if not target.is_hinged(): entity.act("Come puoi %s $N se si trova fuori dai cardini?" % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, sarà un po' dura visto che non si trova sui cardini." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, sarà un po' dura visto che non ti trovi sui cardini..." % verbs["you2"], TO.TARGET, target) return False if DOOR.BASHED in target.door_type.flags: entity.act("Cerchi di %s $N, ma l$O trovi sfondat$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma l$O trova sfondat$O." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma ti trova sfondat$O." % verbs["you2"], TO.TARGET, target) return False entitype = target.door_type bolted_flag = DOOR.BOLTED locked_flag = DOOR.LOCKED closed_flag = DOOR.CLOSED closable_flag = DOOR.CLOSABLE destination, direction = get_destination_room_from_door(entity, target) # Se c'è una stanza di destinazione al di là della porta allora controlla # che da quella stanza sia possibile arrivare a questa, altrimenti non fa # visualizzare i messaggi remoti if destination: reverse_destination = destination.get_destination(direction.reverse_dir) if reverse_destination: reverse_destination_room = reverse_destination.get_room() if entity.location != reverse_destination_room: destination = None direction = DIR.NONE else: entitype = target.container_type bolted_flag = CONTAINER.BOLTED locked_flag = CONTAINER.LOCKED closed_flag = CONTAINER.CLOSED closable_flag = CONTAINER.CLOSABLE destination = None # (TD) supportarlo direction = None #if closed_flag not in entitype.flags: # entity.act("Cerchi di %s $N, ma l$O trovi apert$O." % verbs["infinitive"], TO.ENTITY, target) # entity.act("$n cerca di %s $N, ma l$O trova apert$O." % verbs["infinitive"], TO.OTHERS, target) # entity.act("$n cerca di %s, ma ti trova apert$O." % verbs["you2"], TO.TARGET, target) # if destination: # entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova apert$O." % ( # verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) # return False ### qui invece è ideale ma manca sapere se c'è la sua key # if closed_flag in entitype.flags and locked_flag not in entitype.flags: # entity.act("Cerchi di %s $N, ma l$O trovi già chius$O." % verbs["infinitive"], TO.ENTITY, target) # entity.act("$n cerca di %s $N, ma l$O trova già chius$O." % verbs["infinitive"], TO.OTHERS, target) # entity.act("$n cerca di %s, ma ti trova già chius$O." % verbs["you2"], TO.TARGET, target) # if destination: # entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova già chius$O." % ( # verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) # return True # ##return False # (TD) forse qui è come il test del locked sotto, oppure devo aggiungere # una flag che mi indichi se il bolt permetta o meno di chiudere la porta # if bolted_flag in entitype.flags: # entity.act("Cerchi di %s $N, scopri che è già chius$O con $a." % verbs["infinitive"], TO.ENTITY, target, entitype.bolt) # entity.act("$n cerca di %s $N, scoprendo che è già chius$O con $a." % verbs["infinitive"], TO.OTHERS, target, entitype.bolt) # entity.act("$n cerca di %s, scoprendo che sei già chius$O con $a." % verbs["you2"], TO.TARGET, target, entitype.bolt) # if destination: # entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è già chius$O con $a." % ( # verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) # return False if locked_flag in entitype.flags: entity.act("Cerchi di %s $N, ma non vi riesci perché lo è già." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma per qualche motivo non ci riesce." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non vi riesce perché lo sei già." % verbs["you2"], TO.TARGET, target) if destination: entity.act("Qualcuno, dall'altra parte, non riesce a %s $N %s perché lo è già." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) return False if closable_flag not in entitype.flags: entity.act("Non ti è possibile %s $N." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n fa gesto di voler %s $N, ma gli è impossibile." % verbs["infinitive"], TO.OTHERS, target) if destination: entity.act("Qualcuno, dall'altra parte, cerca di %s $N, scoprendo che gli è impossibile." % ( verbs["infinitive"]), TO.OTHERS, target, send_to_location=destination) entity.act("$n fa gesto di volerti %s, ma gli è impossibile." % verbs["infinitive"], TO.TARGET, target) return False key = None if entitype.key_code: for generic_key in entity.iter_contains(): if generic_key.IS_PLAYER: continue if not entity.can_see(generic_key): continue if generic_key.prototype.code == entitype.key_code: key = entitype.key_code if entitype.key_code == "" or not key: entity.act("Cerchi di %s $N, ma non riesci a trovarne la chiave." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, armeggindo inutilmente." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non vi riesce perché non ha la chiave." % verbs["you2"], TO.TARGET, target) if destination: entity.act("Qualcuno, dall'altra parte, armeggia inutilmente sulla serratura ma non riesce a %s $N %s." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) return False force_return = check_trigger(entity, "before_lock", entity, target, reverse_target, key, behavioured) if force_return: return True force_return = check_trigger(target, "before_locked", entity, target, reverse_target, key, behavioured) if force_return: return True reverse_target = None if destination and entitype_priority == "door" and DOOR.ASYNCHRONOUS not in target.door_type.flags: reverse_target = target.location.get_door(direction, direct_search=False) entitype.send_lock_messages(entity, target, verbs, direction, destination) entitype.flags += locked_flag if reverse_target and reverse_target.door_type: reverse_target.door_type.flags += locked_flag # Serve a cambiare lo status della porta o del contenitore tramite il # meccanismo di repop allo stato originario if target.repop_later: target.deferred_repop = target.repop_later.defer_check_status() if reverse_target and reverse_target.repop_later: reverse_target.deferred_repop = reverse_target.repop_later.defer_check_status() force_return = check_trigger(entity, "after_lock", entity, target, reverse_target, key, behavioured) if force_return: return True force_return = check_trigger(target, "after_locked", entity, target, reverse_target, key, behavioured) if force_return: return True return True
def command_wield(entity, argument="", verbs=VERBS, behavioured=False, command_name="wield"): """ Permette di prendere un oggetto nella mano secondaria o, se quest'ultima è occupata, in quella primaria. """ if not verbs: log.bug("verbs non è un parametro valido: %r" % verbs) return False if command_name not in ("wield", "hold"): log.bug("command_name non è un parametro valido: %r" % command_name) return False # ------------------------------------------------------------------------- # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: entity.send_output("Che cosa vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_wield") entity.send_output(syntax, break_line=False) return False # (TD) Controllo sul mental state dell'entità target = entity.find_entity(argument, location=entity) if not target: entity.act("Non riesci a trovare nessun [white]%s[close] da %s." % (argument, verbs["infinitive"]), TO.ENTITY) entity.act("$n sembra voler %s qualcosa che non trova." % verbs["infinitive"], TO.OTHERS) return False if target == entity: entity.act("Cerchi di %s da sol$o... impossibile!" % verbs["you2_min"], TO.ENTITY) entity.act("$n cerca di %s da sol$o... sarà dura!" % verbs["self_min"], TO.OTHERS) return False if FLAG.NO_HOLD in target.flags: if entity.trust >= TRUST.MASTER: entity.send_to_admin("Raccogli l'oggetto anche se è NO_HOLD") else: entity.act("Cerchi di $a $N... ma [darkgray]senza successo[close].", TO.ENTITY, target, verbs["infinitive"]) entity.act("$n cerca di $a $N... [darkgray]senza successo[close].", TO.OTHERS, target, verbs["infinitive"]) entity.act("\n$n cerca di $a... [darkgray]senza successo[close].", TO.TARGET, target, verbs["you"]) return False if (( entity.location.IS_ROOM and ROOM.NO_HOLD in entity.location.flags) or (not entity.location.IS_ROOM and FLAG.NO_HOLD in entity.location.flags)): if entity.trust >= TRUST.MASTER: entity.send_to_admin("Raccogli l'oggetto anche se la stanza è NO_HOLD") else: entity.act("Cerchi di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo l$o respinge." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingerl$o." % verbs["infinitive"], TO.OTHERS, target) entity.act("\n$n cerca di %s, tuttavia una [royalblue]forza misteriosa[close] del luogo sembra respingerl$o." % verbs["you2"], TO.TARGET, target) return False already_use_hold = entity.get_holded_entity() already_use_wield = entity.get_wielded_entity() if already_use_hold and already_use_wield: entity.act("Non puoi, hai tutte e due le $hands occupate per poter %s $N." % verbs["infinitive_min"], TO.ENTITY, target) entity.act("$n cerca di %s $N ma ha tutte e due le $hands occupate." % verbs["infinitive_min"], TO.OTHERS, target) entity.act("\n$n cerca di %s ma ha tutte e due le $hands occupate." % verbs["you2_min"], TO.TARGET, target) return False # Si salva quali mani si stanno utilizzando per l'operazione if command_name == "wield": if already_use_wield: if already_use_wield.weapon_type and WEAPONFLAG.TWO_HANDS in already_use_wield.weapon_type.flags: hands = [HAND.RIGHT, HAND.LEFT] else: if entity.IS_ITEM: hands = [HAND.RIGHT] else: hands = [entity.hand.reverse] else: if entity.IS_ITEM: hands = [HAND.LEFT] else: hands = [entity.hand] else: if already_use_hold: if already_use_hold.weapon_type and WEAPONFLAG.TWO_HANDS in already_use_hold.weapon_type.flags: hands = [HAND.RIGHT, HAND.LEFT] else: if entity.IS_ITEM: hands = [HAND.LEFT] else: hands = [entity.hand] else: if entity.IS_ITEM: hands = [HAND.RIGHT] else: hands = [entity.hand.reverse] # Raccoglie i dati per una successiva gestione generica dei due comandi if command_name == "wield": first_hand_to_use = "$hand1" second_hand_to_use = "$hand2" already_use_check = already_use_wield already_use_flag = PART.HOLD normal_flag = PART.WIELD if target.level > entity.level: tooltip = create_tooltip(entity.get_conn(), "Ciò significa che il suo livello è troppo alto rispetto al tuo", "{?}") entity.act("Senti che non potrai usufruire al meglio del danno di $N. %s" % tooltip, TO.ENTITY, target) entity.act("$n non si sente a suo agio con in mano $N.", TO.OTHERS, target) entity.act("$n non si sente a suo agio con te in mano.", TO.TARGET, target) else: first_hand_to_use = "$hand2" second_hand_to_use = "$hand1" already_use_check = already_use_hold already_use_flag = PART.WIELD normal_flag = PART.HOLD # Gestione delle armi a due mani if command_name == "wield" and target.weapon_type and WEAPONFLAG.TWO_HANDS in target.weapon_type.flags and (already_use_hold or already_use_wield): entity.act("Non puoi, devi avere tutte e due le $hands libere per poter %s $N." % WIELD_VERBS["infinitive_min"], TO.ENTITY, target) entity.act("$n cerca di %s $N ma non ha tutte e due le $hands libere." % WIELD_VERBS["infinitive_min"], TO.OTHERS, target) entity.act("\n$n cerca di %s ma non ha tutte e due le $hands libere." % WIELD_VERBS["you2_min"], TO.TARGET, target) return False if len(hands) == 2: entity.act("Non puoi, hai tutte e due le $hands occupate per poter %s $N." % WIELD_VERBS["infinitive_min"], TO.ENTITY, target) entity.act("$n cerca di %s $N ma ha tutte e due le $hands occupate." % WIELD_VERBS["infinitive_min"], TO.OTHERS, target) entity.act("\n$n cerca di %s ma ha tutte e due le $hands occupate." % WIELD_VERBS["you2_min"], TO.TARGET, target) return False force_return = check_trigger(entity, "before_" + command_name, entity, target, hands, behavioured) if force_return: return True force_return = check_trigger(target, "before_" + command_name + "ed", entity, target, hands, behavioured) if force_return: return True # Gli oggetti non hanno le mani, quindi utilizzano dei verbi non specifici if entity.IS_ITEM: entity.act("%s $N." % (color_first_upper(verbs["you_min"])), TO.ENTITY, target) entity.act("$n %s $N." % (verbs["it_min"]), TO.OTHERS, target) entity.act("\n$n %s" % (verbs["you3_min"]), TO.TARGET, target) if already_use_check: target.wear_mode = Flags(already_use_flag) else: target.wear_mode = Flags(normal_flag) elif target.weapon_type and WEAPONFLAG.TWO_HANDS in target.weapon_type.flags: entity.act("%s $N con tutte e due le $hands." % color_first_upper(verbs["you_min"]), TO.ENTITY, target) entity.act("$n %s $N con tutte e due le $hands." % verbs["it_min"], TO.OTHERS, target) entity.act("\n$n %s con tutte e due le $hands," % verbs["you3_min"], TO.TARGET, target) target.wear_mode = Flags(normal_flag, already_use_flag) elif already_use_check: entity.act("Cerchi di %s con la %s $N ma essendo già occupata utilizzi la %s." % ( verbs["infinitive_min"], first_hand_to_use, second_hand_to_use), TO.ENTITY, target) entity.act("$n cerca di %s $N con la %s ma essendo già occupata utilizza la %s." % ( verbs["infinitive_min"], first_hand_to_use, second_hand_to_use), TO.OTHERS, target) entity.act("\n$n cerca di %s con la %s ma essendo già occupata utilizza la %s." % ( verbs["you2_min"], first_hand_to_use, second_hand_to_use), TO.TARGET, target) target.wear_mode = Flags(already_use_flag) else: entity.act("%s $N con la %s." % (color_first_upper(verbs["you_min"]), first_hand_to_use), TO.ENTITY, target) entity.act("$n %s $N con la %s." % (verbs["it_min"], first_hand_to_use), TO.OTHERS, target) entity.act("\n$n %s con la %s" % (verbs["you3_min"], first_hand_to_use), TO.TARGET, target) target.wear_mode = Flags(normal_flag) for affect in target.affects: affect.apply() # Poiché l'entità è stata impugnata forse ha un valore nel gioco e non # verrà quindi purificata if target.deferred_purification: target.stop_purification() # Serve a cambiare il wear mode dell'oggetto allo stato originario if target.repop_later: target.deferred_repop = target.repop_later.defer_check_status() force_return = check_trigger(entity, "after_" + command_name, entity, target, hands, behavioured) if force_return: return True force_return = check_trigger(target, "after_" + command_name + "ed", entity, target, hands, behavioured) if force_return: return True return True
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
def update(self): first_day_of_month = False first_day_of_year = False moment_type = "" if self.minute < config.minutes_in_hour - 1: self.minute += 1 else: self.minute = 0 # Controlla il cambio dell'ora if self.hour < config.hours_in_day - 1: self.hour += 1 else: self.hour = 0 # Controlla il cambio del giorno if self.day < config.days_in_month: self.day += 1 else: first_day_of_month = True self.day = 1 # Controlla il cambio del mese if self.month.index < len(MONTH.elements): self.month += 1 else: first_day_of_year = True self.month = MONTH.ONE self.year += 1 if self.hour == config.dawn_hour: moment_type = "dawn" elif self.hour == config.sunrise_hour: moment_type = "sunrise" elif self.hour == config.noon_hour: moment_type = "noon" elif self.hour == config.sunset_hour: moment_type = "sunset" elif self.hour == config.dusk_hour: moment_type = "dusk" elif self.hour == config.midnight_hour: moment_type = "midnight" from src.database import database if moment_type: for area in database["areas"].itervalues(): echoes = globals()["ECHOES_%s" % moment_type.upper()] # (TD) a seconda che nell'area vi sia bello o brutto tempo fa # vedere o meno il sole o la luna con messaggi appositi # E anche il sistema della luna piena area_echoes = getattr(area, "echoes_%s" % moment_type) if area_echoes: echoes = area_echoes # Poiché esistono anche gli echoes personalizzabili per stanza # allora esegue una ricerca stanza per stanza for room in reversed(area.rooms.values()): room_echoes = getattr(room, "echoes_%s" % moment_type) if room_echoes: echoes = room_echoes # Se la stanza è interna allora non fa visualizzare i # messaggi di echo di default, a meno che appunto non # siano stati inseriti ad uopo per la stanza if ROOM.INSIDE in room.flags and not room_echoes: pass elif echoes: # Non esegue il random pg per pg per poter avere un # messaggio unico almeno stanza per stanza room.echo(random.choice(echoes)) # I check sui trigger force_return = check_trigger(room, "on_" + moment_type, room) if force_return: continue for content in room.iter_all_entities(use_reversed=True): force_return = check_trigger(content, "on_" + moment_type, content) if force_return: break # A tutti fa visualizzare se il giorno è il primo dell'anno o del mese # (TD) in futuro anche il nome della settimana for player in database["players"].itervalues(): if not player.game_request: continue if first_day_of_year: player.send_output("\nOggi è il [white]primo giorno[close] dell'anno %d!" % self.year) player.send_prompt() elif first_day_of_month: player.send_output("\nOggi è il [white]primo giorno[close] del mese %s." % self.month.description) player.send_prompt()
def command_open(entity, argument="", verbs=VERBS, behavioured=False, container_only=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_open") entity.send_output(syntax) return False target = entity.find_entity_extensively(argument, inventory_pos="last") if not target or (target.is_secret_door() and len(argument) < config.min_secret_arg_len): entity.act("Cerchi di %s %s che però non riesci a trovare." % (verbs["infinitive"], argument), TO.ENTITY) entity.act("$n cerca qualcosa che non sembra riuscire a trovare." % verbs["infinitive"], TO.OTHERS) return False # Nel caso che la porta, nel lato della stanza in cui si trova entity, sia # già aperta prova a controllare l'eventuale porta dall'altro lato, ma solo # se si tratta di una porta asincrona if (target.door_type and DOOR.CLOSED not in target.door_type.flags and DOOR.ASYNCHRONOUS in target.door_type.flags): reverse_target = entity.find_entity_extensively(argument, direct_search=False) if reverse_target: target = reverse_target if not target.door_type and not target.container_type: if entity == target: entity.act("Cerchi di %s te stess$o, senza molto successo..." % verbs["infinitive"], TO.ENTITY) entity.act("$n cerca di %s sé stess$o, senza molto successo..." % verbs["infinitive"], TO.OTHERS) else: entity.act("Cerchi di %s $N, ma non trovi modo di farlo." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra trovare modo di farlo." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra trovare modo di farlo." % verbs["you2"], TO.TARGET, target) return False if container_only and not target.container_type and target.door_type: entity.act("Cerchi di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra essere un contenitore." % verbs["you2"], TO.TARGET, target) return False if container_only: entitype_priority = "container" else: entitype_priority = target.get_open_close_priority() if entitype_priority != "door" and entitype_priority != "container": log.bug("entitype_priority è un valore errato: %s" % entitype_priority) return False reverse_target = None if entitype_priority == "door": if not target.is_hinged(): entity.act("Come puoi %s $N se si trova fuori dai cardini?" % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, sarà un po' dura visto che non si trova sui cardini." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, sarà un po' dura visto che non ti trovi sui cardini..." % verbs["you2"], TO.TARGET, target) return False if DOOR.BASHED in target.door_type.flags: entity.act("Cerchi di %s $N, ma l$O trovi sfondat$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma l$O trova sfondat$O." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma ti trova sfondat$O." % verbs["you2"], TO.TARGET, target) return False entitype = target.door_type closed_flag = DOOR.CLOSED locked_flag = DOOR.LOCKED bolted_flag = DOOR.BOLTED closable_flag = DOOR.CLOSABLE open_one_time_flag = DOOR.OPEN_ONE_TIME destination_room, direction = get_destination_room_from_door(entity, target) # Se c'è una stanza di destinazione al di là della porta allora # controlla che da quella stanza sia possibile arrivare a questa, # altrimenti non fa visualizzare i messaggi remoti if destination_room: reverse_destination = destination_room.get_destination(direction.reverse_dir) if reverse_destination: reverse_destination_room = reverse_destination.get_room() # Ricava la porta che si vede dall'altro lato if entity.location == reverse_destination_room: reverse_target = destination_room.get_door(direction.reverse_dir, reverse_search=False) else: destination_room = None direction = None else: entitype = target.container_type closed_flag = CONTAINER.CLOSED locked_flag = CONTAINER.LOCKED bolted_flag = CONTAINER.BOLTED closable_flag = CONTAINER.CLOSABLE open_one_time_flag = CONTAINER.OPEN_ONE_TIME destination_room = None # (TD) supportarlo direction = None if closed_flag not in entitype.flags: entity.act("Cerchi di %s $N, ma l$O trovi già apert$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma l$O trova già apert$O." % verbs["infinitive"], TO.OTHERS, target) if destination_room: entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova già apert$O." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, reverse_target, send_to_location=destination_room) entity.act("$n cerca di %s, ma ti trova già apert$O." % verbs["you2"], TO.TARGET, target) return False if locked_flag in entitype.flags: entity.act("Cerchi di %s $N, ma scopri che è chius$O a chiave." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, scoprendo che è chius$O a chiave." % verbs["infinitive"], TO.OTHERS, target) if destination_room: entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è chius$O a chiave." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, reverse_target, send_to_location=destination_room) entity.act("$n cerca di %s , scoprendo che sei chius$O a chiave." % verbs["you2"], TO.TARGET, target) return False if bolted_flag in entitype.flags: entity.act("Cerchi di %s $N, ma scopri che è sprangat$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, scoprendo che è sprangat$O." % verbs["infinitive"], TO.OTHERS, target) if destination_room: entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è sprangat$O." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination_room) entity.act("$n cerca di %s, scoprendo che sei sprangat$O." % verbs["you2"], TO.TARGET, target) return False if closable_flag not in entitype.flags: entity.act("Cerchi di %s $N, ma ti è impossibile." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma $gli è impossibile" % verbs["infinitive"], TO.OTHERS, target) if destination_room: entity.act("Qualcuno, dall'altra parte, cerca di %s $N, ma gli è impossibile." % ( verbs["infinitive"]), TO.OTHERS, reverse_target, send_to_location=destination_room) entity.act("$n cerca di %s, ma $gli è impossibile." % verbs["you2"], TO.TARGET, target) return False force_return = check_trigger(entity, "before_open", entity, target, reverse_target, container_only, behavioured) if force_return: return True force_return = check_trigger(target, "before_opened", entity, target, reverse_target, container_only, behavioured) if force_return: return True entitype.send_open_messages(entity, target, verbs, direction, destination_room, reverse_target) entitype.flags -= closed_flag if reverse_target and reverse_target.door_type and DOOR.ASYNCHRONOUS not in entitype.flags: reverse_target.door_type.flags -= closed_flag # Codice relativo ai frutti che contengono semi, se aperti si rompono e # non possono essere più chiusi, il danno è proporzionale al contenuto if open_one_time_flag in entitype.flags: entitype.flags -= closable_flag if target.entitype in (ENTITYPE.FRUIT, ENTITYPE.FLOWER): target.life -= len(target.items) + len(target.mobs) + len(target.players) if target.life < 0: target.life = 0 # Serve a cambiare lo status della porta o del contenitore tramite il # meccanismo di repop allo stato originario if target.repop_later: target.deferred_repop = target.repop_later.defer_check_status() if reverse_target and reverse_target.repop_later: reverse_target.deferred_repop = reverse_target.repop_later.defer_check_status() # Dona un po' di esperienza ai giocatori che hanno aperto per la prima # volta l'entità if entity.IS_PLAYER: if target.prototype.code in entity.opened_entities: entity.opened_entities[target.prototype.code] += 1 else: entity.opened_entities[target.prototype.code] = 1 reason = "per aver aperto per la prima volta %s" % target.get_name(looker=entity) entity.give_experience(target.level*10, reason=reason) force_return = check_trigger(entity, "after_open", entity, target, reverse_target, container_only, behavioured) if force_return: return True force_return = check_trigger(target, "after_opened", entity, target, reverse_target, container_only, behavioured) if force_return: return True return True
def command_drop(entity, argument="", verbs=VERBS, behavioured=False): """ Permette di abbandonare oggetti per terra oppure posarli in un luogo preciso. """ # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if entity.sended_inputs and is_prefix("abbandon", entity.sended_inputs[-1]): verbs = VERBS2 if not argument: entity.send_output("Che cosa vorresti %s." % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_drop") entity.send_output(syntax, break_line=False) return False # Ricava l'eventuale quantità d'oggetti da posare quantity, argument = quantity_argument(argument) # (TD) Controllo del mental state deviato # Ricerca dell'oggetto nell'inventario, non viene utilizzata la extended target = entity.find_entity(argument, quantity=quantity, location=entity) if not target: entity.act( "Non riesci a trovare nessun [white]%s[close] da poter %s." % (argument, verbs["infinitive"]), TO.ENTITY) entity.act("$n sembra cercare qualcosa ma senza risultato.", TO.OTHERS) return False if quantity == 0: quantity = target.quantity elif target.quantity < quantity: entity.act( "Non puoi %s $N perché ne hai solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target) entity.act( "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target) return False if FLAG.NO_DROP in target.flags: if entity.trust > TRUST.MASTER: entity.send_to_admin( "Questa sarebbe in realtà un'entità NO_DROP e non potresti lasciarla" ) else: entity.act( "Appena cerchi di %s $N te lo ritrovi, con un balzo, in $hand." % verbs["infinitive"], TO.ENTITY, target) entity.act( "Appena $n cerca di %s $N se lo ritrova, con un balzo, in $hand." % verbs["infinitive"], TO.OTHERS, target) entity.act( "\nAppena $n cerca di %s gli ritorni in $hand con un balzo." % verbs["you2"], TO.TARGET, target) return False # Non permette di droppare oggetti nelle stanze con flag di NO_DROP if entity.location.IS_ROOM and ROOM.NO_DROP in entity.location.flags: if entity.trust > TRUST.MASTER: entity.send_to_admin( "Questa sarebbe in realtà una stanza NO_DROP in cui non poter lasciar entità" ) else: entity.act( "Appena %s $N te lo ritrovi in %hand come se una [royalblue]forza misteriosa[close] nel luogo ti impedisse quest'azione!" % verbs["you"], TO.ENTITY, target) entity.act( "Appena $n lascia andare $N, con l'intenzione di %s, se lo ritrova in $hand come se vi fosse una [royalblue]forza misteriosa[close] nel luogo!" % verbs["noun"], TO.OTHERS, target) entity.act( "\nAppena $n ti %s ritorni nella sua $hand grazie ad una [royalblue]forza misteriosa[close] del luogo!" % verbs["it"], TO.TARGET, target) return False # (TD) posare monete # (TD) argomento all, ultima cosa da supportare # Ricava la locazione in cui posare l'oggetto # (TD) location = entity.location force_return = check_trigger(entity, "before_drop", entity, target, location, behavioured) if force_return: return True force_return = check_trigger(target, "before_dropped", entity, target, location, behavioured) if force_return: return True force_return = check_trigger(location, "before_drop_from_location", entity, target, location, behavioured) if force_return: return True entity.act("%s $N in $l." % color_first_upper(verbs["you"]), TO.ENTITY, target) entity.act("$n %s $N in $l." % verbs["it"], TO.OTHERS, target) entity.act("$n ti %s in $l." % verbs["it"], TO.TARGET, target) if not location.IS_ROOM: entity.act("$n ti %s qualcosa." % verbs["it"], TO.TARGET, location) if FLAG.INGESTED in target.flags: if entity.trust >= TRUST.MASTER: entity.send_to_admin("%s %s anche se lo stai digerendo." % (verbs["you"], target.get_name(entity))) else: log.bug( "I giocatori non dovrebbero poter manipolare oggetti ingeriti") entity.send_output( "[cyan]Errore di digestione nel comando, gli amministratori sono stati avvertiti del problema.[close]" ) return False target.stop_digestion() target = target.from_location(quantity, use_repop=True) target.to_location(location) force_return = check_trigger(entity, "after_drop", entity, target, location, behavioured) if force_return: return True force_return = check_trigger(target, "after_dropped", entity, target, location, behavioured) if force_return: return True force_return = check_trigger(location, "after_drop_from_location", entity, target, location, behavioured) if force_return: return True return True
def command_sell(entity, argument="", verbs=VERBS, behavioured=False): """ Permette di vendere entità ai commercianti. """ # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: for dealer in entity.location.iter_contains(): if dealer.shop and SHOP.DISPENSER in dealer.shop.types: entity.act("Cerchi di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer) entity.act("$n cerca di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer) entity.act("$n cerca di %s qualcosa ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) return False entity.send_output("Cosa vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_sell") entity.send_output(syntax, break_line=False) return False # Ricava la quantità da vendere e poi l'eventuale valore facoltativo del negoziante quantity, argument = quantity_argument(argument) arg, argument = one_argument(argument) target = entity.find_entity(arg, quantity=quantity, location=entity) if not target: entity.act("Non trovi nessun [white]%s[close] da %s nel tuo inventario." % (arg, verbs["infinitive"]), TO.ENTITY) entity.act("$n sta cercando qualcosa senza trovarla", TO.OTHERS) return False # Controlla se la quantità da vendere sia sufficente rispetto a quello che si possiede if quantity == 0: quantity = target.quantity elif target.quantity < quantity: entity.act("Non puoi %s $N perché ne possiedi solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target) entity.act("$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target) entity.act("$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target) return False if argument: dealer = entity.find_entity_extensively(argument) if not dealer: entity.act("Non trovi nessun negoziante chiamato [white]%s[close] a cui %s $N." % (argument, verbs["infinitive"]), TO.ENTITY, target) entity.act("$n sembra cercare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False if not dealer.shop: entity.act("$N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act("$n si accorge che $N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act("$n si accorge che tu non sei un negoziante a cui %s $a." % verbs["infinitive"], TO.TARGET, dealer, target) return False else: for dealer in entity.location.iter_contains(): if dealer.shop: break else: entity.act("Qui non trovi nessun negoziante a cui %s $N." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n non sembra trovare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False # Controlla se il negoziante si trova in una locazione che fa, per lui, da negozio if not dealer.shop.in_location(dealer): entity.act("Non puoi %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.ENTITY, dealer) entity.act("$n non può %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.OTHERS, dealer) entity.act("$n non può %s nulla da te se non ti trovi nel tuo negozio." % verbs["infinitive"], TO.TARGET, dealer) return False # Indica che un'entità vuole interagire con il dealer if entity not in dealer.interactions: dealer.interactions.append(entity) if FLAG.NO_DROP in target.flags: if entity.trust > TRUST.MASTER: entity.send_output("{Questa sarebbe in realtà un'entità NO_DROP e potresti venderla}") else: entity.act("Appena cerchi di %s $a a $N te lo ritrovi, con un balzo, in $hand." % verbs["infinitive"], TO.ENTITY, target, dealer) entity.act("Appena $n cerca di %s $a a $N se lo ritrova, con un balzo, in $hand." % verbs["infinitive"], TO.OTHERS, target, dealer) entity.act("Appena $n cerca di %s a $a gli ritorni in $hand con un balzo." % verbs["you2"], TO.TARGET, target, dealer) entity.act("Appena $n cerca di %s $a questi gli ritorna in $hand con un balzo." % verbs["you2"], TO.TARGET, dealer, target) return False if not target.is_empty(): entity.act("Non puoi %s $N a $a perché contiene qualcosa." % verbs["infinitive"], TO.ENTITY, target, dealer) entity.act("$n non può %s $N a $a perché contiene qualcosa." % verbs["infinitive"], TO.OTHERS, target, dealer) entity.act("$n non può %s a $a perché contieni qualcosa." % verbs["you2"], TO.TARGET, target, dealer) entity.act("$n non può %s $a perché contiene qualcosa." % verbs["you2"], TO.TARGET, dealer, target) return False if SHOP.DISPENSER in dealer.shop.types: entity.act("Cerchi di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act("$n cerca di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act("$n cerca di %s $a ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) entity.act("$n cerca di %s a $N ma ciò non è possibile perché è un distributore." % verbs["you2"], TO.TARGET, target, dealer) return False sellable = dealer.shop.get_sellable(target) if not sellable: dealer.shop.send_uninterested_messages(entity, target, dealer) return False if target.value <= 0: entity.act("$N guarda senza molto interesse $a: è senza valore!", TO.ENTITY, dealer, target) entity.act("$N guarda senza molto interesse $a mostrato da $n: è senza valore.", TO.OTHERS, dealer, target) entity.act("Guardi senza molto interesse $a mostrato da $n: è senza valore...", TO.TARGET, dealer, target) entity.act("$a ti guarda senza molto interesse: sei senza valore...", TO.TARGET, target, dealer) return False # I negozianti ora pagano con denaro virtuale, in questa maniera non devono averne apposta addosso #if not can_afford(target.value * quantity, dealer): # entity.act("$a vale più di quanto $N possa permettersi di pagarti.", TO.ENTITY, dealer, target) # entity.act("$a vale più di quanto $N possa permettersi di pagare $n.", TO.OTHERS, dealer, target) # entity.act("$a vale più di quanto tu possa permetterti di pagare $n.", TO.TARGET, dealer, target) # entity.act("Vale più di quanto $N possa permettersi di pagare $n.", TO.TARGET, target, dealer) # return False storage = dealer.shop.get_storage(dealer) if not storage: if dealer.shop.proto_storages and dealer.shop.proto_storages[0].IS_MOB: from_where = "a chi dare" else: from_where = "ove mettere" entity.act("Non puoi %s nulla a $N perché non ha %s la mercanzia!" % (verbs["infinitive"], from_where), TO.ENTITY, dealer) entity.act("$n non può %s nulla a $N perché non ha %s la mercanzia!" % (verbs["infinitive"], from_where), TO.OTHERS, dealer) entity.act("$n non può %s nulla perché non hai %s la mercanzia!" % (verbs["you2"], from_where), TO.TARGET, dealer) return False # Attenzione che qui target non è ancora la quantità giusta force_return = check_trigger(entity, "before_sell", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "before_selling", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "before_sold", entity, dealer, target, quantity, behavioured) if force_return: return True price = math.trunc((target.value * sellable.percent) / 100) * quantity pretty_price = pretty_money_value(price, extended=True) dealer.shop.send_sell_messages(entity, target, dealer, verbs, quantity, pretty_price) dealer.shop.add_buyable(dealer, target, sellable, quantity) target = target.from_location(quantity) target.to_location(storage) give_moneys(dealer, entity, price) # Dona un po' di esperienza ai giocatori che hanno venduto per la prima # volta l'entità if entity.IS_PLAYER: if target.prototype.code in entity.selled_entities: entity.selled_entities[target.prototype.code] += 1 else: entity.selled_entities[target.prototype.code] = 1 reason = "per aver venduto per la prima volta %s" % target.get_name(looker=entity) entity.give_experience(target.level*10, reason=reason) force_return = check_trigger(entity, "after_sell", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "after_selling", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "after_sold", entity, dealer, target, quantity, behavioured) if force_return: return True return True
def check_social(entity, command, argument="", behavioured=False): """ Invia i messaggi corretti relativamente ad un comando di social. """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return if not command: log.bug("command non è un parametro valido: %r" % command) return # ------------------------------------------------------------------------- try: social = database["socials"][command.fun_name] except NameError: log.bug("Social %s, inviato dall'entità %s, errato o inesistente nel database dei social." % (entity.code, command.fun_name)) return active_trigger_suffix = "active_" + social.get_input_argument() passive_trigger_suffix = "passive_" + social.get_input_argument() # Se non è stato passato nessun argomento invia il messaggio di social adatto if not argument: force_return = check_trigger(entity, "before_" + active_trigger_suffix, entity, None, argument, behavioured) if force_return: return force_return = check_trigger(entity.location, "before_" + passive_trigger_suffix, entity, None, argument, behavioured) if force_return: return # Esegue il trigger anche sulle altre entità perché così funziona il # caso in cui per esempio un player ha eseguito un nod e un mob è in # attesa di un sì for contain in entity.location.iter_contains(use_reversed=True): force_return = check_trigger(contain, "before_" + passive_trigger_suffix, entity, None, argument, behavioured) if force_return: continue entity.act(social.get_racial_message(entity, "entity_no_arg"), TO.ENTITY) # others_no_arg è un messaggio facoltativo racial_message = social.get_racial_message(entity, "others_no_arg") if racial_message: entity.act(racial_message, TO.OTHERS) force_return = check_trigger(entity, "after_" + active_trigger_suffix, entity, None, argument, behavioured) if force_return: return force_return = check_trigger(entity.location, "after_" + passive_trigger_suffix, entity, None, argument, behavioured) if force_return: return for contain in entity.location.iter_contains(use_reversed=True): force_return = check_trigger(contain, "after_" + passive_trigger_suffix, entity, None, argument, behavioured) if force_return: continue return # Se invece è stato passato un argomento trova la vittima target = entity.find_entity_extensively(argument) if not target: target = entity.find_entity(argument, location=entity) if not target: entity.send_output("Non trovi nessun [white]%s[close] qui intorno." % argument) return # Se la vittima e l'entità sono uguali cerca il messaggio di sociale _auto # oppure se questo non esiste il no_arg che ne fa le veci if target == entity: force_return = check_trigger(entity, "before_" + active_trigger_suffix, entity, target, argument, behavioured) if force_return: return force_return = check_trigger(target, "before_" + passive_trigger_suffix, entity, target, argument, behavioured) if force_return: return # Se non c'è il messaggio entity_auto c'è entity_no_arg msg_auto = social.get_racial_message(entity, "entity_auto") if not msg_auto: msg_auto = social.get_racial_message(entity, "entity_no_arg") entity.act(msg_auto, TO.ENTITY, target) # Se non c'è il messaggio others_auto c'è others_no_arg msg_auto = social.get_racial_message(entity, "others_auto") if not msg_auto: msg_auto = social.get_racial_message(entity, "others_no_arg") entity.act(msg_auto, TO.OTHERS, target) force_return = check_trigger(entity, "after_" + active_trigger_suffix, entity, target, argument, behavioured) if force_return: return force_return = check_trigger(target, "after_" + passive_trigger_suffix, entity, target, argument, behavioured) if force_return: return return # Se la vittima non è entity provvede ad inviare il messaggio di social adatto force_return = check_trigger(entity, "before_" + active_trigger_suffix, entity, target, argument, behavioured) if force_return: return force_return = check_trigger(target, "before_" + passive_trigger_suffix, entity, target, argument, behavioured) if force_return: return entity.act(social.get_racial_message(entity, "entity_found", target, "tuo"), TO.ENTITY, target) entity.act(social.get_racial_message(entity, "others_found", target, "suo"), TO.OTHERS, target) entity.act(social.get_racial_message(entity, "target_found"), TO.TARGET, target) force_return = check_trigger(entity, "after_" + active_trigger_suffix, entity, target, argument, behavioured) if force_return: return force_return = check_trigger(target, "after_" + passive_trigger_suffix, entity, target, argument, behavioured) if force_return: return # Da qui in poi gestisce l'invio dei social automatici da parte dei mob # rispondendo ai social dei pg if not entity.IS_PLAYER or not target.IS_MOB: return # Invia a caso e dopo un secondo invia un social con la stessa intenzione. # Non viene inviata la risposta social automatica se ci sono dei trigger # relativi a quel social da qualche parte # (bb) tuttavia la ricerca così dei trigger è fallace e ci vorrebbe una funzione a parte if ("before_" + active_trigger_suffix not in entity.gamescripts and "after_" + active_trigger_suffix not in entity.gamescripts and "before_" + active_trigger_suffix not in target.gamescripts and "after_" + active_trigger_suffix not in target.gamescripts and "before_" + active_trigger_suffix not in entity.location.gamescripts and "after_" + active_trigger_suffix not in entity.location.gamescripts and random.randint(0, 3) == 0 and not behavioured): defer(1, social.send_to, target, entity)
def command_unbolt(entity, argument="", verbs=VERBS, behavioured=False, container_only=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_unbolt") entity.send_output(syntax) return False target = entity.find_entity_extensively(argument, inventory_pos="last") if not target or (target.is_secret_door() and len(argument) < config.min_secret_arg_len): entity.act("Cerchi di %s %s che però non riesci a trovare." % (verbs["infinitive"], argument), TO.ENTITY) entity.act("$n cerca qualcosa che non sembra riuscire a trovare.", TO.OTHERS) return False # Nel caso che la porta, nel lato della stanza in cui si trova entity, sia # già aperta prova a controllare l'eventuale porta dall'altro lato, ma solo # se si tratta di una porta asincrona if (target.door_type and DOOR.CLOSED not in target.door_type.flags and DOOR.ASYNCHRONOUS in target.door_type.flags): reverse_target = entity.find_entity_extensively(argument, direct_search=False) if reverse_target: target = reverse_target if not target.door_type and not target.container_type: if entity == target: entity.act("Cerchi di %s te stess$o, senza molto successo..." % verbs["infinitive"], TO.ENTITY) entity.act("$n cerca di %s sé stess$o, senza molto successo..." % verbs["infinitive"], TO.OTHERS) else: entity.act("Cerchi di %s $N, ma non trovi modo di farlo." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra trovare modo di farlo." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra trovare modo di farlo." % verbs["you2"], TO.TARGET, target) return False if container_only and not target.container_type and target.door_type: entity.act("Cerchi di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma non sembra essere un contenitore." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma non sembra essere un contenitore." % verbs["you2"], TO.TARGET, target) return False if container_only: entitype_priority = "container" else: entitype_priority = target.get_open_close_priority() if entitype_priority != "door" and entitype_priority != "container": log.bug("entitype_priority è un valore errato: %s" % entitype_priority) return False if entitype_priority == "door": if not target.is_hinged(): entity.act("Come puoi %s $N se si trova fuori dai cardini?" % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, sarà un po' dura visto che non si trova sui cardini." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, sarà un po' dura visto che non ti trovi sui cardini..." % verbs["you2"], TO.TARGET, target) return False if DOOR.BASHED in target.door_type.flags: entity.act("Cerchi di %s $N, ma l$O trovi sfondat$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma l$O trova sfondat$O." % verbs["infinitive"], TO.OTHERS, target) entity.act("$n cerca di %s, ma ti trova sfondat$O." % verbs["you2"], TO.TARGET, target) return False entitype = target.door_type # (TD) queste flag spostarle nei vari entitype closed_flag = DOOR.CLOSED locked_flag = DOOR.LOCKED boltable_flag = DOOR.BOLTABLE bolted_flag = DOOR.BOLTED destination, direction = get_destination_room_from_door(entity, target) if destination: reverse_destination = destination.get_destination(direction.reverse_dir) if reverse_destination: reverse_destination_room = reverse_destination.get_room() if entity.location != reverse_destination_room: destination = None direction = DIR.NONE else: entitype = target.container_type closed_flag = CONTAINER.CLOSED locked_flag = CONTAINER.LOCKED boltable_flag = CONTAINER.BOLTABLE bolted_flag = CONTAINER.BOLTED destination = None # (TD) supportarlo direction = None if entitype_priority == "container" and CONTAINER.BOLTABLE not in entitype.flags: entity.act("Cerchi di %s $N, ma ti è impossibile." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma $gli è impossibile" % verbs["infinitive"], TO.OTHERS, target) if destination: entity.act("Qualcuno, dall'altra parte, cerca di %s $N, ma gli è impossibile." % ( verbs["infinitive"]), TO.OTHERS, target, send_to_location=destination) entity.act("$n cerca di %s, ma $gli è impossibile." % verbs["you2"], TO.TARGET, target) return False if boltable_flag in entitype.flags and bolted_flag not in entitype.flags: entity.act("Cerchi di %s $N, ma l$O trovi già svincolat$O." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n cerca di %s $N, ma l$O trova già svincolat$O." % verbs["infinitive"], TO.OTHERS, target) if destination: entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, ma l$O trova già svincolat$O." % ( verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) entity.act("$n cerca di %s, ma ti trova già svincolat$O." % verbs["you2"], TO.TARGET, target) return False ### if locked_flag in entitype.flags: ### entity.act("Cerchi di %s $N, ma scopri che è già chius$O a chiave." % verbs["infinitive"], TO.ENTITY, target) ### entity.act("$n cerca di %s $N, scoprendo che è già chius$O a chiave." % verbs["infinitive"], TO.OTHERS, target) ### if destination: ### entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è già chius$O a chiave." % ( ### verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) ### entity.act("$n cerca di %s , scoprendo che sei già chius$O a chiave." % verbs["you2"], TO.TARGET, target) ### return False ## ## if bolted_flag in entitype.flags: ## entity.act("Cerchi di %s $N, ma scopri che è chius$O con $a." % verbs["infinitive"], TO.ENTITY, target, entitype.bolt) ## entity.act("$n cerca di %s $N, scoprendo che è chius$O con $a." % verbs["infinitive"], TO.OTHERS, target, entitype.bolt) ## if destination: ## entity.act("Qualcuno, dall'altra parte, cerca di %s $N %s, scoprendo che è chius$O con $a." % ( ## verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, entitype.bolt, send_to_location=destination) ## entity.act("$n cerca di %s, scoprendo che sei chius$O con $a." % verbs["you2"], TO.TARGET, target, entitype.bolt) ## return False # key = None # if entitype.key_code: # for generic_key in entity.iter_contains(): # if not entity.can_see(generic_key): # continue # if generic_key.prototype.code == entitype.key_code: # key = entitype.key_code # # if not entitype.key_code or not key: # entity.act("Cerchi di %s $N, ma non riesci a trovarne la chiave." % verbs["infinitive"], TO.ENTITY, target) # entity.act("$n cerca di %s $N, armeggindo inutilmente." % verbs["infinitive"], TO.OTHERS, target) # entity.act("$n cerca di %s, ma non vi riesce perché non ha la chiave." % verbs["you2"], TO.TARGET, target) # if destination: # entity.act("Qualcuno, dall'altra parte, armeggia inutilmente sulla serratura ma non riesce a %s $N %s." % ( # verbs["infinitive"], direction.reverse_dir.to_dir2), TO.OTHERS, target, send_to_location=destination) # return False reverse_target = None if destination and entitype_priority == "door" and DOOR.ASYNCHRONOUS not in entitype.flags: reverse_target = target.location.get_door(direction, direct_search=False) force_return = check_trigger(entity, "before_unbolt", entity, target, reverse_target, behavioured) if force_return: return True force_return = check_trigger(target, "before_unbolted", entity, target, reverse_target, behavioured) if force_return: return True entitype.send_unbolt_messages(entity, target, verbs, direction, destination) entitype.flags -= bolted_flag if reverse_target and reverse_target.door_type: reverse_target.door_type.flags -= bolted_flag # Serve a cambiare lo status della porta o del contenitore tramite il # meccanismo di repop allo stato originario if target.repop_later: target.deferred_repop = target.repop_later.defer_check_status() if reverse_target and reverse_target.repop_later: reverse_target.deferred_repop = reverse_target.repop_later.defer_check_status() # Dona un po' di esperienza ai giocatori che hanno svincolato per la prima # volta l'entità if entity.IS_PLAYER: if target.prototype.code in entity.unbolted_entities: entity.unbolted_entities[target.prototype.code] += 1 else: entity.unbolted_entities[target.prototype.code] = 1 reason = "per aver svincolato per la prima volta %s" % target.get_name(looker=entity) entity.give_experience(target.level*10, reason=reason) force_return = check_trigger(entity, "after_unbolt", entity, target, reverse_target, behavioured) if force_return: return True force_return = check_trigger(target, "after_unbolted", entity, target, reverse_target, behavioured) if force_return: return True return True
def command_offer(entity, argument="", verbs=VERBS, behavioured=False): """ Permette di vendere entità ai commercianti. """ # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: for dealer in entity.location.iter_contains(): if dealer.shop: break if SHOP.DISPENSER in dealer.shop.types: entity.act("Cerchi di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer) entity.act("$n cerca di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer) entity.act("$n cerca di %s qualcosa ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) return False entity.send_output("Cosa vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_offer") entity.send_output(syntax, break_line=False) return False # Ricava la quantità da offrire e poi l'eventuale valore facoltativo del negoziante quantity, argument = quantity_argument(argument) arg, argument = one_argument(argument) target = entity.find_entity(arg, quantity=quantity, location=entity) if not target: entity.act("Non trovi nessun [white]%s[close] da %s nel tuo inventario." % (arg, verbs["infinitive"]), TO.ENTITY) entity.act("$n sta cercando qualcosa senza trovarla" % verbs["infinitive"], TO.OTHERS) return False if quantity == 0: quantity = target.quantity elif target.quantity < quantity: entity.act("Non puoi %s $N perché ne possiedi solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target) entity.act("$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target) entity.act("$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target) return False if argument: dealer = entity.find_entity_extensively(argument) if not dealer: entity.act("Non trovi nessun negoziante chiamato [white]%s[close] a cui %s $N." % (argument, verbs["infinitive"]), TO.ENTITY, target) entity.act("$n sembra cercare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False if not dealer.shop: entity.act("$N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act("$n si accorge che $N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act("$n si accorge che tu non sei un negoziante a cui %s $a." % verbs["infinitive"], TO.TARGET, dealer, target) return False else: for dealer in entity.location.iter_contains(): if dealer.shop: break else: entity.act("Qui non trovi nessun negoziante a cui %s $N." % verbs["infinitive"], TO.ENTITY, target) entity.act("$n non sembra trovare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False # Controlla se il negoziante si trova in una locazione che fa, per lui, da negozio if not dealer.shop.in_location(dealer): entity.act("Non puoi %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.ENTITY, dealer) entity.act("$n non può %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.OTHERS, dealer) entity.act("$n non può %s nulla da te se non ti trovi nel tuo negozio." % verbs["infinitive"], TO.TARGET, dealer) return False # Indica che un'entità vuole interagire con il dealer if entity not in dealer.interactions: dealer.interactions.append(entity) if SHOP.DISPENSER in dealer.shop.types: entity.act("Cerchi di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act("$n cerca di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act("$n cerca di %s $a ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) entity.act("$n cerca di %s a $N ma ciò non è possibile perché è un distributore." % verbs["you2"], TO.TARGET, target, dealer) return False sellable = dealer.shop.get_sellable(target) if not sellable: dealer.shop.send_uninterested_messages(entity, target, dealer) return False price = math.trunc((target.value * sellable.percent) / 100) * quantity if price <= 0: entity.act("$N guarda senza molto interesse $a: è senza valore!", TO.ENTITY, dealer, target) entity.act("$N guarda senza molto interesse $a mostrato da $n: è senza valore.", TO.OTHERS, dealer, target) entity.act("Guardi senza molto interesse $a mostrato da $n: è senza valore...", TO.TARGET, dealer, target) entity.act("$a ti guarda senza molto interesse: sei senza valore...", TO.TARGET, target, dealer) return False # Attenzione che qui target non è ancora la quantità giusta force_return = check_trigger(entity, "before_offer", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "before_offering", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "before_offered", entity, dealer, target, quantity, behavioured) if force_return: return True pretty_price = pretty_money_value(price, extended=True) dealer.shop.send_offer_messages(entity, target, dealer, verbs, quantity, pretty_price) force_return = check_trigger(entity, "after_offer", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "after_offering", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "after_offered", entity, dealer, target, quantity, behavioured) if force_return: return True return True
def command_offer(entity, argument="", verbs=VERBS, behavioured=False): """ Permette di vendere entità ai commercianti. """ # È possibile se il comando è stato deferrato if not entity: return False entity = entity.split_entity(1) if not argument: for dealer in entity.location.iter_contains(): if dealer.shop: break if SHOP.DISPENSER in dealer.shop.types: entity.act( "Cerchi di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer) entity.act( "$n cerca di %s qualcosa a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer) entity.act( "$n cerca di %s qualcosa ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) return False entity.send_output("Cosa vorresti %s?" % verbs["infinitive"]) if entity.IS_PLAYER and OPTION.NEWBIE in entity.account.options: syntax = get_command_syntax(entity, "command_offer") entity.send_output(syntax, break_line=False) return False # Ricava la quantità da offrire e poi l'eventuale valore facoltativo del negoziante quantity, argument = quantity_argument(argument) arg, argument = one_argument(argument) target = entity.find_entity(arg, quantity=quantity, location=entity) if not target: entity.act( "Non trovi nessun [white]%s[close] da %s nel tuo inventario." % (arg, verbs["infinitive"]), TO.ENTITY) entity.act( "$n sta cercando qualcosa senza trovarla" % verbs["infinitive"], TO.OTHERS) return False if quantity == 0: quantity = target.quantity elif target.quantity < quantity: entity.act( "Non puoi %s $N perché ne possiedi solo %d e non %d." % (verbs["infinitive"], target.quantity, quantity), TO.ENTITY, target) entity.act( "$n sta cercando di ammucchiare un quantitativo voluto di $N per poterlo %s" % verbs["infinitive"], TO.OTHERS, target) entity.act( "$n sta cercando di ammucchiarti per un quantitativo voluto per poterti %s" % verbs["infinitive"], TO.TARGET, target) return False if argument: dealer = entity.find_entity_extensively(argument) if not dealer: entity.act( "Non trovi nessun negoziante chiamato [white]%s[close] a cui %s $N." % (argument, verbs["infinitive"]), TO.ENTITY, target) entity.act( "$n sembra cercare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False if not dealer.shop: entity.act( "$N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act( "$n si accorge che $N non sembra essere un negoziante a cui %s $a." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act( "$n si accorge che tu non sei un negoziante a cui %s $a." % verbs["infinitive"], TO.TARGET, dealer, target) return False else: for dealer in entity.location.iter_contains(): if dealer.shop: break else: entity.act( "Qui non trovi nessun negoziante a cui %s $N." % verbs["infinitive"], TO.ENTITY, target) entity.act( "$n non sembra trovare qualcuno a cui %s $N." % verbs["infinitive"], TO.OTHERS, target) return False # Controlla se il negoziante si trova in una locazione che fa, per lui, da negozio if not dealer.shop.in_location(dealer): entity.act( "Non puoi %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.ENTITY, dealer) entity.act( "$n non può %s nulla da $N se non si trova nel suo negozio." % verbs["infinitive"], TO.OTHERS, dealer) entity.act( "$n non può %s nulla da te se non ti trovi nel tuo negozio." % verbs["infinitive"], TO.TARGET, dealer) return False # Indica che un'entità vuole interagire con il dealer if entity not in dealer.interactions: dealer.interactions.append(entity) if SHOP.DISPENSER in dealer.shop.types: entity.act( "Cerchi di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.ENTITY, dealer, target) entity.act( "$n cerca di %s $a a $N ma ciò non è possibile perché quest'ultim$O è un distributore." % verbs["infinitive"], TO.OTHERS, dealer, target) entity.act( "$n cerca di %s $a ma ciò non è possibile perché sei un distributore." % verbs["you2"], TO.TARGET, dealer, target) entity.act( "$n cerca di %s a $N ma ciò non è possibile perché è un distributore." % verbs["you2"], TO.TARGET, target, dealer) return False sellable = dealer.shop.get_sellable(target) if not sellable: dealer.shop.send_uninterested_messages(entity, target, dealer) return False price = math.trunc((target.value * sellable.percent) / 100) * quantity if price <= 0: entity.act("$N guarda senza molto interesse $a: è senza valore!", TO.ENTITY, dealer, target) entity.act( "$N guarda senza molto interesse $a mostrato da $n: è senza valore.", TO.OTHERS, dealer, target) entity.act( "Guardi senza molto interesse $a mostrato da $n: è senza valore...", TO.TARGET, dealer, target) entity.act("$a ti guarda senza molto interesse: sei senza valore...", TO.TARGET, target, dealer) return False # Attenzione che qui target non è ancora la quantità giusta force_return = check_trigger(entity, "before_offer", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "before_offering", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "before_offered", entity, dealer, target, quantity, behavioured) if force_return: return True pretty_price = pretty_money_value(price, extended=True) dealer.shop.send_offer_messages(entity, target, dealer, verbs, quantity, pretty_price) force_return = check_trigger(entity, "after_offer", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(dealer, "after_offering", entity, dealer, target, quantity, behavioured) if force_return: return True force_return = check_trigger(target, "after_offered", entity, dealer, target, quantity, behavioured) if force_return: return True return True
def rpg_channel(entity, argument, channel, ask=False, exclaim=False, behavioured=False): """ Gestisce i canali rpg, ha le seguenti caratteristiche: - supporto per gli smile - supporto per i modi di esprimersi con esclamativo e punto di domanda - supporto per gli emote - gestione del bersaglio che può essere un'entità, il gruppo o sé stessi - (TD) parlata da ubriaco - (TD) espansione della potenza della voce in altre stanze - (TD) espressioni per le stanze attorno, anche per coloro che riconoscono la voce, pensare anche alla suddivisione tra social gestuali e 'rumorosi' per gli smile-espressioni around - (TD) modulazione della voce a seconda delle dimensioni di chi parla e della sua voice_potence """ if not entity: log.bug("entity non è un parametro valido: %r" % entity) return False if not channel: log.bug("channel non è un parametro valido: %r" % channel) return False # ------------------------------------------------------------------------- if entity.IS_ROOM: return False objective = OBJECTIVE_ROOM # obiettivo del messaggio # Linguaggio utilizzato per dire il messaggio if entity.IS_ITEM: language = LANGUAGE.COMMON else: language = entity.speaking smile = "" # conterrà l'eventuale espressione di uno smile-social emote = "" # conterrà l'eventuale emote inviato con il messaggio tra due asterischi expres_entity = "" # espressione per chi parla expres_room = "" # espressione per chi sta ascoltando nella stanza expres_objective = "" # espressione per chi riceverà il messaggio # Ricava i verbi e il colore relativi al canale # Se si sta parlando normalmente la propria lingua vengono utilizzati # i verbi razziali per descriverne timbro, flessione o pronuncia if channel == CHANNEL.SAY: verb_you, verb_it = entity.race.say_verb_you, entity.race.say_verb_it else: verb_you, verb_it = channel.verb_you, channel.verb_it color = get_first_color(channel.name) # Se non è stato passato nessun messaggio esce if not argument or not remove_colors(argument): entity.send_output("Cosa vorresti %s?" % channel) return False if len(argument) > config.max_google_translate: entity.send_output("Non puoi %s un messaggio così logorroico." % channel) return False # Copia l'argomento originale, in alcuni casi serve recuperarlo poi original_argument = argument # Controlla se si sta parlando a qualcuno, il controllo sulla particella # la esegue in minuscolo, dando per sottinteso che quando uno scrive # maiuscolo voglia iniziare un discorso target = None if argument[0 : 2] == "a ": arg, argument = one_argument(argument) # Se sta parlando a qualcuno cerca di acquisirlo dal nome successivo objective_name, argument = one_argument(argument) target = entity.find_entity_extensively(objective_name) # con me e self esegue un check senza la is_same volutamente, per evitare # ricerche con nome di player che iniziano con Me o Self if target == entity or objective_name in ("me", "self"): objective = OBJECTIVE_SELF # Se si parla da soli lo si fa utilizzando la lingua madre language = entity.race.natural_language elif target: objective = OBJECTIVE_TARGET # Se si parla con qualcuno della stessa razza lo si fa utilizzando # la lingua preferita dalla razza, è un fattore culturale if entity.race == target.race: language = entity.race.natural_language else: # Se non ha trovato nessun 'a <nome bersaglio>' riprende # l'argument originale argument = original_argument # Stessa cosa di sopra ma qui controlla se si stia parlando al gruppo elif argument[0 : 3] == "al ": arg, argument = one_argument(argument) objective_name, argument = one_argument(argument) if is_prefix(objective_name, "gruppo"): if not entity.group: entity.send_output("Non fai parte di nessun gruppo.") return False # Questa variabile verrà utilizza poi nell'invio del messaggio group_members = entity.get_members_here(entity.location) if not group_members: entity.send_output("Non trovi nessun membro del gruppo vicino a te con cui poter parlare.") return False objective = OBJECTIVE_GROUP # Se si parla in un gruppo in cui tutti sono formati dalla stessa # razza si preferirà parlare con la lingua della propria razza for group_member in group_members: if group_member.race != entity.race: break else: language = entity.race.natural_language else: # Se il personaggio non vuole parlare al gruppo recupera # il valore originale inviato argument = original_argument # (TD) Gestisce il caso in cui l'entità si trovi immersa in un liquido #if entity.is_immersed(): # entity.send_output("Tenti di %s qualcosa ma subito l'acqua ti riempie la gola soffocandoti!" % channel) # entity.points.life -= random.randint(entity.level / 6, entity.level / 4) + 1 # return False if not entity.location: log.bug("entity %s non si trova in una locazione valida: %r (original_argument: %s)" % ( entity.code, entity.location, original_argument)) return False # Gestisce le stanze che obbligano al silenzio if entity.location.IS_ROOM: if ROOM.SILENCE in entity.location.flags: entity.send_output("Il silenzio del luogo ti blocca la gola impedendoti di %s." % channel) return False # (TT) Se nella stanza c'è molto casino, tante persone etc etc è difficile # parlare piano if entity.location.mod_noise > 75 and channel <= CHANNEL.SAY: entity.send_output("Non puoi %s con tutta questa confusione!" % channel) return False # Invia l'appropriato messaggio nel caso in cui trovi argument vuoto if not argument: send_not_argument_message(entity, objective, channel) return False # Cerca eventuali smiles nella stringa controllando gli ultimi caratteri for social in database["socials"].itervalues(): if not social.smiles: continue for single_smile in social.smiles.split(): if single_smile in argument[-config.chars_for_smile : ]: break else: # Se non trova nessun smile esce dal ciclo dei social e continua # col prossimo set di smiles trovato continue cut_smile = argument.rfind(single_smile) # Se argument è formato solo dallo smile invia il corrispondente social if cut_smile == 0: social_name = social.fun_name[len("social_") : ] if objective == OBJECTIVE_TARGET: input_to_send = "%s %s" % (social_name, target.name) elif objective == OBJECTIVE_SELF: input_to_send = "%s %s" % (social_name, entity.name) else: input_to_send = social_name send_input(entity, input_to_send, "en", show_input=False, show_prompt=False) return True # Altrimenti ne ricava l'espressione dello smile-social e toglie lo # smile da argument, se il carattere dopo lo smile era un simbolo di # punteggiatura lo attacca alla frase togliendo gli spazi first_part = argument[ : cut_smile] second_part = argument[cut_smile + len(single_smile) : ] if second_part.strip() and second_part.strip()[0] in "!?.,:;": first_part = first_part.rstrip() second_part = second_part.lstrip() argument = first_part.rstrip() + second_part.rstrip() smile = " %s" % social.expression break # Elabora i punti esclamativi e interrogativi per il canale say. # Qui viene utilizzata l'opzione chars_for_smile visto che si sta facendo # una cosa simile a sopra, ovvero considerare solo l'ultima parte # dell'argomento passato. exclamations = argument[-config.chars_for_smile : ].count("!") questions = argument[-config.chars_for_smile : ].count("?") if exclamations > questions: if channel == CHANNEL.SAY: verb_you = "Esclami" verb_it = " esclama" exclaim = True elif exclamations < questions: if channel == CHANNEL.SAY: verb_you = "Domandi" verb_it = " domanda" ask = True # Questo elif sottintende che exclamations e questions siano uguali elif exclamations != 0 and questions != 0: # Con una stessa quantità di ! e di ? l'ultimo che viene trovato # ha maggiore peso rispetto all'altro exclamation_pos = argument.rfind("!") question_pos = argument.rfind("?") if exclamation_pos > question_pos: if channel == CHANNEL.SAY: verb_you = "Esclami" verb_it = " esclama" exclaim = True else: if channel == CHANNEL.SAY: verb_you = "Domandi" verb_it = " domanda" ask = True # Supporto per piccoli emote separati da * ad inizio argument if argument[0] == "*": cut_emote = argument[1 : ].find("*") if cut_emote != -1: emote = " %s" % argument[1 : cut_emote+1].strip() if smile: emote = " e%s" % emote argument = argument[cut_emote+2 : ].strip() # Unisce i vari pezzi per formare l'output expres_entity = verb_you expres_room = verb_it expres_target = "" if objective == OBJECTIVE_TARGET: name = target.get_name(entity) expres_entity += " a %s" % name expres_room += " a %s" % name expres_target += " ti%s" % verb_it elif objective == OBJECTIVE_SELF: expres_entity += " a te stess%s" % grammar_gender(entity) expres_room += " a sé stess%s" % grammar_gender(entity) elif objective == OBJECTIVE_GROUP: members = entity.get_members_here(entity.location) if len(members) == 1: expres_entity += " a %s" % members[0].name expres_room += " a %s" % members[0].name expres_target += " ti%s" % verb_it else: if len(members) > 5: many = "folto " else: many = "" expres_entity += " al gruppo" expres_room += " ad un %sgruppo" % many expres_target += "%s al gruppo" % verb_it # Aggiunge le eventuali espressioni dello smile e dell'emote expres_entity += smile + emote expres_room += smile + emote expres_target += smile + emote if not argument: send_not_argument_message(entity, objective, channel) return False # Prepara il pezzo riguardante la lingua utilizzata language = "" if not entity.IS_ITEM and entity.speaking != LANGUAGE.COMMON: language = " in lingua %s" % entity.speaking # Mischia il testo se si è ubriachi original_argument = argument = color_first_upper(argument) argument = drunk_speech(argument, entity) # Parlando si impara la lingua if not entity.IS_ITEM: learn_language(entity, channel, entity.speaking) # Controlla se vi sono parolacce o parole offrpg e logga i relativi argument if entity.IS_PLAYER: check_for_badwords(entity, argument) # Invia il messaggio a tutti coloro che lo possono sentire for location in expand_voice_around(entity, channel): if not location: log.bug("location per il canale %s e per l'entità %s non è valida: %r" % (channel, entity.code, location)) continue for listener in location.iter_contains(use_reversed=True): if listener.position <= POSITION.SLEEP: continue if listener == entity: force_return = check_trigger(entity, "before_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger(entity, "before_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue # Invia all'entità il suo stesso messaggio first_part = (close_color(color) + expres_entity).rstrip() message = "%s: '%s'" % (first_part, close_color(argument)) send_channel_message(entity, message, True) force_return = check_trigger(entity, "after_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger(entity, "after_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue else: # Fa ascoltare solo ad un'entità di un eventuale gruppo fisico listener = listener.split_entity(1) force_return = check_trigger(listener, "before_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger(listener, "before_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue # Prepara alcune cose a seconda della stanza di provenienza del messaggio if entity.location == listener.location: entity_name = entity.get_name(listener) entity_name = color_first_upper(entity_name) from_direction = "" elif entity.location.IS_ROOM: # (TD) invia qualcuno a meno che non lo si abbia conosciuto # precedentemente con il sistema di presentazione entity_name = "Qualcuno" from_direction = get_from_direction(listener.location.x, listener.location.y, listener.location.z, entity.location.x, entity.location.y, entity.location.z) elif entity.location.IS_ACTOR: if entity.location != listener: entity_name = "Qualcuno" # (TD) come sopra from_direction = " dall'inventario di %s" % entity.location.get_name(listener) else: entity_name = "Qualcuno" # (TD) come sopra from_direction = " da dentro %s" % entity.location.get_name(listener) # Prepara la prima parte, quella senza il messaggio if objective == OBJECTIVE_ROOM: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction) elif objective == OBJECTIVE_TARGET or OBJECTIVE_SELF: if listener == target: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_target, language, from_direction) else: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction) elif objective == OBJECTIVE_GROUP: if listener in group_members: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_target, language, from_direction) else: output = "%s%s%s%s" % (entity_name, close_color(color) + expres_room, language, from_direction) output = "<br>%s: '%s'" % (close_color(output).rstrip(), close_color(argument)) send_channel_message(listener, output, False) listener.send_prompt() force_return = check_trigger(listener, "after_listen_rpg_channel", listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue force_return = check_trigger(listener, "after_listen_" + channel.trigger_suffix, listener, entity, target, argument, ask, exclaim, behavioured) if force_return: continue return True