|
1 | 1 | package dev.betrix.superSmashMobsBrawl.abilities |
2 | 2 |
|
| 3 | +import dev.betrix.superSmashMobsBrawl.events.BrawlDamageEvent |
| 4 | +import dev.betrix.superSmashMobsBrawl.events.BrawlDamageType |
| 5 | +import dev.betrix.superSmashMobsBrawl.events.Damager |
| 6 | +import dev.betrix.superSmashMobsBrawl.extensions.event |
| 7 | +import dev.betrix.superSmashMobsBrawl.extensions.isOnBlock |
3 | 8 | import dev.betrix.superSmashMobsBrawl.extensions.sendDebugMessage |
| 9 | +import dev.betrix.superSmashMobsBrawl.extensions.setVelocity |
| 10 | +import gg.flyte.twilight.event.event |
| 11 | +import gg.flyte.twilight.extension.getNearbyEntities |
| 12 | +import gg.flyte.twilight.scheduler.TwilightRunnable |
| 13 | +import gg.flyte.twilight.scheduler.repeatingTask |
| 14 | +import kotlin.random.Random |
| 15 | +import org.bukkit.Effect |
| 16 | +import org.bukkit.Material |
| 17 | +import org.bukkit.Particle |
| 18 | +import org.bukkit.Sound |
| 19 | +import org.bukkit.block.BlockFace |
| 20 | +import org.bukkit.entity.LivingEntity |
4 | 21 | import org.bukkit.entity.Player |
| 22 | +import org.bukkit.util.Vector |
5 | 23 |
|
6 | 24 | class WaterSplashAbility(player: Player) : BrawlAbility("water_splash", player) { |
| 25 | + |
| 26 | + private val minimumAirTimeMs: Long = metadata.long("minimumAirTimeMs") ?: 750L |
| 27 | + private val secondBoostTimeMs: Long = metadata.long("secondBoostTimeMs") ?: 800L |
| 28 | + private val firstVelocity: Double = metadata.double("firstVelocity") ?: 1.0 |
| 29 | + private val secondVelocity: Double = metadata.double("secondVelocity") ?: 1.5 |
| 30 | + private val pullInRadius: Double = metadata.double("pullInRadius") ?: 5.0 |
| 31 | + private val damageRadius: Double = metadata.double("damageRadius") ?: 5.0 |
| 32 | + private val damage: Double = metadata.double("damage") ?: 12.0 |
| 33 | + private val pullYStrength: Double = metadata.double("pullYStrength") ?: 0.5 |
| 34 | + private val knockbackMultiplier: Double = metadata.double("knockbackMultiplier") ?: 1.0 |
| 35 | + private val blockEffectRadius: Int = (metadata.int("blockEffectRadius") ?: 5).coerceAtLeast(0) |
| 36 | + private val blockEffectChance: Double = metadata.double("blockEffectChance") ?: 0.1 |
| 37 | + |
| 38 | + private var splashTask: TwilightRunnable? = null |
| 39 | + private var boostUsed: Boolean = false |
| 40 | + |
7 | 41 | override fun activate() { |
8 | 42 | super.activate() |
9 | | - player.sendDebugMessage("Water Splash ability pending implementation") |
| 43 | + |
| 44 | + // Initial upward velocity |
| 45 | + player.setVelocity( |
| 46 | + velocity = Vector(0.0, 1.0, 0.0), |
| 47 | + strength = firstVelocity, |
| 48 | + ySet = true, |
| 49 | + yBase = firstVelocity, |
| 50 | + yAdd = 0.0, |
| 51 | + yMax = 10.0, |
| 52 | + groundBoost = false, |
| 53 | + ) |
| 54 | + |
| 55 | + // Pull nearby players towards owner |
| 56 | + pullNearbyPlayers() |
| 57 | + |
| 58 | + // Start the splash monitoring task |
| 59 | + boostUsed = false |
| 60 | + startSplashTask() |
| 61 | + } |
| 62 | + |
| 63 | + override fun teardown() { |
| 64 | + splashTask?.cancel() |
| 65 | + splashTask = null |
| 66 | + super.teardown() |
| 67 | + } |
| 68 | + |
| 69 | + private fun pullNearbyPlayers() { |
| 70 | + player.location |
| 71 | + .getNearbyEntities(pullInRadius, pullInRadius, pullInRadius) |
| 72 | + .filterIsInstance<LivingEntity>() |
| 73 | + .filter { it != player } |
| 74 | + .forEach { entity -> |
| 75 | + val trajectory = |
| 76 | + player.location |
| 77 | + .toVector() |
| 78 | + .subtract(entity.location.toVector()) |
| 79 | + .normalize() |
| 80 | + trajectory.y = pullYStrength |
| 81 | + |
| 82 | + entity.setVelocity( |
| 83 | + velocity = trajectory, |
| 84 | + strength = 1.0, |
| 85 | + ySet = false, |
| 86 | + yBase = 0.0, |
| 87 | + yAdd = 0.0, |
| 88 | + yMax = 10.0, |
| 89 | + groundBoost = false, |
| 90 | + ) |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + private fun startSplashTask() { |
| 95 | + splashTask?.cancel() |
| 96 | + |
| 97 | + val activationTime = elapsedSinceLastActivation |
| 98 | + |
| 99 | + splashTask = |
| 100 | + repeatingTask(0, 1) { |
| 101 | + if (!player.isValid || player.isDead) { |
| 102 | + cancel() |
| 103 | + splashTask = null |
| 104 | + return@repeatingTask |
| 105 | + } |
| 106 | + |
| 107 | + // Show water particles |
| 108 | + player.world.spawnParticle( |
| 109 | + Particle.DRIPPING_WATER, |
| 110 | + player.location, |
| 111 | + 10, |
| 112 | + 0.5, |
| 113 | + 0.5, |
| 114 | + 0.5, |
| 115 | + 0.01, |
| 116 | + ) |
| 117 | + |
| 118 | + val timeElapsed = System.currentTimeMillis() - (lastUsed - activationTime) |
| 119 | + |
| 120 | + // Check for landing |
| 121 | + if (player.isOnBlock() && timeElapsed >= minimumAirTimeMs) { |
| 122 | + performSplash() |
| 123 | + cancel() |
| 124 | + splashTask = null |
| 125 | + return@repeatingTask |
| 126 | + } |
| 127 | + |
| 128 | + // Check for second boost |
| 129 | + if (player.isBlocking && timeElapsed >= secondBoostTimeMs && !boostUsed) { |
| 130 | + boostUsed = true |
| 131 | + player.sendDebugMessage("[WaterSplash] Second boost activated") |
| 132 | + |
| 133 | + val direction = player.location.direction.multiply(secondVelocity) |
| 134 | + player.setVelocity( |
| 135 | + velocity = direction, |
| 136 | + strength = 1.0, |
| 137 | + ySet = false, |
| 138 | + yBase = 0.0, |
| 139 | + yAdd = 0.0, |
| 140 | + yMax = 10.0, |
| 141 | + groundBoost = false, |
| 142 | + ) |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + splashTask?.let { runnables.add(it) } |
| 147 | + } |
| 148 | + |
| 149 | + private fun performSplash() { |
| 150 | + val ownerLocation = player.location |
| 151 | + |
| 152 | + player.sendDebugMessage("[WaterSplash] Landing splash at ${ownerLocation.x}, ${ownerLocation.y}, ${ownerLocation.z}") |
| 153 | + |
| 154 | + // Firework particles |
| 155 | + player.world.spawnParticle( |
| 156 | + Particle.FIREWORK, |
| 157 | + player.eyeLocation, |
| 158 | + 50, |
| 159 | + 0.0, |
| 160 | + 0.0, |
| 161 | + 0.0, |
| 162 | + 0.5, |
| 163 | + ) |
| 164 | + |
| 165 | + // Block effects |
| 166 | + triggerBlockEffects() |
| 167 | + |
| 168 | + // Sound effect |
| 169 | + player.world.playSound(ownerLocation, Sound.ENTITY_GENERIC_SPLASH, 2f, 0f) |
| 170 | + |
| 171 | + // Damage nearby entities |
| 172 | + ownerLocation |
| 173 | + .getNearbyEntities(damageRadius, damageRadius, damageRadius) |
| 174 | + .filterIsInstance<LivingEntity>() |
| 175 | + .filter { it != player } |
| 176 | + .forEach { target -> |
| 177 | + val distance = target.location.distance(ownerLocation) |
| 178 | + val normalizedDistance = ((damageRadius - distance) / damageRadius).coerceAtLeast(0.0) |
| 179 | + val scaledDamage = damage * normalizedDistance |
| 180 | + |
| 181 | + player.sendDebugMessage("[WaterSplash] Damaging ${target.name} for $scaledDamage") |
| 182 | + |
| 183 | + BrawlDamageEvent( |
| 184 | + target, |
| 185 | + Damager.DamagerLivingEntity(player), |
| 186 | + scaledDamage, |
| 187 | + knockbackMultiplier, |
| 188 | + BrawlDamageType.Explosion, |
| 189 | + ) |
| 190 | + .callEvent() |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + private fun triggerBlockEffects() { |
| 195 | + if (blockEffectRadius <= 0 || blockEffectChance <= 0.0) { |
| 196 | + return |
| 197 | + } |
| 198 | + |
| 199 | + val origin = player.location.block |
| 200 | + val world = origin.world |
| 201 | + |
| 202 | + for (x in -blockEffectRadius..blockEffectRadius) { |
| 203 | + for (y in -blockEffectRadius..blockEffectRadius) { |
| 204 | + for (z in -blockEffectRadius..blockEffectRadius) { |
| 205 | + if (Random.nextDouble() >= blockEffectChance) { |
| 206 | + continue |
| 207 | + } |
| 208 | + |
| 209 | + val checkBlock = origin.getRelative(x, y, z) |
| 210 | + |
| 211 | + if (!checkBlock.type.isSolid || checkBlock.type == Material.AIR) { |
| 212 | + continue |
| 213 | + } |
| 214 | + |
| 215 | + val aboveBlock = checkBlock.getRelative(BlockFace.UP) |
| 216 | + |
| 217 | + if (aboveBlock.type.isSolid) { |
| 218 | + continue |
| 219 | + } |
| 220 | + |
| 221 | + world.playEffect(checkBlock.location, Effect.STEP_SOUND, checkBlock.type) |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + override fun setup() { |
| 228 | + super.setup() |
| 229 | + |
| 230 | + // Listen for damage events to cancel knockback while ability is active |
| 231 | + listeners.add( |
| 232 | + event<BrawlDamageEvent> { |
| 233 | + if (victim != this@WaterSplashAbility.player) { |
| 234 | + return@event |
| 235 | + } |
| 236 | + |
| 237 | + if (splashTask != null) { |
| 238 | + player.sendDebugMessage("[WaterSplash] Cancelling knockback during splash") |
| 239 | + knockbackMultiplier = 0.0 |
| 240 | + } |
| 241 | + } |
| 242 | + ) |
10 | 243 | } |
11 | 244 | } |
0 commit comments