mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Add SendObjectEvent.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package org.apollo.game.event.impl;
|
||||
|
||||
import org.apollo.game.event.Event;
|
||||
import org.apollo.game.model.entity.GameObject;
|
||||
|
||||
/**
|
||||
* An {@link Event} sent to the client to spawn an object.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SendObjectEvent extends Event {
|
||||
|
||||
/**
|
||||
* The id of the object.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The orientation of the object.
|
||||
*/
|
||||
private final int orientation;
|
||||
|
||||
/**
|
||||
* The position of the object.
|
||||
*/
|
||||
private final int positionOffset;
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*/
|
||||
private final int type;
|
||||
|
||||
/**
|
||||
* Creates the send object event.
|
||||
*
|
||||
* @param object The {@link GameObject} to send.
|
||||
*/
|
||||
public SendObjectEvent(GameObject object) {
|
||||
this.id = object.getId();
|
||||
this.positionOffset = 0;
|
||||
this.type = object.getType();
|
||||
this.orientation = object.getRotation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the object.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the orientation of the object.
|
||||
*
|
||||
* @return The orientation.
|
||||
*/
|
||||
public int getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position offset of the object.
|
||||
*
|
||||
* @return The position offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the orientation of the object.
|
||||
*
|
||||
* @return The type.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.event.impl.SendObjectEvent;
|
||||
import org.apollo.net.codec.game.DataOrder;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.EventEncoder;
|
||||
|
||||
/**
|
||||
* An {@link EventEncoder} for the {@link SendObjectEvent}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SendObjectEventEncoder extends EventEncoder<SendObjectEvent> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SendObjectEvent event) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(151);
|
||||
builder.put(DataType.BYTE, DataTransformation.ADD, event.getPositionOffset());
|
||||
builder.put(DataType.SHORT, DataOrder.LITTLE, event.getId());
|
||||
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, event.getType() << 2 + event.getOrientation());
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.apollo.net.release.r377;
|
||||
|
||||
import org.apollo.game.event.impl.SendObjectEvent;
|
||||
import org.apollo.net.codec.game.DataOrder;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.EventEncoder;
|
||||
|
||||
/**
|
||||
* An {@link EventEncoder} for the {@link SendObjectEvent}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SendObjectEventEncoder extends EventEncoder<SendObjectEvent> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SendObjectEvent event) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(152);
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getType() << 2 + event.getOrientation());
|
||||
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, event.getId());
|
||||
builder.put(DataType.BYTE, DataTransformation.ADD, event.getPositionOffset());
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user