class GiveThingCmd(Command): """ give <thing> to <character> Gives something you are holding to another character in the same location as you. """ aliases = ('give', 'hand') syntax = "<obj> to <recipient>" arg_parsers = { 'obj': MatchObject(cls=Object, search_for='object', show=True), 'char': MatchObject(cls=BaseCharacter, search_for='person', show=True), } lock = locks.all_pass def run(self, actor, obj, recipient): """ :type actor: mudslingcore.objects.Character :type obj: mudsling.objects.Object :type recipient: mudsling.objects.BaseCharacter """ if obj.location != actor: actor.tell("You don't have that!") elif recipient.location != actor.location: actor.tell("You see no '", self.args['char'], "' here.") elif recipient == actor: actor.tell("Give it to yourself?") else: obj.move_to(recipient) msg = 'give_fail' if obj.location == actor else 'give' messager = obj if obj.get_message(msg) is not None else actor messager.emit_message(msg, location=actor.location, actor=actor, obj=obj, recipient=recipient)
class DropThingCmd(Command): """ drop <thing> Drops an object in your inventory into your location. """ aliases = ('drop',) syntax = "<obj>" arg_parsers = { 'obj': MatchObject(cls=Object, search_for='object', show=True), } lock = locks.all_pass def run(self, actor, obj): """ :type actor: mudslingcore.objects.Character :type obj: mudsling.objects.Object """ if obj.location == actor: try: obj.move_to(actor.location, by=actor, via='drop') except errors.InvalidObject: pass msg = 'drop_fail' if obj.location == actor else 'drop' messager = obj if obj.get_message(msg) is not None else actor messager.emit_message(msg, location=actor.location, actor=actor, obj=obj) else: actor.msg("You don't have that.") def failed_command_match_help(self): return "You don't see a '%s' to drop." % self.argstr
class MyObjSetCmd(MyObjCommand): """ @myobj <key>=[<object>] Set the value for a personal object shortcut. """ aliases = ('@myobj', ) syntax = '<key>=[<object>]' arg_parsers = {'object': MatchObject(show=True, context=False)} lock = use_myobjs def run(self, actor, key, object): """ :type actor: MyObjCharacter """ key = key.lower().lstrip('%') previous = actor.set_myobj(key, object) actor.tell('Previous value of {y%', key, '{n: ', previous) actor.tell('New setting: {y%', key, '{n = {c', object)
class TakeThingCmd(Command): """ take <object> Picks up an object in the location with you and moves it to your inventory. """ aliases = ('take', 'get', 'pickup') key = 'take thing' syntax = "<obj>" arg_parsers = { 'obj': MatchObject(cls=Object, search_for='object', show=True), } lock = locks.all_pass def run(self, actor, obj): """ :type actor: mudslingcore.objects.Character :type obj: mudsling.object.Object """ from mudslingcore.objects import Thing if (actor.has_perm('pick up anything') or obj.isa(Thing) or obj.owner == actor): if obj.location == actor.location: try: obj.move_to(actor, by=actor, via='take') except errors.InvalidObject: pass # take_fail message will run. msg = 'take' if obj.location == actor else 'take_fail' messager = obj if obj.get_message(msg) is not None else actor messager.emit_message(msg, location=actor.location, actor=actor, obj=obj) elif obj.location == actor: actor.msg("You already have that!") else: actor.msg("You don't see that here.") else: actor.msg("You can't pick that up.") def failed_command_match_help(self): return "You don't see a '%s' to take." % self.argstr
class PutCmd(Command): """ put <thing> in <container> Places a thing inside an open container. """ aliases = ('put', 'place', 'drop') syntax = '<thing> {in|into|inside of|inside} <container>' arg_parsers = { 'thing': MatchObject(cls=Thing, search_for='thing', show=True), 'container': 'this' } lock = locks.all_pass def run(self, this, actor, args): """ :type this: mudslingcore.objects.Container :type actor: mudslingcore.objects.Object :type args: dict """ #: :type: mudslingcore.objects.Object thing = args['thing'] if this.location not in (actor, actor.location): actor.tell("You can't get at ", this, ".") elif thing.location not in (actor, actor.location): actor.tell("You don't have ", thing, ".") elif not this.opened: actor.tell(this, " is closed.") else: try: thing.move_to(this, by=actor) except errors.MoveError as e: if e.message: actor.tell('{r', e.message) this.emit_message('add_fail', actor=actor, thing=thing) else: this.emit_message('add', actor=actor, thing=thing)
from mudsling.commands import Command from mudsling.parsers import MatchObject, StaticParser, StringTupleStaticParser from mudsling.objects import BaseObject from mudsling.locks import Lock import mudslingcore.scripting as s from mudslingcore.editor import EditorError from mudslingcore import lua match_scriptable = MatchObject(cls=s.ScriptableObject, show=True, context=False, search_for='scriptable object') can_script = Lock('has_perm(script anything) or can(script)') class PropertyTypeStaticParser(StaticParser): types = { 'str': str, 'string': str, 'int': int, 'number': int, 'num': int, 'float': float } @classmethod def parse(cls, input): input = input.lower() if input in cls.types:
self.emit_message('follow', actor=self.ref(), char=char) def stop_following(self, following=None): if following is None or self.following == following: following = self.following if self.db.is_valid(following, FollowableObject): following.lose_follower(self.ref()) self.following = None self.emit_message('unfollow', actor=self.ref(), char=following) def do_follow(self, exit): if exit in self.context: exit.invoke(self.ref()) match_follower = MatchObject(cls=Follower, search_for='follower', show=True) match_leader = MatchObject(cls=FollowableObject, search_for='something to follow', show=True) match_followers = ListMatcher(match_follower) class LeadCmd(Command): """ lead <follower>[,<follower>, ...] Invite one or more followers. """ aliases = ('lead', 'invite-follow', 'follow-invite') syntax = '<followers>' arg_parsers = {'followers': match_followers} lock = all_pass
from mudsling.commands import Command from mudsling.locks import Lock from mudsling.parsers import MatchObject, StringListStaticParser from mudsling.objects import BasePlayer import restserver from mudslingcore.ui import ClassicUI ui = ClassicUI() use_api = Lock('has_perm(use api)') administer_api = Lock('has_perm(administer api)') match_player = MatchObject(cls=BasePlayer, search_for='player', show=True, context=False) class APIKeysCmd(Command): """ @apikeys[/all] [<player>] Show API keys for specified player (default: self), or across all players with /all switch. """ aliases = ('@apikeys', '@apikeys-list') syntax = '[<player>]' arg_parsers = {'player': match_player} lock = use_api switch_defaults = {'all': False}