mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Add support for Events defined in Ruby
A slightly complicated and hacky change, because this requires working around JRuby issue 2359.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
|
||||
java_import 'org.apollo.game.action.DistancedAction'
|
||||
java_import 'org.apollo.game.model.event.Event'
|
||||
|
||||
private
|
||||
|
||||
# A distanced action which opens a door.
|
||||
class OpenDoorAction < DistancedAction
|
||||
@@ -24,10 +27,29 @@ class OpenDoorAction < DistancedAction
|
||||
|
||||
end
|
||||
|
||||
# MessageListener for opening and closing doors.
|
||||
# A PlayerEvent that is fired when a player attempts to open a door.
|
||||
class OpenDoorEvent < PlayerEvent
|
||||
attr_reader :door
|
||||
|
||||
def initialize(player, door)
|
||||
super(player)
|
||||
@door = door
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
# Listens for FirstObjectActions performed on doors.
|
||||
on :message, :first_object_action do |player, message|
|
||||
if DoorUtil.door?(message.id)
|
||||
door = DoorUtil.get_door_object(message.position, message.id)
|
||||
player.start_action(OpenDoorAction.new(player, door)) unless door.nil?
|
||||
id = message.id
|
||||
|
||||
if DoorUtil.door?(id)
|
||||
position = message.position
|
||||
door = DoorUtil.get_door_object(position, id)
|
||||
|
||||
if !door.nil? && $world.submit(OpenDoorEvent.new(player, door))
|
||||
player.start_action(OpenDoorAction.new(player, door))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user