mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Make minor code improvements to bootstrap, make spawn_npc return the spawned npc.
This commit is contained in:
@@ -39,6 +39,7 @@ end
|
|||||||
|
|
||||||
# A CommandListener that executes a Proc object with two arguments: the player and the command.
|
# A CommandListener that executes a Proc object with two arguments: the player and the command.
|
||||||
class ProcCommandListener < CommandListener
|
class ProcCommandListener < CommandListener
|
||||||
|
|
||||||
def initialize(rights, block)
|
def initialize(rights, block)
|
||||||
super(rights)
|
super(rights)
|
||||||
@block = block
|
@block = block
|
||||||
@@ -47,6 +48,7 @@ class ProcCommandListener < CommandListener
|
|||||||
def execute(player, command)
|
def execute(player, command)
|
||||||
@block.call(player, command)
|
@block.call(player, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# A LoginListener that executes a Proc object with the player argument.
|
# A LoginListener that executes a Proc object with the player argument.
|
||||||
@@ -75,11 +77,13 @@ class ProcLogoutListener
|
|||||||
def execute(player)
|
def execute(player)
|
||||||
@block.call(player)
|
@block.call(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# An MessageHandler which executes a Proc object with three arguments: the chain
|
# An MessageHandler which executes a Proc object with three arguments: the chain
|
||||||
# context, the player and the message.
|
# context, the player and the message.
|
||||||
class ProcMessageHandler < MessageHandler
|
class ProcMessageHandler < MessageHandler
|
||||||
|
|
||||||
def initialize(block, option)
|
def initialize(block, option)
|
||||||
super() # required (with brackets!), see http://jira.codehaus.org/browse/JRUBY-679
|
super() # required (with brackets!), see http://jira.codehaus.org/browse/JRUBY-679
|
||||||
@block = block
|
@block = block
|
||||||
@@ -87,14 +91,14 @@ class ProcMessageHandler < MessageHandler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle(ctx, player, message)
|
def handle(ctx, player, message)
|
||||||
if (@option == 0 || @option == message.option)
|
@block.call(ctx, player, message) if (@option == 0 || @option == message.option)
|
||||||
@block.call(ctx, player, message)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# A ScheduledTask which executes a Proc object with one argument (itself).
|
# A ScheduledTask which executes a Proc object with one argument (itself).
|
||||||
class ProcScheduledTask < ScheduledTask
|
class ProcScheduledTask < ScheduledTask
|
||||||
|
|
||||||
def initialize(delay, immediate, block)
|
def initialize(delay, immediate, block)
|
||||||
super(delay, immediate)
|
super(delay, immediate)
|
||||||
@block = block
|
@block = block
|
||||||
@@ -103,6 +107,7 @@ class ProcScheduledTask < ScheduledTask
|
|||||||
def execute
|
def execute
|
||||||
@block.call(self)
|
@block.call(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Schedules a ScheduledTask. Can be used in two ways: passing an existing
|
# Schedules a ScheduledTask. Can be used in two ways: passing an existing
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ def spawn_npc(hash)
|
|||||||
raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_keys?(:x, :y)
|
raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_keys?(:x, :y)
|
||||||
npc = get_npc(hash)
|
npc = get_npc(hash)
|
||||||
spawn(npc, hash)
|
spawn(npc, hash)
|
||||||
|
npc
|
||||||
end
|
end
|
||||||
|
|
||||||
# Spawns the specified npc and applies the properties in the hash.
|
# Spawns the specified npc and applies the properties in the hash.
|
||||||
|
|||||||
Reference in New Issue
Block a user