class Rsrb::Net::ActionSender

Constants

Attributes

player[R]

Public Class Methods

new(player) click to toggle source
# File lib/rsrb/net/actionsender.rb, line 11
def initialize(player)
  @player = player
end

Public Instance Methods

send_amount_interface() click to toggle source

Send amount interface.

# File lib/rsrb/net/actionsender.rb, line 146
def send_amount_interface
  @player.connection.send_data PacketBuilder.new(27).to_packet
  self
end
send_chat_interface(id) click to toggle source

Send a chatbox interface.

# File lib/rsrb/net/actionsender.rb, line 123
def send_chat_interface(id)
  @player.connection.send_data PacketBuilder.new(164).add_leshort(id).to_packet
  self
end
send_clear_screen() click to toggle source

Clear the screen from all interfaces.

# File lib/rsrb/net/actionsender.rb, line 152
def send_clear_screen
  @player.connection.send_data PacketBuilder.new(219).to_packet
  self
end
send_config(id, value) click to toggle source
# File lib/rsrb/net/actionsender.rb, line 314
def send_config(id, value)
  @player.connection.send_data PacketBuilder.new(36).add_leshort(id).add_byte(value).to_packet
  self
end
send_grounditem_creation(item) click to toggle source

Create a ground item.

# File lib/rsrb/net/actionsender.rb, line 179
def send_grounditem_creation(item)
  x = item.location.x - (@player.last_location.get_region_x * 8)
  y = item.location.y - (@player.last_location.get_region_y * 8)

  @player.connection.send_data PacketBuilder.new(85).add_byte_c(y).add_byte_c(x).to_packet
  @player.connection.send_data PacketBuilder.new(44).add_leshort_a(item.item.id).add_short(item.item.count).add_byte(0).to_packet

  self
end
send_grounditem_removal(item) click to toggle source

Remove a ground item.

# File lib/rsrb/net/actionsender.rb, line 190
def send_grounditem_removal(item)
  x = item.location.x - (@player.last_location.get_region_x * 8)
  y = item.location.y - (@player.last_location.get_region_y * 8)

  @player.connection.send_data PacketBuilder.new(85).add_byte_c(y).add_byte_c(x).to_packet
  @player.connection.send_data PacketBuilder.new(156).add_byte_s(0).add_short(item.item.id).to_packet

  self
end
send_index() click to toggle source

Send the initial login details.

# File lib/rsrb/net/actionsender.rb, line 38
def send_index
  @player.connection.send_data PacketBuilder.new(249)
                                            .add_byte_a(1)
                                            .add_leshort_a(player.index)
                                            .to_packet
  @player.connection.send_data PacketBuilder.new(107)
                                            .to_packet
  self
end
send_interaction_option(option, slot, top) click to toggle source

Add an option for interactions.

# File lib/rsrb/net/actionsender.rb, line 158
def send_interaction_option(option, slot, top)
  bldr = PacketBuilder.new(104, :VAR)
  bldr.add_byte_c(slot)
  bldr.add_byte_a(top ? 0 : 1)
  bldr.add_str(option)

  @player.connection.send_data bldr.to_packet
  self
end
send_interface(id, walkable = false) click to toggle source

Open an interface on the client.

# File lib/rsrb/net/actionsender.rb, line 97
def send_interface(id, walkable = false)
  bldr = PacketBuilder.new(walkable ? 208 : 97)

  if walkable
    bldr.add_leshort id
  else
    bldr.add_short id
  end

  @player.connection.send_data bldr.to_packet
  self
end
send_interface_inventory(interface_id, inv_id) click to toggle source

Send an interface within the inventory interface.

# File lib/rsrb/net/actionsender.rb, line 111
def send_interface_inventory(interface_id, inv_id)
  @player.interface_state.interface_opened interface_id
  @player.connection.send_data PacketBuilder.new(248).add_short_a(interface_id).add_short(inv_id).to_packet
end
send_interface_model(id, zoom, model) click to toggle source

Send a model within an interface.

# File lib/rsrb/net/actionsender.rb, line 117
def send_interface_model(id, zoom, model)
  @player.connection.send_data PacketBuilder.new(246).add_leshort(id).add_short(zoom).add_short(model).to_packet
  self
end
send_login() click to toggle source
# File lib/rsrb/net/actionsender.rb, line 15
def send_login
  send_rights
  send_index
  send_message('Welcome to Rsrb.')

  send_skills
  send_sidebar_interfaces

  send_interaction_option('Trade', 2, true)
  send_interaction_option('Follow', 3, true)
  send_interaction_option('More...', 4, true)

  send_map_region
  self
end
send_logout() click to toggle source

Log the player out.

# File lib/rsrb/net/actionsender.rb, line 32
def send_logout
  @player.connection.send_data PacketBuilder.new(109).to_packet
  self
end
send_map_region() click to toggle source

Send map region.

# File lib/rsrb/net/actionsender.rb, line 61
def send_map_region
  @player.last_location = player.location
  @player.connection.send_data PacketBuilder.new(73)
                                            .add_short_a(@player.location.get_region_x + 6)
                                            .add_short(@player.location.get_region_y + 6)
                                            .to_packet
  self
end
send_message(message) click to toggle source

Send player a message in chatbox.

# File lib/rsrb/net/actionsender.rb, line 71
def send_message(message)
  @player.connection.send_data PacketBuilder.new(253, :VAR)
                                            .add_str(message)
                                            .to_packet
  self
end
send_replace_object(loc, rel, new_id, face, type) click to toggle source

Replace an object within the world.

# File lib/rsrb/net/actionsender.rb, line 279
def send_replace_object(loc, rel, new_id, face, type)
  # Face: 0 = WEST, -1 = NORTH, -2 = EAST, -3 = SOUTH
  # Type: 0-3 = Wall Objects, 4-8 = Wall Deco., 9 = Diag. Walls,
  #       10-11 = World Objects, 12-21 = Roofs, 22 = Floor Deco.

  bldr = PacketBuilder.new(60, :VARSH)

  # Location to modify
  bldr.add_byte (loc.y - (rel.get_region_y * 8))
  bldr.add_byte_c (loc.x - (rel.get_region_x * 8))

  # Delete object
  bldr.add_byte 101
  bldr.add_byte_c ((type << 2) + (face & 3))
  bldr.add_byte 0

  # Place object
  if new_id != -1
    bldr.add_byte 151
    bldr.add_byte_s 0
    bldr.add_leshort new_id
    bldr.add_byte_s ((type << 2) + (face & 3))
  end

  @player.connection.send_data bldr.to_packet

  self
end
send_rights() click to toggle source

Send rights.

# File lib/rsrb/net/actionsender.rb, line 50
def send_rights
  rights = Rsrb::World::Constants::RIGHTS.index(@player.rights)
  @player.connection.send_data Rsrb::Net::PacketBuilder
    .new(-1, :RAW)
    .add_byte(2)
    .add_byte(rights > 2 ? 2 : rights)
    .add_byte(0)
    .to_packet
end
send_sidebar_interface(icon, id) click to toggle source

Send a specific sidebar interface.

# File lib/rsrb/net/actionsender.rb, line 136
def send_sidebar_interface(icon, id)
  @player.connection.send_data PacketBuilder
    .new(71)
    .add_short(id)
    .add_byte_a(icon)
    .to_packet
  self
end
send_sidebar_interfaces() click to toggle source

Send sidebar interfaces.

# File lib/rsrb/net/actionsender.rb, line 129
def send_sidebar_interfaces
  SIDEBAR_INTERFACES[0].each_with_index { |_e, index| send_sidebar_interface(SIDEBAR_INTERFACES[0][index], SIDEBAR_INTERFACES[1][index]) }

  self
end
send_skill(skill) click to toggle source

Send a specific skill update.

# File lib/rsrb/net/actionsender.rb, line 85
def send_skill(skill)
  bldr = PacketBuilder.new(134)
  bldr.add_byte Rsrb::Player::Skills::SKILLS.index(skill)
  bldr.add_int1 @player.skills.exps[skill]
  bldr.add_byte @player.skills.skills[skill]


  @player.connection.send_data bldr.to_packet
  self
end
send_skills() click to toggle source

Update all player skills.

# File lib/rsrb/net/actionsender.rb, line 79
def send_skills
  Rsrb::Player::Skills::SKILLS.each { |s| send_skill s }
  self
end
send_string(id, string) click to toggle source

Send a string replacement.

# File lib/rsrb/net/actionsender.rb, line 169
def send_string(id, string)
  @player.connection.send_data PacketBuilder
    .new(126, :VARSH)
    .add_str(string)
    .add_short_a(id)
    .to_packet
  self
end
send_system_update(time) click to toggle source

Start system update countdown.

# File lib/rsrb/net/actionsender.rb, line 309
def send_system_update(time)
  @player.connection.send_data PacketBuilder.new(114).add_leshort(5 * time / 3).to_packet
  self
end
send_update_item(interface, slot, item) click to toggle source

Sends an update to a single item.

# File lib/rsrb/net/actionsender.rb, line 255
def send_update_item(interface, slot, item)
  bldr = PacketBuilder.new(34, :VARSH)
  bldr.add_short interface
  bldr.add_smart slot

  if item != nil
    bldr.add_short (item.id + 1)
    count = item.count
    if count > 254
      bldr.add_byte 255
      bldr.add_int count
    else
      bldr.add_byte count
    end
  else
    bldr.add_short 0
    bldr.add_byte 0
  end

  @player.connection.send_data bldr.to_packet
  self
end
send_update_items(interface, items) click to toggle source

Send updates to a group of items.

# File lib/rsrb/net/actionsender.rb, line 201
def send_update_items(interface, items)
  bldr = PacketBuilder.new(53, :VARSH)
  bldr.add_short interface
  bldr.add_short items.size

  items.each {|item|
    if item != nil
      count = item.count
      if count > 254
        bldr.add_byte 255
        bldr.add_int2 count
      else
        bldr.add_byte count
      end
      bldr.add_leshort_a (item.id + 1)
    else
      bldr.add_byte 0
      bldr.add_leshort_a 0
    end
  }

  @player.connection.send_data bldr.to_packet

  self
end
send_update_some_items(interface, slots, items) click to toggle source

Send an update to mutliple items, but not all.

# File lib/rsrb/net/actionsender.rb, line 228
def send_update_some_items(interface, slots, items)
  bldr = PacketBuilder.new(34, :VARSH).add_short(interface)
  slots.each {|slot|
    item = items[slot]
    bldr.add_smart slot

    if item != nil
      bldr.add_short (item.id + 1)
      count = item.count
      if count > 254
        bldr.add_byte 255
        bldr.add_int count
      else
        bldr.add_byte count
      end
    else
      bldr.add_short 0
      bldr.add_byte 0
    end
  }

  @player.connection.send_data bldr.to_packet

  self
end