Skip to content

Commit

Permalink
Merge pull request #4 from drfiveminusmint/dev
Browse files Browse the repository at this point in the history
Implement Per-Shot penalty
  • Loading branch information
drfiveminusmint authored Jun 28, 2024
2 parents 28d7670 + 666fa87 commit 09b5b74
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.movecraftoverheat.tracking.CraftHeat;
import net.countercraft.movecraft.util.ChatUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.libs.net.kyori.adventure.key.Key;
import net.countercraft.movecraft.libs.net.kyori.adventure.sound.Sound;
import net.countercraft.movecraft.movecraftoverheat.tracking.CraftHeat;
import net.countercraft.movecraft.util.ChatUtils;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.PlayerCraft;
import net.countercraft.movecraft.libs.net.kyori.adventure.key.Key;
import net.countercraft.movecraft.libs.net.kyori.adventure.sound.Sound;
import net.countercraft.movecraft.movecraftoverheat.tracking.CraftHeat;
import net.countercraft.movecraft.util.ChatUtils;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package net.countercraft.movecraft.movecraftoverheat.listener;

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.combat.features.tracking.events.CraftFireWeaponEvent;
import net.countercraft.movecraft.combat.features.tracking.types.Fireball;
import net.countercraft.movecraft.combat.features.tracking.types.TNTCannon;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.movecraftoverheat.Keys;
import net.countercraft.movecraft.movecraftoverheat.MovecraftOverheat;
import net.countercraft.movecraft.movecraftoverheat.config.Settings;
import net.countercraft.movecraft.movecraftoverheat.tracking.CraftHeat;
import net.countercraft.movecraft.util.MathUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;

public class WeaponFireListener implements Listener {

@EventHandler
public void onFire (CraftFireWeaponEvent event) {
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWeaponFire (CraftFireWeaponEvent event) {
Craft craft = event.getCraft();
CraftHeat craftHeat = MovecraftOverheat.getInstance().getHeatManager().getHeat(craft);
if (craftHeat == null) {
Expand All @@ -38,4 +45,26 @@ public void onFire (CraftFireWeaponEvent event) {
craftHeat.addHeat(Settings.HeatPerTNT*multiplier);
}
}

@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityExplode (EntityExplodeEvent event) {
// Don't run this check if there's no per shot heat cost
if (Settings.HeatPerGunShot <= 0) return;
// Only detect explosions in ballistic water or lava for the purposes of catching cannon shots
Location location = event.getLocation();
if (!(location.getBlock().isLiquid())) return;
Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), location);
// Check if the location is within the craft's hitbox

if (!craft.getHitBox().contains(new MovecraftLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ())))
return;
CraftHeat craftHeat = MovecraftOverheat.getInstance().getHeatManager().getHeat(craft);
if (craftHeat == null) {
return;
}
if (!craftHeat.hasFiredThisTick()) {
craftHeat.setFiredThisTick(true);
craftHeat.addHeat(Settings.HeatPerGunShot);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class CraftHeat {
private long lastUpdate;
private long lastDisaster;
private boolean silenced;

private boolean firedThisTick;
private final BossBar bossBar;

public CraftHeat (@NotNull Craft c) {
Expand Down Expand Up @@ -122,7 +124,7 @@ public long getLastDisaster() {
return lastDisaster;
}

public boolean getIsSilenced () {
public boolean isSilenced() {
return silenced;
}

Expand All @@ -142,4 +144,9 @@ private void updateBossBar () {
public void removeBossBar () {
bossBar.removeAll();
}

public boolean hasFiredThisTick () {return firedThisTick;}

public void setFiredThisTick (boolean b) {firedThisTick = b;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class HeatManager extends BukkitRunnable {
public void run() {
long time = System.currentTimeMillis();
for (CraftHeat heat : heatTracking.values()) {
if (heat.hasFiredThisTick()) heat.setFiredThisTick(false);
if (heat.getLastUpdate() + Settings.HeatCheckInterval >= time) {
continue;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ HeatPerGunShot: 30.0
HeatSinkBlocks:
gold_block: 10.0

#Similar to Heat Sink Blocks, but for heat dissapation instead
#Each block of these materials will contribute [multiplier] times as much to the craft's heat dissapation
#Similar to Heat Sink Blocks, but for heat dissipation instead
#Each block of these materials will contribute [multiplier] times as much to the craft's heat dissipation
RadiatorBlocks:
lapis_block: 10.0

Expand All @@ -39,5 +39,9 @@ Disasters:
RandomChance: 0.3
RandomChancePowerFactor: 0.001

# Prevent crafts above a certain heat threshold from firing weapons
SilenceOverheatedCrafts: true
SilenceHeatThreshold: 2.0

#Enable/disable debug mode (CURRENTLY UNIMPLEMENTED)
DebugMode: false

0 comments on commit 09b5b74

Please sign in to comment.