mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Add AttackRequirementDSL and small changes to CombatSpellDSL
This commit is contained in:
committed by
Gary Tierney
parent
ec248a185b
commit
682e48bdc8
@@ -1,5 +1,6 @@
|
||||
java_import 'org.apollo.cache.def.ItemDefinition'
|
||||
java_import 'org.apollo.game.model.entity.EquipmentConstants'
|
||||
java_import 'org.apollo.game.model.entity.Skill'
|
||||
java_import 'org.apollo.cache.def.EquipmentDefinition'
|
||||
|
||||
class AttackRequirementException < Exception
|
||||
@@ -20,6 +21,26 @@ class AttackRequirement
|
||||
end
|
||||
end
|
||||
|
||||
class AttackRequirementDSL
|
||||
|
||||
attr_reader :requirements
|
||||
|
||||
def initialize(&block)
|
||||
@requirements = []
|
||||
|
||||
instance_eval(&block)
|
||||
end
|
||||
|
||||
def rune(type, amount:)
|
||||
requirements << RuneRequirement.new(type, amount)
|
||||
end
|
||||
|
||||
def skill(skill, level:)
|
||||
requirements << LevelRequirement.new(skill, level)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class SpecialEnergyRequirement < AttackRequirement
|
||||
def initialize(amount)
|
||||
@amount = amount
|
||||
@@ -36,15 +57,76 @@ class SpecialEnergyRequirement < AttackRequirement
|
||||
|
||||
def apply!(player)
|
||||
player.special_energy = player.special_energy - @amount
|
||||
player.using_special = false
|
||||
player.using_special = false
|
||||
|
||||
update_special_bar player
|
||||
end
|
||||
end
|
||||
|
||||
class LevelRequirement < AttackRequirement
|
||||
|
||||
SKILLS = {
|
||||
:magic => Skill::MAGIC
|
||||
}
|
||||
|
||||
def initialize(type, level)
|
||||
fail "Could not find '#{type}' skill." unless SKILLS.has_key?(type)
|
||||
|
||||
@skill = SKILLS[type]
|
||||
@level = level
|
||||
end
|
||||
|
||||
def validate(player)
|
||||
current_level = player.skill_set.current_level(@skill)
|
||||
|
||||
throw AttackRequirementException.new(skill_requirement_message) unless current_level >= @level
|
||||
end
|
||||
|
||||
def apply!(player)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def skill_requirement_message
|
||||
"TODO"
|
||||
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
|
||||
@item = item
|
||||
@amount = amount
|
||||
end
|
||||
|
||||
@@ -72,10 +154,10 @@ class AmmoRequirement < AttackRequirement
|
||||
|
||||
def validate(player)
|
||||
equipped_weapon_item = player.equipment.get(EquipmentConstants::WEAPON)
|
||||
equipped_weapon_def = EquipmentDefinition.lookup(equipped_weapon_item.id)
|
||||
equipped_weapon = EquipmentUtil.equipped_weapon player
|
||||
equipped_ammo = EquipmentUtil.equipped_ammo player
|
||||
equipped_ammo_amt = player.equipment.get(EquipmentConstants::AMMO).amount
|
||||
equipped_weapon_def = EquipmentDefinition.lookup(equipped_weapon_item.id)
|
||||
equipped_weapon = EquipmentUtil.equipped_weapon player
|
||||
equipped_ammo = EquipmentUtil.equipped_ammo player
|
||||
equipped_ammo_amt = player.equipment.get(EquipmentConstants::AMMO).amount
|
||||
|
||||
if equipped_ammo.nil?
|
||||
fail AttackRequirementException.new('You have no ammo left in your quiver!')
|
||||
|
||||
Reference in New Issue
Block a user