mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Replace RuneRequirement with ItemRequirement
This commit is contained in:
@@ -22,6 +22,11 @@ class AttackRequirement
|
|||||||
end
|
end
|
||||||
|
|
||||||
class AttackRequirementDSL
|
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
|
attr_reader :requirements
|
||||||
|
|
||||||
@@ -31,8 +36,9 @@ class AttackRequirementDSL
|
|||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rune(type, amount:)
|
def rune(type, amount: 1)
|
||||||
requirements << RuneRequirement.new(type, amount)
|
fail 'Invalid rune type' unless RUNES.key? type
|
||||||
|
requirements << ItemRequirement.new(RUNES[type], amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
def skill(skill, level:)
|
def skill(skill, level:)
|
||||||
@@ -92,38 +98,6 @@ class LevelRequirement < AttackRequirement
|
|||||||
end
|
end
|
||||||
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
|
class ItemRequirement < AttackRequirement
|
||||||
def initialize(item, amount)
|
def initialize(item, amount)
|
||||||
@item = item
|
@item = item
|
||||||
|
|||||||
Reference in New Issue
Block a user