Skip to content

Commit 4c11fc2

Browse files
authored
Merge pull request #141 from BetrixDev/kit/ig
Iron golem stub and iron hook ability
2 parents 735495e + 9edd27a commit 4c11fc2

File tree

6 files changed

+159
-2
lines changed

6 files changed

+159
-2
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package dev.betrix.superSmashMobsBrawl.abilities
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.doKnockback
7+
import dev.betrix.superSmashMobsBrawl.extensions.playSound
8+
import dev.betrix.superSmashMobsBrawl.extensions.sendDebugMessage
9+
import dev.betrix.superSmashMobsBrawl.extensions.setVelocity
10+
import dev.betrix.superSmashMobsBrawl.projectiles.BrawlProjectile
11+
import dev.betrix.superSmashMobsBrawl.projectiles.ProjectileAction
12+
import gg.flyte.twilight.extension.round
13+
import org.bukkit.Material
14+
import org.bukkit.Particle
15+
import org.bukkit.Sound
16+
import org.bukkit.entity.Entity
17+
import org.bukkit.entity.LivingEntity
18+
import org.bukkit.entity.Player
19+
import org.bukkit.inventory.ItemStack
20+
21+
class IronHookAbility(player: Player) : BrawlAbility("iron_hook", player) {
22+
private val activeProjectiles = mutableListOf<BrawlProjectile>()
23+
24+
private val projectileDamage = metadata.double("projectileDamage") ?: 4.0
25+
private val projectileSize = (metadata.double("projectileSize") ?: 0.6).coerceAtLeast(0.1)
26+
27+
28+
override fun activate() {
29+
super.activate()
30+
throwProjectile()
31+
}
32+
33+
override fun teardown() {
34+
while (activeProjectiles.isNotEmpty()) {
35+
val projectile = activeProjectiles.removeAt(activeProjectiles.lastIndex)
36+
projectile.teardown()
37+
}
38+
super.teardown()
39+
}
40+
41+
private fun throwProjectile() {
42+
player.playSound(Sound.ENTITY_IRON_GOLEM_ATTACK, volume = 1.5f, pitch = 0.8f)
43+
44+
val ironHookProjectile =
45+
BrawlProjectile.potion(
46+
player,
47+
ItemStack.of(Material.TRIPWIRE_HOOK),
48+
"abilities.iron_hook.name",
49+
)
50+
.setInitialVelocity { projectile ->
51+
projectile.setVelocity(player.eyeLocation.direction, 1.8, false, 0.0, 0.2, 10.0, false)
52+
}
53+
.projectileSize(projectileSize)
54+
.trailEffect(Particle.CRIT)
55+
.trailSoundEffect(Sound.ITEM_FLINTANDSTEEL_USE, volume = 1.4f, pitch = 0.8f)
56+
.onHitEntity { entity, projectile ->
57+
handleIronHookHit(entity, projectile)
58+
ProjectileAction.DESTROY
59+
}
60+
.onTeardown { activeProjectiles.remove(it) }
61+
.launch()
62+
63+
activeProjectiles.add(ironHookProjectile)
64+
}
65+
66+
private fun handleIronHookHit(entity: Entity?, projectile: BrawlProjectile) {
67+
player.sendDebugMessage(
68+
"[SB] Iron hook hit at ${projectile.projectileEntity?.x?.round(1)}, ${
69+
projectile.projectileEntity?.y?.round(
70+
1
71+
)
72+
}, ${projectile.projectileEntity?.z?.round(1)} after ${projectile.projectileEntity?.ticksLived} ticks"
73+
)
74+
75+
if (entity != null && entity is LivingEntity) {
76+
player.sendDebugMessage("[SB] ${entity.name} was hit")
77+
78+
val damage = projectileDamage * projectile.velocityBeforeImpact.length()
79+
80+
val damageEvent =
81+
BrawlDamageEvent(
82+
entity,
83+
Damager.DamagerLivingEntity(player),
84+
damage,
85+
0.0,
86+
BrawlDamageType.Projectile,
87+
)
88+
89+
damageEvent.callEvent()
90+
91+
val pull = player.location.toVector().subtract(entity.location.toVector()).normalize()
92+
entity.setVelocity(pull, 2.0, false, 0.0, 0.8, 1.5, true)
93+
} else {
94+
player.sendDebugMessage("[SB] No entity was hit")
95+
}
96+
}
97+
}

plugin/src/main/kotlin/dev/betrix/superSmashMobsBrawl/kits/BrawlKit.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ open class BrawlKit(val id: String, val player: Player) : KoinComponent {
8080
"deaths_grasp" -> DeathsGraspAbility(player)
8181
"slime_rocket" -> SlimeRocketAbility(player)
8282
"slime_slam" -> SlimeSlamAbility(player)
83+
"iron_hook" -> IronHookAbility(player)
8384
else -> {
8485
logger.severe(
8586
"No ability found with id ${it.id} reference on kit ${kitData.id}"

plugin/src/main/kotlin/dev/betrix/superSmashMobsBrawl/projectiles/BrawlProjectile.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ abstract class BrawlProjectile(open val owner: Player, open val name: String) :
7272
protected var projectileSize = 0.5
7373
protected open var velocityMultiplier = 1.0
7474
protected var velocityAddend: Vector? = null
75+
protected var customSetInitialVelocity: ((projectile: Entity) -> Unit)? = null
7576

7677
// Callback collections
7778
private val entityHitCallbacks = mutableListOf<EntityHitCallback>()
@@ -173,11 +174,29 @@ abstract class BrawlProjectile(open val owner: Player, open val name: String) :
173174
addEffect(StandardTrailEffect(particle, count, offset ?: Vector(0.1, 0.1, 0.1)))
174175
}
175176

177+
fun trailSoundEffect(sound: Sound, volume: Float = 1.0f, pitch: Float = 1.0f): BrawlProjectile =
178+
apply {
179+
addEffect(object : ProjectileEffect {
180+
override fun onTick(projectile: BrawlProjectile) {
181+
val entity = projectile.projectileEntity ?: return
182+
entity.world.playSound(entity.location, sound, volume, pitch)
183+
}
184+
185+
override fun onHit(projectile: BrawlProjectile, hitType: HitType) {
186+
// No special hit behavior for trail sound effects
187+
}
188+
})
189+
}
190+
176191
fun impactEffect(particle: Particle, sound: Sound? = null, count: Int = 1): BrawlProjectile =
177192
apply {
178193
addEffect(StandardImpactEffect(particle, sound, count))
179194
}
180195

196+
fun setInitialVelocity(velocityFunction: ((projectile: Entity) -> Unit)): BrawlProjectile = apply {
197+
customSetInitialVelocity = velocityFunction
198+
}
199+
181200
fun launch(): BrawlProjectile {
182201
projectileEntity = createProjectileEntity()
183202
projectileEntity?.isCustomNameVisible = false
@@ -272,6 +291,11 @@ abstract class BrawlProjectile(open val owner: Player, open val name: String) :
272291
abstract fun createProjectileEntity(): Entity
273292

274293
open fun doVelocity() {
294+
if (customSetInitialVelocity != null && projectileEntity != null) {
295+
customSetInitialVelocity?.invoke(projectileEntity!!)
296+
return
297+
}
298+
275299
val baseVelocity = owner.eyeLocation.direction
276300
val finalVelocity =
277301
if (velocityAddend != null) {

plugin/src/main/resources/data/abilities.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,12 @@ abilities:
309309
itemSlot: 1
310310
usage: left_click
311311
hotbarItem: bow
312-
displayItem: bow
312+
displayItem: bow
313+
314+
- id: iron_hook
315+
cooldown: 8.0
316+
itemSlot: 1
317+
type: projectile
318+
usage: right_click
319+
hotbarItem: iron_pickaxe
320+
displayItem: tripwire_hook

plugin/src/main/resources/data/kits.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,25 @@ kits:
292292
helmet: chainmail_helmet
293293
chestplate: chainmail_chestplate
294294
leggings: null
295-
boots: chainmail_boots
295+
boots: chainmail_boots
296+
297+
# Iron Golem
298+
- id: iron_golem
299+
meleeDamage: 7.0
300+
armor: 8.0
301+
knockbackMultiplier: 1.0
302+
disguiseId: iron_golem
303+
passives:
304+
- id: double_jump
305+
- id: regeneration
306+
overrides:
307+
metadata:
308+
regenRate: 0.2
309+
- id: hunger
310+
abilities:
311+
- id: iron_hook
312+
armorItems:
313+
helmet: iron_helmet
314+
chestplate: iron_chestplate
315+
leggings: iron_leggings
316+
boots: diamond_boots

plugin/src/main/resources/data/lang/en.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ kits:
3636
slime:
3737
name: "Slime"
3838
description: "Glass cannon jumper with unmatched regen and explosive bursts"
39+
iron_golem:
40+
name: "Iron Golem"
41+
description: "Slow but tanky bruiser with devastating melee and knockback"
3942
abilities:
4043
sulphur_bomb:
4144
name: "Sulphur Bomb"
@@ -115,6 +118,9 @@ abilities:
115118
slime_slam:
116119
name: "Slime Slam"
117120
description: "Crash downward and rebound to safety"
121+
iron_hook:
122+
name: "Iron Hook"
123+
description: "Hook enemies and yank them toward you"
118124
maps:
119125
blue_forest:
120126
name: "Blue Forest"

0 commit comments

Comments
 (0)