actual burst fire logic

also adds burst fire to josh
This commit is contained in:
70000hp 2023-09-01 11:43:59 -04:00
parent 96c1986ae9
commit 16f710450c
3 changed files with 52 additions and 10 deletions

View File

@ -25,6 +25,8 @@ public class GunConfiguration implements Cloneable {
public int rateOfFire;
//amount of bullets fired per delay passed
public int roundsPerCycle;
/** Amount of rounds per burst, irrelevant if not a burst fire weapon**/
public int roundsPerBurst;
//0 = normal, 1 = release, 2 = both
public int gunMode;
//0 = manual, 1 = automatic
@ -46,7 +48,7 @@ public class GunConfiguration implements Cloneable {
//how long the reload animation will play
//MUST BE GREATER THAN ZERO ! ! !
public int reloadDuration;
//duration of every animation cycle
//duration of every animation cycle, used also for how quickly a burst fire rifle can fire
public int firingDuration;
//sound path to the reload sound
public String reloadSound = "";

View File

@ -157,7 +157,18 @@ public class Gun50BMGFactory {
return config;
}
public static GunConfiguration getAR15BurstConfig(){
GunConfiguration config = getAR15Config();
config.rateOfFire = 4;
config.roundsPerBurst = 3;
config.firingDuration = 2;
config.gunMode = GunConfiguration.MODE_NORMAL;
config.firingMode = GunConfiguration.FIRE_BURST;
return config;
}
public static GunConfiguration getM2Config() {
GunConfiguration config = getAR15Config();

View File

@ -55,7 +55,8 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
public boolean m1;// = false;
@SideOnly(Side.CLIENT)
public boolean m2;// = false;
public int burstDuration = 0;
public ItemGunBase(GunConfiguration config) {
mainConfig = config;
this.setMaxStackSize(1);
@ -131,13 +132,26 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
if(getIsMouseDown(stack) && !(player.getHeldItem() == stack)) {
setIsMouseDown(stack, false);
}
if(burstDuration > 0) {
if(altConfig == null) {
if (world.getWorldTime() % mainConfig.firingDuration == 0 && tryShoot(stack, world, player, true)) {
fire(stack, world, player);
}
} else {
boolean canFire = altConfig.firingDuration == 1 || world.getWorldTime() % altConfig.firingDuration == 0;
if (canFire && tryShoot(stack, world, player, false)) {
altFire(stack, world, player);
}
}
if(--burstDuration == 0) setDelay(stack, mainConfig.rateOfFire);
}
if(getIsAltDown(stack) && !isCurrentItem) {
setIsAltDown(stack, false);
}
if(GeneralConfig.enableGuns && mainConfig.firingMode == 1 && getIsMouseDown(stack) && tryShoot(stack, world, player, isCurrentItem)) {
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire);
}
@ -284,17 +298,32 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
//called on click (server side, called by mouse packet) for semi-automatics and specific events
public void startAction(ItemStack stack, World world, EntityPlayer player, boolean main) {
if(mainConfig.firingMode == mainConfig.FIRE_MANUAL && main && tryShoot(stack, world, player, main)) {
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire);
boolean validConfig = mainConfig.firingMode == GunConfiguration.FIRE_MANUAL || mainConfig.firingMode == GunConfiguration.FIRE_BURST;
if(validConfig && main && tryShoot(stack, world, player, main)) {
if(mainConfig.firingMode == GunConfiguration.FIRE_BURST){
if(burstDuration <= 0)
burstDuration = mainConfig.firingDuration * mainConfig.roundsPerBurst;
} else {
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire);
}
//setMag(stack, getMag(stack) - 1);
//useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges();
}
if(!main && altConfig != null && tryShoot(stack, world, player, main)) {
altFire(stack, world, player);
setDelay(stack, altConfig.rateOfFire);
if(altConfig.firingMode == GunConfiguration.FIRE_BURST && burstDuration <= 0){
burstDuration = altConfig.firingDuration * altConfig.roundsPerBurst;
} else {
altFire(stack, world, player);
setDelay(stack, altConfig.rateOfFire);
}
//useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges();
}