From 9327239959bea6955da387c715c51fb655e1b221 Mon Sep 17 00:00:00 2001 From: Evyatar108 Date: Mon, 17 May 2021 05:26:17 +0300 Subject: [PATCH 1/2] Fixed ShatterSentinel magic spell --- Source/TMagic/TMagic/Verb_ShatterSentinel.cs | 49 +++++++++----------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/Source/TMagic/TMagic/Verb_ShatterSentinel.cs b/Source/TMagic/TMagic/Verb_ShatterSentinel.cs index 5a2ba6c2..6d7bab47 100644 --- a/Source/TMagic/TMagic/Verb_ShatterSentinel.cs +++ b/Source/TMagic/TMagic/Verb_ShatterSentinel.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using RimWorld; @@ -13,15 +12,15 @@ public class Verb_ShatterSentinel : Verb_UseAbility { protected override bool TryCastShot() { - Pawn caster = base.CasterPawn; Pawn pawn = this.currentTarget.Thing as Pawn; CompAbilityUserMagic comp = pawn.GetComp(); - if(comp.IsMagicUser) + if (comp.IsMagicUser) { - if(comp.summonedSentinels.Count > 0) + if (comp.summonedSentinels.Count > 0) { - for(int i =0; i < comp.summonedSentinels.Count; i++) + var toRemove = new HashSet(); + for (int i = 0; i < comp.summonedSentinels.Count; i++) { Thing sentinel = comp.summonedSentinels[i]; if (!sentinel.DestroyedOrNull()) @@ -33,15 +32,11 @@ protected override bool TryCastShot() sentinel.Destroy(DestroyMode.Vanish); } } - else - { - comp.summonedSentinels.Remove(comp.summonedSentinels[i]); - } + + toRemove.Add(sentinel); } - } - else - { + comp.summonedSentinels.RemoveAll(toRemove.Contains); } } return true; @@ -50,42 +45,42 @@ protected override bool TryCastShot() private void ShatterSentinel(Thing sentinel, Map map) { float radius = 4f; - Vector3 center = sentinel.DrawPos; + Vector3 center = sentinel.DrawPos; - List damageRing = GenRadial.RadialCellsAround(sentinel.Position, radius, true).ToList(); - List outsideRing = GenRadial.RadialCellsAround(sentinel.Position, radius, false).Except(GenRadial.RadialCellsAround(sentinel.Position, radius - 1, true)).ToList(); - for (int i = 0; i < damageRing.Count; i++) + IEnumerable damageRing = GenRadial.RadialCellsAround(sentinel.Position, radius, true); + IEnumerable outsideRing = GenRadial.RadialCellsAround(sentinel.Position, radius, false).Except(GenRadial.RadialCellsAround(sentinel.Position, radius - 1, true)); + foreach (var location in damageRing) { - List allThings = damageRing[i].GetThingList(map); + List allThings = location.GetThingList(map); for (int j = 0; j < allThings.Count; j++) { - if (allThings[j] is Pawn) + var thing = allThings[j]; + if (thing is Pawn) { - Pawn p = allThings[j] as Pawn; + Pawn p = thing as Pawn; TM_Action.DamageEntities(p, p.health.hediffSet.GetRandomNotMissingPart(DamageDefOf.Blunt, BodyPartHeight.Undefined, BodyPartDepth.Outside, null), Rand.Range(14, 22), DamageDefOf.Blunt, this.CasterPawn); } - else if (allThings[j] is Building) + else if (thing is Building) { - TM_Action.DamageEntities(allThings[j], null, Rand.Range(56, 88), DamageDefOf.Blunt, this.CasterPawn); + TM_Action.DamageEntities(thing, null, Rand.Range(56, 88), DamageDefOf.Blunt, this.CasterPawn); } else { if (Rand.Chance(.1f)) { - GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], map, ThingPlaceMode.Near); + GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), location, map, ThingPlaceMode.Near); } } } } - for (int i = 0; i < outsideRing.Count; i++) + foreach (var outerLoc in outsideRing) { - IntVec3 intVec = outsideRing[i]; - if (intVec.IsValid && intVec.InBounds(map)) + if (outerLoc.IsValid && outerLoc.InBounds(map)) { - Vector3 moteDirection = TM_Calc.GetVector(sentinel.DrawPos.ToIntVec3(), intVec); + Vector3 moteDirection = TM_Calc.GetVector(sentinel.DrawPos.ToIntVec3(), outerLoc); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), sentinel.DrawPos, map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, sentinel.DrawPos, map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); - GenExplosion.DoExplosion(intVec, map, .4f, DamageDefOf.Blunt, this.CasterPawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .4f, 1, false, null, 0f, 1, 0, false); + GenExplosion.DoExplosion(outerLoc, map, .4f, DamageDefOf.Blunt, this.CasterPawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .4f, 1, false, null, 0f, 1, 0, false); //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f)); } } From bcc8d358228ff724319244ff058c54946c7d00bf Mon Sep 17 00:00:00 2001 From: Evyatar108 Date: Mon, 17 May 2021 05:28:06 +0300 Subject: [PATCH 2/2] Update Verb_ShatterSentinel.cs --- Source/TMagic/TMagic/Verb_ShatterSentinel.cs | 31 ++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/TMagic/TMagic/Verb_ShatterSentinel.cs b/Source/TMagic/TMagic/Verb_ShatterSentinel.cs index 6d7bab47..ae53a628 100644 --- a/Source/TMagic/TMagic/Verb_ShatterSentinel.cs +++ b/Source/TMagic/TMagic/Verb_ShatterSentinel.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using RimWorld; @@ -45,42 +46,42 @@ protected override bool TryCastShot() private void ShatterSentinel(Thing sentinel, Map map) { float radius = 4f; - Vector3 center = sentinel.DrawPos; + Vector3 center = sentinel.DrawPos; - IEnumerable damageRing = GenRadial.RadialCellsAround(sentinel.Position, radius, true); - IEnumerable outsideRing = GenRadial.RadialCellsAround(sentinel.Position, radius, false).Except(GenRadial.RadialCellsAround(sentinel.Position, radius - 1, true)); - foreach (var location in damageRing) + List damageRing = GenRadial.RadialCellsAround(sentinel.Position, radius, true).ToList(); + List outsideRing = GenRadial.RadialCellsAround(sentinel.Position, radius, false).Except(GenRadial.RadialCellsAround(sentinel.Position, radius - 1, true)).ToList(); + for (int i = 0; i < damageRing.Count; i++) { - List allThings = location.GetThingList(map); + List allThings = damageRing[i].GetThingList(map); for (int j = 0; j < allThings.Count; j++) { - var thing = allThings[j]; - if (thing is Pawn) + if (allThings[j] is Pawn) { - Pawn p = thing as Pawn; + Pawn p = allThings[j] as Pawn; TM_Action.DamageEntities(p, p.health.hediffSet.GetRandomNotMissingPart(DamageDefOf.Blunt, BodyPartHeight.Undefined, BodyPartDepth.Outside, null), Rand.Range(14, 22), DamageDefOf.Blunt, this.CasterPawn); } - else if (thing is Building) + else if (allThings[j] is Building) { - TM_Action.DamageEntities(thing, null, Rand.Range(56, 88), DamageDefOf.Blunt, this.CasterPawn); + TM_Action.DamageEntities(allThings[j], null, Rand.Range(56, 88), DamageDefOf.Blunt, this.CasterPawn); } else { if (Rand.Chance(.1f)) { - GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), location, map, ThingPlaceMode.Near); + GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], map, ThingPlaceMode.Near); } } } } - foreach (var outerLoc in outsideRing) + for (int i = 0; i < outsideRing.Count; i++) { - if (outerLoc.IsValid && outerLoc.InBounds(map)) + IntVec3 intVec = outsideRing[i]; + if (intVec.IsValid && intVec.InBounds(map)) { - Vector3 moteDirection = TM_Calc.GetVector(sentinel.DrawPos.ToIntVec3(), outerLoc); + Vector3 moteDirection = TM_Calc.GetVector(sentinel.DrawPos.ToIntVec3(), intVec); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), sentinel.DrawPos, map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, sentinel.DrawPos, map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); - GenExplosion.DoExplosion(outerLoc, map, .4f, DamageDefOf.Blunt, this.CasterPawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .4f, 1, false, null, 0f, 1, 0, false); + GenExplosion.DoExplosion(intVec, map, .4f, DamageDefOf.Blunt, this.CasterPawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .4f, 1, false, null, 0f, 1, 0, false); //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f)); } }