Merge pull request #172 from ryleykimmel/issue169

Pass the new Position of Players to area listeners
This commit is contained in:
Major
2016-02-09 16:02:29 +00:00
3 changed files with 24 additions and 23 deletions
+6 -6
View File
@@ -32,18 +32,18 @@ class AreaAction
end end
# Called when the player has entered an area this action is registered to. # Called when the player has entered an area this action is registered to.
def entered(player) def entered(player, position)
@on_enter.call(player) unless @on_enter.nil? @on_enter.call(player, position) unless @on_enter.nil?
end end
# Called while the player is in area this action is registered to. # Called while the player is in area this action is registered to.
def inside(player) def inside(player, position)
@while_in.call(player) unless @while_in.nil? @while_in.call(player, position) unless @while_in.nil?
end end
# Called when the player has exited an area this action is registered to. # Called when the player has exited an area this action is registered to.
def exited(player) def exited(player, position)
@on_exit.call(player) unless @on_exit.nil? @on_exit.call(player, position) unless @on_exit.nil?
end end
end end
+10 -9
View File
@@ -51,18 +51,18 @@ class Area
end end
# Called when the player has entered the area. # Called when the player has entered the area.
def entered(player) def entered(player, position)
@actions.each { |action| action.entered(player) } @actions.each { |action| action.entered(player, position) }
end end
# Called when the player has moved, but is still inside the area (and was in the area before). # Called when the player has moved, but is still inside the area (and was in the area before).
def inside(player) def inside(player, position)
@actions.each { |action| action.inside(player) } @actions.each { |action| action.inside(player, position) }
end end
# Called when the player has exited the area. # Called when the player has exited the area.
def exited(player) def exited(player, position)
@actions.each { |action| action.exited(player) } @actions.each { |action| action.exited(player, position) }
end end
end end
@@ -81,14 +81,15 @@ on :mob_position_update do |event|
next unless mob.entity_type == EntityType::PLAYER next unless mob.entity_type == EntityType::PLAYER
old = mob.position old = mob.position
updated = event.next
@areas.each do |area| @areas.each do |area|
was_inside = old.inside(area) was_inside = old.inside(area)
next_inside = event.next.inside(area) next_inside = updated.inside(area)
if was_inside if was_inside
next_inside ? area.inside(mob) : area.exited(mob) next_inside ? area.inside(mob, updated) : area.exited(mob, updated)
else else
area.entered(mob) if next_inside area.entered(mob, updated) if next_inside
end end
end end
end end
+8 -8
View File
@@ -17,14 +17,14 @@ module WildernessConstants
end end
# Determines the wilderness level for the specified player's position # Determines the wilderness level for the specified position
def wilderness_level(player) def wilderness_level(position)
((player.position.y - 3520) / 8).ceil + 1 ((position.y - 3520) / 8).ceil + 1
end end
area_action :wilderness_level do area_action :wilderness_level do
on_entry do |player| on_entry do |player, position|
player.wilderness_level = wilderness_level(player) player.wilderness_level = wilderness_level(position)
player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID)
id = WildernessConstants::LEVEL_STRING_ID id = WildernessConstants::LEVEL_STRING_ID
@@ -32,9 +32,9 @@ area_action :wilderness_level do
show_action(player, ATTACK_ACTION) show_action(player, ATTACK_ACTION)
end end
while_in do |player| while_in do |player, position|
current = player.wilderness_level current = player.wilderness_level
updated = wilderness_level(player) updated = wilderness_level(position)
if current != updated if current != updated
player.wilderness_level = updated player.wilderness_level = updated
@@ -44,7 +44,7 @@ area_action :wilderness_level do
end end
end end
on_exit do |player| on_exit do |player, position|
player.wilderness_level = 0 player.wilderness_level = 0
player.interface_set.close player.interface_set.close