Skip to content

Commit

Permalink
EDShields patch (not tested, maybe need cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDorob committed Jan 17, 2024
1 parent 1ce7027 commit 8c3a115
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions Source/CombatExtended/Compatibility/EDShields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public IEnumerable<string> GetCompatList()
{
yield break;
}
public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vector3 from, Vector3 to)
public static IEnumerable<(Vector3 IntersectionPos, Action OnIntersection)> CheckForCollisionBetweenCallback(ProjectileCE projectile, Vector3 from, Vector3 to)
{
/* Check if an active shield can block this projectile
*/
if (projectile.def.projectile.flyOverhead)
{
return false;
yield break;
}
Thing launcher = projectile.launcher;
Map map = projectile.Map;
Expand Down Expand Up @@ -87,22 +87,8 @@ public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vec
continue;
}

Quaternion shieldProjAng = Quaternion.LookRotation(from - shieldPosition2D);
if ((Quaternion.Angle(targetAngle, shieldProjAng) > 90))
{
HitSoundDef.PlayOneShot((SoundInfo)new TargetInfo(shield.Position, map, false));

int damage = (projectile.def.projectile.GetDamageAmount(launcher));

generator.FieldIntegrity_Current -= damage;

exactPosition = nep;
FleckMakerCE.ThrowLightningGlow(exactPosition, map, 0.5f);
projectile.InterceptProjectile(shield, exactPosition, false);
return true;
}
yield return (nep, () => OnInterception(projectile, generator, nep));
}
return false;
}
public static bool ImpactSomethingCallback(ProjectileCE projectile, Thing launcher)
{
Expand Down Expand Up @@ -183,6 +169,17 @@ private static IEnumerable<IEnumerable<IntVec3>> ShieldZonesCallback(Thing pawnT
}
return result;
}
private static void OnInterception(ProjectileCE projectile, ThingComp comp, Vector3 exactPosition)
{
var generator = comp as Comp_ShieldGenerator;
HitSoundDef.PlayOneShot((SoundInfo)new TargetInfo(comp.parent.Position, comp.parent.Map, false));

int damage = (projectile.def.projectile.GetDamageAmount(projectile.launcher));

generator.FieldIntegrity_Current -= damage;
FleckMakerCE.ThrowLightningGlow(exactPosition, comp.parent.Map, 0.5f);
projectile.InterceptProjectile(comp.parent, exactPosition, false);
}

}
}

0 comments on commit 8c3a115

Please sign in to comment.