private void damageOnlineShip() { List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>(); thisGrid.GetBlocks(gridBlocks, b => b.FatBlock is IMyFunctionalBlock && isValidForOnlineDamage(b.FatBlock as IMyFunctionalBlock)); foreach (IMySlimBlock slim in gridBlocks) { IMyFunctionalBlock block = slim.FatBlock as IMyFunctionalBlock; empBlock(slim, block, 0, true, Configuration.getEMPReaction(block), true, true); } }
private bool affectEnemyBlocks() { bool done = true; scanArea = scanRange.TransformSlow(thisBlock.WorldMatrix); List <IMyEntity> entityList = null; lock (MyAPIGateway.Entities) { // Scan for nearby entities (grids) entityList = MyAPIGateway.Entities.GetElementsInBox(ref scanArea); } if (entityList != null) { List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>(); foreach (IMyEntity entity in entityList) { try { if (entity is IMyCubeGrid) { IMyCubeGrid grid = entity as IMyCubeGrid; if (isEnemyGrid(grid)) { gridBlocks.Clear(); grid.GetBlocks(gridBlocks, b => b.FatBlock is IMyTerminalBlock && (b.FatBlock as IMyTerminalBlock).IsWorking && isEnemyBlock(b.FatBlock)); //MyAPIGateway.Utilities.ShowNotification("Found grid #"+i+" named "+grid.Name+" & "+grid.GetFriendlyName()+", ID="+grid.EntityId+"; size = "+grid.GridSizeEnum+", owners = "+grid.SmallOwners.ToString()+", grid elements = "+gridBlocks.ToString(), 5000, MyFontEnum.Red); foreach (IMySlimBlock slim in gridBlocks) { IMyTerminalBlock block = slim.FatBlock as IMyTerminalBlock; EMPReaction reaction = Configuration.getEMPReaction(block); if (reaction != null) { bool share = thisGrid == grid; if (rand.Next(100) >= (share ? reaction.ResistanceSameGrid : reaction.Resistance)) { bool inRange = reaction.InfRangeSharedGrid; double distance = reaction.InfRangeSharedGrid ? 0 : Vector3D.Distance(thisBlock.GetPosition(), block.GetPosition()); if (!inRange) { double d = reaction.MaxDistance; if (share) { //MyAPIGateway.Utilities.ShowNotification("boosting range (from "+d+" by "+reaction.SameGridBoost+"x) due to grid sharing ("+emp_grid.EntityId+"/"+emp_grid.GridSizeEnum+" & "+grid.EntityId+"/"+grid.GridSizeEnum+") for block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red); d *= reaction.SameGridBoost; } else { //MyAPIGateway.Utilities.ShowNotification("Not boosting range (from "+d+", using native "+distanceMultiplier+"x instead); no grid sharing ("+emp_grid.EntityId+"/"+emp_grid.GridSizeEnum+" & "+grid.EntityId+"/"+grid.GridSizeEnum+") for block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red); d *= distanceMultiplier; } inRange = distance < d; } if (inRange) { done &= empBlock(slim, block, distance, share, reaction, !(block is IMyFunctionalBlock), false); } else { //MyAPIGateway.Utilities.ShowNotification("Not EMPing block "+block.CustomName+" @ "+distance+"; out of range", 5000, MyFontEnum.Red); } } else if (reaction.Resistance < 100) { done = false; } } } } } } catch (Exception ex) { //MyAPIGateway.Utilities.ShowNotification("Could not run EMP cycle: "+ex.ToString(), 5000, MyFontEnum.Red); IO.log("Could not run EMP cycle: " + ex.ToString()); } } } return(done); }