From b1df52e0c83ae44f5bd70892fcda5ac2fa69e36c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 19 Jan 2020 10:43:38 -0500 Subject: [PATCH] Added self-destruct bullet property --- core/src/mindustry/content/UnitTypes.java | 29 ++++++------------- .../mindustry/entities/bullet/BulletType.java | 5 ++++ .../entities/traits/HealthTrait.java | 5 ++++ core/src/mindustry/entities/type/Unit.java | 5 ---- core/src/mindustry/mod/Scripts.java | 2 +- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 1c5202ab46..975cd87232 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -1,10 +1,8 @@ package mindustry.content; import arc.struct.*; -import mindustry.ctype.ContentList; +import mindustry.ctype.*; import mindustry.entities.bullet.*; -import mindustry.entities.type.*; -import mindustry.entities.type.Bullet; import mindustry.entities.type.base.*; import mindustry.gen.*; import mindustry.type.*; @@ -103,23 +101,14 @@ public class UnitTypes implements ContentList{ reload = 12f; ejectEffect = Fx.none; shootSound = Sounds.explosion; - bullet = new BombBulletType(2f, 3f, "clear"){ - { - hitEffect = Fx.pulverize; - lifetime = 30f; - speed = 1.1f; - splashDamageRadius = 55f; - splashDamage = 30f; - } - - @Override - public void init(Bullet b){ - if(b.getOwner() instanceof Unit){ - ((Unit)b.getOwner()).kill(); - } - b.time(b.lifetime()); - } - }; + bullet = new BombBulletType(2f, 3f, "clear"){{ + hitEffect = Fx.pulverize; + lifetime = 2f; + speed = 1.1f; + splashDamageRadius = 55f; + splashDamage = 30f; + killShooter = true; + }}; }}; }}; diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 6c5417d0ca..51e74cf383 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -39,6 +39,8 @@ public abstract class BulletType extends Content{ public float reloadMultiplier = 1f; /** Recoil from shooter entities. */ public float recoil; + /** Whether to kill the shooter when this is shot. For suicide bombers. */ + public boolean killShooter; public float splashDamage = 0f; /** Knockback in velocity. */ @@ -146,6 +148,9 @@ public abstract class BulletType extends Content{ } public void init(Bullet b){ + if(killShooter && b.getOwner() instanceof HealthTrait){ + ((HealthTrait)b.getOwner()).kill(); + } } public void update(Bullet b){ diff --git a/core/src/mindustry/entities/traits/HealthTrait.java b/core/src/mindustry/entities/traits/HealthTrait.java index fb241e0d1b..8eb4cff2bd 100644 --- a/core/src/mindustry/entities/traits/HealthTrait.java +++ b/core/src/mindustry/entities/traits/HealthTrait.java @@ -14,6 +14,11 @@ public interface HealthTrait{ void setDead(boolean dead); + default void kill(){ + health(-1); + damage(1); + } + default void onHit(SolidTrait entity){ } diff --git a/core/src/mindustry/entities/type/Unit.java b/core/src/mindustry/entities/type/Unit.java index 05dd89a4d6..8b8a5c3ac8 100644 --- a/core/src/mindustry/entities/type/Unit.java +++ b/core/src/mindustry/entities/type/Unit.java @@ -185,11 +185,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ y = Mathf.clamp(y, 0, world.height() * tilesize - tilesize); } - public void kill(){ - health = -1; - damage(1); - } - public boolean isImmune(StatusEffect effect){ return false; } diff --git a/core/src/mindustry/mod/Scripts.java b/core/src/mindustry/mod/Scripts.java index eb575bad80..1ba32b2e1e 100644 --- a/core/src/mindustry/mod/Scripts.java +++ b/core/src/mindustry/mod/Scripts.java @@ -11,7 +11,7 @@ import org.mozilla.javascript.*; public class Scripts implements Disposable{ private final Array blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk", - "runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system"); + "runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system", ".awt", "socket"); private final Array whitelist = Array.with("mindustry.net"); private final Context context; private final String wrapper;