Rebase the MessageHandler, MessageHandlerChain and MessageHandlerChainSet

Rebased several other pieces of code
This commit is contained in:
atomicint
2015-03-29 12:52:55 -04:00
parent 7f345fffac
commit 654a1a6dfd
71 changed files with 452 additions and 457 deletions
+4 -4
View File
@@ -30,17 +30,17 @@ class BankAction < DistancedAction
end
# Intercepts the object action message
on :message, :second_object_action do |ctx, player, message|
on :message, :second_object_action do |player, message|
if message.id == BANK_BOOTH_ID
player.start_action(BankAction.new(player, message.position))
ctx.break_handler_chain
message.terminate
end
end
on :message, :second_npc_action do |ctx, player, message|
on :message, :second_npc_action do |player, message|
npc = $world.npc_repository.get(message.index)
if BANKER_NPCS.include?(npc.id)
player.start_action(BankAction.new(player, npc.position))
ctx.break_handler_chain
message.terminate
end
end
+7 -8
View File
@@ -15,7 +15,7 @@
require 'java'
java_import 'org.apollo.game.command.CommandListener'
java_import 'org.apollo.game.message.handler.MessageHandler'
java_import 'org.apollo.game.message.MessageHandler'
java_import 'org.apollo.game.model.World'
java_import 'org.apollo.game.model.entity.Player'
java_import 'org.apollo.game.model.event.EventListener'
@@ -75,11 +75,10 @@ class ProcEventListener
end
# A MessageHandler which executes a Proc object with three arguments: the chain
# context, the player and the message.
# A MessageHandler which executes a Proc object with two arguments: the player and the message.
class ProcMessageHandler < MessageHandler
# Creates the ProcMessageListener.
# Creates the ProcMessageHandler.
def initialize(block, option)
super($world)
@block = block
@@ -87,8 +86,8 @@ class ProcMessageHandler < MessageHandler
end
# Handles the message.
def handle(ctx, player, message)
@block.call(ctx, player, message) if (@option == 0 || @option == message.option)
def handle(player, message)
@block.call(player, message) if (@option == 0 || @option == message.option)
end
end
@@ -166,7 +165,7 @@ def on_button(args, proc)
id = args[0].to_i
on :message, :button do |ctx, player, message|
on :message, :button do |player, message|
proc.call(player) if message.widget_id == id
end
end
@@ -192,7 +191,7 @@ def on_message(args, proc)
class_name = message.to_s.camelize.concat('Message')
message = Java::JavaClass.for_name("org.apollo.game.message.impl.#{class_name}")
$ctx.add_last_message_handler(message, ProcMessageHandler.new(proc, option))
$ctx.add_message_handler(message, ProcMessageHandler.new(proc, option))
end
# Defines an action to be taken upon a command.
+1 -1
View File
@@ -3,7 +3,7 @@ require 'java'
java_import 'org.apollo.game.model.entity.setting.PrivacyState'
java_import 'org.apollo.game.message.impl.SendFriendMessage'
on :message, :privacy_option do |ctx, player, message|
on :message, :privacy_option do |player, message|
player.chat_privacy = message.chat_privacy
player.friend_privacy = message.friend_privacy
player.trade_privacy = message.trade_privacy
@@ -11,7 +11,7 @@ java_import 'org.apollo.game.model.entity.Player'
# Processes an add friend message, updating the logged-in status of the player (and the person they added) if necessary.
on :message, :add_friend do |ctx, player, message|
on :message, :add_friend do |player, message|
friend_username = message.username
player_username = player.username
@@ -30,7 +30,7 @@ on :message, :add_friend do |ctx, player, message|
end
# Processes a remove friend message, updating the logged-in status of the player if necessary.
on :message, :remove_friend do |ctx, player, message|
on :message, :remove_friend do |player, message|
friend_username = message.username
player_username = player.username
@@ -1,9 +1,9 @@
on :message, :add_ignore do |ctx, player, message|
on :message, :add_ignore do |player, message|
username = message.username
player.add_ignore(username)
end
on :message, :remove_ignore do |ctx, player, message|
on :message, :remove_ignore do |player, message|
username = message.username
player.remove_ignore(username)
end
@@ -4,7 +4,7 @@ java_import 'org.apollo.game.message.impl.ForwardPrivateChatMessage'
java_import 'org.apollo.game.model.World'
java_import 'org.apollo.game.model.entity.setting.PrivacyState'
on :message, :private_chat do |ctx, player, message|
on :message, :private_chat do |player, message|
friend = $world.get_player(message.username)
friend.send(ForwardPrivateChatMessage.new(player.username, player.privilege_level, message.compressed_chat)) if interaction_permitted(player, friend)
end
+2 -2
View File
@@ -54,11 +54,11 @@ class ConsumeAction < Action
end
# Intercepts the first item option message and consumes the consumable, if necessary.
on :message, :first_item_option do |ctx, player, message|
on :message, :first_item_option do |player, message|
consumable = CONSUMABLES[message.id]
unless consumable.nil?
player.start_action(ConsumeAction.new(player, message.slot, consumable))
ctx.break_handler_chain
message.terminate
end
end
+3 -3
View File
@@ -71,13 +71,13 @@ class Conversation
raise 'Npc cannot be null when opening a dialogue.' if npc_index.nil?
@starters << dialogue
on :message, :first_npc_action do |ctx, player, event|
npc = $world.npc_repository.get(event.index)
on :message, :first_npc_action do |player, message|
npc = $world.npc_repository.get(message.index)
if npc_index == npc.id
@starters.each do |start|
if dialogue.precondition(player)
player.start_action(OpenDialogueAction.new(player, npc, dialogue))
ctx.break_handler_chain()
message.terminate
break
end
end
+1 -1
View File
@@ -45,6 +45,6 @@ class DummyAction < DistancedAction
end
end
on :message, :second_object_action do |ctx, player, message|
on :message, :second_object_action do |player, message|
player.start_action(DummyAction.new(player, message.position)) if message.id == DUMMY_ID
end
+2 -2
View File
@@ -12,10 +12,10 @@ ANIMATIONS = {
}
# Intercept the button message.
on :message, :button do |ctx, player, message|
on :message, :button do |player, message|
anim = ANIMATIONS[message.widget_id]
unless anim == nil
player.play_animation(anim)
ctx.break_handler_chain
message.terminate
end
end
@@ -126,7 +126,7 @@ def add_survival_items(player)
end
# Intercept the FirstObjectActionMessage to send tutorial-only events if the player is chopping down a tree.
on :message, :first_object_action do |ctx, player, message|
on :message, :first_object_action do |player, message|
if (player.in_tutorial_island && message.id == SurvivalConstants::TREE_ID)
progress = player.tutorial_island_progress
if (progress < :cut_tree)
@@ -138,9 +138,9 @@ on :message, :first_object_action do |ctx, player, message|
end
# Intercept the FlashingTabClickedMessage to update the player's progress, if applicable.
on :message, :flashing_tab_clicked do |ctx, player, message|
on :message, :flashing_tab_clicked do |player, message|
if (player.in_tutorial_island && message.tab == SurvivalConstants::INVENTORY_TAB_INDEX && player.tutorial_island_progress == :given_axe)
player.tutorial_island_progress = :cut_tree
ctx.break_handler_chain()
message.terminate
end
end
+2 -2
View File
@@ -23,8 +23,8 @@ class OpenDoorAction < DistancedAction
end
# Message handler for opening and closing doors.
on :message, :first_object_action do |ctx, player, message|
# MessageListener for opening and closing doors.
on :message, :first_object_action do |player, message|
if DoorUtil::is_door?(message.id)
puts "Player: #{player.position}, door: #{message.position}"
door = DoorUtil::get_door_object(message.position, message.id)
+2 -2
View File
@@ -100,12 +100,12 @@ class FishingAction < DistancedAction
end
# Intercepts the NpcAction message to determine whether or not a clicked npc was a fishing spot.
on :message, :npc_action do |ctx, player, message|
on :message, :npc_action do |player, message|
npc = $world.npc_repository.get(message.index)
spot = FISHING_SPOTS[npc.id]
unless spot.nil?
player.start_action(FishingAction.new(player, npc.position, spot, message.option))
ctx.break_handler_chain
message.terminate
end
end
+7 -7
View File
@@ -25,8 +25,8 @@ module HerbloreMethod
end
end
# The ItemOnItemMessage handler for all Herblore-related functions.
on :message, :item_on_item do |ctx, player, message|
# The ItemOnItemMessage listener for all Herblore-related functions.
on :message, :item_on_item do |player, message|
primary = message.id
secondary = message.target_id
hash = HERBLORE_ITEM_ON_ITEM[primary]
@@ -41,25 +41,25 @@ on :message, :item_on_item do |ctx, player, message|
method = hash[secondary]
unless method.nil?
method.invoke(player, primary, secondary)
ctx.break_handler_chain
message.terminate
end
end
end
# The ItemOptionMessage handler for all Herblore-related functions.
on :message, :first_item_option do |ctx, player, message|
# The ItemOptionMessage listener for all Herblore-related functions.
on :message, :first_item_option do |player, message|
id = message.id
method = HERBLORE_ITEM[id]
unless method.nil?
method.invoke(player, id, message.slot)
ctx.break_handler_chain
message.terminate
end
method = DRINK_ITEM[id]
unless method.nil?
method.invoke(player, id, message.slot)
ctx.break_handler_chain
message.terminate
end
end
+1 -1
View File
@@ -223,7 +223,7 @@ class GrindingAction < Action
end
end
# Appends a ground ingredient to the ItemOnItemMessage handler interception.
# Appends a ground ingredient to the ItemOnItemMessage listener interception.
def append_ground(id, raw)
ground = GroundIngredient.new(id, raw)
append_herblore_item(ground, PESTLE_MORTAR, raw)
+6 -6
View File
@@ -118,7 +118,7 @@ class ItemSpellAction < SpellAction
end
# Intercepts the magic on item message.
on :message, :magic_on_item do |ctx, player, message|
on :message, :magic_on_item do |player, message|
spell = message.spell_id
alch = ALCHEMY_SPELLS[spell]
@@ -126,7 +126,7 @@ on :message, :magic_on_item do |ctx, player, message|
slot = message.slot
item = player.inventory.get(slot)
player.start_action(AlchemyAction.new(player, alch, slot, item))
ctx.break_handler_chain
message.terminate
return
end
@@ -135,18 +135,18 @@ on :message, :magic_on_item do |ctx, player, message|
slot = message.slot
item = player.inventory.get(slot)
player.start_action(EnchantAction.new(player, ench, slot, item, ENCHANT_ITEMS[item.id]))
ctx.break_handler_chain
message.terminate
end
end
# Intercepts the button message
on :message, :button do |ctx, player, message|
on :message, :button do |player, message|
button = message.widget_id
tele = TELEPORT_SPELLS[button]
unless tele.nil?
player.start_action(TeleportingAction.new(player, tele))
ctx.break_handler_chain
message.terminate
return
end
@@ -155,6 +155,6 @@ on :message, :button do |ctx, player, message|
slots = bone_slots player
if slots.length == 0 then player.send_message("You can't convert these bones!") else player.start_action(ConvertingAction.new(player, conv, slots)) end
ctx.break_handler_chain
message.terminate
end
end
+2 -2
View File
@@ -134,7 +134,7 @@ class ProspectingAction < DistancedAction
end
on :message, :first_object_action do |ctx, mob, message|
on :message, :first_object_action do |mob, message|
ore = ORES[message.id]
unless ore.nil?
@@ -142,7 +142,7 @@ on :message, :first_object_action do |ctx, mob, message|
end
end
on :message, :second_object_action do |ctx, mob, message|
on :message, :second_object_action do |mob, message|
ore = ORES[message.id]
if !ore.nil?
+2 -2
View File
@@ -51,11 +51,11 @@ class BuryBoneAction < Action
end
# Intercepts the first item option message.
on :message, :first_item_option do |ctx, player, message|
on :message, :first_item_option do |player, message|
bone = BONES[message.id]
unless bone == nil
player.start_action(BuryBoneAction.new(player, message.slot, bone))
ctx.break_handler_chain
message.terminate
end
end
+1 -1
View File
@@ -9,7 +9,7 @@ declare_attribute(:active_prayer, -1, :persistent)
PRAYERS = {}
# Intercept the ButtonMessage to toggle a prayer.
on :message, :button do |ctx, player, message|
on :message, :button do |player, message|
button = message.widget_id
prayer = PRAYERS[button]
+5 -5
View File
@@ -24,26 +24,26 @@ end
# Intercepts the item on object message.
on :message, :item_on_object do |ctx, player, message|
on :message, :item_on_object do |player, message|
talisman = TALISMANS[message.id]; altar = ENTRANCE_ALTARS[message.object_id]
unless (talisman.nil? || altar.nil?)
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position))
ctx.break_handler_chain
message.terminate
end
end
# Intercepts the first object action message.
on :message, :object_action do |ctx, player, message|
on :message, :object_action do |player, message|
if (message.option == 1)
object_id = message.id
if (altar = PORTALS[object_id]) != nil # Get the altar associated with this exit portal.
player.start_action(TeleportAction.new(player, altar.entrance_position, 1, altar.exit_position))
ctx.break_handler_chain
message.terminate
elsif (rune = RUNES[object_id]) != nil # Get the rune associated with this altar.
altar = CRAFTING_ALTARS[object_id]
player.start_action(RunecraftingAction.new(player, rune, altar.crafting_centre))
ctx.break_handler_chain
message.terminate
end
end
end
+2 -2
View File
@@ -30,11 +30,11 @@ def append_talisman(hash)
end
# Intercepts the item option message.
on :message, :fourth_item_option do |ctx, player, message|
on :message, :fourth_item_option do |player, message|
talisman = TALISMANS[message.id]
if (talisman != nil)
player.send_message(talisman.get_message(player.position))
ctx.break_handler_chain
message.terminate
end
end
+8 -8
View File
@@ -62,7 +62,7 @@ on :login do |event, player|
end
# Intercepts the SecondObjectAction message to support left-click access to the altar when wielding the correct tiara.
on :message, :second_object_action do |ctx, player, message|
on :message, :second_object_action do |player, message|
object_id = message.id
tiara = TIARAS_BY_ALTAR[object_id]
next if tiara.nil?
@@ -73,37 +73,37 @@ on :message, :second_object_action do |ctx, player, message|
altar = ENTRANCE_ALTARS[tiara.altar]
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) unless altar.nil?
ctx.break_handler_chain
message.terminate
end
end
# Intercepts the SecondItemAction message to allow for config sending.
on :message, :second_item_option do |ctx, player, message|
on :message, :second_item_option do |player, message|
tiara = TIARAS_BY_ID[message.id]
unless tiara.nil?
tiara.send_config(player)
ctx.break_handler_chain
message.terminate
end
end
# Intercepts the FirstItemAction message to allow for config sending.
on :message, :first_item_action do |ctx, player, message|
on :message, :first_item_action do |player, message|
tiara = TIARAS_BY_ID[message.id]
unless tiara.nil?
send_empty_config(player)
ctx.break_handler_chain
message.terminate
end
end
# Intercepts the ItemOnObject message to create the tiara.
on :message, :item_on_object do |ctx, player, message|
on :message, :item_on_object do |player, message|
tiara= TIARAS_BY_TALISMAN[message.id]; altar = CRAFTING_ALTARS[message.object_id]
return if (tiara.nil? || altar.nil?)
player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar))
ctx.break_handler_chain
message.terminate
end
# An action lets the player create a tiara when it comes within the specified distance of a specified position.
+1 -1
View File
@@ -5,7 +5,7 @@
#
# If you only wish to intercept a message, use the intercept method, e.g.
#
# intercept :item_on_item, used_id, target_id, :irreversible do |ctx, player, message|
# intercept :item_on_item, used_id, target_id, :irreversible do |player, message|
# # code here
# end
+3 -3
View File
@@ -36,11 +36,11 @@ class ItemOnItemPair
end
# Adds a message handler to the item on item message.
on :message, :item_on_item do |ctx, player, message|
# Adds a message listener to the item on item message.
on :message, :item_on_item do |player, message|
used, target = message.id, message.target_id
pair = ItemOnItemPair.new(used, target)
block = ITEM_PAIRS[pair]
block.call(ctx, player, message) unless block == nil
block.call(player, message) unless block == nil
end