コード例 #1
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            int index = 0;

            SettingsBlockEnforcementItem blockItem = new SettingsBlockEnforcementItem();

            if (words.Length > 1)
            {
                Communication.SendPrivateInformation(userId, "Too many arguments detected. Doing nothing to be safe.");
                return true;
            }
            else if (words.Length == 0)
            {
                HandleSettingsGetBlockEnforcement getEnf = new HandleSettingsGetBlockEnforcement();
                getEnf.HandleCommand(userId, null);
            }

            if (!int.TryParse(words[0], out index))
            {
                Communication.SendPrivateInformation(userId, "Couldn't parse index; make sure it's a number.");
                return true;
            }
            else
            {
                MTObservableCollection<SettingsBlockEnforcementItem> _BlockEnforcementItems = PluginSettings.Instance.BlockEnforcementItems;
                _BlockEnforcementItems.RemoveAt(index);
                PluginSettings.Instance.BlockEnforcementItems = _BlockEnforcementItems;
                Communication.SendPrivateInformation(userId, "Removed enforcement item " + index.ToString() + ".");
                return true;
            }
        }
コード例 #2
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            int mode = 0;
            string outputName = "";

            string typeID = null;
            string maxPerGrid = null;
            string reachWarning = null;
            string exceedWarning = null;

            int gridMax = 0;

            SettingsBlockEnforcementItem blockItem = new SettingsBlockEnforcementItem();

            if (words.Length > 5)
            {
                Communication.SendPrivateInformation(userId, "Too many arguments detected. Doing nothing to be safe.");
                return true;
            }
            else if (words.Length < 3)
            {
                Communication.SendPrivateInformation(userId, "Too few arguments detected. Doing nothing to be safe.");
                return true;
            }

            typeID = words[1];
            maxPerGrid = words[2];

            if (words.Length > 3)
                reachWarning = words[3];
            if (words.Length > 4)
                exceedWarning = words[4];

            if (int.TryParse(words[0], out mode))
            {
                if (mode == 0)
                    blockItem.Mode = SettingsBlockEnforcementItem.EnforcementMode.Off;
                else if (mode == 1)
                    blockItem.Mode = SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId;
                else if (mode == 2)
                    blockItem.Mode = SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId;
                else
                {
                    Communication.SendPrivateInformation(userId, "Couldn't parse Mode; make sure it's 0, 1, or 2.");
                    return true;
                }
            }
            else
            {
                Communication.SendPrivateInformation(userId, "Couldn't parse Mode; make sure it's 0, 1, or 2.");
                return true;
            }

            if (mode == 1)
            {
                blockItem.BlockTypeId = typeID;
                outputName = blockItem.BlockTypeId;
            }
            else if (mode == 2)
            {
                blockItem.BlockSubtypeId = typeID;
                outputName = blockItem.BlockSubtypeId;
            }

            if (int.TryParse(maxPerGrid, out gridMax))
            {
                blockItem.MaxPerGrid = gridMax;
            }
            else
            {
                Communication.SendPrivateInformation(userId, "Couldn't parse maxPerGrid; make sure it's a number");
                return true;
            }

            if (reachWarning != null)
                blockItem.MaxReachWarning = reachWarning;

            if (exceedWarning != null)
                blockItem.MaxExceedWarning = exceedWarning;

            MTObservableCollection<SettingsBlockEnforcementItem> _BlockEnforcementItems = PluginSettings.Instance.BlockEnforcementItems;
            _BlockEnforcementItems.Add(blockItem);
            PluginSettings.Instance.BlockEnforcementItems = _BlockEnforcementItems;
            Communication.SendPrivateInformation(userId, "Set enforcement item for " + outputName + ".");
            return true;
        }
        private void DeleteReverse( SettingsBlockEnforcementItem blockEnforcementSetting, int remove, IMyCubeGrid grid )
        {
            int count = 0;
            IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid( grid );

            List<Sandbox.ModAPI.IMyTerminalBlock> blocksToRemove = new List<Sandbox.ModAPI.IMyTerminalBlock>( );
            for ( int r = gridTerminal.Blocks.Count - 1; r >= 0; r-- )
            {
                Sandbox.ModAPI.IMyTerminalBlock block = (Sandbox.ModAPI.IMyTerminalBlock)gridTerminal.Blocks[ r ];
                switch ( blockEnforcementSetting.Mode )
                {
                    case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
                        if ( !string.IsNullOrEmpty( block.BlockDefinition.SubtypeId ) && block.BlockDefinition.SubtypeId.Contains( blockEnforcementSetting.BlockSubtypeId ) )
                        {
                            blocksToRemove.Add( block );
                            count++;
                        }
                        break;
                    case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId:
                        if ( block.BlockDefinition.TypeIdString.Contains( blockEnforcementSetting.BlockTypeId ) )
                        {
                            blocksToRemove.Add( block );
                            count++;
                        }
                        break;
                }

                if ( count == remove )
                    break;
            }

            /*
            List<MyObjectBuilder_CubeBlock> blocksToRemove = new List<MyObjectBuilder_CubeBlock>();
            for (int r = gridBuilder.CubeBlocks.Count - 1; r >= 0; r--)
            {
                MyObjectBuilder_CubeBlock block = gridBuilder.CubeBlocks[r];
                if (block.GetId().ToString().Contains(id))
                {
                    blocksToRemove.Add(block);
                    count++;
                }

                if (count == remove)
                    break;
            }
            */

            if ( blocksToRemove.Count < 1 )
                return;

            List<Vector3I> razeList = new List<Vector3I>( );
            foreach ( Sandbox.ModAPI.IMyTerminalBlock block in blocksToRemove )
            {
                razeList.Add( block.Min );
            }

            Wrapper.GameAction( ( ) =>
            {
                grid.RazeBlocks( razeList );
            } );
        }