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 npc sounds #534

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
@@ -1,18 +1,22 @@
package world.gregs.voidps.world.interact.entity.npc.combat

import world.gregs.voidps.engine.data.definition.AnimationDefinitions
import world.gregs.voidps.engine.data.definition.SoundDefinitions
import world.gregs.voidps.engine.data.definition.WeaponStyleDefinitions
import world.gregs.voidps.engine.entity.character.mode.Retreat
import world.gregs.voidps.engine.entity.character.npc.NPC
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.distanceTo
import world.gregs.voidps.engine.inject
import world.gregs.voidps.world.activity.skill.slayer.race
import world.gregs.voidps.world.interact.entity.combat.hit.hit
import world.gregs.voidps.world.interact.entity.combat.npcCombatSwing
import world.gregs.voidps.world.interact.entity.sound.playSound

val definitions: WeaponStyleDefinitions by inject()
val animationDefinitions: AnimationDefinitions by inject()
val soundDefinitions: SoundDefinitions by inject()

npcCombatSwing { npc ->
if (npc.tile.distanceTo(target) > npc.def["attack_radius", 8]) {
Expand All @@ -21,7 +25,7 @@ npcCombatSwing { npc ->
return@npcCombatSwing
}
npc.setAnimation(attackAnimation(npc))
// (target as? Player)?.playSound(attackSound(npc))
(target as? Player)?.playSound(attackSound(npc))
npc.hit(target)
}

Expand Down Expand Up @@ -60,8 +64,22 @@ fun attackAnimation(npc: NPC): String {
}

fun attackSound(npc: NPC): String {
var sound: String
if (npc.def.contains("attack_sound")) {
sound = npc.def["attack_sound"]
if (soundDefinitions.contains(sound)) {
return sound
}
}
if (npc.race.isNotEmpty()) {
return "${npc.race}_attack"
sound = "${npc.race}_attack"
if (soundDefinitions.contains(sound)) {
return sound
}
}
return npc.def.getOrNull("hit_sound") ?: ""
sound = "${npc.id}_attack"
if (soundDefinitions.contains(sound)) {
return sound
}
return ""
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package world.gregs.voidps.world.interact.entity.player.combat.melee

import world.gregs.voidps.engine.data.definition.AnimationDefinitions
import world.gregs.voidps.engine.data.definition.SoundDefinitions
import world.gregs.voidps.engine.data.definition.WeaponAnimationDefinitions
import world.gregs.voidps.engine.data.definition.WeaponStyleDefinitions
import world.gregs.voidps.engine.entity.character.Character
Expand All @@ -20,6 +21,7 @@ import world.gregs.voidps.world.interact.entity.sound.playSound
val styleDefinitions: WeaponStyleDefinitions by inject()
val weaponDefinitions: WeaponAnimationDefinitions by inject()
val animationDefinitions: AnimationDefinitions by inject()
val soundDefinitions: SoundDefinitions by inject()

characterCombatAttack { character ->
character.playSound(calculateHitSound(target), delay)
Expand Down Expand Up @@ -71,7 +73,24 @@ fun hitAnimation(npc: NPC): String {

fun calculateHitSound(target: Character): String {
if (target is NPC) {
return "${target.race}_hit"
var sound: String
if (target.def.contains("hit_sound")) {
sound = target.def["hit_sound"]
if (soundDefinitions.contains(sound)) {
return sound
}
}
sound = "${target.id}_hit"
if (soundDefinitions.contains(sound)) {
return sound
}
if (target.race.isNotEmpty()) {
sound = "${target.race}_hit"
if (soundDefinitions.contains(sound)) {
return sound
}
}
return ""
}

if (target is Player) {
Expand Down
Loading