예제 #1
0
        public static MapSettings Load()
        {
            try
            {
                if (Constants.IsServer && MyAPIGateway.Utilities.FileExistsInWorldStorage(Constants.mapFile, typeof(MapSettings)))
                {
                    var    reader  = MyAPIGateway.Utilities.ReadFileInWorldStorage(Constants.mapFile, typeof(MapSettings));
                    string xmlText = reader.ReadToEnd();
                    reader.Close();
                    MapSettings config = MyAPIGateway.Utilities.SerializeFromXML <MapSettings>(xmlText);
                    if (config == null)
                    {
                        throw new NullReferenceException("Failed to serialize from xml.");
                    }
                    config.SyncData = true;
                    return(config);
                }
            }
            catch
            { }

            MapSettings result = new MapSettings();

            result.Save();
            result.SyncData = true;
            return(result);
        }
        // Context: All
        public override void Close()
        {
            if (me != null)
            {
                me.IsWorkingChanged    -= Me_IsWorkingChanged;
                me.AppendingCustomInfo -= CustomInfo;
                if (_state != null)
                {
                    _state.OnValueReceived -= ReceivedNewState;
                    _state.Close();
                }
                if (_settings != null)
                {
                    _settings.OnValueReceived -= SaveStorage;
                    _settings.OnValueReceived -= RefreshUI;
                    _settings.Close();
                }

                Settings.MapSettings config = IPSession.Instance.MapSettings;
                config.OnSubgridsChanged -= ClearCachedComps;
                config.OnComponentCostModifierChanged -= ClearCachedComps;
                config.OnExtraComponentChanged        -= ClearCachedComps;
                config.OnExtraCompCostChanged         -= ClearCachedComps;
            }
        }
예제 #3
0
        public void Copy(MapSettings config)
        {
            blockBuildTime = config.blockBuildTime;
            if (OnBlockBuildTimeChanged != null)
            {
                OnBlockBuildTimeChanged.Invoke(blockBuildTime);
            }

            componentCostModifier = config.componentCostModifier;
            if (OnComponentCostModifierChanged != null)
            {
                OnComponentCostModifierChanged.Invoke(componentCostModifier);
            }

            minBlocks = config.minBlocks;
            if (OnMinBlocksChanged != null)
            {
                OnMinBlocksChanged.Invoke(minBlocks);
            }

            maxBlocks = config.maxBlocks;
            if (OnMaxBlocksChanged != null)
            {
                OnMaxBlocksChanged.Invoke(maxBlocks);
            }

            subgrids = config.subgrids;
            if (OnSubgridsChanged != null)
            {
                OnSubgridsChanged.Invoke(subgrids);
            }

            powerModifier = config.powerModifier;
            if (OnPowerModifierChanged != null)
            {
                OnPowerModifierChanged.Invoke(powerModifier);
            }

            extraComponent = config.extraComponent;
            if (OnExtraComponentChanged != null)
            {
                OnExtraComponentChanged.Invoke(extraComponent);
            }

            extraCompCost = config.extraCompCost;
            if (OnExtraCompCostChanged != null)
            {
                OnExtraCompCostChanged.Invoke(extraCompCost);
            }

            SyncData = true;
        }
        // Context: All
        public override void UpdateOnceBeforeFrame()
        {
            if (me.CubeGrid?.Physics == null)
            {
                return;
            }

            _state = new SyncableProjectorState(me, ProjectorState.Idle, 0);

            if (Constants.IsServer)
            {
                LoadStorage();
                _settings.OnValueReceived += SaveStorage;
                BuildState           = ProjectorState.Idle;
                me.IsWorkingChanged += Me_IsWorkingChanged;
            }
            else
            {
                _settings = new SyncableProjectorSettings(me, 0, true);
                _state.RequestFromServer();
                _settings.RequestFromServer();
                _state.OnValueReceived += ReceivedNewState;
            }

            MyProjectorDefinition def = (MyProjectorDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(me.BlockDefinition);

            minPower = def.RequiredPowerInput;
            sink     = me.Components.Get <MyResourceSinkComponent>();
            MyDefinitionId powerDef = MyResourceDistributorComponent.ElectricityId;

            sink.SetRequiredInputFuncByType(powerDef, GetCurrentPower);
            sink.Update();
            _settings.OnValueReceived += RefreshUI;

            me.AppendingCustomInfo += CustomInfo;
            me.RefreshCustomInfo();

            Settings.MapSettings config = IPSession.Instance.MapSettings;
            config.OnSubgridsChanged += ClearCachedComps;
            config.OnComponentCostModifierChanged += ClearCachedComps;
            config.OnExtraComponentChanged        += ClearCachedComps;
            config.OnExtraCompCostChanged         += ClearCachedComps;

            ProjectorControls.Create();
        }
            public override void Received(ulong sender)
            {
                MapSettings config = IPSession.Instance.MapSettings;

                switch ((PacketEnum)type)
                {
                case PacketEnum.BlockBuildTime:
                {
                    float num = BitConverter.ToSingle(value, 0);
                    config.blockBuildTime = num;
                    if (config.OnBlockBuildTimeChanged != null)
                    {
                        config.OnBlockBuildTimeChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.ComponentCostModifier:
                {
                    float num = BitConverter.ToSingle(value, 0);
                    config.componentCostModifier = num;
                    if (config.OnComponentCostModifierChanged != null)
                    {
                        config.OnComponentCostModifierChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.MinBlocks:
                {
                    int num = BitConverter.ToInt32(value, 0);
                    config.minBlocks = num;
                    if (config.OnMinBlocksChanged != null)
                    {
                        config.OnMinBlocksChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.MaxBlocks:
                {
                    int num = BitConverter.ToInt32(value, 0);
                    config.maxBlocks = num;
                    if (config.OnMaxBlocksChanged != null)
                    {
                        config.OnMaxBlocksChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.Subgrids:
                {
                    bool b = value[0] == 1;
                    config.subgrids = b;
                    if (config.OnSubgridsChanged != null)
                    {
                        config.OnSubgridsChanged.Invoke(b);
                    }
                }
                break;

                case PacketEnum.PowerModifier:
                {
                    float num = BitConverter.ToSingle(value, 0);
                    config.powerModifier = num;
                    if (config.OnPowerModifierChanged != null)
                    {
                        config.OnPowerModifierChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.ExtraCompCostModifier:
                {
                    float num = BitConverter.ToSingle(value, 0);
                    config.extraCompCost = num;
                    if (config.OnExtraCompCostChanged != null)
                    {
                        config.OnExtraCompCostChanged.Invoke(num);
                    }
                }
                break;

                case PacketEnum.ExtraComponent:
                {
                    SerializableDefinitionId?id = null;
                    if (value.Length > 0)
                    {
                        id = MyAPIGateway.Utilities.SerializeFromBinary <SerializableDefinitionId>(value);
                    }

                    config.extraComponent = id;
                    if (config.OnExtraComponentChanged != null)
                    {
                        config.OnExtraComponentChanged.Invoke(id);
                    }
                }
                break;
                }
            }
        // Context: All
        public override void UpdateOnceBeforeFrame()
        {
            if (me.CubeGrid?.Physics == null)
            {
                return;
            }

            _state = new SyncableProjectorState(me, State.Idle, 0);

            if (Constants.IsServer)
            {
                LoadStorage();
                _settings.OnValueReceived += SaveStorage;
                BuildState           = State.Idle;
                me.IsWorkingChanged += Me_IsWorkingChanged;
            }
            else
            {
                _settings = new SyncableProjectorSettings(me, 0, true);
                _state.RequestFromServer();
                _settings.RequestFromServer();
                _state.OnValueReceived += ReceivedNewState;
            }

            MyProjectorDefinition def = (MyProjectorDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(me.BlockDefinition);

            minPower = def.RequiredPowerInput;
            sink     = me.Components.Get <MyResourceSinkComponent>();
            MyDefinitionId powerDef = MyResourceDistributorComponent.ElectricityId;

            sink.SetRequiredInputFuncByType(powerDef, GetCurrentPower);
            sink.Update();
            _settings.OnValueReceived += RefreshUI;

            me.AppendingCustomInfo += CustomInfo;
            me.RefreshCustomInfo();

            Settings.MapSettings config = IPSession.Instance.MapSettings;
            config.OnSubgridsChanged += ClearCachedComps;
            config.OnComponentCostModifierChanged += ClearCachedComps;
            config.OnExtraComponentChanged        += ClearCachedComps;
            config.OnExtraCompCostChanged         += ClearCachedComps;

            if (!controls)
            {
                // Terminal controls

                IMyTerminalControlSeparator sep = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyProjector>("BuildGridSep");
                sep.Enabled = IsValid;
                sep.Visible = IsValid;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sep);

                IMyTerminalControlButton btnBuild = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("BuildGrid");
                btnBuild.Enabled = IsWorking;
                btnBuild.Visible = IsValid;
                btnBuild.SupportsMultipleBlocks = true;
                btnBuild.Title   = MyStringId.GetOrCompute("Build Grid");
                btnBuild.Action  = BuildClient;
                btnBuild.Tooltip = MyStringId.GetOrCompute("Builds the projection instantly.\nThere will be a cooldown after building.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnBuild);

                IMyTerminalControlButton btnCancel = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("CancelBuildGrid");
                btnCancel.Enabled = IsWorking;
                btnCancel.Visible = IsValid;
                btnCancel.SupportsMultipleBlocks = true;
                btnCancel.Title   = MyStringId.GetOrCompute("Cancel");
                btnCancel.Action  = CancelClient;
                btnCancel.Tooltip = MyStringId.GetOrCompute("Cancels the build process.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(btnCancel);

                IMyTerminalControlCheckbox chkShift = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCheckbox, IMyProjector>("MoveProjectionArea");
                chkShift.Enabled = IsWorking;
                chkShift.Visible = IsValid;
                chkShift.SupportsMultipleBlocks = true;
                chkShift.Title   = MyStringId.GetOrCompute("Loose Projection Area");
                chkShift.OnText  = MyStringId.GetOrCompute("On");
                chkShift.OffText = MyStringId.GetOrCompute("Off");
                chkShift.Tooltip = MyStringId.GetOrCompute("Allow the projection to spawn in a different area if the original area is occupied.");
                chkShift.Setter  = SetLooseArea;
                chkShift.Getter  = GetLooseArea;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(chkShift);

                IMyTerminalControlSlider sliderSpeed = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyProjector>("BuildSpeed");
                sliderSpeed.Enabled = IsWorking;
                sliderSpeed.Visible = IsValid;
                sliderSpeed.SupportsMultipleBlocks = true;
                sliderSpeed.Title   = MyStringId.GetOrCompute("Speed");
                sliderSpeed.Tooltip = MyStringId.GetOrCompute("Increasing the speed will use more energy.");
                sliderSpeed.SetLogLimits(Constants.minSpeed, Constants.maxSpeed);
                sliderSpeed.Writer = GetSpeedText;
                sliderSpeed.Getter = GetSpeed;
                sliderSpeed.Setter = SetSpeed;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(sliderSpeed);

                IMyTerminalControlTextbox txtTimeout = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlTextbox, IMyProjector>("GridTimer");
                txtTimeout.Enabled = (b) => false;
                txtTimeout.Visible = IsValid;
                txtTimeout.Getter  = GetTimer;
                txtTimeout.Setter  = (b, s) => { };
                txtTimeout.SupportsMultipleBlocks = false;
                txtTimeout.Title   = MyStringId.GetOrCompute("Build Timer");
                txtTimeout.Tooltip = MyStringId.GetOrCompute("The amount of time you must wait after building a grid to be able to build another.");
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(txtTimeout);

                // Terminal actions
                // Button panels are special and trigger on the server instead of the client, making everything more complicated.

                IMyTerminalAction aCancel = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildAction");
                aCancel.Enabled             = IsValid;
                aCancel.Action              = CancelClient; // For all except button panels
                aCancel.ValidForGroups      = true;
                aCancel.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel.Writer              = (b, s) => s.Append("Cancel");
                aCancel.InvalidToolbarTypes = new[] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel);
                IMyTerminalAction aCancel2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("CancelBuildGrid");
                aCancel2.Enabled             = IsValid;
                aCancel2.Action              = CancelClientUnsafe; // For only button panels
                aCancel2.ValidForGroups      = true;
                aCancel2.Name                = new StringBuilder("Cancel Spawn Grid");
                aCancel2.Writer              = (b, s) => s.Append("Cancel");
                aCancel2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aCancel2);

                IMyTerminalAction aBuild = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGridAction");
                aBuild.Enabled             = IsValid;
                aBuild.Action              = BuildClient; // For all except button panels
                aBuild.ValidForGroups      = true;
                aBuild.Name                = new StringBuilder("Spawn Grid");
                aBuild.Writer              = (b, s) => s.Append("Spawn");
                aBuild.InvalidToolbarTypes = new [] { MyToolbarType.ButtonPanel }.ToList();
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild);
                IMyTerminalAction aBuild2 = MyAPIGateway.TerminalControls.CreateAction <IMyProjector>("BuildGrid");
                aBuild2.Enabled             = IsValid;
                aBuild2.Action              = BuildClientUnsafe; // For only button panels
                aBuild2.ValidForGroups      = true;
                aBuild2.Name                = new StringBuilder("Spawn Grid");
                aBuild2.Writer              = (b, s) => s.Append("Spawn");
                aBuild2.InvalidToolbarTypes = new List <MyToolbarType> {
                    MyToolbarType.BuildCockpit, MyToolbarType.Character, MyToolbarType.LargeCockpit,
                    MyToolbarType.None, MyToolbarType.Seat, MyToolbarType.Ship, MyToolbarType.SmallCockpit, MyToolbarType.Spectator
                };
                MyAPIGateway.TerminalControls.AddAction <IMyProjector>(aBuild2);

                IMyTerminalControlListbox itemList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("ComponentList");
                itemList.Enabled                = IsWorking;
                itemList.Visible                = IsValid;
                itemList.ListContent            = GetItemList;
                itemList.Multiselect            = false;
                itemList.SupportsMultipleBlocks = false;
                itemList.Title            = MyStringId.GetOrCompute("Components");
                itemList.VisibleRowsCount = 10;
                itemList.ItemSelected     = (b, l) => { };
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemList);


                // Programmable Block stuff

                IMyTerminalControlProperty <Dictionary <MyItemType, int> > itemListProp
                    = MyAPIGateway.TerminalControls.CreateProperty <Dictionary <MyItemType, int>, IMyProjector>("RequiredComponents");
                itemListProp.Enabled = IsWorking;
                itemListProp.Visible = IsValid;
                itemListProp.SupportsMultipleBlocks = false;
                itemListProp.Setter = (b, l) => { };
                itemListProp.Getter = GetItemListPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(itemListProp);

                IMyTerminalControlProperty <int> gridTimeoutProp
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerProjection");
                gridTimeoutProp.Enabled = IsWorking;
                gridTimeoutProp.Visible = IsValid;
                gridTimeoutProp.SupportsMultipleBlocks = false;
                gridTimeoutProp.Setter = (b, l) => { };
                gridTimeoutProp.Getter = GetMaxTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutProp);

                IMyTerminalControlProperty <int> gridTimeoutActive
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("GridTimerCurrent");
                gridTimeoutActive.Enabled = IsWorking;
                gridTimeoutActive.Visible = IsValid;
                gridTimeoutActive.SupportsMultipleBlocks = false;
                gridTimeoutActive.Setter = (b, l) => { };
                gridTimeoutActive.Getter = GetCurrentTimerPB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                IMyTerminalControlProperty <int> buildState
                    = MyAPIGateway.TerminalControls.CreateProperty <int, IMyProjector>("BuildState");
                buildState.Enabled = IsWorking;
                buildState.Visible = IsValid;
                buildState.SupportsMultipleBlocks = false;
                buildState.Setter = (b, l) => { };
                buildState.Getter = GetStatePB;
                MyAPIGateway.TerminalControls.AddControl <IMyProjector>(gridTimeoutActive);

                MyLog.Default.WriteLineAndConsole("Initialized Instant Projector.");
                controls = true;
            }
        }
예제 #7
0
        private void ChatMessage(string messageText, ref bool sendToOthers)
        {
            string[] args;
            if (messageText.StartsWith(prefix2) || messageText.StartsWith(prefix1))
            {
                args = messageText.Split(space, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                return;
            }

            sendToOthers = false;

            if (!IsPlayerAdmin(true))
            {
                return;
            }

            if (args.Length < 2)
            {
                ShowHelp();
                return;
            }


            MapSettings config = IPSession.Instance.MapSettings;

            switch (args[1])
            {
            case "blocktime":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip blocktime <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Block Build Time: " + config.BlockBuildTime);
                    return;
                }

                float n;
                if (!float.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || float.IsInfinity(n) || float.IsNaN(n))
                {
                    Show("Value must be greater than 0.");
                    return;
                }
                config.BlockBuildTime = n;
                Show("Block Build Time: " + n);
            }
            break;

            case "compcost":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip compcost <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Component Cost Modifier: " + config.ComponentCostModifier);
                    return;
                }

                float n;
                if (!float.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || float.IsInfinity(n) || float.IsNaN(n))
                {
                    Show("Value must be greater than 0.");
                    return;
                }
                config.ComponentCostModifier = n;
                Show("Component Cost Modifier: " + n);
            }
            break;

            case "minblocks":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip minblocks <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Min Blocks: " + config.MinBlocks);
                    return;
                }

                int n;
                if (!int.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || n >= config.MaxBlocks)
                {
                    Show("Value must be greater than 0 and less than" + config.MaxBlocks);
                    return;
                }
                config.MinBlocks = n;
                Show("Min Blocks: " + n);
            }
            break;

            case "maxblocks":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip maxblocks <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Max Blocks: " + config.MaxBlocks);
                    return;
                }

                int n;
                if (!int.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || n <= config.MinBlocks)
                {
                    Show("Value must be greater than " + config.MinBlocks);
                    return;
                }
                config.MaxBlocks = n;
                Show("Max Blocks: " + n);
            }
            break;

            case "subgrids":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip subgrids <true|false>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Subgrids: " + config.Subgrids);
                    return;
                }

                bool b;
                if (!bool.TryParse(args[2], out b))
                {
                    Show("Unable to parse '" + args[2] + "' into true or false.");
                    return;
                }
                config.Subgrids = b;
                Show("Subgrids: " + b);
            }
            break;

            case "power":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip power <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Power Modifier: " + config.PowerModifier);
                    return;
                }

                float n;
                if (!float.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || float.IsInfinity(n) || float.IsNaN(n))
                {
                    Show("Value must be greater than 0.");
                    return;
                }
                config.PowerModifier = n;
                Show("Power Modifier: " + n);
            }
            break;

            case "extracomp":
            {
                if (args.Length > 4)
                {
                    Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Extra Component: " + config.GetExtraCompName());
                    return;
                }


                string typeId = args[2];
                string subtypeId;

                if (args.Length == 3)
                {
                    if (typeId.Equals("null", StringComparison.OrdinalIgnoreCase) || typeId.Equals("none", StringComparison.OrdinalIgnoreCase))
                    {
                        config.ExtraComponent = null;
                        Show("Extra Component: None");
                        return;
                    }

                    if (typeId.Contains("/"))
                    {
                        string[] typeArgs = typeId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        if (typeArgs.Length != 2)
                        {
                            Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]");
                            return;
                        }
                        typeId    = typeArgs[0];
                        subtypeId = typeArgs[1];
                    }
                    else
                    {
                        Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]");
                        return;
                    }
                }
                else
                {
                    subtypeId = args[3];
                }

                string obTypeId;
                if (!typeId.StartsWith("MyObjectBuilder_"))
                {
                    obTypeId = "MyObjectBuilder_" + typeId;
                }
                else
                {
                    obTypeId = typeId;
                    typeId   = typeId.Replace("MyObjectBuilder_", "");
                }

                MyDefinitionId id;
                if (!MyDefinitionId.TryParse(obTypeId, subtypeId, out id))
                {
                    Show($"Unable to parse {typeId}/{subtypeId} into an id.");
                    return;
                }

                MyPhysicalItemDefinition comp;
                if (!MyDefinitionManager.Static.TryGetPhysicalItemDefinition(id, out comp))
                {
                    Show($"Unable to find an item with id {typeId}/{subtypeId} in the game.");
                    return;
                }
                config.ExtraComponent = id;
                Show("Extra Component: " + config.GetExtraCompName());
            }
            break;

            case "extracompcost":
            {
                if (args.Length > 3)
                {
                    Show("Usage: /ip extracompcost <value>");
                    return;
                }

                if (args.Length == 2)
                {
                    Show("Extra Component Cost: " + config.ExtraCompCost);
                    return;
                }

                float n;
                if (!float.TryParse(args[2], out n))
                {
                    Show("Unable to parse '" + args[2] + "' into a number.");
                    return;
                }
                if (n < 0 || float.IsInfinity(n) || float.IsNaN(n))
                {
                    Show("Value must be greater than 0.");
                    return;
                }
                config.ExtraCompCost = n;
                Show("Extra Component Cost: " + n);
            }
            break;

            default:
                ShowHelp();
                break;
            }
        }
예제 #8
0
 public SettingsHud()
 {
     hud    = new HudAPIv2(OnHudReady);
     config = IPSession.Instance.MapSettings;
 }