mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Start an action on consumption to prevent multiple consumptions per tick.
This commit is contained in:
@@ -26,15 +26,38 @@ def append_consumable(consumable)
|
|||||||
CONSUMABLES[consumable.id] = consumable
|
CONSUMABLES[consumable.id] = consumable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ConsumeAction < Action
|
||||||
|
attr_reader :consumable
|
||||||
|
|
||||||
|
def initialize(player, slot, consumable)
|
||||||
|
super(0, true, player)
|
||||||
|
@consumable = consumable
|
||||||
|
@slot = slot
|
||||||
|
@executions = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute()
|
||||||
|
if @executions == 0
|
||||||
|
mob.inventory.reset(@slot)
|
||||||
|
consumable.consume(mob)
|
||||||
|
mob.play_animation(Animation.new(CONSUME_ANIMATION_ID))
|
||||||
|
@executions += 1
|
||||||
|
else
|
||||||
|
stop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def equals(other)
|
||||||
|
return (mob == other.mob && @consumable.id == other.consumable.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Intercepts the first item option event and consumes the consumable, if necessary.
|
# Intercepts the first item option event and consumes the consumable, if necessary.
|
||||||
on :event, :item_option do |ctx, player, event|
|
on :event, :item_option do |ctx, player, event|
|
||||||
if (event.option == 1)
|
if (event.option == 1)
|
||||||
consumable = CONSUMABLES[event.id]
|
consumable = CONSUMABLES[event.id]
|
||||||
unless consumable == nil
|
unless consumable == nil
|
||||||
player.inventory.reset(event.slot)
|
player.start_action(ConsumeAction.new(player, event.slot, consumable))
|
||||||
player.play_animation(Animation.new(CONSUME_ANIMATION_ID))
|
|
||||||
consumable.consume(player)
|
|
||||||
|
|
||||||
ctx.break_handler_chain
|
ctx.break_handler_chain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user