class Rsrb::Model::Equipment::SidebarContainerListener

Attributes

player[R]

Public Class Methods

new(player) click to toggle source
# File lib/rsrb/model/equipment.rb, line 108
def initialize(player)
  @player = player
end

Public Instance Methods

items_changed(container) click to toggle source
# File lib/rsrb/model/equipment.rb, line 121
def items_changed(container)
  send_weapon
end
send_weapon() click to toggle source
# File lib/rsrb/model/equipment.rb, line 125
def send_weapon
  weapon = player.equipment.items[3]

  if weapon
    name = weapon.definition.name
    send_sidebar name, weapon.id, find_sidebar_interface(name)
  else
    # No weapon wielded
    @player.io.send_sidebar_interface 0, 5855
    @player.io.send_string 5857, "Unarmed"
  end
end
slot_changed(container, slot) click to toggle source
# File lib/rsrb/model/equipment.rb, line 112
def slot_changed(container, slot)
  send_weapon if slot == 3
end
slots_changed(container, slots) click to toggle source
# File lib/rsrb/model/equipment.rb, line 116
def slots_changed(container, slots)
  slot = slots.find {|e| e == 3}
  send_weapon unless slot == nil
end

Private Instance Methods

filter_name(name) click to toggle source
# File lib/rsrb/model/equipment.rb, line 158
def filter_name(name)
  name = name.dup
  MATERIALS.each {|m| name.gsub!(Regexp.new(m), "") }
  name.strip
end
find_sidebar_interface(name) click to toggle source
# File lib/rsrb/model/equipment.rb, line 140
def find_sidebar_interface(name)
  SIDEBARS.each {|matcher, data|
    formatted_name = data[:type] == :generic ? filter_name(name) : name

    if formatted_name =~ matcher
      return data[:id]
    end
  }

  2423
end
send_sidebar(name, id, interface_id) click to toggle source
# File lib/rsrb/model/equipment.rb, line 152
def send_sidebar(name, id, interface_id)
  @player.io.send_sidebar_interface(0, interface_id)
  @player.io.send_interface_model(interface_id + 1, 200, id)
  @player.io.send_string(interface_id + 3, name)
end