Files
apollo/data/plugins/consumables/consumable.rb
T
WizardJesse1 e194a6b46c Fixed food eating delays
* Removed the equal check due to causing issue's with food delays since when you eat one food it should be on the same tick
2016-01-31 15:50:20 -05:00

68 lines
1.4 KiB
Ruby

require 'java'
# A map of item ids to consumables.
CONSUMABLES = {}
# The id of the food consumption animation.
CONSUME_ANIMATION_ID = 829
# An item that can be consumed to produce a skill effect.
class Consumable
attr_reader :name, :id, :sound
def initialize(name, id, sound)
@name = name.to_s.gsub(/_/, ' ')
@id = id
@sound = sound
end
def consume(_player)
# Override to provide specific functionality.
end
end
# Appends a consumable to the map, with its id as the key.
def append_consumable(consumable)
CONSUMABLES[consumable.id] = consumable
end
# An Action used for food consumption.
class ConsumeAction < Action
attr_reader :consumable
def initialize(player, slot, consumable)
super(2, 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)
mob == other.mob
end
end
# Intercepts the first item option message and consumes the consumable, if necessary.
on :message, :first_item_option do |player, message|
consumable = CONSUMABLES[message.id]
unless consumable.nil?
player.start_action(ConsumeAction.new(player, message.slot, consumable))
message.terminate
end
end