public static void TrashGrids(List <long> gridsToTrash) { MyVisualScriptLogicProvider.SendChatMessage($"Trashing {gridsToTrash.Count} offending grids", "SERVER", 0, "Red"); foreach (long removeGridId in gridsToTrash) { MyCubeGrid grid = MyVisualScriptLogicProvider.GetEntityById(removeGridId) as MyCubeGrid; // Possible trash collector gets it first if (grid != null) { grid.MarkAsTrash(); } } }
public IEnumerator <bool> Run() { while (true) { // Get Position Position = Entity.GetPosition(); yield return(true); // Get Entities Targets.Clear(); List <long> entities = MyVisualScriptLogicProvider.GetEntitiesInSphere(Position, Config.Instance.Radius); foreach (long entityId in entities) { if (entityId == Entity.EntityId) { continue; } IMyEntity entity = MyVisualScriptLogicProvider.GetEntityById(entityId); if (entity is IMyBatteryBlock) { IMyBatteryBlock bat = entity as IMyBatteryBlock; if (bat.IsSameConstructAs(Battery)) { continue; } if (!bat.Enabled) { continue; } if (bat.ChargeMode == Sandbox.ModAPI.Ingame.ChargeMode.Discharge) { continue; } Target targ = new Target() { IBattery = bat, Distance = (float)Vector3D.Distance(entity.GetPosition(), Position) }; targ.Loss = targ.Distance * Config.Instance.LossPercentPerM; Targets.Add(targ); } } yield return(true); yield return(true); } }
public static BroadcastError ValidateBlockRequirements(BroadcastInfo broadcastInfo) { if (_ModConfig.MinBlockCount > 0 && broadcastInfo.BlockCount < _ModConfig.MinBlockCount) { return(BroadcastError.NotEnoughBlocks); } MyCubeGrid cubeGrid = MyVisualScriptLogicProvider.GetEntityById(broadcastInfo.EntityId) as MyCubeGrid; if (cubeGrid != null && cubeGrid.GetFatBlocks().Count < _ModConfig.MinFatBlockCount) { // Probably not an interesting grid return(BroadcastError.NotEnoughFatBlocks); } return(BroadcastError.Ok); }
public void UpgradeAction(IMyTerminalBlock block) { Dictionary <int, List <MyInventoryItem> > InventoryTransfer = new Dictionary <int, List <MyInventoryItem> >(); MyEntity entity = MyVisualScriptLogicProvider.GetEntityById(block.EntityId); var blockSelf = entity as VRage.Game.ModAPI.IMyCubeBlock; var selfPos = blockSelf.Position; var selfGrid = blockSelf.CubeGrid; var selfOb = blockSelf.GetObjectBuilderCubeBlock(true); var ob = new MyObjectBuilder_CubeBlock() { SubtypeName = Upgrades[block.BlockDefinition.SubtypeId], BuildPercent = selfOb.BuildPercent, IntegrityPercent = selfOb.IntegrityPercent, Min = selfOb.Min, BlockOrientation = selfOb.BlockOrientation, SkinSubtypeId = selfOb.SkinSubtypeId, ColorMaskHSV = selfOb.ColorMaskHSV, BuiltBy = selfOb.BuiltBy, ShareMode = selfOb.ShareMode, Owner = selfOb.Owner }; MyCubeBlockDefinition def = MyDefinitionManager.Static.GetDefinition <CBT>(Upgrades[block.BlockDefinition.SubtypeId]); if (block.InventoryCount > 0) { for (int i = 0; i < block.InventoryCount; i++) { List <MyInventoryItem> items = new List <MyInventoryItem>(); block.GetInventory(i).GetItems(items); InventoryTransfer.Add(i, items); while (block.GetInventory(i).ItemCount > 0) { block.GetInventory(i).RemoveItemsAt(0); } } } MyAPIGateway.Utilities.InvokeOnGameThread(() => { selfGrid.RazeBlock(selfPos); var newBlock = selfGrid.AddBlock(ob, false); VRage.Game.ModAPI.IMyCubeBlock fatNewBlock = newBlock.FatBlock; var terminal = fatNewBlock as IMyTerminalBlock; terminal.CustomName = block.CustomName; terminal.CustomData = block.CustomData; terminal.ShowInInventory = block.ShowInInventory; terminal.ShowInTerminal = block.ShowInTerminal; terminal.ShowInToolbarConfig = block.ShowInToolbarConfig; terminal.ShowOnHUD = block.ShowOnHUD; if (InventoryTransfer.Count > 0) { List <MyInventoryItem> items = new List <MyInventoryItem>(); for (int i = 0; i < terminal.InventoryCount; i++) { foreach (MyInventoryItem item in InventoryTransfer[i]) { terminal.GetInventory(i).AddItems(item.Amount, GetBuilder(item.Type.TypeId, item.Type.SubtypeId)); } } } TransferCustomSettings((BT)block, (BT)fatNewBlock); }); }