From 1c6091251aa5751a0e478f69ed76f938b898f780 Mon Sep 17 00:00:00 2001 From: thispixel Date: Mon, 1 Feb 2016 11:26:31 +0000 Subject: [PATCH] fixes issue #148 - add consumable delays --- data/plugins/consumables/consumable.rb | 12 ++++++++---- data/plugins/consumables/food.rb | 8 ++++---- data/plugins/consumables/potions.rb | 4 +++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/data/plugins/consumables/consumable.rb b/data/plugins/consumables/consumable.rb index 5f34760c..a5b927e6 100644 --- a/data/plugins/consumables/consumable.rb +++ b/data/plugins/consumables/consumable.rb @@ -8,12 +8,13 @@ CONSUME_ANIMATION_ID = 829 # An item that can be consumed to produce a skill effect. class Consumable - attr_reader :name, :id, :sound + attr_reader :name, :id, :sound, :delay - def initialize(name, id, sound) + def initialize(name, id, sound, delay) @name = name.to_s.gsub(/_/, ' ') @id = id @sound = sound + @delay = delay end def consume(_player) @@ -44,8 +45,11 @@ class ConsumeAction < Action @consumable.consume(mob) mob.play_animation(Animation.new(CONSUME_ANIMATION_ID)) - @executions += 1 - else + end + + @executions += 1 + + if @executions >= @consumable.delay stop end end diff --git a/data/plugins/consumables/food.rb b/data/plugins/consumables/food.rb index 3b3ea219..7bab7185 100644 --- a/data/plugins/consumables/food.rb +++ b/data/plugins/consumables/food.rb @@ -13,8 +13,8 @@ EAT_FOOD_SOUND = 317 # TODO: delay eating times class Food < Consumable - def initialize(name, id, restoration, replace) - super(name, id, EAT_FOOD_SOUND) + def initialize(name, id, restoration, replace, delay) + super(name, id, EAT_FOOD_SOUND, delay) @restoration = restoration @replace = replace end @@ -48,7 +48,7 @@ def food(hash) replace = hash[:replace] || -1 delay = hash[:delay] || DEFAULT_DELAY # TODO: ?? - append_consumable(Food.new(name, id, restoration, replace)) + append_consumable(Food.new(name, id, restoration, replace, delay)) end # TODO: special effects @@ -88,7 +88,7 @@ food name: :bass, id: 365, restoration: 13 food name: :swordfish, id: 373, restoration: 14 food name: :cooked_jubbly, id: 7568, restoration: 15 food name: :monkfish, id: 7946, restoration: 16 -food name: :cooked_karambwan, id: 3144, restoration: 18 +food name: :cooked_karambwan, id: 3144, restoration: 18, delay: 0 food name: :shark, id: 385, restoration: 20 food name: :sea_turtle, id: 397, restoration: 21 food name: :manta_ray, id: 391, restoration: 22 diff --git a/data/plugins/consumables/potions.rb b/data/plugins/consumables/potions.rb index db32cd27..ee3cd009 100644 --- a/data/plugins/consumables/potions.rb +++ b/data/plugins/consumables/potions.rb @@ -13,13 +13,15 @@ module Constants # The id of an empty vial. EMPTY_VIAL_ID = 229 + # The delay between drinking potions + POTION_DELAY = 2 end # A drinkable potion. class Potion < Consumable def initialize(id, name, doses) - super(name, id, Constants::DRINK_POTION_SOUND) + super(name, id, Constants::DRINK_POTION_SOUND, Constants::POTION_DELAY) @doses = doses end