Properly handle missile units shooting more missile units (#8359)

* Properly handle missile units shooting more missile units

* Remove `shooter`, just pass down the owner
This commit is contained in:
MEEPofFaith
2023-05-09 20:34:13 -04:00
committed by GitHub
parent 2289f29bd5
commit 1373381554
2 changed files with 9 additions and 5 deletions
@@ -554,7 +554,7 @@ public class BulletType extends Content implements Cloneable{
public void init(Bullet b){
if(killShooter && b.owner() instanceof Healthc h){
if(killShooter && b.owner() instanceof Healthc h && !h.dead()){
h.kill();
}
@@ -700,7 +700,6 @@ public class BulletType extends Content implements Cloneable{
return create(owner, team, x, y, angle, -1, velocityScl, lifetimeScl, null);
}
public @Nullable Bullet create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Mover mover){
return create(owner, team, x, y, angle, -1, velocityScl, lifetimeScl, null, mover);
}
@@ -732,24 +731,27 @@ public class BulletType extends Content implements Cloneable{
Unit spawned = spawnUnit.create(team);
spawned.set(x, y);
spawned.rotation = angle;
//immediately spawn at top speed, since it was launched
if(spawnUnit.missileAccelTime <= 0f){
spawned.vel.trns(angle, spawnUnit.speed);
}
//assign unit owner
if(spawned.controller() instanceof MissileAI ai){
if(owner instanceof Unit unit){
ai.shooter = unit;
}
if(owner instanceof ControlBlock control){
ai.shooter = control.unit();
}
}
spawned.add();
}
//Since bullet init is never called, handle killing shooter here
if(killShooter && owner instanceof Healthc h && !h.dead()) h.kill();
//no bullet returned
return null;
}