Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed May 8, 2024
1 parent 07bb685 commit f21a97f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand All @@ -15,6 +16,7 @@ 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 Down Expand Up @@ -62,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.id}_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,9 +1,9 @@
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.data.definition.SoundDefinitions
import world.gregs.voidps.engine.entity.character.Character
import world.gregs.voidps.engine.entity.character.npc.NPC
import world.gregs.voidps.engine.entity.character.player.Player
Expand Down Expand Up @@ -73,11 +73,24 @@ fun hitAnimation(npc: NPC): String {

fun calculateHitSound(target: Character): String {
if (target is NPC) {
var sound = "${target.id}_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
}
return "${target.race}_hit"
if (target.race.isNotEmpty()) {
sound = "${target.race}_hit"
if (soundDefinitions.contains(sound)) {
return sound
}
}
return ""
}

if (target is Player) {
Expand Down

0 comments on commit f21a97f

Please sign in to comment.