use of org.apollo.game.model.Item in project apollo by apollo-rsps.
the class BinaryPlayerSerializer method writeInventory.
/**
* Writes an inventory to the specified output stream.
*
* @param out The output stream.
* @param inventory The inventory.
* @throws IOException If an I/O error occurs.
*/
private void writeInventory(DataOutputStream out, Inventory inventory) throws IOException {
int capacity = inventory.capacity();
out.writeShort(capacity);
for (int slot = 0; slot < capacity; slot++) {
Item item = inventory.get(slot);
if (item != null) {
out.writeShort(item.getId() + 1);
out.writeInt(item.getAmount());
} else {
out.writeShort(0);
out.writeInt(0);
}
}
}
use of org.apollo.game.model.Item in project apollo by apollo-rsps.
the class ItemVerificationHandler method handle.
@Override
public void handle(Player player, InventoryItemMessage message) {
InventorySupplier supplier = inventories.get(message.getInterfaceId());
if (supplier == null) {
message.terminate();
return;
}
Inventory inventory = supplier.getInventory(player);
int slot = message.getSlot();
if (inventory == null || slot < 0 || slot >= inventory.capacity()) {
message.terminate();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != message.getId()) {
message.terminate();
}
}
use of org.apollo.game.model.Item in project apollo by apollo-rsps.
the class ItemOnObjectVerificationHandler method handle.
@Override
public void handle(Player player, ItemOnObjectMessage message) {
if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
message.terminate();
return;
}
Inventory inventory = player.getInventory();
int slot = message.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
message.terminate();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != message.getId()) {
message.terminate();
return;
}
int objectId = message.getObjectId();
if (objectId < 0 || objectId >= ObjectDefinition.count()) {
message.terminate();
return;
}
Position position = message.getPosition();
Region region = world.getRegionRepository().fromPosition(position);
Set<GameObject> objects = region.getEntities(position, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT);
if (!player.getPosition().isWithinDistance(position, 15) || !ObjectActionVerificationHandler.containsObject(objectId, objects)) {
message.terminate();
return;
}
}
use of org.apollo.game.model.Item in project apollo by apollo-rsps.
the class UpdateSlottedItemsMessageEncoder method encode.
@Override
public GamePacket encode(UpdateSlottedItemsMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(34, PacketType.VARIABLE_SHORT);
SlottedItem[] items = message.getSlottedItems();
builder.put(DataType.SHORT, message.getInterfaceId());
for (SlottedItem slottedItem : items) {
builder.putSmart(slottedItem.getSlot());
Item item = slottedItem.getItem();
int id = item == null ? -1 : item.getId();
int amount = item == null ? 0 : item.getAmount();
builder.put(DataType.SHORT, id + 1);
if (amount > 254) {
builder.put(DataType.BYTE, 255);
builder.put(DataType.INT, amount);
} else {
builder.put(DataType.BYTE, amount);
}
}
return builder.toGamePacket();
}
Aggregations