示例#1
0
        public override DreamValue OnVariableGet(DreamObject dreamObject, string variableName, DreamValue variableValue)
        {
            switch (variableName)
            {
            case "tick_lag":
                return(new DreamValue(_gameTiming.TickPeriod.TotalMilliseconds / 100));

            case "fps":
                return(new DreamValue(_gameTiming.TickRate));

            case "timeofday":
                return(new DreamValue((int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds / 100));

            case "time":
                return(new DreamValue(_gameTiming.CurTime.TotalMilliseconds / 100));

            case "realtime":
                return(new DreamValue((DateTime.Now - new DateTime(2000, 1, 1)).Milliseconds / 100));

            case "tick_usage": {
                var tickUsage = (_gameTiming.RealTime - _gameTiming.LastTick) / _gameTiming.TickPeriod;
                return(new DreamValue(tickUsage * 100));
            }

            case "maxx":
                return(new DreamValue(_dreamMapManager.Size.X));

            case "maxy":
                return(new DreamValue(_dreamMapManager.Size.Y));

            case "maxz":
                return(new DreamValue(_dreamMapManager.Levels));

            //case "address":
            //    return new(Runtime.Server.Address.ToString());
            //case "port":
            //    return new(Runtime.Server.Port);
            //case "url":
            //    return new("opendream://" + Runtime.Server.Address + ":" + Runtime.Server.Port);
            case "system_type": {
                //system_type value should match the defines in Defines.dm
                if (Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX or PlatformID.Other)
                {
                    return(new DreamValue(0));
                }
                //Windows
                return(new DreamValue(1));
            }

            case "view": {
                //Number if square & centerable, string representation otherwise
                return(new DreamValue((_viewRange.IsSquare && _viewRange.IsCenterable) ? _viewRange.Width : _viewRange.ToString()));
            }

            default:
                return(base.OnVariableGet(dreamObject, variableName, variableValue));
            }
        }