public virtual DamageResult Apply(DamageInfo dinfo, Thing victim) { DamageResult damageResult = new DamageResult(); if (victim.SpawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(victim, dinfo.Def.impactSoundType, victim.MapHeld); } if (victim.def.useHitPoints && dinfo.Def.harmsHealth) { float num = dinfo.Amount; if (victim.def.category == ThingCategory.Building) { num *= dinfo.Def.buildingDamageFactor; } if (victim.def.category == ThingCategory.Plant) { num *= dinfo.Def.plantDamageFactor; } damageResult.totalDamageDealt = (float)Mathf.Min(victim.HitPoints, GenMath.RoundRandom(num)); victim.HitPoints -= Mathf.RoundToInt(damageResult.totalDamageDealt); if (victim.HitPoints <= 0) { victim.HitPoints = 0; victim.Kill(dinfo); } } return(damageResult); }
public virtual DamageWorker.DamageResult Apply(DamageInfo dinfo, Thing victim) { DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult(); if (victim.SpawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(victim, dinfo.Def.impactSoundType, victim.MapHeld); } if (victim.def.useHitPoints && dinfo.Def.harmsHealth) { damageResult.totalDamageDealt = Mathf.Min((float)victim.HitPoints, dinfo.Amount); victim.HitPoints -= (int)damageResult.totalDamageDealt; if (victim.HitPoints <= 0) { victim.HitPoints = 0; victim.Kill(new DamageInfo?(dinfo), null); } } return(damageResult); }
public virtual DamageResult Apply(DamageInfo dinfo, Thing victim) { DamageResult result = DamageResult.MakeNew(); if (victim.SpawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(victim, dinfo.Def.impactSoundType, victim.MapHeld); } if (victim.def.useHitPoints && dinfo.Def.harmsHealth) { result.totalDamageDealt = (float)Mathf.Min(victim.HitPoints, dinfo.Amount); victim.HitPoints -= (int)result.totalDamageDealt; if (victim.HitPoints <= 0) { victim.HitPoints = 0; victim.Kill(dinfo, null); } } return(result); }
private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings) { RoofDef roofDef = map.roofGrid.RoofAt(c); if (roofDef == null) { return; } if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable) { for (int i = 0; i < 2; i++) { List <Thing> thingList = c.GetThingList(map); for (int j = thingList.Count - 1; j >= 0; j--) { Thing thing = thingList[j]; RoofCollapserImmediate.TryAddToCrushedThingsList(thing, outCrushedThings); Pawn pawn = thing as Pawn; DamageInfo dinfo; if (pawn != null) { DamageDef crush = DamageDefOf.Crush; float amount = 99999f; float armorPenetration = 999f; BodyPartRecord brain = pawn.health.hediffSet.GetBrain(); dinfo = new DamageInfo(crush, amount, armorPenetration, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse, null); } else { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null); dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null; if (i == 0 && pawn != null) { battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken); } thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken); if (!thing.Destroyed && thing.def.destroyable) { thing.Kill(new DamageInfo?(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null)), null); } } } } else { List <Thing> thingList2 = c.GetThingList(map); for (int k = thingList2.Count - 1; k >= 0; k--) { Thing thing2 = thingList2[k]; if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn) { RoofCollapserImmediate.TryAddToCrushedThingsList(thing2, outCrushedThings); float num = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange; if (thing2.def.building != null) { num *= thing2.def.building.roofCollapseDamageMultiplier; } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null; if (thing2 is Pawn) { battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling, null); Find.BattleLog.Add(battleLogEntry_DamageTaken2); } DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, (float)GenMath.RoundRandom(num), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null); dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2); } } } if (roofDef.collapseLeavingThingDef != null) { Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map, WipeMode.Vanish); if (thing3.def.rotatable) { thing3.Rotation = Rot4.Random; } } for (int l = 0; l < 1; l++) { Vector3 vector = c.ToVector3Shifted(); vector += Gen.RandomHorizontalVector(0.6f); MoteMaker.ThrowDustPuff(vector, map, 2f); } }
private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings) { RoofDef roofDef = map.roofGrid.RoofAt(c); if (roofDef == null) { return; } if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable) { for (int i = 0; i < 2; i++) { List <Thing> thingList = c.GetThingList(map); for (int num = thingList.Count - 1; num >= 0; num--) { Thing thing = thingList[num]; TryAddToCrushedThingsList(thing, outCrushedThings); Pawn pawn = thing as Pawn; DamageInfo dinfo; if (pawn != null) { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, pawn.health.hediffSet.GetBrain(), null, DamageInfo.SourceCategory.Collapse); } else { dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null; if (i == 0 && pawn != null) { battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling); Find.BattleLog.Add(battleLogEntry_DamageTaken); } thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken); if (!thing.Destroyed && thing.def.destroyable) { thing.Kill(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse)); } } } } else { List <Thing> thingList2 = c.GetThingList(map); for (int num2 = thingList2.Count - 1; num2 >= 0; num2--) { Thing thing2 = thingList2[num2]; if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn) { TryAddToCrushedThingsList(thing2, outCrushedThings); float num3 = ThinRoofCrushDamageRange.RandomInRange; if (thing2.def.building != null) { num3 *= thing2.def.building.roofCollapseDamageMultiplier; } BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null; if (thing2 is Pawn) { battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling); Find.BattleLog.Add(battleLogEntry_DamageTaken2); } DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse); dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside); thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2); } } } if (roofDef.collapseLeavingThingDef != null) { Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map); if (thing3.def.rotatable) { thing3.Rotation = Rot4.Random; } } for (int j = 0; j < 1; j++) { MoteMaker.ThrowDustPuff(c.ToVector3Shifted() + Gen.RandomHorizontalVector(0.6f), map, 2f); } }