Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix death sound #535

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.pearx.kasechange.toSnakeCase
import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.client.ui.chat.plural
import world.gregs.voidps.engine.data.definition.AnimationDefinitions
import world.gregs.voidps.engine.data.definition.SoundDefinitions
import world.gregs.voidps.engine.entity.Despawn
import world.gregs.voidps.engine.entity.Spawn
import world.gregs.voidps.engine.entity.World
Expand Down Expand Up @@ -40,6 +41,7 @@ val npcs: NPCs by inject()
val floorItems: FloorItems by inject()
val tables: DropTables by inject()
val animationDefinitions: AnimationDefinitions by inject()
val soundDefinitions: SoundDefinitions by inject()

npcDeath { npc ->
npc.mode = PauseMode
Expand All @@ -52,7 +54,7 @@ npcDeath { npc ->
npc["death_tile"] = tile
npc.setAnimation(deathAnimation(npc))
val name = npc.def.name.toSnakeCase()
(killer as? Player)?.playSound("${name}_death", delay = 40)
(killer as? Player)?.playSound(deathSound(npc))
pause(4)
dropLoot(npc, killer, name, tile)
npc.attackers.clear()
Expand Down Expand Up @@ -98,6 +100,22 @@ fun deathAnimation(npc: NPC): String {
return ""
}


fun deathSound(npc: NPC): String {
var sound: String
if (npc.race.isNotEmpty()) {
sound = "${npc.race}_death"
if (soundDefinitions.contains(sound)) {
return sound
}
}
sound = "${npc.id}_death"
if (soundDefinitions.contains(sound)) {
return sound
}
return ""
}

fun dropLoot(npc: NPC, killer: Character?, name: String, tile: Tile) {
var table = tables.get("${npc.def["drop_table", name]}_drop_table")
if (table == null) {
Expand Down
Loading