class RuneRb::World::NPCSpawns

Constants

DIRECTIONS

Public Class Methods

load() click to toggle source
# File app/world/npc_spawns.rb, line 14
def NPCSpawns.load
  npc = XmlSimple.xml_in("data/npc_spawns.xml")
  npc["npc"].each_with_index {|row, idx|
    NPCSpawns.spawn(row)
  }
end
spawn(data) click to toggle source
# File app/world/npc_spawns.rb, line 21
def NPCSpawns.spawn(data)
  npc = RuneRb::NPC::NPC.new RuneRb::NPC::NPCDefinition.for_id(data['id'].to_i)
  npc.location = RuneRb::Model::Location.new(data['x'].to_i, data['y'].to_i, data['z'].to_i)
    
  WORLD.register_npc npc
  
  if data.include?('face')
    npc.direction = data['face'].to_sym
    
    offsets = DIRECTIONS[npc.direction]
    npc.face(npc.location.transform(offsets[0], offsets[1], 0))
  end
  
  # Add shop hook if NPC owns a shop
  if data.include?('shop')
    handler = HOOKS[:npc_option2][data['id'].to_i]

    if !handler.instance_of?(Proc)
      on_npc_option2(data['id'].to_i) {|player, npc|
        RuneRb::Shops::ShopManager.open(data['shop'].to_i, player)
        player.interacting_entity = npc
      }
    end
  end
end