public static bool ApplyDamage(this IMyDestroyableObject obj, float damage, MyStringHash damageType, Vector3D position, long attackerId = 0) { return(obj.DoDamage(damage, damageType, NetworkHandlerSystem.IsServer, new MyHitInfo() { Position = position }, attackerId)); }
public MyJumpExplode(IMyDestroyableObject damageblock, float power, Vector3D center, long entityid) { m_damageblock = damageblock; m_power = power; m_center = center; m_entityid = entityid; m_explosion = new BoundingSphereD(center, Math.Pow(power, 1d / 3d)); m_damageblock.DoDamage(float.MaxValue / 2f, MyDamageType.Destruction, true); }
public static void DoDamageSynced(MyEntity entity, float damage, MyStringHash type, long attackerId) { Debug.Assert(Sync.IsServer); IMyDestroyableObject destroyable = entity as IMyDestroyableObject; if (destroyable == null) { return; } destroyable.DoDamage(damage, type, false, attackerId: attackerId); MyMultiplayer.RaiseStaticEvent(s => MySyncDamage.OnDoDamage, entity.EntityId, damage, type, attackerId); }
/// <summary> /// Applies overheating mechanics /// </summary> /// <param name="energy"></param> /// <param name="entity"></param> public void ApplyOverheating(float energy, IMyDestroyableObject entity, bool removeEnergy, MyStringHash?damageName = null) { var slim = entity as IMySlimBlock; var massToDestroy = energy / Material.EnthalpyOfFusion; var maxIntegrity = Math.Max(entity?.Integrity ?? 1, 1); if (slim != null) { maxIntegrity = slim.MaxIntegrity; } else { MyEntityStat healthStat = null; (entity as IMyEntity)?.Components.Get <MyEntityStatComponent>() ?.TryGetStat(MyCharacterStatComponent.HealthId, out healthStat); var floating = entity as MyFloatingObject; if (healthStat != null) { maxIntegrity = healthStat.MaxValue; } else if (floating != null) { maxIntegrity = MyDefinitionManager.Static.GetPhysicalItemDefinition(floating.Item.Content) .Health; } } var integrityPerKg = maxIntegrity / Mass; var damageToDo = Math.Min(integrityPerKg * massToDestroy, (entity?.Integrity + 0.1f) ?? 1.1f); if (removeEnergy) { var massToDestroyReal = damageToDo / integrityPerKg; AddEnergy(-massToDestroyReal * Material.EnthalpyOfFusion); } if (!MyAPIGateway.Session.IsServerDecider()) { return; } if ((slim?.CubeGrid != null && !slim.IsDestroyed && !slim.CubeGrid.Closed && slim.CubeGrid.GetCubeBlock(slim.Position) == slim) || !((entity as IMyEntity)?.Closed ?? true)) { entity?.DoDamage(damageToDo, damageName ?? _overheatingHash, true); } }
static void OnDoDamage(long destroyableId, float damage, MyStringHash type, long attackerId) { MyEntity ent; if (!MyEntities.TryGetEntityById(destroyableId, out ent)) { return; } IMyDestroyableObject destroyable = ent as IMyDestroyableObject; if (destroyable == null) { Debug.Fail("Damage can be done to destroyable only"); return; } destroyable.DoDamage(damage, type, false, null, attackerId); }
private void DoDamage(float damage, MyHitInfo hitInfo, object customdata, IMyEntity damagedEntity) { //damage tracking MyEntity ent = (MyEntity)MySession.Static.ControlledEntity; if (this.OwnerEntityAbsolute != null && this.OwnerEntityAbsolute.Equals(MySession.Static.ControlledEntity) && (damagedEntity is IMyDestroyableObject || damagedEntity is MyCubeGrid)) { MySession.Static.TotalDamageDealt += (uint)damage; } if (!Sync.IsServer) { return; } if (m_projectileAmmoDefinition.PhysicalMaterial == m_hashBolt) { IMyDestroyableObject destroyable = damagedEntity as IMyDestroyableObject; if (destroyable != null && damagedEntity is MyCharacter) { destroyable.DoDamage(damage, MyDamageType.Bolt, true, hitInfo, m_weapon != null ? GetSubpartOwner(m_weapon).EntityId : 0); } } else { var grid = damagedEntity as MyCubeGrid; IMyDestroyableObject destroyable; if (grid != null) { if (grid.Physics != null && grid.Physics.Enabled && (grid.BlocksDestructionEnabled || MyFakes.ENABLE_VR_FORCE_BLOCK_DESTRUCTIBLE)) { bool causeDeformation = false; var block = grid.GetTargetedBlock(hitInfo.Position); if (block != null && (grid.BlocksDestructionEnabled || block.ForceBlockDestructible)) { block.DoDamage(damage, MyDamageType.Bullet, true, hitInfo, m_weapon != null ? GetSubpartOwner(m_weapon).EntityId : 0); if (block.FatBlock == null) { causeDeformation = true; } } if (grid.BlocksDestructionEnabled && causeDeformation) { ApllyDeformationCubeGrid(hitInfo.Position, grid); } } } //By Gregory: When MyEntitySubpart (e.g. extended parts of pistons and doors) damage the whole parent component //Temporary fix! Maybe other solution? MyEntitySubpart cannot implement IMyDestroyableObject cause is on dependent namespace else if (damagedEntity is MyEntitySubpart) { if (damagedEntity.Parent != null && damagedEntity.Parent.Parent is MyCubeGrid) { hitInfo.Position = damagedEntity.Parent.WorldAABB.Center; DoDamage(damage, hitInfo, customdata, damagedEntity.Parent.Parent); } } else if ((destroyable = damagedEntity as IMyDestroyableObject) != null) { destroyable.DoDamage(damage, MyDamageType.Bullet, true, hitInfo, m_weapon != null ? GetSubpartOwner(m_weapon).EntityId : 0); } } //Handle damage ?? some WIP code by Ondrej //MyEntity damagedObject = entity; //damagedObject.DoDamage(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, m_ammoProperties.DamageType, m_ammoProperties.AmmoType, m_ignorePhysObject); //if (MyMultiplayerGameplay.IsRunning) // MyMultiplayerGameplay.Static.ProjectileHit(damagedObject, intersectionValue.IntersectionPointInWorldSpace, this.m_directionNormalized, MyAmmoConstants.FindAmmo(m_ammoProperties), this.OwnerEntity); }
public override void UpdateBeforeSimulation() { int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds [damageUpgrades]); IMyCubeBlock cube = Entity as IMyCubeBlock; long currentShootTime = ((MyObjectBuilder_InteriorTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime; if (currentHeat > 0f) { if ((ticks - lastShootTimeTicks) > beamWeaponInfo.heatDissipationDelay) { currentHeat -= beamWeaponInfo.heatDissipationPerTick; if (currentHeat <= 0f) { currentHeat = 0f; overheated = false; } } } //MyAPIGateway.Utilities.ShowNotification("TIME: " + currentShootTime + " :: " + lastShootTime, 17, MyFontEnum.Red); if (currentShootTime != lastShootTime) { // test hitBool = false; MyEntitySubpart subpart1 = cubeBlock.GetSubpart("InteriorTurretBase1"); MyEntitySubpart subpart2 = subpart1.GetSubpart("InteriorTurretBase2");; //MyAPIGateway.Utilities.ShowNotification("Dif: " + (currentShootTime - lastShootTime), 17, MyFontEnum.Blue); from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 1.25d; to = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 3000d; LineD testRay = new LineD(from, to); List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetAllEntitiesInRay(ref testRay, result); foreach (var resultItem in result) { IMyCubeGrid grid = resultItem.Element as IMyCubeGrid; IMyDestroyableObject destroyableEntity = resultItem.Element as IMyDestroyableObject; if (grid != null) { IMySlimBlock slimblock; double hitd; Vector3D?resultVec = grid.GetLineIntersectionExactAll(ref testRay, out hitd, out slimblock); if (resultVec != null) { hitBool = true; toTarget = from + subpart2.WorldMatrix.Forward * hitd; if (!MyAPIGateway.Session.CreativeMode) { slimblock.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } else { slimblock.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } //MyAPIGateway.Utilities.ShowNotification("" + s.BlockDefinition.Id.SubtypeId + " ::: " + resultItem.Distance, 17); } } if (destroyableEntity != null) { IMyEntity ent = (IMyEntity)destroyableEntity; double hitd = (from - ent.WorldMatrix.Translation).Length(); toTarget = from + subpart2.WorldMatrix.Forward * hitd; hitBool = true; if (!MyAPIGateway.Session.CreativeMode) { destroyableEntity.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } else { destroyableEntity.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId); } } } // test lastShootTime = currentShootTime; lastShootTimeTicks = ticks; currentHeat += beamWeaponInfo.heatPerTick; if (currentHeat > beamWeaponInfo.maxHeat) { currentHeat = beamWeaponInfo.maxHeat; overheated = true; } } if (ticks - lastShootTimeTicks < 3) { var beamcolor = Color.DodgerBlue; var beamcolor_aux = Color.LightSkyBlue; var maincolor = new Vector4(beamcolor.X / 30, beamcolor.Y / 30, beamcolor.Z / 30, 1f); var auxcolor = new Vector4(beamcolor_aux.X / 30, beamcolor_aux.Y / 30, beamcolor_aux.Z / 30, 1f); var material = MyStringId.GetOrCompute("WeaponLaser"); if (hitBool == false) { if (!MyAPIGateway.Utilities.IsDedicated) { if (!MyAPIGateway.Session.CreativeMode) { VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f); VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f); } else { VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f * 1.2f); VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f * 1.2f); } } } else { if (!MyAPIGateway.Utilities.IsDedicated) { if (!MyAPIGateway.Session.CreativeMode) { VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f); VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f); } else { VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f * 1.2f); VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f * 1.2f); } } } } if (chargesInInventory < beamWeaponInfo.keepAtCharge) { if (resourceSink.RequiredInputByType(electricityDefinition) != (beamWeaponInfo.powerUsage / efficiencyUpgrades)) { resourceSink.SetRequiredInputByType(electricityDefinition, (beamWeaponInfo.powerUsage / efficiencyUpgrades)); setPowerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades); powerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades); } else { if (!functionalBlock.Enabled) { powerConsumption = 0.0001f; } } if (resourceSink.CurrentInputByType(electricityDefinition) == (beamWeaponInfo.powerUsage / efficiencyUpgrades)) { if (!overheated) { m_inventory.AddItems((MyFixedPoint)(beamWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]); } } } else if (chargesInInventory > beamWeaponInfo.keepAtCharge) { m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - beamWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]); } else { if (setPowerConsumption != 0.0001f) { resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f); setPowerConsumption = 0.0001f; powerConsumption = 0.0001f; } } terminalBlock.RefreshCustomInfo(); ticks++; }
private void handler(object target, MyDamageInformation info) { if (target is IMySlimBlock) { var entity = target as IMySlimBlock; { if (entity.FatBlock is IMyOxygenTank) { if (info.Type == MyDamageType.Fire || info.Type == MyDamageType.Explosion || info.Type == MyDamageType.Bullet || info.Type == MyDamageType.Mine || info.Type == MyDamageType.Rocket || info.Type == MyDamageType.Bolt ) { var explode = ((entity.CurrentDamage + info.Amount)) > entity.MaxIntegrity * 0.1; //MyAPIGateway.Utilities.ShowNotification(string.Format("explode: {0}", explode)); var block = entity.FatBlock as IMyOxygenTank; if (block.MarkedForClose || block.Closed) { return; } var gas = block.GetOxygenLevel(); MyCubeBlockDefinition bdef; MyDefinitionManager.Static.TryGetCubeBlockDefinition((MyDefinitionId)block.BlockDefinition, out bdef); MyGasTankDefinition odef = bdef as MyGasTankDefinition; gas *= (odef.Capacity / (50 * odef.Size.Size * (odef.CubeSize == MyCubeSize.Small ? 0.5f : 2.5f))); if (block.IsFunctional && explode) { //MyAPIGateway.Utilities.ShowNotification("BOOM " + gas.ToString()); if (gas < 0.2f) { return; } var damageblock = (IMyDestroyableObject)entity; BoundingSphereD explosion = new BoundingSphereD(block.WorldAABB.Center, Math.Pow(gas, 1d / 3d)); //Log.DebugWrite(DebugLevel.Info, string.Format("Radius: {0}", explosion.Radius)); List <MyEntity> entities = MyEntities.GetEntitiesInSphere(ref explosion); //PLAY SOUND emitter = new MyEntity3DSoundEmitter(null); emitter.SetPosition(explosion.Center); emitter.SetVelocity(Vector3.Zero); MySoundPair m_bombExpl = new MySoundPair("ArcWepLrgWarheadExpl"); emitter.CustomMaxDistance = (float)Math.Pow(explosion.Radius, 2); emitter.CustomVolume = (float)explosion.Radius / 5; emitter.PlaySingleSound(m_bombExpl, true); try { foreach (var loopentity in entities) { //Log.DebugWrite(DebugLevel.Info, "loop"); //Log.DebugWrite(DebugLevel.Info, loopentity); IMyDestroyableObject destroyableObj = null; if (loopentity.EntityId == entity.FatBlock.EntityId) { continue; } float damage = gas; if (loopentity is IMyCharacter) { damage /= 10; } else { damage *= 50; } if (loopentity is MyCubeBlock) { continue; } if (loopentity is MyCubeGrid) { var grid = (IMyCubeGrid)loopentity; List <IMySlimBlock> blocks = grid.GetBlocksInsideSphere(ref explosion); try { foreach (var bck in blocks) { if (bck.FatBlock != null) { if (bck.FatBlock.EntityId == entity.FatBlock.EntityId) { continue; } } destroyableObj = bck as IMyDestroyableObject; var cdist = (float)Vector3D.Distance(explosion.Center, grid.GridIntegerToWorld(bck.Position)) - grid.GridSize; if (cdist < 1) { cdist = 1; } Vector3D dir = Vector3D.Normalize(grid.GridIntegerToWorld(bck.Position) - explosion.Center); if (isServer) { grid.Physics.ApplyImpulse(Vector3D.Multiply(dir, (damage / cdist) * 10), grid.GridIntegerToWorld(bck.Position)); } if (isServer) { destroyableObj.DoDamage(damage / cdist, MyDamageType.Explosion, true); } } continue; } catch { continue; } } if ((loopentity is IMyDestroyableObject)) { destroyableObj = loopentity as IMyDestroyableObject; } if (destroyableObj == null) { continue; } //Log.DebugWrite(DebugLevel.Info, " destroyable"); var dist = (float)Vector3D.Distance(loopentity.WorldMatrix.Translation, explosion.Center) - 1; if (dist < 1) { dist = 1; } ////Log.DebugWrite(DebugLevel.Info, damage); //Log.DebugWrite(DebugLevel.Info, dist); //Log.DebugWrite(DebugLevel.Info, damage / dist); if (isServer) { destroyableObj.DoDamage(damage / dist, MyDamageType.Explosion, true); } } if (isServer) { damageblock.DoDamage(1000000, MyDamageType.Deformation, true); } } catch { } } } } } } }