Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.44 KB | None | 0 0
  1. #commands.command.py
  2.  
  3. """
  4. Commands
  5.  
  6. Commands describe the input the player can do to the game.
  7.  
  8. """
  9.  
  10. from evennia import Command as BaseCommand
  11. from commands.dice import RE_PARTS
  12. from commands.dice import roll_dice
  13. import time
  14.  
  15.  
  16. class CmdSmile(BaseCommand):
  17. """
  18. A smile command
  19.  
  20. Usage:
  21. smile [at] [<someone>]
  22. grin [at] [<someone>]
  23.  
  24. Smiles to someone in your vicinity or to the room
  25. in general.
  26.  
  27. (This initial string (the __doc__ string)
  28. is also used to auto-generate the help
  29. for this command)
  30. """
  31. key = "smile"
  32. aliases = ["smile at", "sm"]
  33. locks = "cmd:all()"
  34. help_category = "General"
  35.  
  36. def func(self):
  37. "This actually does things"
  38. caller = self.caller
  39. if not self.args or self.caller == "here":
  40. string = "%s smiles." % caller.name
  41. caller.location.msg_contents(string, exclude=caller)
  42. caller.msg("You smile.")
  43. else:
  44. target = caller.search(self.args)
  45. if not target:
  46. # caller.search handles error messages
  47. return
  48. string = "%s smiles at you." % caller.name
  49. target.msg(string)
  50. string = "You smile at %s." % target.name
  51. caller.msg(string)
  52. string = "%s smiles at %s." % (caller.name, target.name)
  53. caller.location.msg_contents(exclude=[caller,target])
  54.  
  55. class CmdFart(BaseCommand):
  56. """
  57. A smile command
  58.  
  59. Usage:
  60. fart [at] [<someone>]
  61.  
  62. Farts on someone in your vicinity or to the room
  63. in general.
  64.  
  65. (This initial string (the __doc__ string)
  66. is also used to auto-generate the help
  67. for this command)
  68. """
  69. key = "fart"
  70. aliases = ["fart", "fart at"]
  71. locks = "cmd:all()"
  72. help_category = "General"
  73.  
  74. def func(self):
  75. "This actually does things"
  76. caller = self.caller
  77. if not self.args or self.caller == "here":
  78. string = "%s farts loudly. Wow, that smells terrible!" % caller.name
  79. caller.location.msg_contents(string, exclude=caller)
  80. caller.msg("You fart loudly. Wow, what did you eat?")
  81. else:
  82. target = caller.search(self.args)
  83. if not target:
  84. # caller.search handles error messages
  85. return
  86. string = "%s farts on you. It looks as if that singed some nose hairs!" % caller.name
  87. target.msg(string)
  88. string = "You fart on %s." % target.name
  89. caller.msg(string)
  90. string = "%s farts on %s. Wow, that was rude!" % (caller.name, target.name)
  91. caller.location.msg_contents(exclude=[caller,target])
  92.  
  93.  
  94. class CmdCackle(BaseCommand):
  95. """
  96. A cackle command
  97.  
  98. Usage:
  99. fart [at] [<someone>]
  100.  
  101. Cackles with an insane glee.
  102.  
  103. (This initial string (the __doc__ string)
  104. is also used to auto-generate the help
  105. for this command)
  106. """
  107. key = "cackle"
  108. aliases = ["cackle", "ca"]
  109. locks = "cmd:all()"
  110. help_category = "General"
  111.  
  112. def func(self):
  113. "This actually does things"
  114. caller = self.caller
  115. if not self.args or self.caller == "here":
  116. string = "%s throws his head back and cackles with an insane glee." % caller.name
  117. caller.location.msg_contents(string, exclude=caller)
  118. caller.msg("You throw your head back and cackle with an insane glee.")
  119.  
  120. class CmdGrin(BaseCommand):
  121. """
  122. A grin command
  123.  
  124. Usage:
  125. grin [at] [<someone>]
  126.  
  127. Grins evilly at you.
  128.  
  129. (This initial string (the __doc__ string)
  130. is also used to auto-generate the help
  131. for this command)
  132. """
  133. key = "grin"
  134. aliases = "grin"
  135. locks = "cmd:all()"
  136. help_category = "General"
  137.  
  138. def func(self):
  139. "This actually does things"
  140. caller = self.caller
  141. if not self.args or self.caller == "here":
  142. string = "%s grins evilly." % caller.name
  143. caller.location.msg_contents(string, exclude=caller)
  144. caller.msg("You grin evilly.")
  145. else:
  146. target = caller.search(self.args)
  147. if not target:
  148. # caller.search handles error messages
  149. return
  150. string = "%s grins at you evilly." % caller.name
  151. target.msg(string)
  152. string = "You grin evilly at %s." % target.name
  153. caller.msg(string)
  154. string = "%s grins evilly at %s." % (caller.name, target.name)
  155. caller.location.msg_contents(exclude=[caller,target])
  156.  
  157. #from evennia import default_cmds
  158. #class CmdEcho(default_cmds.MuxCommand):
  159. # """
  160. # Simple Command Example
  161. # Usage:
  162. # echo: [text]
  163. # This command simply echoes text back to the caller.
  164. # """
  165. #
  166. # key = "echo"
  167. #
  168. # def func(self):
  169. # "This actually does things"
  170. # if not self.args:
  171. # self.caller.msg("You didn't enter anything!")
  172. # else:
  173. # self.caller.msg("You gave the string: '%s'" % self.args)
  174.  
  175. class CmdNod(BaseCommand):
  176. """
  177. A nod command
  178.  
  179. Usage:
  180. nod [at] [<someone>]
  181. nod [<someone>]
  182.  
  183. Nods at someone in your vicinity or to the room
  184. in general.
  185.  
  186. (This initial string (the __doc__ string)
  187. is also used to auto-generate the help
  188. for this command)
  189. """
  190. key = "nod"
  191. aliases = ["nod", "nod at"]
  192. locks = "cmd:all()"
  193. help_category = "General"
  194.  
  195. def func(self):
  196. "This actually does things"
  197. caller = self.caller
  198. if not self.args or self.caller == "here":
  199. string = "%s nods solemnly." % caller.name
  200. caller.location.msg_contents(string, exclude=caller)
  201. caller.msg("You nod solemnly.")
  202. else:
  203. target = caller.search(self.args)
  204. if not target:
  205. # caller.search handles error messages
  206. return
  207. string = "%s nods at you solemnly" % caller.name
  208. target.msg(string)
  209. string = "You nod at %s." % target.name
  210. caller.msg(string)
  211. string = "%s nods at %s solemnly." % (caller.name, target.name)
  212. caller.location.msg_contents(exclude=[caller,target])
  213.  
  214. class CmdShake(BaseCommand):
  215. """
  216. A shake your head command
  217.  
  218. Usage:
  219. shake [at] [<someone>]
  220. shake [<someone>]
  221.  
  222. Nods at someone in your vicinity or to the room
  223. in general.
  224.  
  225. (This initial string (the __doc__ string)
  226. is also used to auto-generate the help
  227. for this command)
  228. """
  229. key = "shake"
  230. aliases = ["shake", "shake at"]
  231. locks = "cmd:all()"
  232. help_category = "General"
  233.  
  234. def func(self):
  235. "This actually does things"
  236. caller = self.caller
  237. if not self.args or self.caller == "here":
  238. string = "%s shakes their head profusely." % caller.name
  239. caller.location.msg_contents(string, exclude=caller)
  240. caller.msg("You shake your head profusely.")
  241. else:
  242. target = caller.search(self.args)
  243. if not target:
  244. # caller.search handles error messages
  245. return
  246. string = "%s shakes their head at you profusely." % caller.name
  247. target.msg(string)
  248. string = "You shake your head profusely at %s." % target.name
  249. caller.msg(string)
  250. string = "%s shakes their head profusely at %s." % (caller.name, target.name)
  251. caller.location.msg_contents(exclude=[caller,target])
  252.  
  253. class CmdFlip(BaseCommand):
  254. """
  255. A flip off command
  256.  
  257. Usage:
  258. flip [off] [<someone>]
  259. flip [<someone>]
  260.  
  261. Flips the bird at someone.
  262.  
  263. """
  264. key = "flip"
  265. aliases = ["flip", "flip off"]
  266. locks = "cmd:all()"
  267. help_category = "General"
  268.  
  269. def func(self):
  270. "This actually does things"
  271. caller = self.caller
  272. if not self.args or self.caller == "here":
  273. string = "%s flips the bird at no one in particular." % caller.name
  274. caller.location.msg_contents(string, exclude=caller)
  275. caller.msg("You flip the bird.")
  276. else:
  277. target = caller.search(self.args)
  278. if not target:
  279. # caller.search handles error messages
  280. return
  281. string = "%s flips you the bird." % caller.name
  282. target.msg(string)
  283. string = "You flip %s the bird." % target.name
  284. caller.msg(string)
  285. string = "%s flips %s the bird." % (caller.name, target.name)
  286. caller.location.msg_contents(exclude=[caller,target])
  287.  
  288.  
  289. class CmdDice(BaseCommand):
  290. """
  291. roll dice
  292. Usage:
  293. dice[/switch] <nr>d<sides> [modifier] [success condition]
  294. Switch:
  295. hidden - tell the room the roll is being done, but don't show the result
  296. secret - don't inform the room about neither roll nor result
  297. Examples:
  298. dice 3d6 + 4
  299. dice 1d100 - 2 < 50
  300. This will roll the given number of dice with given sides and modifiers.
  301. So e.g. 2d6 + 3 means to 'roll a 6-sided die 2 times and add the result,
  302. then add 3 to the total'.
  303. Accepted modifiers are +, -, * and /.
  304. A success condition is given as normal Python conditionals
  305. (<,>,<=,>=,==,!=). So e.g. 2d6 + 3 > 10 means that the roll will succeed
  306. only if the final result is above 8. If a success condition is given, the
  307. outcome (pass/fail) will be echoed along with how much it succeeded/failed
  308. with. The hidden/secret switches will hide all or parts of the roll from
  309. everyone but the person rolling.
  310. """
  311.  
  312. key = "dice"
  313. aliases = ["roll", "@dice"]
  314. locks = "cmd:all()"
  315.  
  316. def func(self):
  317. """Mostly parsing for calling the dice roller function"""
  318.  
  319. if not self.args:
  320. self.caller.msg("Usage: @dice <nr>d<sides> [modifier] [conditional]")
  321. return
  322. argstring = "".join(str(arg) for arg in self.args)
  323.  
  324. parts = [part for part in RE_PARTS.split(self.args) if part]
  325. len_parts = len(parts)
  326. modifier = None
  327. conditional = None
  328.  
  329. if len_parts < 3 or parts[1] != 'd':
  330. self.caller.msg("You must specify the die roll(s) as <nr>d<sides>."
  331. " For example, 2d6 means rolling a 6-sided die 2 times.")
  332. return
  333.  
  334.  
  335.  
  336. ndice, nsides = parts[0], parts[2]
  337. if len_parts == 3:
  338. # just something like 1d6
  339. pass
  340. elif len_parts == 5:
  341. # either e.g. 1d6 + 3 or something like 1d6 > 3
  342. if parts[3] in ('+', '-', '*', '/'):
  343. modifier = (parts[3], parts[4])
  344. else: # assume it is a conditional
  345. conditional = (parts[3], parts[4])
  346. elif len_parts == 7:
  347. # the whole sequence, e.g. 1d6 + 3 > 5
  348. modifier = (parts[3], parts[4])
  349. conditional = (parts[5], parts[6])
  350. else:
  351. # error
  352. self.caller.msg("You must specify a valid die roll")
  353. return
  354. # do the roll
  355. try:
  356. result, outcome, diff, rolls = roll_dice(ndice,
  357. nsides,
  358. modifier=modifier,
  359. conditional=conditional,
  360. return_tuple=True)
  361. except ValueError:
  362. self.caller.msg("You need to enter valid integer numbers, modifiers and operators."
  363. " |w%s|n was not understood." % self.args)
  364. return
  365. # format output
  366. if len(rolls) > 1:
  367. rolls = ", ".join(str(roll) for roll in rolls[:-1]) + " and " + str(rolls[-1])
  368. else:
  369. rolls = rolls[0]
  370. if outcome is None:
  371. outcomestring = ""
  372. elif outcome:
  373. outcomestring = " This is a |gsuccess|n (by %s)." % diff
  374. else:
  375. outcomestring = " This is a |rfailure|n (by %s)." % diff
  376. yourollstring = "You roll %s%s."
  377. roomrollstring = "%s rolls %s%s."
  378. resultstring = " Roll(s): %s. Total result is |w%s|n."
  379.  
  380. if 'secret' in self.args:
  381. # don't echo to the room at all
  382. string = yourollstring % (argstring, " (secret, not echoed)")
  383. string += "\n" + resultstring % (rolls, result)
  384. string += outcomestring + " (not echoed)"
  385. self.caller.msg(string)
  386. elif 'hidden' in self.args:
  387. # announce the roll to the room, result only to caller
  388. string = yourollstring % (argstring, " (hidden)")
  389. self.caller.msg(string)
  390. string = roomrollstring % (self.caller.key, argstring, " (hidden)")
  391. self.caller.location.msg_contents(string, exclude=self.caller)
  392. # handle result
  393. string = resultstring % (rolls, result)
  394. string += outcomestring + " (not echoed)"
  395. self.caller.msg(string)
  396. else:
  397. # normal roll
  398. string = yourollstring % (argstring, "")
  399. self.caller.msg(string)
  400. string = roomrollstring % (self.caller.key, argstring, "")
  401. self.caller.location.msg_contents(string, exclude=self.caller)
  402. string = resultstring % (rolls, result)
  403. string += outcomestring
  404. self.caller.location.msg_contents(string)
  405.  
  406. # Limit the number of dice and sides a character can roll to prevent server slow down and crashes
  407. ndicelimit = 10000 # Maximum number of dice
  408. nsidelimit = 10000 # Maximum number of sides
  409. if int(parts[0]) > ndicelimit or int(parts[2]) > nsidelimit:
  410. self.caller.msg("The maximum roll allowed is %sd%s." % (ndicelimit, nsidelimit))
  411. return
  412.  
  413. class CmdSpellFireball(BaseCommand):
  414. """
  415. Spell - Fireball
  416.  
  417. Usage:
  418. cast fireball <target>
  419.  
  420. This will unleash a storm of flame. You can only release one
  421. firestorm every five minutes (assuming you have the mana).
  422. """
  423. key = "cast fireball"
  424. locks = "cmd:all()"
  425.  
  426. def func(self):
  427. caller = self.caller
  428. if not self.args or self.caller == "here":
  429. string = "%s conjures a fireball." % caller.name
  430. caller.location.msg_contents(string, exclude=caller)
  431. caller.msg("You conjure a fireball.")
  432. else:
  433. target = caller.search(self.args)
  434. if not target:
  435. # caller.search handles error messages
  436. return
  437. string = "%s conjures a fireball and hurls it at you hitting you in the face!" % caller.name
  438. target.msg(string)
  439. string = "You conjure a fireball and hurl into the face of %s!" % target.name
  440. caller.msg(string)
  441. string = "%s conjures a fireball and hurls it into %s's face!" % (caller.name, target.name)
  442.  
  443. # check cooldown (5 minute cooldown)
  444. if hasattr(self, "lastcast") and \
  445. time.time() - self.lastcast < 5 * 60:
  446. mess = "You cannot cast this spell again yet."
  447. self.caller.msg(mess)
  448. return
  449.  
  450. #[the spell effect is implemented]
  451.  
  452. # if the spell was successfully cast, store the casting time
  453. self.lastcast = time.time()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement