Пример #1
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            _dreamManager.WorldContentsList = dreamObject.GetVariable("contents").GetValueAsDreamList();

            DreamValue log = dreamObject.ObjectDefinition.Variables["log"];

            dreamObject.SetVariable("log", log);

            DreamValue fps = dreamObject.ObjectDefinition.Variables["fps"];

            if (fps.Value != null)
            {
                _cfg.SetCVar(CVars.NetTickrate, fps.GetValueAsInteger());
            }

            DreamValue view = dreamObject.ObjectDefinition.Variables["view"];

            if (view.TryGetValueAsString(out string viewString))
            {
                _viewRange = new ViewRange(viewString);
            }
            else
            {
                _viewRange = new ViewRange(view.GetValueAsInteger());
            }
        }
Пример #2
0
        public void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            ParentType?.OnObjectCreated(dreamObject, creationArguments);

            _dreamManager.WorldContentsList = dreamObject.GetVariable("contents").GetValueAsDreamList();

            DreamValue log = dreamObject.ObjectDefinition.Variables["log"];

            dreamObject.SetVariable("log", log);

            DreamValue fps = dreamObject.ObjectDefinition.Variables["fps"];

            if (fps.TryGetValueAsInteger(out var fpsValue))
            {
                _cfg.SetCVar(CVars.NetTickrate, fpsValue);
            }

            DreamValue view = dreamObject.ObjectDefinition.Variables["view"];

            if (view.TryGetValueAsString(out string viewString))
            {
                _viewRange = new ViewRange(viewString);
            }
            else
            {
                if (!view.TryGetValueAsInteger(out var viewInt))
                {
                    Logger.Warning("world.view did not contain a valid value. A default of 5 is being used.");
                    viewInt = 5;
                }

                _viewRange = new ViewRange(viewInt);
            }
        }
Пример #3
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            ContentsList = dreamObject.GetVariable("contents").GetValueAsDreamList();

            //New() is not called here
        }
Пример #4
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            lock (Mobs) {
                Mobs.Add(dreamObject);
            }
        }
Пример #5
0
        // Execute this proc. This will behave as if the proc has `set waitfor = 0`
        public DreamValue Spawn(DreamObject src, DreamProcArguments arguments, DreamObject usr = null)
        {
            var context = new DreamThread();
            var state   = CreateState(context, src, usr, arguments);

            context.PushProcState(state);
            return(context.Resume());
        }
Пример #6
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            if (creationArguments.GetArgument(0, "Size").TryGetValueAsInteger(out int size))
            {
                ((DreamList)dreamObject).Resize(size);
            }
        }
Пример #7
0
        public void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            if (!dreamObject.IsSubtypeOf(DreamPath.Atom)) // Atoms are in world.contents
            {
                _dreamManager.Datums.Add(dreamObject);
            }

            ParentType?.OnObjectCreated(dreamObject, creationArguments);
        }
Пример #8
0
        public void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            ParentType?.OnObjectCreated(dreamObject, creationArguments);

            DreamValue screenLocationValue = dreamObject.GetVariable("screen_loc");

            if (screenLocationValue != DreamValue.Null)
            {
                UpdateScreenLocation(dreamObject, screenLocationValue);
            }
        }
Пример #9
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            DreamValue screenLocationValue = dreamObject.GetVariable("screen_loc");

            if (screenLocationValue.Value != null)
            {
                UpdateScreenLocation(dreamObject, screenLocationValue);
            }
        }
Пример #10
0
        public void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            ParentType?.OnObjectCreated(dreamObject, creationArguments);

            // Named arguments are ignored
            if (creationArguments.OrderedArguments.Count > 1)   // Multi-dimensional
            {
                DreamList[] lists = { (DreamList)dreamObject };

                int dimensions = creationArguments.OrderedArguments.Count;
                for (int argIndex = 0; argIndex < dimensions; argIndex++)
                {
                    DreamValue arg = creationArguments.OrderedArguments[argIndex];
                    arg.TryGetValueAsInteger(out int size);

                    DreamList[] newLists = null;
                    if (argIndex < dimensions)
                    {
                        newLists = new DreamList[size * lists.Length];
                    }

                    for (int i = 0; i < lists.Length; i++)
                    {
                        DreamList list = lists[i];

                        for (int j = 0; j < size; j++)
                        {
                            if (argIndex < dimensions - 1)
                            {
                                DreamList newList = DreamList.Create();

                                list.AddValue(new DreamValue(newList));
                                newLists[i * size + j] = newList;
                            }
                            else
                            {
                                list.AddValue(DreamValue.Null);
                            }
                        }
                    }

                    lists = newLists;
                }
            }
            else if (creationArguments.OrderedArguments.Count == 1 && creationArguments.OrderedArguments[0].TryGetValueAsInteger(out int size))
            {
                ((DreamList)dreamObject).Resize(size);
            }
        }
Пример #11
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            ContentsList = dreamObject.GetVariable("contents").GetValueAsDreamList();

            dreamObject.SetVariable("log", new DreamValue(new ConsoleOutputResource()));

            DreamValue fps = dreamObject.ObjectDefinition.Variables["fps"];

            if (fps.Value != null)
            {
                dreamObject.SetVariable("tick_lag", new DreamValue(10.0f / fps.GetValueAsInteger()));
            }

            //New() is not called here
        }
Пример #12
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            _dreamManager.WorldContentsList.AddValue(new DreamValue(dreamObject));

            DreamValue locArgument = creationArguments.GetArgument(0, "loc");

            if (locArgument.TryGetValueAsDreamObjectOfType(DreamPath.Atom, out _))
            {
                dreamObject.SetVariable("loc", locArgument); //loc is set before /New() is ever called
            }
            else if (creationArguments.ArgumentCount == 0)
            {
                creationArguments.OrderedArguments.Add(DreamValue.Null); //First argument is loc, which is null
            }

            base.OnObjectCreated(dreamObject, creationArguments);
        }
Пример #13
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            DreamObject loc = DreamMetaObjectAtom.FindLocArgument(creationArguments);

            base.OnObjectCreated(dreamObject, creationArguments);

            if (loc != null && loc.IsSubtypeOf(DreamPath.Turf))
            {
                DreamList contents = loc.GetVariable("contents").GetValueAsDreamList();
                while (contents.GetLength() > 0)   //Transfer all the old turf's contents
                {
                    contents.GetValue(new DreamValue(1)).GetValueAsDreamObjectOfType(DreamPath.Atom).SetVariable("loc", new DreamValue(dreamObject));
                }

                Program.DreamMap.SetTurf(loc.GetVariable("x").GetValueAsInteger(), loc.GetVariable("y").GetValueAsInteger(), dreamObject);
            }
        }
Пример #14
0
        public void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            DreamList contents = DreamList.Create();

            contents.ValueAssigned += (DreamList list, DreamValue key, DreamValue value) => {
                if (value.TryGetValueAsDreamObjectOfType(DreamPath.Turf, out DreamObject turf))
                {
                    int x = turf.GetVariable("x").GetValueAsInteger();
                    int y = turf.GetVariable("y").GetValueAsInteger();
                    int z = turf.GetVariable("z").GetValueAsInteger();

                    _dreamMapManager.SetArea(x, y, z, dreamObject);
                }
            };

            _dreamManager.AreaContents.Add(dreamObject, contents);

            ParentType?.OnObjectCreated(dreamObject, creationArguments);
        }
Пример #15
0
        public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
        {
            base.OnObjectCreated(dreamObject, creationArguments);

            dreamObject.CallProc("New", creationArguments);
        }
Пример #16
0
 public override void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
 {
     base.OnObjectCreated(dreamObject, creationArguments);
     _dreamManager.Mobs.Add(dreamObject);
 }
Пример #17
0
        public static DreamValue NativeProc_Find(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamValue element = arguments.GetArgument(0, "Elem");
            int        start   = arguments.GetArgument(1, "Start").GetValueAsInteger(); //1-indexed
            int        end     = arguments.GetArgument(2, "End").GetValueAsInteger();   //1-indexed
            DreamList  list    = (DreamList)instance;

            if (start != 1 || end != 0)
            {
                throw new NotImplementedException("Ranged /list.Find() is not implemented");
            }
            return(new DreamValue(list.FindValue(element)));
        }
Пример #18
0
        public static DreamValue NativeProc_Add(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamList list = (DreamList)instance;

            foreach (DreamValue argument in arguments.OrderedArguments)
            {
                if (argument.TryGetValueAsDreamList(out DreamList argumentList))
                {
                    foreach (DreamValue value in argumentList.GetValues())
                    {
                        list.AddValue(value);
                    }
                }
                else
                {
                    list.AddValue(argument);
                }
            }

            return(DreamValue.Null);
        }
Пример #19
0
 public abstract ProcState CreateState(DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments);
Пример #20
0
        public static DreamValue NativeProc_Find(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamValue element = arguments.GetArgument(0, "Elem");
            int        start   = arguments.GetArgument(1, "Start").GetValueAsInteger(); //1-indexed
            int        end     = arguments.GetArgument(2, "End").GetValueAsInteger();   //1-indexed
            DreamList  list    = (DreamList)instance;

            return(new(list.FindValue(element, start, end)));
        }
Пример #21
0
        public static DreamValue NativeProc_Insert(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            int       index = arguments.GetArgument(0, "Index").GetValueAsInteger(); //1-indexed
            DreamList list  = (DreamList)instance;

            if (arguments.OrderedArguments.Count < 2)
            {
                throw new Exception("No value given to insert");
            }

            for (int i = 1; i < arguments.OrderedArguments.Count; i++)
            {
                DreamValue item = arguments.OrderedArguments[i];

                if (item.TryGetValueAsDreamList(out DreamList valueList))
                {
                    foreach (DreamValue value in valueList.GetValues())
                    {
                        list.Insert(index++, value);
                    }
                }
                else
                {
                    list.Insert(index++, item);
                }
            }

            return(new DreamValue(index));
        }
Пример #22
0
        public static DreamValue NativeProc_Copy(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            int       start    = arguments.GetArgument(0, "Start").GetValueAsInteger(); //1-indexed
            int       end      = arguments.GetArgument(1, "End").GetValueAsInteger();   //1-indexed
            DreamList list     = (DreamList)instance;
            DreamList listCopy = list.CreateCopy(start, end);

            return(new DreamValue(listCopy));
        }
Пример #23
0
        public static DreamValue NativeProc_Cut(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            int       start = arguments.GetArgument(0, "Start").GetValueAsInteger(); //1-indexed
            int       end   = arguments.GetArgument(1, "End").GetValueAsInteger();   //1-indexed
            DreamList list  = (DreamList)instance;

            list.Cut(start, end);
            return(DreamValue.Null);
        }
Пример #24
0
        public static DreamValue NativeProc_Remove(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamList         list           = (DreamList)instance;
            List <DreamValue> argumentValues = arguments.GetAllArguments();
            bool itemRemoved = false;

            foreach (DreamValue argument in argumentValues)
            {
                if (list.ContainsValue(argument))
                {
                    list.RemoveValue(argument);

                    itemRemoved = true;
                }
            }

            return(new DreamValue(itemRemoved ? 1 : 0));
        }
Пример #25
0
        public static DreamValue NativeProc_Swap(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamList list   = (DreamList)instance;
            int       index1 = arguments.GetArgument(0, "Index1").GetValueAsInteger();
            int       index2 = arguments.GetArgument(1, "Index2").GetValueAsInteger();

            list.Swap(index1, index2);
            return(DreamValue.Null);
        }
Пример #26
0
        public static DreamValue NativeProc_Width(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamMetaObjectIcon.DreamIconObject dreamIconObject = DreamMetaObjectIcon.ObjectToDreamIcon[instance];

            return(new DreamValue(dreamIconObject.Description.Width));
        }
Пример #27
0
        public static DreamValue NativeProc_Replace(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamRegex dreamRegex = DreamMetaObjectRegex.ObjectToDreamRegex[instance];

            DreamValue haystack = arguments.GetArgument(0, "haystack");
            DreamValue replace  = arguments.GetArgument(1, "replacement");
            int        start    = arguments.GetArgument(2, "Start").GetValueAsInteger();
            int        end      = arguments.GetArgument(3, "End").GetValueAsInteger();

            if (!haystack.TryGetValueAsString(out var haystackString))
            {
                if (haystack == DreamValue.Null)
                {
                    return(DreamValue.Null);
                }
                //TODO Check what actually happens
                throw new ArgumentException("Bad regex haystack");
            }
            string haystackSubstring = haystackString;

            if (end != 0)
            {
                haystackSubstring = haystackString.Substring(0, end - start);
            }

            if (replace.TryGetValueAsProc(out DreamProc replaceProc))
            {
                return(DoProcReplace(replaceProc));
            }
            if (replace.TryGetValueAsString(out string replaceString))
            {
                return(DoTextReplace(replaceString));
            }

            if (replace.TryGetValueAsPath(out var procPath) && procPath.LastElement is not null)
            {
                var dreamMan = IoCManager.Resolve <IDreamManager>();
                if (dreamMan.ObjectTree.TryGetGlobalProc(procPath.LastElement, out DreamProc? proc))
                {
                    return(DoProcReplace(proc));
                }
            }

            throw new ArgumentException("Replacement argument must be a string or a proc");

            DreamValue DoProcReplace(DreamProc proc)
            {
                if (dreamRegex.IsGlobal)
                {
                    throw new NotImplementedException("Proc global regex replacements are not implemented");
                }
                var match              = dreamRegex.Regex.Match(haystackSubstring);
                var groups             = match.Groups;
                List <DreamValue> args = new List <DreamValue>(groups.Count);

                foreach (Group group in groups)
                {
                    args.Add(new DreamValue(group.Value));
                }
                var result = DreamThread.Run(async(state) => await state.Call(proc, instance, null, new DreamProcArguments(args)));

                if (result.TryGetValueAsString(out var replacement))
                {
                    return(DoTextReplace(replacement));
                }
                //TODO Confirm this behavior
                if (result == DreamValue.Null)
                {
                    return(new DreamValue(haystackSubstring));
                }
                throw new ArgumentException("Replacement is not a string");
            }

            DreamValue DoTextReplace(string replacement)
            {
                string replaced = dreamRegex.Regex.Replace(haystackSubstring, replacement, dreamRegex.IsGlobal ? -1 : 1, start - 1);

                if (end != 0)
                {
                    replaced += haystackString.Substring(end - start + 1);
                }

                instance.SetVariable("text", new DreamValue(replaced));
                return(new DreamValue(replaced));
            }
        }
Пример #28
0
        public static DreamValue NativeProc_Find(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamRegex dreamRegex = DreamMetaObjectRegex.ObjectToDreamRegex[instance];
            DreamValue haystack   = arguments.GetArgument(0, "haystack");
            int        next       = GetNext(instance, arguments.GetArgument(1, "Start"), dreamRegex.IsGlobal);
            int        end        = arguments.GetArgument(2, "End").GetValueAsInteger();

            instance.SetVariable("text", haystack);

            string haystackString;

            if (!haystack.TryGetValueAsString(out haystackString))
            {
                haystackString = String.Empty;
            }

            if (end == 0)
            {
                end = haystackString.Length;
            }
            if (haystackString.Length == next - 1)
            {
                return(new DreamValue(0));
            }

            Match match = dreamRegex.Regex.Match(haystackString, next - 1, end - next);

            if (match.Success)
            {
                instance.SetVariable("index", new DreamValue(match.Index + 1));
                instance.SetVariable("match", new DreamValue(match.Value));
                if (match.Groups.Count > 0)
                {
                    DreamList groupList = DreamList.Create(match.Groups.Count);

                    for (int i = 1; i < match.Groups.Count; i++)
                    {
                        groupList.AddValue(new DreamValue(match.Groups[i].Value));
                    }

                    instance.SetVariable("group", new DreamValue(groupList));
                }

                if (dreamRegex.IsGlobal)
                {
                    instance.SetVariable("next", new DreamValue(match.Index + match.Length));
                }

                return(new DreamValue(match.Index + 1));
            }
            else
            {
                return(new DreamValue(0));
            }
        }
Пример #29
0
        public static DreamValue NativeProc_Replace(DreamObject instance, DreamObject usr, DreamProcArguments arguments)
        {
            DreamRegex dreamRegex = DreamMetaObjectRegex.ObjectToDreamRegex[instance];

            if (!dreamRegex.IsGlobal)
            {
                throw new NotImplementedException("Non-global regex replaces are not implemented");
            }

            DreamValue haystack = arguments.GetArgument(0, "haystack");
            DreamValue replace  = arguments.GetArgument(1, "replacement");
            int        start    = arguments.GetArgument(2, "Start").GetValueAsInteger();
            int        end      = arguments.GetArgument(3, "End").GetValueAsInteger();

            string haystackString = haystack.GetValueAsString();

            if (end == 0)
            {
                end = haystackString.Length;
            }

            if (replace.TryGetValueAsProc(out DreamProc replaceProc))
            {
                throw new NotImplementedException("Proc replacements are not implemented");
            }
            else if (replace.TryGetValueAsString(out string replaceString))
            {
                string replaced = dreamRegex.Regex.Replace(haystackString, replaceString, end - start, start - 1);

                instance.SetVariable("text", new DreamValue(replaced));
                return(new DreamValue(replaced));
            }
            else
            {
                throw new ArgumentException("Replacement argument must be a string");
            }
        }
Пример #30
0
 public virtual void OnObjectCreated(DreamObject dreamObject, DreamProcArguments creationArguments)
 {
 }