Multi shotgun fix (#8460)

* Multi-barrel shotgun fix

* multi-recoil support

* @Nullable for everything
This commit is contained in:
MEEPofFaith
2023-04-03 13:38:10 -07:00
committed by GitHub
parent 2075a226e1
commit 6d71bcd2eb
13 changed files with 73 additions and 20 deletions

View File

@@ -112,6 +112,8 @@ public class Turret extends ReloadTurret{
public boolean linearWarmup = false;
/** Visual amount by which the turret recoils back per shot. */
public float recoil = 1f;
/** Number of additional counters for recoil. */
public int recoils = -1;
/** ticks taken for turret to return to starting position in ticks. uses reload time by default */
public float recoilTime = -1f;
/** power curve applied to visual recoil */
@@ -210,8 +212,9 @@ public class Turret extends ReloadTurret{
public Seq<AmmoEntry> ammo = new Seq<>();
public int totalAmmo;
public float curRecoil, heat, logicControlTime = -1;
public @Nullable float[] curRecoils;
public float shootWarmup, charge, warmupHold = 0f;
public int totalShots;
public int totalShots, barrelCounter;
public boolean logicShooting = false;
public @Nullable Posc target;
public Vec2 targetPos = new Vec2();
@@ -365,6 +368,12 @@ public class Turret extends ReloadTurret{
wasShooting = false;
curRecoil = Mathf.approachDelta(curRecoil, 0, 1 / recoilTime);
if(recoils > 0){
if(curRecoils == null) curRecoils = new float[recoils];
for(int i = 0; i < recoils; i++){
curRecoils[i] = Mathf.approachDelta(curRecoils[i], 0, 1 / recoilTime);
}
}
heat = Mathf.approachDelta(heat, 0, 1 / cooldownTime);
charge = charging() ? Mathf.approachDelta(charge, 1, 1 / shoot.firstShotDelay) : 0;
@@ -537,15 +546,14 @@ public class Turret extends ReloadTurret{
type.chargeEffect.at(bulletX, bulletY, rotation);
}
shoot.shoot(totalShots, (xOffset, yOffset, angle, delay, mover) -> {
queuedBullets ++;
shoot.shoot(barrelCounter, (xOffset, yOffset, angle, delay, mover) -> {
queuedBullets++;
if(delay > 0f){
Time.run(delay, () -> bullet(type, xOffset, yOffset, angle, mover));
}else{
bullet(type, xOffset, yOffset, angle, mover);
}
totalShots ++;
});
}, () -> barrelCounter++);
if(consumeAmmoOnce){
useAmmo();
@@ -583,7 +591,11 @@ public class Turret extends ReloadTurret{
}
curRecoil = 1f;
if(recoils > 0){
curRecoils[barrelCounter % recoils] = 1f;
}
heat = 1f;
totalShots++;
if(!consumeAmmoOnce){
useAmmo();

View File

@@ -75,6 +75,7 @@ public class DrawTurret extends DrawBlock{
var params = DrawPart.params.set(build.warmup(), 1f - progress, 1f - progress, tb.heat, tb.curRecoil, tb.charge, tb.x + tb.recoilOffset.x, tb.y + tb.recoilOffset.y, tb.rotation);
for(var part : parts){
params.setRecoil(part.recoilIndex >= 0 ? tb.curRecoils[part.recoilIndex] : tb.curRecoil);
part.draw(params);
}
}