From 0122b735a04058b76eca561092bdc32d05edfdc0 Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Sat, 25 Mar 2023 11:06:14 -0700 Subject: [PATCH] Pierce damage decay (#8416) --- .../mindustry/entities/bullet/BulletType.java | 17 +++++++++++++++++ .../entities/bullet/RailBulletType.java | 15 ++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index caee6d3cc7..e749c99058 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -46,6 +46,8 @@ public class BulletType extends Content implements Cloneable{ public boolean pierceBuilding; /** Maximum # of pierced objects. */ public int pierceCap = -1; + /** Multiplier of damage decreased per health pierced. */ + public float pierceDamageFactor = 0f; /** If false, this bullet isn't removed after pierceCap is exceeded. Expert usage only. */ public boolean removeAfterPierce = true; /** For piercing lasers, setting this to true makes it get absorbed by plastanium walls. */ @@ -360,6 +362,8 @@ public class BulletType extends Content implements Cloneable{ }else if(build.team != b.team && direct){ hit(b); } + + handlePierce(b, initialHealth, x, y); } public void hitEntity(Bullet b, Hitboxc entity, float health){ @@ -385,6 +389,19 @@ public class BulletType extends Content implements Cloneable{ if(!wasDead && entity instanceof Unit unit && unit.dead){ Events.fire(new UnitBulletDestroyEvent(unit, b)); } + + handlePierce(b, health, entity.x(), entity.y()); + } + + public void handlePierce(Bullet b, float initialHealth, float x, float y){ + float sub = Math.max(initialHealth*pierceDamageFactor, 0); + //subtract health from each consecutive pierce + b.damage -= Math.min(b.damage, sub); + + if(removeAfterPierce && b.damage <= 0){ + b.hit = true; + b.remove(); + } } public float damageMultiplier(Bullet b){ diff --git a/core/src/mindustry/entities/bullet/RailBulletType.java b/core/src/mindustry/entities/bullet/RailBulletType.java index fcc667553c..9058d2cd90 100644 --- a/core/src/mindustry/entities/bullet/RailBulletType.java +++ b/core/src/mindustry/entities/bullet/RailBulletType.java @@ -13,8 +13,6 @@ public class RailBulletType extends BulletType{ public Effect pierceEffect = Fx.hitBulletSmall, pointEffect = Fx.none, lineEffect = Fx.none; public Effect endEffect = Fx.none; - /** Multiplier of damage decreased per health pierced. */ - public float pierceDamageFactor = 1f; public float length = 100f; @@ -37,8 +35,9 @@ public class RailBulletType extends BulletType{ return length; } - void handle(Bullet b, float initialHealth, float x, float y){ - float sub = Math.max(initialHealth*pierceDamageFactor, 0); + @Override + public void handlePierce(Bullet b, float initialHealth, float x, float y){ + float sub = Math.max(initialHealth * pierceDamageFactor, 0); if(b.damage <= 0){ b.fdata = Math.min(b.fdata, b.dst(x, y)); @@ -93,14 +92,8 @@ public class RailBulletType extends BulletType{ return bullet.team != tile.team; } - @Override - public void hitEntity(Bullet b, Hitboxc entity, float health){ - super.hitEntity(b, entity, health); - handle(b, health, entity.getX(), entity.getY()); - } - @Override public void hitTile(Bullet b, Building build, float x, float y, float initialHealth, boolean direct){ - handle(b, initialHealth, x, y); + handlePierce(b, initialHealth, x, y); } }