mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 16:49:11 +00:00
654a1a6dfd
Rebased several other pieces of code
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
|
|
# Adds an interception for the ItemOnItem message
|
|
add_interception :item_on_item do |used, target, reversible, block|
|
|
interception = ItemOnItemPair.new(used, target)
|
|
|
|
ITEM_PAIRS[interception] = block
|
|
ITEM_PAIRS[interception.reverse] = block if reversible == :reversible
|
|
end
|
|
|
|
private
|
|
|
|
# A hash of ItemOnItemPairs to blocks.
|
|
ITEM_PAIRS = {}
|
|
|
|
# A pair of items that will cause a block to be executed if one (the 'used' item) is used on the other (the 'target' item).
|
|
class ItemOnItemPair
|
|
attr_reader :used, :target
|
|
|
|
def initialize(used, target)
|
|
@used = used
|
|
@target = target
|
|
end
|
|
|
|
# Returns a new ItemOnItemPair that is the reverse of this.
|
|
def reverse
|
|
return ItemOnItemPair.new(@target, @used)
|
|
end
|
|
|
|
def eql?(other)
|
|
return (other.kind_of?(ItemOnItemPair) && @used == other.used && @target == other.target)
|
|
end
|
|
|
|
def hash
|
|
return @used << 16 | @target
|
|
end
|
|
|
|
end
|
|
|
|
# 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(player, message) unless block == nil
|
|
end |