class RuneRb::Model::RegionManager

Manage all active regions within the server

Constants

REGION_SIZE

Attributes

active_regions[R]

Public Class Methods

new() click to toggle source
# File app/model/region.rb, line 7
def initialize
  @active_regions = []
end

Public Instance Methods

get_local_npcs(entity) click to toggle source
# File app/model/region.rb, line 23
def get_local_npcs(entity)
  get_surrounding_regions(entity.location).inject([]) {|npcs, region|
    npcs + region.npcs.select {|n| n.location.within_distance?(entity.location) }
  }
end
get_local_players(ref, check_distance=true) click to toggle source
# File app/model/region.rb, line 11
def get_local_players(ref, check_distance=true)
  loc = ref.is_a?(Location) ? ref : ref.location

  get_surrounding_regions(loc).inject([]){|players, region|
    if check_distance
      players + region.players.select {|p| p.location.within_distance?(loc) }
    else
      players + region.players
    end
  }
end
get_region(x, y) click to toggle source
# File app/model/region.rb, line 40
def get_region(x, y)
  region = @active_regions.find {|region| region.x == x and region.y == y }
  
  if region == nil
    region = Region.new x, y
    @active_regions << region
  end
  
  region
end
get_region_for_location(location) click to toggle source
# File app/model/region.rb, line 51
def get_region_for_location(location)
  get_region location.x / REGION_SIZE, location.y / REGION_SIZE
end
get_surrounding_regions(location) click to toggle source
# File app/model/region.rb, line 29
def get_surrounding_regions(location)
  regions = []
  (-2..2).each {|x|
    (-2..2).each {|y|
      regions << get_region((location.x / 32)+x, (location.y / 32)+y)
    }
  }
  
  regions
end