cmd_comm.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. '''
  2. cmd_comm.c
  3. Various commands used in NakedMud(tm) for communicating with other
  4. characters, and NPCs.
  5. '''
  6. from mud import *
  7. from mudsys import add_cmd, add_cmd_check
  8. import mudsys, mud, inform, hooks, mudsock, history
  9. def cmd_ask(ch, cmd, arg):
  10. '''Usage: ask <person> [about] <question>
  11. This command is used to pose a question to another character. Mostly,
  12. this is intended to be used to carry on dialogs with NPCs. Ask has a
  13. local range (i.e. you can only ask questions to people in the same room
  14. as you.
  15. '''
  16. try:
  17. tgt, question =mud.parse_args(ch, True, cmd, arg,
  18. "ch.room.noself [about] string(question)")
  19. except: return
  20. question = question.replace("$", "$$")
  21. mud.message(ch, tgt, None, None, False, "to_vict",
  22. "{w$n asks you, '" + question + "'{n")
  23. mud.message(ch, tgt, None, None, False, "to_char",
  24. "{wYou ask $N, '" + question + "'{n")
  25. # run our ask hooks
  26. hooks.run("ask", hooks.build_info("ch ch str", (ch, tgt, question)))
  27. def cmd_tell(ch, cmd, arg):
  28. '''Usage: tell <person> <message>
  29. This command sends a message to another character. Primarily intended
  30. for player-to-player communication. Players can tell other players
  31. things even if they are not in the same room.
  32. see also: reply'''
  33. try:
  34. tgt, mssg = mud.parse_args(ch, True, cmd, arg,
  35. "ch.world.noself string(message)")
  36. except: return
  37. mssg = mssg.replace("$", "$$")
  38. tovict = "{r$n tells you, '" + mssg + "'{n"
  39. toch = "{rYou tell $N, '" + mssg + "'{n"
  40. mud.message(ch, tgt, None, None, False, "to_vict", tovict)
  41. mud.message(ch, tgt, None, None, False, "to_char", toch)
  42. history.add_history(ch, "tell", "{r%-10s: %s{n" % (ch.name, mssg))
  43. history.add_history(tgt, "tell", "{r%-10s: %s{n" % (ch.name, mssg))
  44. hooks.run("tell", hooks.build_info("ch ch str", (ch, tgt, mssg)))
  45. def cmd_chat(ch, cmd, arg):
  46. '''Usage: chat <message>
  47. This command will send a message to all players currently logged on.
  48. '''
  49. if arg == '':
  50. ch.send("Chat what?")
  51. else:
  52. arg = arg.replace("$", "$$")
  53. mssg = "{y$n chats, '" + arg + "'{n"
  54. mud.message(ch, None, None, None, False, "to_world", mssg)
  55. mud.message(ch, None, None, None,False,"to_char", "{yyou chat, '"+arg+"'{n")
  56. history.add_history(ch, "chat", "{y%-10s: %s{n" % (ch.name, arg))
  57. def cmd_wiz(ch, cmd, arg):
  58. if arg == '':
  59. ch.send("WizChat what?")
  60. else:
  61. mssg = "{b%s WizChats, '{c%s{b'{n" % (ch.name, arg)
  62. for sock in mudsock.socket_list():
  63. if sock.ch != None and sock.ch.isInGroup("wizard"):
  64. sock.ch.send(mssg)
  65. def cmd_say(ch, cmd, arg):
  66. '''Usage: say <message>
  67. This command will send a message to everyone in the same room as you. Say,
  68. like ask, can trigger NPC dialogs.'''
  69. if arg == '':
  70. ch.send("Say what?")
  71. else:
  72. arg = arg.replace("$", "$$")
  73. mud.message(ch, None, None, None, False, "to_room",
  74. "{y$n says, '" + arg + "'{n")
  75. mud.message(ch, None, None, None, False, "to_char",
  76. "{yyou say, '" + arg + "'{n")
  77. # run say hooks
  78. hooks.run("say", hooks.build_info("ch str", (ch, arg)))
  79. def cmd_greet(ch, cmd, arg):
  80. '''Usage: greet <person>
  81. NPCs with dialogs will often have something to say when you greet or
  82. approach then. Greeting an NPC is a way to get them talking.'''
  83. try:
  84. tgt, = mud.parse_args(ch, True, cmd, arg, "ch.room.noself")
  85. except: return
  86. mud.message(ch, tgt, None, None, False, "to_char", "You greet $N.")
  87. mud.message(ch, tgt, None, None, False, "to_vict", "$n greets you.")
  88. mud.message(ch, tgt, None, None, False, "to_room", "$n greets $N.")
  89. # run greet hooks
  90. hooks.run("greet", hooks.build_info("ch ch", (ch, tgt)))
  91. hooks.run("post_greet", hooks.build_info("ch ch", (ch, tgt)))
  92. def cmd_emote(ch, cmd, arg):
  93. '''Usage: emote <text>
  94. Send a special text message to the room you are in. The message is
  95. preceded by your name, unless you put a $n somewhere in the text, in
  96. which case the $n is replaced by your name. For example:
  97. > emote A gunshot sounds, and $n is laying on the ground, dead.
  98. Would show a message to everyone in the room saying that you are dead
  99. to a gunshot.'''
  100. if arg == '':
  101. ch.send("Emote we must, but emote what?")
  102. else:
  103. # see if a $n is within the argument ... if there is, let the person
  104. # put his or her name where it's wanted. Otherwise, tag it onto the
  105. # front of the message
  106. if arg.find("$n") == -1:
  107. arg = "$n " + arg
  108. mud.message(ch, None, None, None, False, "to_room, to_char", arg)
  109. def cmd_gemote(ch, cmd, arg):
  110. '''Gemote is similar to emote, except that it sends a mud-wide message
  111. instead of a room-specific message.'''
  112. if arg == '':
  113. ch.send("Gemote we must, but gemote what?")
  114. else:
  115. # same as emote, but global
  116. if arg.find("$n") == -1:
  117. arg = "$n " + arg
  118. mud.message(ch, None, None, None, False, "to_world, to_char",
  119. "{bGLOBAL:{c " + arg + "{n")
  120. def cmd_page(ch, cmd, arg):
  121. '''Usage: page <person> <message>
  122. Paging a person will send them a message, as well as making a beeping
  123. sound on their computer to get their attention. Page can be used on
  124. anyone in the mud, regardless if you are in the same room as them or not.
  125. '''
  126. try:
  127. tgt, mssg = mud.parse_args(ch, True, cmd, arg,
  128. "ch.world.noself string(message)")
  129. except: return
  130. ch.send("\007\007You page " + ch.see_as(tgt))
  131. tgt.send("\007\007*" + tgt.see_as(ch) + "* " + mssg)
  132. ################################################################################
  133. # add our commands
  134. ################################################################################
  135. mudsys.add_cmd("ask", None, cmd_ask, "player", False)
  136. mudsys.add_cmd("say", None, cmd_say, "player", False)
  137. mudsys.add_cmd("'", None, cmd_say, "player", False)
  138. mudsys.add_cmd("tell", None, cmd_tell, "player", False)
  139. mudsys.add_cmd("chat", None, cmd_chat, "player", False)
  140. mudsys.add_cmd("wizchat", "wiz",cmd_wiz, "wizard", False)
  141. mudsys.add_cmd("gossip", None, cmd_chat, "player", False)
  142. mudsys.add_cmd("\"", None, cmd_chat, "player", False)
  143. mudsys.add_cmd("page", None, cmd_page, "player", False)
  144. mudsys.add_cmd("greet", None, cmd_greet, "player", False)
  145. mudsys.add_cmd("approach",None, cmd_greet, "player", False)
  146. mudsys.add_cmd("emote", None, cmd_emote, "player", False)
  147. mudsys.add_cmd("gemote", None, cmd_gemote,"player", False)
  148. mudsys.add_cmd(":", None, cmd_emote, "player", False)
  149. def chk_room_communication(ch, cmd):
  150. if ch.pos in ("sleeping", "unconscious"):
  151. ch.send("You cannot do that while " + ch.pos + ".")
  152. return False
  153. for cmd in ["ask", "say", "'", "greet", "approach", "emote", ":"]:
  154. mudsys.add_cmd_check(cmd, chk_room_communication)
  155. # register our history handling
  156. history.register_comm_history("chat", lambda ch: "chat")
  157. # history.register_comm_history("say", lambda ch: ch.name)
  158. history.register_comm_history("tell", lambda ch: ch.name)