/// <summary> /// Execute the input as if it were a tiny MooScript verb attached to the player. /// </summary> /// <returns> /// If the MooScript returns a value, it will be sent back to the player. /// </returns> public static string ExecuteImmediate(string input, Player player) { Verb v = new Verb() { name = "inline", help = "", code = input.Substring(1) + ';' }; var param = new Verb.VerbParameters() { input = input, self = player.world.findObject( player.id ), dobj = Mob.None, prep = Verb.Prep.None, iobj = Mob.None, player = player, world = player.world }; object rv; using( var ac = new ActorContext( player, player.id ) ) rv = v.invoke( param ); // Try to do some reallly basic type massaging to make it viewable on the terminal. string rvs; if (rv is string) { rvs = "\"{0}\"".FormatI(rv); } else if (rv is System.Collections.IEnumerable) { rvs = string.Join(", ", (from object i in (System.Collections.IEnumerable)rv select i.ToStringI())); } else rvs = rv.ToStringI(); return MooCode.PrepareForClient(rvs); }
/// <summary> /// Loads the specified Mob from the current checkpoint. /// </summary> /// <param name="objectId">The Mob's object ID (not database ID)</param> /// <param name="world">The World object to attach this Mob to</param> /// <returns> /// The loaded Mob, or null if it doesn't exist in this checkpoint. /// </returns> public CanonMob loadMob( int objectId, CanonWorld world ) { // We don't need to write anything here, but the transaction may give us reader semantics too. lock( _lock ) using( var token = _db.token() ) using( var trans = _db.transaction( token ) ) { // Get the current checkpoint ID. ulong curCheckpoint = getLatestCheckpoint( token ); // Find the existing object in the MobTable. IEnumerable<DBMobTable> results = _db.select( token, new DBMobTable() { objectId = objectId, checkpoint = curCheckpoint }, new string[] { "objectId", "checkpoint" } ); if( !results.Any() ) return null; ulong mobDbId = results.First().mob; // Get the mob itself. IEnumerable<DBMob> mobs = _db.select( token, new DBMob() { id = mobDbId }, new string[] { "id" } ); if( !results.Any() ) throw new ArgumentException( "Database error: Mob is in mobtable, but non-existant" ); DBMob mob = mobs.First(); // Look for all of its attributes. IEnumerable<DBAttr> attrs = _db.select( token, new DBAttr() { mob = mobDbId }, new string[] { "mob" } ); // And all of its verbs. IEnumerable<DBVerb> verbs = _db.select( token, new DBVerb() { mob = mobDbId }, new string[] { "mob" } ); // Now put it all together into a world object. CanonMob cm = new CanonMob( world, objectId ); Mob m = Mob.Wrap( cm ); m.parentId = mob.parent ?? 0; m.locationId = mob.location ?? 0; m.ownerId = mob.owner; m.pathId = mob.pathId ?? null; foreach( DBAttr attr in attrs ) { AttributeSerialized ser = new AttributeSerialized() { mimetype = attr.mime, binvalue = attr.data, strvalue = attr.text }; var ta = TypedAttribute.FromSerialized( ser ); m.attrSet(attr.name, ta); } foreach( DBVerb verb in verbs ) { Verb v = new Verb() { name = verb.name, code = verb.code, }; m.verbSet(verb.name, v); } return cm; } }
static IEnumerable<FoundVerb> SearchWildcardVerbsFrom(Mob m, string verbName, Verb.VerbParameters param) { param.self = m; foreach (var v in m.allVerbs) if (v.Value.item.name == verbName) { if (v.Value.item.matchWildcards(param).Count() > 0) yield return new FoundVerb() { foundOn = m, definedOn = v.Value.source, verb = v.Value.item }; } }
public void verbSet( StringI name, Verb v ) { }
public void verbSet( StringI name, Verb v ) { throw new NotImplementedException(); }
public void verbSet( StringI name, Verb v ) { _verbs[name] = v; }