Audio Refactor

1st of many audio refactors, the end goal is removing AudioManager.java and using contentAPI functions for all sound
Refactored playAudio
Refactored playGlobalAudio
Fixed lunar teleport sounds to not play if teleblocked
Refactored the following sounds:
All the special attack and DFS sounds defaulting to new API radius of 8 instead of 5
Dropping coins, item, and destroying object sounds fixed
Ectophial refill sound
Agility pyramid sounds
Emptying a fishbowl
Enchanted jewellery teleport sound
Enchanted jewellery enchant tab sound
All the sounds for Elemental Workshop 1 listeners
The sound when getting experience from a lamp
Blessing and repairing a grave
Hunter pitfall sounds
Hunter sound when catching a kebbit with a noose
Lunar cure me and cure group spell sound
High and low alchemy spells
Silver crafting at a furnace
Spinning at a spinning wheel
Drinking from a waterskin in the desert
Sound when being blessed by drezel in nature's spirit quest
Sound when poison immunity has 30 seconds left and when your immunity expires
Shearing regular sheep and the penguin sheep at lumbridge
Sound when regular spell book charge spell expires
GE sounds: making 0 coin offer when buying, not having enough money, placing a buy offer, not enough room in inventory
Sound when filling vessels from a water source
Regular and ancient combat spells
This commit is contained in:
Zerken
2023-08-20 07:21:24 +00:00
committed by Ryan
parent 7a585796be
commit a105821427
69 changed files with 180 additions and 231 deletions
+9 -35
View File
@@ -60,7 +60,6 @@ import core.game.system.config.ItemConfigParser
import core.game.system.config.ServerConfigParser
import core.game.world.GameWorld
import core.game.world.GameWorld.Pulser
import core.game.world.map.path.ProjectilePathfinder
import core.game.world.repository.Repository
import core.game.consumable.*
import core.ServerConstants
@@ -555,13 +554,6 @@ fun getWorldTicks(): Int {
return GameWorld.ticks
}
/**
* Gets an Audio object with specified id, volume, etc
*/
fun getAudio(id: Int, volume: Int = 10, delay: Int = 1): Audio {
return Audio(id, volume, delay)
}
/**
* Plays a jingle by id
* @param player the player to play the jingle for
@@ -815,51 +807,33 @@ fun <T> animate(entity: Entity, anim: T, forced: Boolean = false) {
}
}
/**
* Plays the given Audio for the given Entity
* @param player the player to play the audio for
* @param audio the Audio to play
* @param global if other nearby entities should be able to hear it
*/
fun playAudio(player: Player, audio: Audio, global: Boolean = false) {
player.audioManager.send(audio, global)
}
/**
* Plays audio for the player
* @param player the player to play the defined audio for
* @param audio the audio id to play
* @param volume the volume for the audio (for some audio ids it is used to define how many times to play/loop the audio)
* @param delay the delay in client cycles (50 cycles = 1 second)
* @param global if other nearby players should be able to hear the audio
* @param location the location where the audio will play from (if a location is defined the sound will fade with distance)
* @param loops the number of times to loop audio (for some audio ids it is used to define how many times to loop the audio)
* @param location the location where the audio will play from (The sound will fade with distance)
* @param radius the distance the audio can be heard from the defined location (default = 8 tiles if undefined)
*/
@JvmOverloads
fun playAudio(player: Player, audio: Int, volume: Int = 10, delay: Int = 0, global: Boolean = false, location: Location? = null, radius: Int = 8) {
if (global) {
val nearbyPlayers = RegionManager.getLocalPlayers(location ?: player.location, radius)
for ( player in nearbyPlayers ) {
PacketRepository.send(AudioPacket::class.java, DefaultContext(player, Audio(audio, volume, delay, radius), location))
}
} else {
PacketRepository.send(AudioPacket::class.java, DefaultContext(player, Audio(audio, volume, delay, radius), location))
}
fun playAudio(player: Player, audio: Int, delay: Int = 0, loops: Int = 1, location: Location? = null, radius: Int = 8) {
PacketRepository.send(AudioPacket::class.java, DefaultContext(player, Audio(audio, loops, delay, radius), location))
}
/**
* Plays audio for players near a defined location
* @param location the location where the audio will play from (The sound will fade with distance)
* @param audio the audio id to play
* @param volume the volume for the audio (for some audio ids it is used to define how many times to play/loop the audio)
* @param delay the delay in client cycles (50 cycles = 1 second)
* @param loops the number of times to loop audio (for some audio ids it is used to define how many times to loop the audio)
* @param radius the distance the audio can be heard from the defined location (default = 8 tiles if undefined)
*/
@JvmOverloads
fun playGlobalAudio(location: Location, audio: Int, volume: Int = 10, delay: Int = 0, radius: Int = 8) {
fun playGlobalAudio(location: Location, audio: Int, delay: Int = 0, loops: Int = 1, radius: Int = 8) {
val nearbyPlayers = RegionManager.getLocalPlayers(location, radius)
for (player in nearbyPlayers) {
PacketRepository.send(AudioPacket::class.java, DefaultContext(player, Audio(audio, volume, delay, radius), location))
PacketRepository.send(AudioPacket::class.java, DefaultContext(player, Audio(audio, loops, delay, radius), location))
}
}
@@ -872,9 +846,9 @@ fun playHurtAudio(player: Player, delay: Int = 0) {
val maleHurtAudio = intArrayOf(Sounds.HUMAN_HIT4_516, Sounds.HUMAN_HIT5_517, Sounds.HUMAN_HIT_518, Sounds.HUMAN_HIT_6_522)
val femaleHurtAudio = intArrayOf(Sounds.FEMALE_HIT_506, Sounds.FEMALE_HIT_507, Sounds.FEMALE_HIT2_508, Sounds.FEMALE_HIT_2_510)
if (player.isMale) {
playAudio(player, maleHurtAudio.random(), 10, delay)
playAudio(player, maleHurtAudio.random(), delay)
} else {
playAudio(player, femaleHurtAudio.random(), 10, delay)
playAudio(player, femaleHurtAudio.random(), delay)
}
}
@@ -8,12 +8,12 @@ import core.game.node.Node
import core.game.node.entity.combat.graves.GraveController
import core.game.node.entity.player.Player
import core.game.node.entity.player.info.login.PlayerParser
import core.game.node.entity.player.link.audio.Audio
import core.game.node.item.GroundItemManager
import core.game.node.item.Item
import core.game.system.config.ItemConfigParser
import content.global.skill.summoning.pet.Pets
import org.rs09.consts.Items
import org.rs09.consts.Sounds
/**
* Represents the item drop/destroy/dissolve handler.
@@ -25,9 +25,9 @@ class DropListener : InteractionListener {
}
companion object {
private val DROP_COINS_SOUND = Audio(10, 1, 0)
private val DROP_ITEM_SOUND = Audio(2739, 1, 0)
private val DESTROY_ITEM_SOUND = Audio(4500, 1, 0)
private val DROP_COINS_SOUND = Sounds.EYEGLO_COIN_10
private val DROP_ITEM_SOUND = Sounds.PUT_DOWN_2739
private val DESTROY_ITEM_SOUND = Sounds.DESTROY_OBJECT_2381
@JvmStatic fun drop(player: Player, item: Item) : Boolean {
return handleDropAction(player, item)
}
@@ -6,7 +6,6 @@ import core.game.node.entity.combat.ImpactHandler
import core.game.node.entity.player.Player
import core.game.node.entity.player.info.Rights
import core.game.node.entity.player.link.IronmanMode
import core.game.node.entity.player.link.audio.Audio
import core.game.node.entity.skill.Skills
import core.game.node.item.Item
import core.game.system.task.Pulse
@@ -24,6 +23,7 @@ import core.game.world.map.zone.impl.WildernessZone
import core.game.world.repository.Repository
import core.tools.secondsToTicks
import core.tools.colorize
import org.rs09.consts.Sounds
import java.util.Map
import kotlin.math.min
@@ -122,7 +122,7 @@ class GraveController : PersistWorld, TickListener, InteractionListener, Command
player.skills.prayerPoints -= blessAmount
setAttribute(g, "blessed", true)
playAudio(player, Audio(2674))
playAudio(player, Sounds.PRAYER_RECHARGE_2674)
animate(player, 645)
val gOwner = Repository.uid_map[g.ownerUid]
@@ -155,7 +155,7 @@ class GraveController : PersistWorld, TickListener, InteractionListener, Command
player.skills.prayerPoints -= restoreAmount
setAttribute(g, "repaired", true)
playAudio(player, Audio(2674))
playAudio(player, Sounds.PRAYER_RECHARGE_2674)
animate(player, 645)
return true
}
@@ -136,12 +136,12 @@ public abstract class CombatSpell extends MagicSpell {
*/
public void visualizeImpact(Entity entity, Entity target, BattleState state) {
if (state.getEstimatedHit() == -1) {
playGlobalAudio(target.getLocation(), Sounds.SPELLFAIL_227, 1, 20);
playGlobalAudio(target.getLocation(), Sounds.SPELLFAIL_227, 20);
target.graphics(SPLASH_GRAPHIC);
return;
}
target.graphics(endGraphic);
playGlobalAudio(target.getLocation(), impactAudio, 1, 20);
playGlobalAudio(target.getLocation(), impactAudio, 20);
}
@Override
@@ -173,7 +173,7 @@ public abstract class CombatSpell extends MagicSpell {
entity.animate(animation);
}
}
playGlobalAudio(entity.getLocation(), audio.getId(), 1, 20);
playGlobalAudio(entity.getLocation(), audio.getId(), 20);
}
@Override
@@ -20,7 +20,6 @@ import core.tools.RandomFunction;
import java.util.ArrayList;
import java.util.List;
import static core.api.ContentAPIKt.playAudio;
import static core.api.ContentAPIKt.playGlobalAudio;
/**
@@ -161,7 +160,7 @@ public abstract class MagicSpell implements Plugin<SpellType> {
public void visualize(Entity entity, Node target) {
entity.graphics(graphic);
entity.animate(animation);
playGlobalAudio(entity.getLocation(), audio.getId(), 1, 20);
playGlobalAudio(entity.getLocation(), audio.getId(), 20);
}
/**
@@ -5,10 +5,8 @@ import core.api.*
import core.tools.*
import core.game.node.entity.Entity
import core.game.node.entity.player.Player
import core.game.node.entity.combat.ImpactHandler
import core.game.world.repository.Repository
import core.game.node.entity.player.link.audio.Audio
import org.json.simple.*
import org.rs09.consts.Sounds
/**
* A timer that replicates the behavior of poison immunity mechanics. Runs every tick.
@@ -35,11 +33,11 @@ class PoisonImmunity : PersistTimer (1, "poison:immunity", isSoft = true, flags
if (entity is Player && ticksRemaining == secondsToTicks(30)) {
sendMessage(entity, colorize("%RYou have 30 seconds remaining on your poison immunity."))
playAudio(entity, Audio(3120))
playAudio(entity, Sounds.CLOCK_TICK_1_3120, 0, 3)
}
else if (entity is Player && ticksRemaining == 0) {
sendMessage(entity, colorize("%RYour poison immunity has expired."))
playAudio(entity, Audio(2607))
playAudio(entity, Sounds.DRAGON_POTION_FINISHED_2607)
}
return ticksRemaining > 0