Repository navigation
Add ExplosionCollider component - #1195
earthwise01 wants to merge 3 commits into
Conversation
| public static void TriggerExplosionColliders(Entity entity) { | ||
| // collect the colliding components beforehand so no side effects from their `OnCollide` will affect which components are checked | ||
| ExplosionCollider[] collidingExplosionColliders = entity.Scene.Tracker | ||
| .GetComponents<ExplosionCollider>() | ||
| .Cast<ExplosionCollider>() | ||
| .Where(c => c.OnCollide != null && c.Check(entity)) | ||
| .ToArray(); | ||
|
|
||
| foreach (ExplosionCollider explosionCollider in collidingExplosionColliders) { | ||
| explosionCollider.OnCollide(entity, entity.Center); | ||
| } | ||
| } |
There was a problem hiding this comment.
would b nice to be able to specify the explosion center separately, e.g.
| public static void TriggerExplosionColliders(Entity entity) { | |
| // collect the colliding components beforehand so no side effects from their `OnCollide` will affect which components are checked | |
| ExplosionCollider[] collidingExplosionColliders = entity.Scene.Tracker | |
| .GetComponents<ExplosionCollider>() | |
| .Cast<ExplosionCollider>() | |
| .Where(c => c.OnCollide != null && c.Check(entity)) | |
| .ToArray(); | |
| foreach (ExplosionCollider explosionCollider in collidingExplosionColliders) { | |
| explosionCollider.OnCollide(entity, entity.Center); | |
| } | |
| } | |
| public static void TriggerExplosionColliders(Entity entity, Vector2? explosionCenter = null) { | |
| // collect the colliding components beforehand so no side effects from their `OnCollide` will affect which components are checked | |
| ExplosionCollider[] collidingExplosionColliders = entity.Scene.Tracker | |
| .GetComponents<ExplosionCollider>() | |
| .Cast<ExplosionCollider>() | |
| .Where(c => c.OnCollide != null && c.Check(entity)) | |
| .ToArray(); | |
| foreach (ExplosionCollider explosionCollider in collidingExplosionColliders) { | |
| explosionCollider.OnCollide(entity, explosionCenter ?? entity.Center); | |
| } | |
| } |
(would require changes to patches obviously)
There was a problem hiding this comment.
ohh true that would be very nicies
would it b too evil to make the vector2 arg not nullable and have a TriggerExplosionColliders(Entity entity) => TriggerExplosionColliders(entity, entity.Center); overload though .. depending on if i feel like doing more generics in ilpatches ..
There was a problem hiding this comment.
afaik you shouldnt even need to do any more generics stuff, just a ldnull should work to emit a null Vector2?, but like ya idm
(edit: don't do this. Vector2? is still a value type so emitting a null reference explod s 💥 )
There was a problem hiding this comment.
fun fact: try Ldnull and Unbox_Any<Nullable<Vector2>>
Adds an
ExplosionCollidercomponent to allow modded entities to more easily define custom interactions with the explosions created by puffers and seekers, without each mod having to hook the relevant explosion code.Vanilla entities affected by puffer/seeker explosions (excluding players and theo crystals) have also been made to use
ExplosionCollidercomponents instead of having their interactions hardcoded.This also allows modded entities which produce similar explosions to easily handle explosion interactions (including with other modded entities!) by calling the
ExplosionCollider.TriggerExplosionCollidersmethod.