From 27e06c304d8a778c8a96f6b3b37d1b2639be9678 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Fri, 29 Jan 2016 21:29:18 +0000 Subject: [PATCH] Replace RuneRequirement with ItemRequirement --- data/plugins/combat/attack_requirements.rb | 44 +++++----------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/data/plugins/combat/attack_requirements.rb b/data/plugins/combat/attack_requirements.rb index 8032691f..afb449b9 100644 --- a/data/plugins/combat/attack_requirements.rb +++ b/data/plugins/combat/attack_requirements.rb @@ -22,6 +22,11 @@ class AttackRequirement end class AttackRequirementDSL + RUNES = { + :air => 556, :water => 555, :earth => 557, :fire => 554, + :mind => 558, :chaos => 562, :death => 560, :blood => 565, + :cosmic => 564, :law => 563, :nature => 561, :soul => 566 + } attr_reader :requirements @@ -31,14 +36,15 @@ class AttackRequirementDSL instance_eval(&block) end - def rune(type, amount:) - requirements << RuneRequirement.new(type, amount) + def rune(type, amount: 1) + fail 'Invalid rune type' unless RUNES.key? type + requirements << ItemRequirement.new(RUNES[type], amount) end def skill(skill, level:) requirements << LevelRequirement.new(skill, level) end - + end class SpecialEnergyRequirement < AttackRequirement @@ -92,38 +98,6 @@ class LevelRequirement < AttackRequirement end end -class RuneRequirement < AttackRequirement - - RUNES = { - :air => 556, :water => 555, :earth => 557, :fire => 554, - :mind => 558, :chaos => 562, :death => 560, :blood => 565, - :cosmic => 564, :law => 563, :nature => 561, :soul => 566 - } - - def initialize(type, amount) - fail "Could not find '#{type}' rune." unless RUNES.has_key?(type) - - @rune = RUNES[type] - @amount = amount - end - - def validate(player) - throw AttackRequirementException.new(item_missing_message) unless player.inventory.get_amount(@rune) >= @amount - end - - def apply!(player) - player.inventory.remove(@rune, @amount) - end - - private - - def item_missing_message - definition = ItemDefinition.lookup(@rune) - - "You don't have enough #{definition.name}s" - end -end - class ItemRequirement < AttackRequirement def initialize(item, amount) @item = item