Exemple #1
0
        override public MudObject ReloadObject(String Path)
        {
            Path = Path.Replace('\\', '/');

            if (NamedObjects.ContainsKey(Path))
            {
                var existing  = NamedObjects[Path];
                var newObject = CompileObject(Path);
                if (newObject == null)
                {
                    return(null);
                }

                existing.State = ObjectState.Destroyed;
                NamedObjects.Upsert(Path, newObject);
                MudObject.InitializeObject(newObject);

                //Preserve contents
                if (existing is Container && newObject is Container)
                {
                    foreach (var item in (existing as Container).EnumerateObjectsAndRelloc())
                    {
                        (newObject as Container).Add(item.Item1, item.Item2);
                        item.Item1.Location = newObject;
                    }
                }

                //Preserve location
                if (existing is MudObject && newObject is MudObject)
                {
                    if ((existing as MudObject).Location != null)
                    {
                        var loc = ((existing as MudObject).Location as Container).RelativeLocationOf(existing);
                        MudObject.Move(newObject as MudObject, (existing as MudObject).Location, loc);
                        MudObject.Move(existing as MudObject, null, RelativeLocations.None);
                    }
                }

                existing.Destroy(false);

                return(newObject);
            }
            else
            {
                return(GetObject(Path));
            }
        }
Exemple #2
0
        override public MudObject GetObject(String Path)
        {
            Path = Path.Replace('\\', '/');

            String BasePath, InstanceName;

            SplitObjectName(Path, out BasePath, out InstanceName);

            if (!String.IsNullOrEmpty(InstanceName))
            {
                MudObject activeInstance = null;
                if (ActiveInstances.TryGetValue(Path, out activeInstance))
                {
                    return(activeInstance);
                }
                else
                {
                    return(CreateInstance(Path));
                }
            }
            else
            {
                MudObject r = null;

                if (NamedObjects.ContainsKey(BasePath))
                {
                    r = NamedObjects[BasePath];
                }
                else
                {
                    r = CompileObject(BasePath);
                    if (r != null)
                    {
                        NamedObjects.Upsert(BasePath, r);
                    }
                }

                if (r != null && r.State == ObjectState.Unitialized)
                {
                    MudObject.InitializeObject(r);
                }

                return(r);
            }
        }
Exemple #3
0
        public RMUD.MudObject ResetObject(string Path)
        {
            Path = Path.Replace('\\', '/');

            if (NamedObjects.ContainsKey(Path))
            {
                var existing = NamedObjects[Path];
                existing.State = ObjectState.Destroyed;

                var newObject = Activator.CreateInstance(existing.GetType()) as MudObject;
                NamedObjects.Upsert(Path, newObject);
                MudObject.InitializeObject(newObject);

                //Preserve the location of actors, and actors only.
                if (existing is Container)
                {
                    foreach (var item in (existing as Container).EnumerateObjectsAndRelloc())
                    {
                        if (item.Item1 is Actor)
                        {
                            (newObject as Container).Add(item.Item1, item.Item2);
                            item.Item1.Location = newObject;
                        }
                    }
                }

                if (existing is MudObject && (existing as MudObject).Location != null)
                {
                    var loc = ((existing as MudObject).Location as Container).RelativeLocationOf(existing);
                    MudObject.Move(newObject as MudObject, (existing as MudObject).Location, loc);
                    MudObject.Move(existing as MudObject, null, RelativeLocations.None);
                }

                existing.Destroy(false);

                return(newObject);
            }
            else
            {
                return(null);
            }
        }