Added self-destruct bullet property

This commit is contained in:
Anuken
2020-01-19 10:43:38 -05:00
parent 87b4c37d82
commit b1df52e0c8
5 changed files with 20 additions and 26 deletions

View File

@@ -1,10 +1,8 @@
package mindustry.content; package mindustry.content;
import arc.struct.*; import arc.struct.*;
import mindustry.ctype.ContentList; import mindustry.ctype.*;
import mindustry.entities.bullet.*; import mindustry.entities.bullet.*;
import mindustry.entities.type.*;
import mindustry.entities.type.Bullet;
import mindustry.entities.type.base.*; import mindustry.entities.type.base.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
@@ -103,23 +101,14 @@ public class UnitTypes implements ContentList{
reload = 12f; reload = 12f;
ejectEffect = Fx.none; ejectEffect = Fx.none;
shootSound = Sounds.explosion; shootSound = Sounds.explosion;
bullet = new BombBulletType(2f, 3f, "clear"){ bullet = new BombBulletType(2f, 3f, "clear"){{
{
hitEffect = Fx.pulverize; hitEffect = Fx.pulverize;
lifetime = 30f; lifetime = 2f;
speed = 1.1f; speed = 1.1f;
splashDamageRadius = 55f; splashDamageRadius = 55f;
splashDamage = 30f; splashDamage = 30f;
} killShooter = true;
}};
@Override
public void init(Bullet b){
if(b.getOwner() instanceof Unit){
((Unit)b.getOwner()).kill();
}
b.time(b.lifetime());
}
};
}}; }};
}}; }};

View File

@@ -39,6 +39,8 @@ public abstract class BulletType extends Content{
public float reloadMultiplier = 1f; public float reloadMultiplier = 1f;
/** Recoil from shooter entities. */ /** Recoil from shooter entities. */
public float recoil; public float recoil;
/** Whether to kill the shooter when this is shot. For suicide bombers. */
public boolean killShooter;
public float splashDamage = 0f; public float splashDamage = 0f;
/** Knockback in velocity. */ /** Knockback in velocity. */
@@ -146,6 +148,9 @@ public abstract class BulletType extends Content{
} }
public void init(Bullet b){ public void init(Bullet b){
if(killShooter && b.getOwner() instanceof HealthTrait){
((HealthTrait)b.getOwner()).kill();
}
} }
public void update(Bullet b){ public void update(Bullet b){

View File

@@ -14,6 +14,11 @@ public interface HealthTrait{
void setDead(boolean dead); void setDead(boolean dead);
default void kill(){
health(-1);
damage(1);
}
default void onHit(SolidTrait entity){ default void onHit(SolidTrait entity){
} }

View File

@@ -185,11 +185,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
y = Mathf.clamp(y, 0, world.height() * tilesize - tilesize); y = Mathf.clamp(y, 0, world.height() * tilesize - tilesize);
} }
public void kill(){
health = -1;
damage(1);
}
public boolean isImmune(StatusEffect effect){ public boolean isImmune(StatusEffect effect){
return false; return false;
} }

View File

@@ -11,7 +11,7 @@ import org.mozilla.javascript.*;
public class Scripts implements Disposable{ public class Scripts implements Disposable{
private final Array<String> blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk", private final Array<String> 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<String> whitelist = Array.with("mindustry.net"); private final Array<String> whitelist = Array.with("mindustry.net");
private final Context context; private final Context context;
private final String wrapper; private final String wrapper;