def _on_cmd_time( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: localtime = time.asctime( time.localtime(time.time()) ) if not args: text = f'現在時間為{" ".join(localtime)}' role = Role.instance(entity) Channel.toRoom(role.room, Message.TEXT, text) else: text = f'目前不支援參數請勿輸入任何數值' role = Role.instance(entity) Channel.toRole(entity, Message.TEXT, text)
def _on_cmd_echo(self, e: Event, entity: str = '', args: str = '') -> None: if not args: text = f'Echo : ?' Channel.toRole(entity, Message.TEXT, text) else: text = f'Echo:{" ".join(args)}' role = Role.instance(entity) Channel.toRoom(role.room, Message.TEXT, text)
def _on_cmd_say( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: if not args: text = f'你想說什麼?' Channel.toRole(entity, Message.TEXT, text) else: text = f'{Name.instance(entity).text} 說:{" ".join(args)}' role = Role.instance(entity) Channel.toRoom(role.room, Message.TEXT, text)
def _on_cmd_logout(self, e: Event, entity: str = '', args: List[str] = []) -> None: if not args: socket.disconnect() else: text = f'目前不支援參數請勿輸入任何數值' role = Role.instance(entity) Channel.toRole(entity, Message.TEXT, text)
def _on_sign_in(self, e: Event, entity: str, user_id: str = '', passwd: str = '') -> None: role = Role.instance(user_id, name=user_id) Name.instance(entity, name=role.name) Room.instance(role.room).enter(entity) text = f'歡迎來到 MUTE: Multi-User Texting Environment' Channel.toRole(entity, Message.SYSTEM, text) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity))
def _on_cmd_exit(self, e: Event, entity: str = '', args: List[str] = []) -> None: luckynumber = random.randint(0, 100) if args: text = f'請不要輸入參數' Channel.to_role(entity, Message.TEXT, text) else: text = f'{Name.instance(entity).text} 的幸運數字{" ".join(str(luckynumber))}請記住這個號碼' role = Role.instance(entity) Channel.to_room(role.room, Message.TEXT, text)
def _on_cmd_guess(self, e: Event, entity: str = '', args: List[str] = []) -> None: if not args: text = f'張三 說:請猜一個數字(1~10)' #Channel.to_role(entity, Message.TEXT, text) else: s = args[0] if s != '1': text = f'張三 說:猜錯囉,在猜一次' else: text = f'Echo 說: {"答對了"}' role = Role.instance(entity) Channel.to_role(entity, Message.TEXT, text)
def _on_cmd_look( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: role = Role.instance(entity) if not args: text = [ *self._room_desc(role.room), self._room_passer(role.room), self._room_exit(role.room) ] else: text = self._look_at(role.room, args[0]) for line in text: Channel.to_role(entity, Message.TEXT, line)
def _on_cmd_move( self, e: Event, entity: str = '', args: List[str] = [] ) -> None: role = Role.instance(entity) exit = Exit.instance(role.room) room = exit.to(e.type[0]) if None != room: Room.instance(role.room).leave(entity) Room.instance(room).enter(entity) role.enter(room) Event.trigger(Event(Event.CMD_LOOK, self._servant, entity=entity)) else: Channel.to_role(entity, Message.TEXT, f' 這裡沒有出口')
def _on_cmd_look(self, e: Event, entity: str = '', args: str = '') -> None: role = Role.instance(entity) if not args: room = Room.instance(role.room) text = f'{room.name} -' Channel.toRole(entity, Message.TEXT, text) for text in room.description: Channel.toRole(entity, Message.TEXT, text) if not room.exits: text = '這裡沒有出口' else: text = room.exits else: text = f'你在看什麼?' Channel.toRole(entity, Message.TEXT, text)
def _on_cmd_combat(self, e: Event, entity: str = '', args: List[str] = []) -> None: role = Role.instance(entity) if not args: text = f' 你想要殺誰?' else: target = Passer.instance(role.room).with_tag(args[0]) if not target: text = f' 這裡沒有這個人。' else: name = Name.instance(Genus.instance(target)).text text = f' 你大喝一聲:「{name}納命來。」就朝{name}發起攻擊。' Attack.instance().enlist(entity, target) Channel.to_role(entity, Message.TEXT, text)