|
| 1 | +package net.swofty.type.skyblockgeneric.enchantment.debuff; |
| 2 | + |
| 3 | +import net.minestom.server.entity.EntityType; |
| 4 | +import net.minestom.server.entity.LivingEntity; |
| 5 | +import net.minestom.server.entity.damage.Damage; |
| 6 | +import net.minestom.server.entity.damage.DamageType; |
| 7 | +import net.swofty.type.skyblockgeneric.entity.mob.SkyBlockMob; |
| 8 | +import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; |
| 9 | +import net.swofty.type.skyblockgeneric.utility.DamageIndicator; |
| 10 | + |
| 11 | +import java.util.Map; |
| 12 | +import java.util.UUID; |
| 13 | +import java.util.concurrent.ConcurrentHashMap; |
| 14 | + |
| 15 | + |
| 16 | +public class ThunderboltTracker { |
| 17 | + |
| 18 | + public static final double[] THUNDERBOLT_DAMAGE_PERCENTAGES = new double[]{0.04, 0.08, 0.12, 0.16, 0.20, 0.25, 0.30}; |
| 19 | + public static final double[] THUNDERLORD_DAMAGE_PERCENTAGES = new double[]{0.08, 0.16, 0.24, 0.32, 0.40, 0.50, 0.60}; |
| 20 | + |
| 21 | + private static final int HITS_PER_LIGHTNING = 3; |
| 22 | + |
| 23 | + // Map<playerId, Map<mobId, hitCount>> - tracks hits per mob per player |
| 24 | + private static final Map<UUID, Map<UUID, Integer>> playerMobHitCounters = new ConcurrentHashMap<>(); |
| 25 | + |
| 26 | + public enum LightningType { |
| 27 | + THUNDERBOLT, |
| 28 | + THUNDERLORD |
| 29 | + } |
| 30 | + |
| 31 | + public static void registerHit(SkyBlockPlayer player, LivingEntity target, double damageDealt, int level, LightningType type) { |
| 32 | + if (level < 1 || level > 7) return; |
| 33 | + if (!(target instanceof SkyBlockMob)) return; |
| 34 | + |
| 35 | + UUID playerId = player.getUuid(); |
| 36 | + UUID mobId = target.getUuid(); |
| 37 | + |
| 38 | + // Get or create the player's mob hit counter map |
| 39 | + Map<UUID, Integer> mobCounters = playerMobHitCounters.computeIfAbsent(playerId, k -> new ConcurrentHashMap<>()); |
| 40 | + |
| 41 | + // Increment hit counter for this specific mob |
| 42 | + int currentHits = mobCounters.getOrDefault(mobId, 0); |
| 43 | + currentHits++; |
| 44 | + |
| 45 | + if (currentHits >= HITS_PER_LIGHTNING) { |
| 46 | + triggerLightningStrike(player, target, damageDealt, level, type); |
| 47 | + mobCounters.remove(mobId); // Reset counter for this mob |
| 48 | + } else { |
| 49 | + mobCounters.put(mobId, currentHits); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + private static void triggerLightningStrike(SkyBlockPlayer player, LivingEntity originalTarget, double baseDamage, int level, LightningType type) { |
| 54 | + if (!(originalTarget instanceof SkyBlockMob)) return; |
| 55 | + |
| 56 | + double[] damagePercentages = (type == LightningType.THUNDERBOLT) ? THUNDERBOLT_DAMAGE_PERCENTAGES : THUNDERLORD_DAMAGE_PERCENTAGES; |
| 57 | + double damagePercentage = damagePercentages[level - 1]; |
| 58 | + double lightningDamage = baseDamage * damagePercentage; |
| 59 | + |
| 60 | + if (lightningDamage <= 0) return; |
| 61 | + |
| 62 | + originalTarget.damage(new Damage(DamageType.PLAYER_ATTACK, player, player, player.getPosition(), (float) lightningDamage)); |
| 63 | + |
| 64 | + new DamageIndicator() |
| 65 | + .damage((float) lightningDamage) |
| 66 | + .pos(originalTarget.getPosition()) |
| 67 | + .critical(false) |
| 68 | + .display(originalTarget.getInstance()); |
| 69 | + |
| 70 | + LivingEntity lightningBolt = new LivingEntity(EntityType.LIGHTNING_BOLT); |
| 71 | + lightningBolt.setInstance(originalTarget.getInstance(), originalTarget.getPosition()); |
| 72 | + lightningBolt.scheduleRemove(java.time.Duration.ofSeconds(1)); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Cleans up hit counters for a specific mob (call when mob dies or is removed) |
| 77 | + */ |
| 78 | + public static void cleanupMobCounters(UUID mobId) { |
| 79 | + for (Map<UUID, Integer> mobCounters : playerMobHitCounters.values()) { |
| 80 | + mobCounters.remove(mobId); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | +} |
| 85 | + |
0 commit comments