def fish_eat(player, gatto, pesce): """ Cerca la keyword di ciò che mangerà il gatto """ # Può capitare poiché questa funzione è deferrata if not player or not gatto or not pesce: return numbered_keyword = pesce.get_numbered_keyword(looker=player) command_eat(gatto, first_keyword)
def cibo_eat(cibo, bimba): # Può accadere visto che tale funzione è deferrata if not bimba: return if not cibo: to_say = "Non riesco a mangiare..." command_say(bimba, to_say) return numbered_keyword = cibo.get_numbered_keyword(looker=bimba) command_eat(bimba, numbered_keyword)
def command_swallow(entity, argument="", verbs=VERBS, behavioured=False): """ Comando che serve per mangiare un entità. """ # È possibile se il comando è stato deferrato if not entity: return False return command_eat(entity, argument=argument, verbs=verbs, behavioured=behavioured, swallow=True, function_name="command_swallow")
def command_devours(entity, argument="", verbs=VERBS, behavioured=False): # È possibile se il comando è stato deferrato if not entity: return False return command_eat(entity, argument=argument, verbs=verbs, behavioured=behavioured, devours=True, swallow=False, function_name="command_devours")
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
polverina.split_entity(1) break else: return # Prima di mangiare viene trasformato in un altro bruco in modo che # non venga killato dallo script delle farfalle oppure che non si # trasformi in una crisalide canonica location = caterpillar.location caterpillar.extract(1) caterpillar2 = Mob(PROTO_CATERPILLAR2_CODE) caterpillar2.inject(location) # Ora il bruco mangia la polverina, dopo che l'ha mangiata facciamo # passare un po di tempo e gli facciamo cambiare colore command_eat(caterpillar2, polverina.get_numbered_keyword(looker=caterpillar2)) defer(10, change_color, caterpillar2) #- Fine Funzione - def change_color(caterpillar2): # C'è da verificare che abbia mangiato davvero la polvere giusta # ora diviene crisalide # GATTO: ma se c'è il check PROTO_DUST_CODE precedente a questa chiamata # ha per forza mangiato la polverina giusta, o ci sono più tipi di polverina? location = caterpillar2.location caterpillar2.extract(1) crisalide_crisanta = Item(PROTO_CRISALIDE_CODE) crisalide_crisanta.inject(location) #- Fine Funzione -