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

refactor: convert "play sound at position" to message #140

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -15,6 +15,7 @@
import org.runejs.client.message.handler.rs435.chat.*;
import org.runejs.client.message.handler.rs435.console.*;
import org.runejs.client.message.handler.rs435.misc.*;
import org.runejs.client.message.handler.rs435.world.*;
import org.runejs.client.message.inbound.camera.*;
import org.runejs.client.message.inbound.chat.*;
import org.runejs.client.message.handler.rs435.audio.PlayQuickSongMessageHandler;
Expand All @@ -34,6 +35,7 @@
import org.runejs.client.message.inbound.widget.model.*;
import org.runejs.client.message.inbound.widget.text.*;
import org.runejs.client.message.inbound.widget.visibility.*;
import org.runejs.client.message.inbound.world.*;

/**
* A {@link MessageHandlerRegistry} for the RS revision 435 client.
Expand Down Expand Up @@ -124,5 +126,8 @@ public RS435HandlerRegistry() {
register(LoadStandardRegionInboundMessage.class, new LoadStandardRegionMessageHandler());
register(LoadConstructedRegionInboundMessage.class, new LoadConstructedRegionMessageHandler());
register(UpdateReferencePositionInboundMessage.class, new UpdateReferencePositionMessageHandler());

// world
register(PlaySoundAtPositionInboundMessage.class, new PlaySoundAtPositionMessageHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.runejs.client.message.handler.rs435.world;

import org.runejs.client.MovedStatics;
import org.runejs.client.cache.def.OverlayDefinition;
import org.runejs.client.media.renderable.actor.Player;
import org.runejs.client.message.handler.MessageHandler;
import org.runejs.client.message.inbound.world.PlaySoundAtPositionInboundMessage;
import org.runejs.client.sound.SoundSystem;

public class PlaySoundAtPositionMessageHandler implements MessageHandler<PlaySoundAtPositionInboundMessage> {
@Override
public void handle(PlaySoundAtPositionInboundMessage message) {
int localY = message.y + OverlayDefinition.placementY;
int localX = message.x + MovedStatics.placementX;

if (localX >= 0 && localY >= 0 && localX < 104 && localY < 104) {
int i_26_ = 1 + message.radius;
if (Player.localPlayer.pathY[0] >= localX - i_26_ && Player.localPlayer.pathY[0] <= localX + i_26_ && localY - i_26_ <= Player.localPlayer.pathX[0] && localY + i_26_ >= Player.localPlayer.pathX[0]) {
SoundSystem.play(message.soundId, message.volume, message.delay, message.radius + (localY << 8) + (localX << 16));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.runejs.client.message.inbound.world;

import org.runejs.client.message.InboundMessage;

public class PlaySoundAtPositionInboundMessage implements InboundMessage {
public final int x;

public final int y;

public final int soundId;

public final int radius;

public final int volume;

public final int delay;

public PlaySoundAtPositionInboundMessage(int x, int y, int soundId, int radius, int volume, int delay) {
this.x = x;
this.y = y;
this.soundId = soundId;
this.radius = radius;
this.volume = volume;
this.delay = delay;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/runejs/client/net/IncomingPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static boolean parseIncomingPackets() {
return true;
}
// object/ground item update packets?
if(opcode == PacketType.PLAY_SOUND_AT_POSITION.getOpcode() || opcode == PacketType.UPDATE_GROUND_ITEM_AMOUNT.getOpcode() || opcode == PacketType.TRANSFORM_PLAYER_TO_OBJECT.getOpcode() || opcode == PacketType.ADD_GROUND_ITEM_EXCLUDE_SOME_PLAYER.getOpcode() || opcode == PacketType.CREATE_STATIONARY_GFX.getOpcode() || opcode == PacketType.CREATE_PROJECTILE.getOpcode() || opcode == PacketType.REMOVE_GROUND_ITEM.getOpcode() || opcode == PacketType.ADD_GROUND_ITEM.getOpcode() || opcode == PacketType.ROTATE_ANIMATE_OBJECT.getOpcode() || opcode == PacketType.REMOVE_OBJECT.getOpcode() || opcode == PacketType.SPAWN_OBJECT.getOpcode()) {
if(opcode == PacketType.UPDATE_GROUND_ITEM_AMOUNT.getOpcode() || opcode == PacketType.TRANSFORM_PLAYER_TO_OBJECT.getOpcode() || opcode == PacketType.ADD_GROUND_ITEM_EXCLUDE_SOME_PLAYER.getOpcode() || opcode == PacketType.CREATE_STATIONARY_GFX.getOpcode() || opcode == PacketType.CREATE_PROJECTILE.getOpcode() || opcode == PacketType.REMOVE_GROUND_ITEM.getOpcode() || opcode == PacketType.ADD_GROUND_ITEM.getOpcode() || opcode == PacketType.ROTATE_ANIMATE_OBJECT.getOpcode() || opcode == PacketType.REMOVE_OBJECT.getOpcode() || opcode == PacketType.SPAWN_OBJECT.getOpcode()) {
parseMapIncomingPacket();
opcode = -1;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.runejs.client.net.codec.runejs435.decoder.widget.model.*;
import org.runejs.client.net.codec.runejs435.decoder.widget.text.*;
import org.runejs.client.net.codec.runejs435.decoder.widget.visibility.*;
import org.runejs.client.net.codec.runejs435.decoder.world.*;
import org.runejs.client.net.codec.runejs435.encoder.chat.*;
import org.runejs.client.net.codec.runejs435.encoder.console.*;
import org.runejs.client.net.codec.runejs435.encoder.examine.*;
Expand Down Expand Up @@ -185,5 +186,8 @@ private void registerDecoders() {
register(PacketType.CUTSCENE_CAMERA_MOVE_TO.getOpcode(), new CutsceneCameraMoveToMessageDecoder());
register(PacketType.CLOSE_CUTSCENE.getOpcode(), new CutsceneExitMessageDecoder());
register(PacketType.SHAKE_CAMERA.getOpcode(), new ShakeCameraMessageDecoder());

// world
register(PacketType.PLAY_SOUND_AT_POSITION.getOpcode(), new PlaySoundAtPositionMessageDecoder());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.runejs.client.net.codec.runejs435.decoder.world;

import org.runejs.client.message.inbound.world.PlaySoundAtPositionInboundMessage;
import org.runejs.client.net.PacketBuffer;
import org.runejs.client.net.codec.MessageDecoder;

public class PlaySoundAtPositionMessageDecoder implements MessageDecoder<PlaySoundAtPositionInboundMessage> {
@Override
public PlaySoundAtPositionInboundMessage decode(PacketBuffer buffer) {
int offset = buffer.getUnsignedByte();
int y = (offset & 0x7);
int x = (0x7 & offset >> 4);
int soundId = buffer.getUnsignedShortBE();

int soundData = buffer.getUnsignedByte();
int radius = soundData >> 4 & 0xf;
int volume = 0x7 & soundData;
int delay = buffer.getUnsignedByte();

return new PlaySoundAtPositionInboundMessage(x, y, soundId, radius, volume, delay);
}
}