public static bool MyProjectileDoDamage(float damage, ref VRageMath.Vector3D hitPosition, ref IMyEntity damagedEntity) { var cubeGrid = damagedEntity as IMyCubeGrid; if (cubeGrid == null) { return(true); } try { damage *= DamageRate; List <IMySlimBlock> shieldblocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(shieldblocks, (block) => { if (block.FatBlock == null) { return(false); } return(block.FatBlock.BlockDefinition.SubtypeId == ShipShieldSubtypeId); }); bool isdef = false; foreach (var shielditem in shieldblocks) { if (shielditem.FatBlock.IsFunctional && shielditem.FatBlock.IsWorking) { // hitPosition = shielditem.FatBlock.WorldMatrix.Translation; SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity cube = null; SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity BatteryBlockEntity = null; BatteryBlockEntity = (SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity)SEModAPIInternal.API.Common.GameEntityManager.GetEntity(shielditem.FatBlock.EntityId); var BatteryBlock = (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(); if (BatteryBlockEntity == null) { cube = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity((Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeGrid)cubeGrid.GetObjectBuilder(), cubeGrid); BatteryBlockEntity = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity(cube, (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(), shielditem); } if (BatteryBlock.CurrentStoredPower > damage) { BatteryBlockEntity.CurrentStoredPower = BatteryBlock.CurrentStoredPower - damage; isdef = true; break; } else { if (BatteryBlock.CurrentStoredPower > 0) { BatteryBlockEntity.CurrentStoredPower = 0; isdef = true; break; } } } } if (isdef == true) { return(false); } } catch (Exception e) { // Logging.WriteLineAndConsole(e.ToString()); } //Logging.WriteLineAndConsole("DoDamage"); return(true); }
public static bool MyMissileUpdateBeforeSimulation(float damage, IMyEntity missile, float missileExplosionRadius, ref VRageMath.BoundingSphereD ed) { try { damage *= MissileDamageRate; var entitys = MyAPIGateway.Entities.GetEntitiesInSphere(ref ed); bool isdef = false; foreach (var entityitem in entitys) { var cubeGrid = entityitem as IMyCubeGrid; if (cubeGrid == null) { continue; } List <IMySlimBlock> shieldblocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(shieldblocks, (block) => { if (block.FatBlock == null) { return(false); } return(block.FatBlock.BlockDefinition.SubtypeId == ShipShieldSubtypeId); }); foreach (var shielditem in shieldblocks) { if (shielditem.FatBlock.IsFunctional && shielditem.FatBlock.IsWorking) { SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity cube = null; SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity BatteryBlockEntity = null; BatteryBlockEntity = (SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity)SEModAPIInternal.API.Common.GameEntityManager.GetEntity(shielditem.FatBlock.EntityId); var BatteryBlock = (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(); if (BatteryBlockEntity == null) { cube = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGridEntity((Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeGrid)cubeGrid.GetObjectBuilder(), cubeGrid); BatteryBlockEntity = new SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock.BatteryBlockEntity(cube, (Sandbox.Common.ObjectBuilders.MyObjectBuilder_BatteryBlock)shielditem.FatBlock.GetObjectBuilderCubeBlock(), shielditem); } if (BatteryBlock.CurrentStoredPower > damage) { BatteryBlockEntity.CurrentStoredPower = BatteryBlock.CurrentStoredPower - damage; isdef = true; break; } else { if (BatteryBlock.CurrentStoredPower > 0) { BatteryBlockEntity.CurrentStoredPower = 0; isdef = true; break; } } } } } if (isdef == true) { return(false); } } catch (Exception e) { } return(true); }