mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 00:38:46 +00:00
Add the new utils plugin, change entity spawning and the lookup command plugins to use it.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
|
||||
# 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 handler to the item on item message.
|
||||
on :message, :item_on_item do |ctx, 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
|
||||
end
|
||||
Reference in New Issue
Block a user