Module: RuneRb::Network::RS377::OptionClickMessage

Includes:
System::Log
Defined in:
app/network/protocol/rs377/incoming/option.rb

Overview

Since:

  • 0.9.3

Instance Method Summary collapse

Methods included from System::Log

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

Instance Method Details

#parse(context) ⇒ Object

Parses the OptionClickMessage

Parameters:

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
30
31
32
33
34
35
36
37
38
39
40
# File 'app/network/protocol/rs377/incoming/option.rb', line 6

def parse(context)
  case @header[:op_code]
  when 203 # First
    interface = read_short(false, :ADD)
    slot = read_short(false, :STD, :LITTLE)
    item_id = read_short(true, :STD, :LITTLE)
  when 24 # Second
    interface = read_short(false, :STD, :LITTLE)
    item_id = read_short(false, :STD, :LITTLE)
    slot = read_short(false, :ADD) + 1
    item = context.inventory[:container].at(slot)
    return unless item # This check is for instances where a context may perform a 5thoptclick followed by this 2ndoptclick. this slot may be nil, so we do nothing and sort of force a proper click.

    old = context.equipment[item.definition[:slot]]
    context.equipment[item.definition[:slot]] = item
    context.inventory[:container].remove_at(slot)
    context.add_item(old, slot) if old.is_a?(RuneRb::Game::Item::Stack)
    update(:equipment)
    update(:inventory)
  when 161 # Third
    slot = read_short(false, :ADD, :LITTLE)
    item_id = read_short(false, :ADD, :LITTLE)
    interface = read_short(false, :STD, :LITTLE)
  when 228 # Fourth
    slot = read_short(false, :STD, :LITTLE)
    item_id = read_short(false, :ADD)
    interface = read_short
  when 4 # Fifth
    slot = read_short(false, :STD, :LITTLE)
    item_id = read_short(false, :ADD, :LITTLE)
    interface = read_short(false, :ADD, :LITTLE)
  end

  log_item_click(interface, slot, item_id)
end