Fix bug where multiple (identical) bone burying actions would replace each other instead of cancelling.

This commit is contained in:
Major-
2014-08-08 14:13:58 +01:00
parent 3931b9eb48
commit 7924791405
+18 -11
View File
@@ -2,18 +2,17 @@ require 'java'
java_import 'org.apollo.game.action.Action' java_import 'org.apollo.game.action.Action'
java_import 'org.apollo.game.model.Animation' java_import 'org.apollo.game.model.Animation'
java_import 'org.apollo.game.model.entity.Skill'
BURY_BONE_ANIMATION = 827 BURY_BONE_ANIMATION = 827
BONES = {} BONES = {}
# Represents a bone with an id and experience value. # A bone with an id and experience value.
class Bone class Bone
attr_reader :id, :exp attr_reader :id, :experience
def initialize(id, exp) def initialize(id, experience)
@id = id @id = id
@exp = exp @experience = experience
end end
end end
@@ -21,28 +20,36 @@ end
# An action where a bone in a player's inventory is buried. # An action where a bone in a player's inventory is buried.
class BuryBoneAction < Action class BuryBoneAction < Action
attr_reader :slot, :bone
def initialize(mob, slot, bone) def initialize(mob, slot, bone)
super(1, false, mob) super(1, true, mob)
@slot = slot @slot = slot
@bone = bone @bone = bone
@executions = 0
mob.play_animation(Animation.new(BURY_BONE_ANIMATION))
mob.send_message('You dig a hole in the ground...')
end end
def execute def execute
if @executions == 0
mob.send_message('You dig a hole in the ground...')
@executions += 1
elsif @executions == 1
if mob.inventory.get(@slot).id == @bone.id if mob.inventory.get(@slot).id == @bone.id
mob.play_animation(Animation.new(BURY_BONE_ANIMATION))
mob.send_message('You bury the bones.') mob.send_message('You bury the bones.')
mob.inventory.reset(@slot) mob.inventory.reset(@slot)
mob.skill_set.add_experience(Skill::PRAYER, @bone.exp) mob.skill_set.add_experience(PRAYER_SKILL_ID, @bone.experience)
end end
stop stop
end end
end
def equals(other)
return (get_class == other.get_class and @bone == other.bone)
end
end end
# Intercepts the first item option message, # Intercepts the first item option message.
on :message, :first_item_option do |ctx, player, message| on :message, :first_item_option do |ctx, player, message|
bone = BONES[message.id] bone = BONES[message.id]
unless bone == nil unless bone == nil