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; public int rateOfFire;
//amount of bullets fired per delay passed //amount of bullets fired per delay passed
public int roundsPerCycle; public int roundsPerCycle;
/** Amount of rounds per burst, irrelevant if not a burst fire weapon**/
public int roundsPerBurst;
//0 = normal, 1 = release, 2 = both //0 = normal, 1 = release, 2 = both
public int gunMode; public int gunMode;
//0 = manual, 1 = automatic //0 = manual, 1 = automatic
@ -46,7 +48,7 @@ public class GunConfiguration implements Cloneable {
//how long the reload animation will play //how long the reload animation will play
//MUST BE GREATER THAN ZERO ! ! ! //MUST BE GREATER THAN ZERO ! ! !
public int reloadDuration; 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; public int firingDuration;
//sound path to the reload sound //sound path to the reload sound
public String reloadSound = ""; public String reloadSound = "";

View File

@ -158,6 +158,17 @@ public class Gun50BMGFactory {
return config; 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() { public static GunConfiguration getM2Config() {
GunConfiguration config = getAR15Config(); GunConfiguration config = getAR15Config();

View File

@ -56,6 +56,7 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public boolean m2;// = false; public boolean m2;// = false;
public int burstDuration = 0;
public ItemGunBase(GunConfiguration config) { public ItemGunBase(GunConfiguration config) {
mainConfig = config; mainConfig = config;
this.setMaxStackSize(1); this.setMaxStackSize(1);
@ -132,12 +133,25 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
setIsMouseDown(stack, false); 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) { if(getIsAltDown(stack) && !isCurrentItem) {
setIsAltDown(stack, false); setIsAltDown(stack, false);
} }
if(GeneralConfig.enableGuns && mainConfig.firingMode == 1 && getIsMouseDown(stack) && tryShoot(stack, world, player, isCurrentItem)) { if(GeneralConfig.enableGuns && mainConfig.firingMode == 1 && getIsMouseDown(stack) && tryShoot(stack, world, player, isCurrentItem)) {
fire(stack, world, player); fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire); 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 //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) { public void startAction(ItemStack stack, World world, EntityPlayer player, boolean main) {
if(mainConfig.firingMode == mainConfig.FIRE_MANUAL && main && tryShoot(stack, world, player, main)) { boolean validConfig = mainConfig.firingMode == GunConfiguration.FIRE_MANUAL || mainConfig.firingMode == GunConfiguration.FIRE_BURST;
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire); 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); //setMag(stack, getMag(stack) - 1);
//useUpAmmo(player, stack, main); //useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges(); //player.inventoryContainer.detectAndSendChanges();
} }
if(!main && altConfig != null && tryShoot(stack, world, player, main)) { 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); //useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges(); //player.inventoryContainer.detectAndSendChanges();
} }