Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #commands.command.py
- """
- Commands
- Commands describe the input the player can do to the game.
- """
- from evennia import Command as BaseCommand
- from commands.dice import RE_PARTS
- from commands.dice import roll_dice
- import time
- class CmdSmile(BaseCommand):
- """
- A smile command
- Usage:
- smile [at] [<someone>]
- grin [at] [<someone>]
- Smiles to someone in your vicinity or to the room
- in general.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "smile"
- aliases = ["smile at", "sm"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s smiles." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You smile.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s smiles at you." % caller.name
- target.msg(string)
- string = "You smile at %s." % target.name
- caller.msg(string)
- string = "%s smiles at %s." % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- class CmdFart(BaseCommand):
- """
- A smile command
- Usage:
- fart [at] [<someone>]
- Farts on someone in your vicinity or to the room
- in general.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "fart"
- aliases = ["fart", "fart at"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s farts loudly. Wow, that smells terrible!" % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You fart loudly. Wow, what did you eat?")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s farts on you. It looks as if that singed some nose hairs!" % caller.name
- target.msg(string)
- string = "You fart on %s." % target.name
- caller.msg(string)
- string = "%s farts on %s. Wow, that was rude!" % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- class CmdCackle(BaseCommand):
- """
- A cackle command
- Usage:
- fart [at] [<someone>]
- Cackles with an insane glee.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "cackle"
- aliases = ["cackle", "ca"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s throws his head back and cackles with an insane glee." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You throw your head back and cackle with an insane glee.")
- class CmdGrin(BaseCommand):
- """
- A grin command
- Usage:
- grin [at] [<someone>]
- Grins evilly at you.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "grin"
- aliases = "grin"
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s grins evilly." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You grin evilly.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s grins at you evilly." % caller.name
- target.msg(string)
- string = "You grin evilly at %s." % target.name
- caller.msg(string)
- string = "%s grins evilly at %s." % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- #from evennia import default_cmds
- #class CmdEcho(default_cmds.MuxCommand):
- # """
- # Simple Command Example
- # Usage:
- # echo: [text]
- # This command simply echoes text back to the caller.
- # """
- #
- # key = "echo"
- #
- # def func(self):
- # "This actually does things"
- # if not self.args:
- # self.caller.msg("You didn't enter anything!")
- # else:
- # self.caller.msg("You gave the string: '%s'" % self.args)
- class CmdNod(BaseCommand):
- """
- A nod command
- Usage:
- nod [at] [<someone>]
- nod [<someone>]
- Nods at someone in your vicinity or to the room
- in general.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "nod"
- aliases = ["nod", "nod at"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s nods solemnly." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You nod solemnly.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s nods at you solemnly" % caller.name
- target.msg(string)
- string = "You nod at %s." % target.name
- caller.msg(string)
- string = "%s nods at %s solemnly." % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- class CmdShake(BaseCommand):
- """
- A shake your head command
- Usage:
- shake [at] [<someone>]
- shake [<someone>]
- Nods at someone in your vicinity or to the room
- in general.
- (This initial string (the __doc__ string)
- is also used to auto-generate the help
- for this command)
- """
- key = "shake"
- aliases = ["shake", "shake at"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s shakes their head profusely." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You shake your head profusely.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s shakes their head at you profusely." % caller.name
- target.msg(string)
- string = "You shake your head profusely at %s." % target.name
- caller.msg(string)
- string = "%s shakes their head profusely at %s." % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- class CmdFlip(BaseCommand):
- """
- A flip off command
- Usage:
- flip [off] [<someone>]
- flip [<someone>]
- Flips the bird at someone.
- """
- key = "flip"
- aliases = ["flip", "flip off"]
- locks = "cmd:all()"
- help_category = "General"
- def func(self):
- "This actually does things"
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s flips the bird at no one in particular." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You flip the bird.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s flips you the bird." % caller.name
- target.msg(string)
- string = "You flip %s the bird." % target.name
- caller.msg(string)
- string = "%s flips %s the bird." % (caller.name, target.name)
- caller.location.msg_contents(exclude=[caller,target])
- class CmdDice(BaseCommand):
- """
- roll dice
- Usage:
- dice[/switch] <nr>d<sides> [modifier] [success condition]
- Switch:
- hidden - tell the room the roll is being done, but don't show the result
- secret - don't inform the room about neither roll nor result
- Examples:
- dice 3d6 + 4
- dice 1d100 - 2 < 50
- This will roll the given number of dice with given sides and modifiers.
- So e.g. 2d6 + 3 means to 'roll a 6-sided die 2 times and add the result,
- then add 3 to the total'.
- Accepted modifiers are +, -, * and /.
- A success condition is given as normal Python conditionals
- (<,>,<=,>=,==,!=). So e.g. 2d6 + 3 > 10 means that the roll will succeed
- only if the final result is above 8. If a success condition is given, the
- outcome (pass/fail) will be echoed along with how much it succeeded/failed
- with. The hidden/secret switches will hide all or parts of the roll from
- everyone but the person rolling.
- """
- key = "dice"
- aliases = ["roll", "@dice"]
- locks = "cmd:all()"
- def func(self):
- """Mostly parsing for calling the dice roller function"""
- if not self.args:
- self.caller.msg("Usage: @dice <nr>d<sides> [modifier] [conditional]")
- return
- argstring = "".join(str(arg) for arg in self.args)
- parts = [part for part in RE_PARTS.split(self.args) if part]
- len_parts = len(parts)
- modifier = None
- conditional = None
- if len_parts < 3 or parts[1] != 'd':
- self.caller.msg("You must specify the die roll(s) as <nr>d<sides>."
- " For example, 2d6 means rolling a 6-sided die 2 times.")
- return
- ndice, nsides = parts[0], parts[2]
- if len_parts == 3:
- # just something like 1d6
- pass
- elif len_parts == 5:
- # either e.g. 1d6 + 3 or something like 1d6 > 3
- if parts[3] in ('+', '-', '*', '/'):
- modifier = (parts[3], parts[4])
- else: # assume it is a conditional
- conditional = (parts[3], parts[4])
- elif len_parts == 7:
- # the whole sequence, e.g. 1d6 + 3 > 5
- modifier = (parts[3], parts[4])
- conditional = (parts[5], parts[6])
- else:
- # error
- self.caller.msg("You must specify a valid die roll")
- return
- # do the roll
- try:
- result, outcome, diff, rolls = roll_dice(ndice,
- nsides,
- modifier=modifier,
- conditional=conditional,
- return_tuple=True)
- except ValueError:
- self.caller.msg("You need to enter valid integer numbers, modifiers and operators."
- " |w%s|n was not understood." % self.args)
- return
- # format output
- if len(rolls) > 1:
- rolls = ", ".join(str(roll) for roll in rolls[:-1]) + " and " + str(rolls[-1])
- else:
- rolls = rolls[0]
- if outcome is None:
- outcomestring = ""
- elif outcome:
- outcomestring = " This is a |gsuccess|n (by %s)." % diff
- else:
- outcomestring = " This is a |rfailure|n (by %s)." % diff
- yourollstring = "You roll %s%s."
- roomrollstring = "%s rolls %s%s."
- resultstring = " Roll(s): %s. Total result is |w%s|n."
- if 'secret' in self.args:
- # don't echo to the room at all
- string = yourollstring % (argstring, " (secret, not echoed)")
- string += "\n" + resultstring % (rolls, result)
- string += outcomestring + " (not echoed)"
- self.caller.msg(string)
- elif 'hidden' in self.args:
- # announce the roll to the room, result only to caller
- string = yourollstring % (argstring, " (hidden)")
- self.caller.msg(string)
- string = roomrollstring % (self.caller.key, argstring, " (hidden)")
- self.caller.location.msg_contents(string, exclude=self.caller)
- # handle result
- string = resultstring % (rolls, result)
- string += outcomestring + " (not echoed)"
- self.caller.msg(string)
- else:
- # normal roll
- string = yourollstring % (argstring, "")
- self.caller.msg(string)
- string = roomrollstring % (self.caller.key, argstring, "")
- self.caller.location.msg_contents(string, exclude=self.caller)
- string = resultstring % (rolls, result)
- string += outcomestring
- self.caller.location.msg_contents(string)
- # Limit the number of dice and sides a character can roll to prevent server slow down and crashes
- ndicelimit = 10000 # Maximum number of dice
- nsidelimit = 10000 # Maximum number of sides
- if int(parts[0]) > ndicelimit or int(parts[2]) > nsidelimit:
- self.caller.msg("The maximum roll allowed is %sd%s." % (ndicelimit, nsidelimit))
- return
- class CmdSpellFireball(BaseCommand):
- """
- Spell - Fireball
- Usage:
- cast fireball <target>
- This will unleash a storm of flame. You can only release one
- firestorm every five minutes (assuming you have the mana).
- """
- key = "cast fireball"
- locks = "cmd:all()"
- def func(self):
- caller = self.caller
- if not self.args or self.caller == "here":
- string = "%s conjures a fireball." % caller.name
- caller.location.msg_contents(string, exclude=caller)
- caller.msg("You conjure a fireball.")
- else:
- target = caller.search(self.args)
- if not target:
- # caller.search handles error messages
- return
- string = "%s conjures a fireball and hurls it at you hitting you in the face!" % caller.name
- target.msg(string)
- string = "You conjure a fireball and hurl into the face of %s!" % target.name
- caller.msg(string)
- string = "%s conjures a fireball and hurls it into %s's face!" % (caller.name, target.name)
- # check cooldown (5 minute cooldown)
- if hasattr(self, "lastcast") and \
- time.time() - self.lastcast < 5 * 60:
- mess = "You cannot cast this spell again yet."
- self.caller.msg(mess)
- return
- #[the spell effect is implemented]
- # if the spell was successfully cast, store the casting time
- self.lastcast = time.time()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement