Class: RuneRb::Network::RS377::UpdateItemsMessage

Inherits:
Message
  • Object
show all
Defined in:
app/network/protocol/rs377/outgoing/update_items.rb

Overview

Since:

  • 0.9.3

Constant Summary

Constants included from Constants

Constants::BIT_MASK_OUT, Constants::BYTE_MUTATIONS, Constants::BYTE_ORDERS, Constants::BYTE_SIZE, Constants::CONNECTION_TYPES, Constants::LOGIN_RESPONSES, Constants::MESSAGE_SIZES, Constants::PROTOCOL_TEMPLATES, Constants::RW_TYPES, Constants::SIDEBAR_INTERFACES

Instance Attribute Summary

Attributes inherited from Message

#header, #mode

Instance Method Summary collapse

Methods inherited from Message

compile_header, #inspect, #peek, validate

Methods included from System::Log

#class_name, #err, #err!, #log, #log!, #symbolize_file

Constructor Details

#initialize(data) ⇒ UpdateItemsMessage

Constructs a new ContextInventoryMessage.

Parameters:

  • data (Hash)

    inventory data including items, amounts and corresponding slots

Since:

  • 0.9.3


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/network/protocol/rs377/outgoing/update_items.rb', line 6

def initialize(data)
  super('w', { op_code: 206 }, :VARIABLE_SHORT)

  # ContextInventoryForm ID
  write_short(3214)

  # Container length
  write_short(data[:size])

  data[:data].each do |_slot_id, item_stack|

    id = item_stack.nil? || item_stack.id.nil? || item_stack.id.negative? ? -1 : item_stack.id
    amount = item_stack.nil? || item_stack.size.nil? || item_stack.size.negative? ? 0 : item_stack.size

    write_short(id + 1, :ADD, :LITTLE)

    if amount > 254
      write_byte(0xFF, :NEGATE)
      write_int(amount, :STD, :LITTLE)
    else
      write_byte(amount, :NEGATE)
    end
  end
end