mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Add AttackRequirementDSL and small changes to CombatSpellDSL
This commit is contained in:
committed by
Gary Tierney
parent
ec248a185b
commit
682e48bdc8
@@ -72,7 +72,7 @@ class MagicAttack < BaseAttack
|
|||||||
SPEED = 5
|
SPEED = 5
|
||||||
|
|
||||||
def initialize(spell)
|
def initialize(spell)
|
||||||
super(animation: spell.animation, graphic: spell.graphic, speed: SPEED, range: MAX_DISTANCE)
|
super(animation: spell.animation, graphic: spell.graphic, requirements: spell.requirements, speed: SPEED, range: MAX_DISTANCE)
|
||||||
|
|
||||||
@damage = spell.damage
|
@damage = spell.damage
|
||||||
@hit_graphic = spell.hit_graphic
|
@hit_graphic = spell.hit_graphic
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
java_import 'org.apollo.cache.def.ItemDefinition'
|
java_import 'org.apollo.cache.def.ItemDefinition'
|
||||||
java_import 'org.apollo.game.model.entity.EquipmentConstants'
|
java_import 'org.apollo.game.model.entity.EquipmentConstants'
|
||||||
|
java_import 'org.apollo.game.model.entity.Skill'
|
||||||
java_import 'org.apollo.cache.def.EquipmentDefinition'
|
java_import 'org.apollo.cache.def.EquipmentDefinition'
|
||||||
|
|
||||||
class AttackRequirementException < Exception
|
class AttackRequirementException < Exception
|
||||||
@@ -20,6 +21,26 @@ class AttackRequirement
|
|||||||
end
|
end
|
||||||
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
|
class SpecialEnergyRequirement < AttackRequirement
|
||||||
def initialize(amount)
|
def initialize(amount)
|
||||||
@amount = amount
|
@amount = amount
|
||||||
@@ -36,15 +57,76 @@ class SpecialEnergyRequirement < AttackRequirement
|
|||||||
|
|
||||||
def apply!(player)
|
def apply!(player)
|
||||||
player.special_energy = player.special_energy - @amount
|
player.special_energy = player.special_energy - @amount
|
||||||
player.using_special = false
|
player.using_special = false
|
||||||
|
|
||||||
update_special_bar player
|
update_special_bar player
|
||||||
end
|
end
|
||||||
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
|
class ItemRequirement < AttackRequirement
|
||||||
def initialize(item, amount)
|
def initialize(item, amount)
|
||||||
@item = item
|
@item = item
|
||||||
@amount = amount
|
@amount = amount
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,10 +154,10 @@ class AmmoRequirement < AttackRequirement
|
|||||||
|
|
||||||
def validate(player)
|
def validate(player)
|
||||||
equipped_weapon_item = player.equipment.get(EquipmentConstants::WEAPON)
|
equipped_weapon_item = player.equipment.get(EquipmentConstants::WEAPON)
|
||||||
equipped_weapon_def = EquipmentDefinition.lookup(equipped_weapon_item.id)
|
equipped_weapon_def = EquipmentDefinition.lookup(equipped_weapon_item.id)
|
||||||
equipped_weapon = EquipmentUtil.equipped_weapon player
|
equipped_weapon = EquipmentUtil.equipped_weapon player
|
||||||
equipped_ammo = EquipmentUtil.equipped_ammo player
|
equipped_ammo = EquipmentUtil.equipped_ammo player
|
||||||
equipped_ammo_amt = player.equipment.get(EquipmentConstants::AMMO).amount
|
equipped_ammo_amt = player.equipment.get(EquipmentConstants::AMMO).amount
|
||||||
|
|
||||||
if equipped_ammo.nil?
|
if equipped_ammo.nil?
|
||||||
fail AttackRequirementException.new('You have no ammo left in your quiver!')
|
fail AttackRequirementException.new('You have no ammo left in your quiver!')
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ class CombatSpell
|
|||||||
|
|
||||||
attr_reader :spellbook
|
attr_reader :spellbook
|
||||||
|
|
||||||
attr_reader :level
|
attr_reader :requirements
|
||||||
|
|
||||||
attr_reader :damage
|
attr_reader :damage
|
||||||
|
|
||||||
attr_reader :runes
|
|
||||||
|
|
||||||
attr_reader :animation
|
attr_reader :animation
|
||||||
|
|
||||||
attr_reader :graphic
|
attr_reader :graphic
|
||||||
@@ -20,12 +18,11 @@ class CombatSpell
|
|||||||
|
|
||||||
attr_reader :projectile_type
|
attr_reader :projectile_type
|
||||||
|
|
||||||
def initialize(button, spellbook, level, damage, runes, animation, graphic, hit_graphic, projectile, projectile_type)
|
def initialize(button, spellbook, requirements, damage, animation, graphic, hit_graphic, projectile, projectile_type)
|
||||||
@spellbook = spellbook
|
@spellbook = spellbook
|
||||||
@button = button
|
@button = button
|
||||||
@level = level
|
@requirements = requirements
|
||||||
@damage = damage
|
@damage = damage
|
||||||
@runes = runes
|
|
||||||
@animation = animation
|
@animation = animation
|
||||||
@graphic = graphic
|
@graphic = graphic
|
||||||
@hit_graphic = hit_graphic
|
@hit_graphic = hit_graphic
|
||||||
@@ -41,7 +38,7 @@ class CombatSpellDSL
|
|||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def interface(spellbook:, button:)
|
def spellbook(spellbook, button:)
|
||||||
@spellbook = spellbook
|
@spellbook = spellbook
|
||||||
@button = button
|
@button = button
|
||||||
end
|
end
|
||||||
@@ -52,9 +49,15 @@ class CombatSpellDSL
|
|||||||
@hit_graphic = hit_graphic
|
@hit_graphic = hit_graphic
|
||||||
end
|
end
|
||||||
|
|
||||||
def projectile(projectile:, projectile_type:)
|
def projectile(id:, type:)
|
||||||
@projectile = projectile
|
@projectile = id
|
||||||
@projectile_type = projectile_type
|
@projectile_type = type
|
||||||
|
end
|
||||||
|
|
||||||
|
def requirements(&block)
|
||||||
|
fail 'Block not given' unless block_given?
|
||||||
|
|
||||||
|
@requirements = AttackRequirementDSL.new(&block).requirements
|
||||||
end
|
end
|
||||||
|
|
||||||
def level_requirement(level)
|
def level_requirement(level)
|
||||||
@@ -70,7 +73,7 @@ class CombatSpellDSL
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_combat_spell
|
def to_combat_spell
|
||||||
return CombatSpell.new(@button, @spellbook, @level, @damage, @runes, @animation, @graphic, @hit_graphic, @projectile, @projectile_type)
|
return CombatSpell.new(@button, @spellbook, @requirements, @damage, @animation, @graphic, @hit_graphic, @projectile, @projectile_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
create_combat_spell :wind_bolt do
|
create_combat_spell :wind_bolt do
|
||||||
interface spellbook: :modern, button: 10
|
|
||||||
|
|
||||||
level_requirement 17
|
spellbook :modern, button: 10
|
||||||
max_damage 8
|
max_damage 8
|
||||||
runes {}
|
|
||||||
|
|
||||||
effects animation: 1162, graphic: {id: 117, height: 100}, hit_graphic: {id: 119, delay: 100}
|
effects animation: 1162, graphic: {id: 117, height: 100}, hit_graphic: {id: 119, delay: 100}
|
||||||
projectile projectile: 118, projectile_type: :bolt_spells
|
projectile id: 118, type: :bolt_spells
|
||||||
|
|
||||||
|
requirements do
|
||||||
|
rune :air, amount: 3
|
||||||
|
rune :chaos, amount: 1
|
||||||
|
|
||||||
|
skill :magic, level: 17
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_projectile_type :bolt_spells, start_height: 46, end_height: 36, delay: 51, speed: 12, slope: 15, radius: 86
|
create_projectile_type :bolt_spells, start_height: 46, end_height: 36, delay: 51, speed: 12, slope: 15, radius: 86
|
||||||
Reference in New Issue
Block a user