diff --git a/data/plugins/combat/attack.rb b/data/plugins/combat/attack.rb index bf4ccd9d..42ad25ca 100644 --- a/data/plugins/combat/attack.rb +++ b/data/plugins/combat/attack.rb @@ -72,7 +72,7 @@ class MagicAttack < BaseAttack SPEED = 5 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 @hit_graphic = spell.hit_graphic diff --git a/data/plugins/combat/attack_requirements.rb b/data/plugins/combat/attack_requirements.rb index 3c0fd449..8032691f 100644 --- a/data/plugins/combat/attack_requirements.rb +++ b/data/plugins/combat/attack_requirements.rb @@ -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!') diff --git a/data/plugins/combat/combat_spell.rb b/data/plugins/combat/combat_spell.rb index 68aca543..58dc0e80 100644 --- a/data/plugins/combat/combat_spell.rb +++ b/data/plugins/combat/combat_spell.rb @@ -3,13 +3,11 @@ class CombatSpell attr_reader :button attr_reader :spellbook - - attr_reader :level + + attr_reader :requirements attr_reader :damage - attr_reader :runes - attr_reader :animation attr_reader :graphic @@ -20,12 +18,11 @@ class CombatSpell 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 @button = button - @level = level + @requirements = requirements @damage = damage - @runes = runes @animation = animation @graphic = graphic @hit_graphic = hit_graphic @@ -41,7 +38,7 @@ class CombatSpellDSL instance_eval(&block) end - def interface(spellbook:, button:) + def spellbook(spellbook, button:) @spellbook = spellbook @button = button end @@ -52,9 +49,15 @@ class CombatSpellDSL @hit_graphic = hit_graphic end - def projectile(projectile:, projectile_type:) - @projectile = projectile - @projectile_type = projectile_type + def projectile(id:, type:) + @projectile = id + @projectile_type = type + end + + def requirements(&block) + fail 'Block not given' unless block_given? + + @requirements = AttackRequirementDSL.new(&block).requirements end def level_requirement(level) @@ -70,7 +73,7 @@ class CombatSpellDSL end 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 diff --git a/data/plugins/combat/spells/bolts.rb b/data/plugins/combat/spells/bolts.rb index 10821883..fcad6cb5 100644 --- a/data/plugins/combat/spells/bolts.rb +++ b/data/plugins/combat/spells/bolts.rb @@ -1,12 +1,18 @@ create_combat_spell :wind_bolt do - interface spellbook: :modern, button: 10 - - level_requirement 17 + + spellbook :modern, button: 10 max_damage 8 - runes {} - + 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 create_projectile_type :bolt_spells, start_height: 46, end_height: 36, delay: 51, speed: 12, slope: 15, radius: 86 \ No newline at end of file