示例#1
0
        public T GetProperty <T>(String Name)
        {
            T r;

            if (Properties.ContainsKey(Name))
            {
                r = (T)Properties[Name];
            }
            else
            {
                var info = PropertyManifest.GetPropertyInformation(Name);
                if (info == null)
                {
                    throw new InvalidOperationException("Property " + Name + " does not exist.");
                }
                r = (T)info.DefaultValue;
            }

            var payload = new PropertyPayload <T>
            {
                Name  = Name,
                Value = r
            };

            ConsiderPerformRule("modify property", this, payload);

            return(payload.Value);
        }
示例#2
0
文件: Set.cs 项目: Blecki/RMUDReboot
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("!SET"),
                    MustMatch("I don't see that here.",
                              Object("OBJECT", InScope)),
                    SingleWord("PROPERTY"),
                    Rest("VALUE")))
            .Manual("Set the value of a property on an object.")
            .ProceduralRule((match, actor) =>
            {
                var _object       = match["OBJECT"] as MudObject;
                var property_name = match["PROPERTY"].ToString();
                var stringValue   = match["VALUE"].ToString();

                var propertyInfo = PropertyManifest.GetPropertyInformation(property_name);

                if (propertyInfo == null)
                {
                    Core.SendMessage(actor, "That property does not exist.");
                    return(PerformResult.Stop);
                }

                var realValue = propertyInfo.Converter.ConvertFromString(stringValue);

                _object.SetProperty(property_name, realValue);

                Core.SendMessage(actor, "Property set.");
                return(PerformResult.Continue);
            });
        }
示例#3
0
        public override void Create(CommandParser Parser)
        {
            Parser.AddCommand(
                Sequence(
                    RequiredRank(500),
                    KeyWord("!INSPECT"),
                    MustMatch("I don't see that here.",
                              Or(
                                  Object("OBJECT", InScope),
                                  KeyWord("HERE")))))
            .Manual("Take a peek at the internal workings of any mud object.")
            .ProceduralRule((match, actor) =>
            {
                if (!match.ContainsKey("OBJECT"))
                {
                    match.Upsert("OBJECT", actor.Location);
                }
                return(PerformResult.Continue);
            }, "Convert locale option to standard form rule.")
            .ProceduralRule((match, actor) =>
            {
                var target = match["OBJECT"] as MudObject;

                Core.SendMessage(actor, "*** INSPECT LISTING ***");
                Core.SendMessage(actor, "Path: <s0>", target.Path);
                Core.SendMessage(actor, "Instance: <s0>", target.Instance);
                Core.SendMessage(actor, "Persistent: <s0>", target.IsPersistent.ToString());
                if (!target.Location.HasValue(out var loc))
                {
                    Core.SendMessage(actor, "Location: NOWHERE");
                }
                else
                {
                    Core.SendMessage(actor, "Location: <s0>", loc.GetFullName());
                }
                Core.SendMessage(actor, "*** DYNAMIC PROPERTIES ***");

                foreach (var property in target.Properties)
                {
                    var info = PropertyManifest.GetPropertyInformation(property.Key);
                    Core.SendMessage(actor, "<s0>: <s1>", property.Key, info.Converter.ConvertToString(property.Value));
                }

                Core.SendMessage(actor, "*** END OF LISTING ***");

                return(PerformResult.Continue);
            }, "List all the damn things rule.");
        }