Multi shotgun fix (#8460)
* Multi-barrel shotgun fix * multi-recoil support * @Nullable for everything
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootAlternate extends ShootPattern{
|
||||
/** number of barrels used for shooting. */
|
||||
public int barrels = 2;
|
||||
@@ -16,10 +18,11 @@ public class ShootAlternate extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
float index = ((totalShots + i + barrelOffset) % barrels) - (barrels-1)/2f;
|
||||
handler.shoot(index * spread, 0, 0f, firstShotDelay + shotDelay * i);
|
||||
if(barrelIncrementer != null) barrelIncrementer.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootBarrel extends ShootPattern{
|
||||
/** barrels [in x, y, rotation] format. */
|
||||
public float[] barrels = {0f, 0f, 0f};
|
||||
@@ -16,10 +18,11 @@ public class ShootBarrel extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
int index = ((i + totalShots + barrelOffset) % (barrels.length / 3)) * 3;
|
||||
handler.shoot(barrels[index], barrels[index + 1], barrels[index + 2], firstShotDelay + shotDelay * i);
|
||||
if(barrelIncrementer != null) barrelIncrementer.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootHelix extends ShootPattern{
|
||||
public float scl = 2f, mag = 1.5f, offset = Mathf.PI * 1.25f;
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
for(int sign : Mathf.signs){
|
||||
handler.shoot(0, 0, 0, firstShotDelay + shotDelay * i,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootMulti extends ShootPattern{
|
||||
public ShootPattern source;
|
||||
public ShootPattern[] dest = {};
|
||||
@@ -25,7 +27,7 @@ public class ShootMulti extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
source.shoot(totalShots, (x, y, rotation, delay, move) -> {
|
||||
for(var pattern : dest){
|
||||
pattern.shoot(totalShots, (x2, y2, rot2, delay2, mover) -> {
|
||||
@@ -35,6 +37,6 @@ public class ShootMulti extends ShootPattern{
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}, barrelIncrementer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.entities.*;
|
||||
|
||||
/** Handles different types of bullet patterns for shooting. */
|
||||
@@ -12,12 +13,17 @@ public class ShootPattern implements Cloneable{
|
||||
public float shotDelay = 0;
|
||||
|
||||
/** Called on a single "trigger pull". This function should call the handler with any bullets that result. */
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
handler.shoot(0, 0, 0, firstShotDelay + shotDelay * i);
|
||||
}
|
||||
}
|
||||
|
||||
/** Called on a single "trigger pull". This function should call the handler with any bullets that result. */
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
shoot(totalShots, handler, null);
|
||||
}
|
||||
|
||||
/** Subclasses should override this to flip its sides. */
|
||||
public void flip(){
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootSine extends ShootPattern{
|
||||
/** scaling applied to bullet index */
|
||||
@@ -17,7 +18,7 @@ public class ShootSine extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
float angleOffset = Mathf.sin(i + totalShots, scl, mag);
|
||||
handler.shoot(0, 0, angleOffset, firstShotDelay + shotDelay * i);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mindustry.entities.pattern;
|
||||
|
||||
import arc.util.*;
|
||||
|
||||
public class ShootSpread extends ShootPattern{
|
||||
/** spread between bullets, in degrees. */
|
||||
public float spread = 5f;
|
||||
@@ -13,7 +15,7 @@ public class ShootSpread extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
float angleOffset = i * spread - (shots - 1) * spread / 2f;
|
||||
handler.shoot(0, 0, angleOffset, firstShotDelay + shotDelay * i);
|
||||
|
||||
@@ -14,9 +14,7 @@ public class ShootSummon extends ShootPattern{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shoot(int totalShots, BulletHandler handler){
|
||||
|
||||
|
||||
public void shoot(int totalShots, BulletHandler handler, @Nullable Runnable barrelIncrementer){
|
||||
for(int i = 0; i < shots; i++){
|
||||
Tmp.v1.trns(Mathf.random(360f), Mathf.random(radius));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user