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); } }
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); }); }
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); }
public override bool HandleCommand(ulong userId, string[] words = null) { int index = 0; string outList = ""; if (PluginSettings.Instance.BlockEnforcementItems.Count == 0) { Communication.SendPrivateInformation(userId, "No block enforcement items defined."); return(true); } if (!words.Any()) { foreach (SettingsBlockEnforcementItem blockItem in PluginSettings.Instance.BlockEnforcementItems) { //Communication.SendPrivateInformation(userId, string.Format("item: {0} {1} {2} {3} {4}", blockItem.BlockSubtypeId, blockItem.BlockTypeId, blockItem.MaxPerGrid, blockItem.MaxReachWarning, blockItem.MaxExceedWarning, blockItem.Mode)); outList += PluginSettings.Instance.BlockEnforcementItems.IndexOf(blockItem).ToString() + ": "; if (!string.IsNullOrEmpty(blockItem.BlockTypeId)) { outList += "BlockType: " + blockItem.BlockTypeId + "|"; } else if (!string.IsNullOrEmpty(blockItem.BlockSubtypeId)) { outList += "BlockSubtype: " + blockItem.BlockSubtypeId + "|"; } else { outList += "No block type defined.|"; } if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.Off) { outList += "Item is disabled."; } else if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId) { outList += "Item sorts TypeID."; } else if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId) { outList += "Item sorts SubtypeID."; } } } else { if (words.Length > 1) { Communication.SendPrivateInformation(userId, "Too many arguments detected. Doing nothing to be safe."); return(true); } if (!int.TryParse(words[0], out index)) { Communication.SendPrivateInformation(userId, "Couldn't parse index; make sure it's a number"); return(true); } //if (int.TryParse(words[0], out index)) // Communication.SendPrivateInformation(userId, "requested index: " + index.ToString()); if (index > PluginSettings.Instance.BlockEnforcementItems.Count) { Communication.SendPrivateInformation(userId, string.Format("Invalid index number, there are {0} block enforcement items.", PluginSettings.Instance.BlockEnforcementItems.Count)); return(true); } SettingsBlockEnforcementItem blockItem = PluginSettings.Instance.BlockEnforcementItems[index]; if (!string.IsNullOrEmpty(blockItem.BlockTypeId)) { outList += "Block Type: " + blockItem.BlockTypeId; } else if (!string.IsNullOrEmpty(blockItem.BlockSubtypeId)) { outList += "Block Subtype: " + blockItem.BlockSubtypeId; } else { outList += "No block type defined"; } if (!string.IsNullOrEmpty(blockItem.MaxPerGrid.ToString())) { outList += "|Max per grid: " + blockItem.MaxPerGrid.ToString(); } else { outList += "|Max per grid not defined."; } if (!string.IsNullOrEmpty(blockItem.MaxReachWarning)) { outList += "|Reach Warning: " + blockItem.MaxReachWarning; } if (!string.IsNullOrEmpty(blockItem.MaxExceedWarning)) { outList += "|Exceed Warning: " + blockItem.MaxExceedWarning; } if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.Off) { outList += "|Item is disabled."; } else if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId) { outList += "|Item sorts TypeID."; } else if (blockItem.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId) { outList += "|Item sorts SubtypeID."; } } Communication.SendClientMessage(userId, string.Format("/dialog \"Block Enforcement\" \"Get Help\" \"\" \"{0}\" \"close\"", outList)); return(true); }