From c9592c38df621abe5b06745cd2201d12bf9c665a Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Thu, 24 Dec 2015 05:02:54 +0000 Subject: [PATCH] Complete special attacks; Fix WeaponClass issues * Adds a button property to a WeaponClasses styles, which maps a combat style to the button that was pressed in the combat tab. * Adds full support for special attacks, with their config IDs and buttons. * Adds the DDS special attack, along with the D2H special attack as some starting examples. * Rename the "no_weapon" Weapon to "unarmed", so it shows up better in the UI. --- data/plugins/combat/combat_action.rb | 2 - data/plugins/combat/weapon.rb | 28 ++++++------- data/plugins/combat/weapon_class.rb | 42 +++++++++++++------ data/plugins/combat/weapons/daggers.rb | 37 ++++++++++++++++ data/plugins/combat/weapons/scimitars.rb | 15 +++---- .../combat/weapons/two_handed_swords.rb | 21 ++++++---- data/plugins/combat/weapons/unarmed.rb | 4 +- 7 files changed, 101 insertions(+), 48 deletions(-) diff --git a/data/plugins/combat/combat_action.rb b/data/plugins/combat/combat_action.rb index b886a8ce..57d9fa33 100644 --- a/data/plugins/combat/combat_action.rb +++ b/data/plugins/combat/combat_action.rb @@ -100,7 +100,5 @@ class CombatAction < Action @combat_state.reset mob.attacking = false - - puts 'stopped combat action' end end \ No newline at end of file diff --git a/data/plugins/combat/weapon.rb b/data/plugins/combat/weapon.rb index 428efe52..930e7ec1 100644 --- a/data/plugins/combat/weapon.rb +++ b/data/plugins/combat/weapon.rb @@ -8,14 +8,6 @@ java_import 'org.apollo.game.model.inv.SynchronizationInventoryListener' WEAPONS = {} NAMED_WEAPONS = {} -COMBAT_STYLES = [ - :accurate, - :aggressive, - :defensive, - :controlled, - :alt_aggressive -] - def create_weapon(identifier, class_name = nil, named: false, &block) if named create_named_weapon(identifier, class_name, &block) @@ -28,11 +20,11 @@ end private def create_normal_weapon(item_matcher, class_name = nil, &block) - items = find_entities :item, item_matcher.to_s.gsub(/_/, ' '), -1 + items = find_entities :item, item_matcher, -1 items.each do |item_id| definition = ItemDefinition.lookup(item_id) definition_name = definition.name.downcase.to_s - + if class_name.nil? class_name = case definition_name @@ -40,18 +32,20 @@ def create_normal_weapon(item_matcher, class_name = nil, &block) :two_handed_sword when /[a-zA-Z]+ scimitar/ :scimitar + when /[a-zA-Z]+ dagger/ + :dagger else raise "Couldn't find a suitable weapon class for the given weapon." end end - WEAPONS[item_id] = Weapon.new(WEAPON_CLASSES[class_name]) + WEAPONS[item_id] = Weapon.new(definition.name, WEAPON_CLASSES[class_name]) WEAPONS[item_id].instance_eval &block end end def create_named_weapon(name, class_name, &block) - NAMED_WEAPONS[name] = Weapon.new WEAPON_CLASSES[class_name] + NAMED_WEAPONS[name] = Weapon.new name.to_s.capitalize, WEAPON_CLASSES[class_name] NAMED_WEAPONS[name].instance_eval &block end @@ -60,11 +54,12 @@ end # * has an optional special_attack # * belongs to a certain WeaponClass, and inherits bonuses from it. class Weapon - attr_reader :weapon_class, :special_attack + attr_reader :name, :weapon_class, :special_attack include Combat::BonusContainer - def initialize(weapon_class) + def initialize(name, weapon_class) + @name = name @weapon_class = weapon_class @special_attack = nil end @@ -74,7 +69,10 @@ class Weapon end def set_special_attack(energy_requirement:, animation:, graphic: nil, &block) + # todo figure out if ranged or melee + requirements = [SpecialEnergyRequirement.new(energy_requirement)] + @special_attack = ProcAttack.new(block, animation: animation, graphic: graphic, requirements: requirements) end end @@ -96,9 +94,7 @@ def update_weapon_animations(player) [:stand, :walk, :run, :idle_turn, :turn_around, :turn_left, :turn_right].each do |key| animation = weapon_class.other_animation(key) - puts animation - puts key unless animation.nil? case key when :stand diff --git a/data/plugins/combat/weapon_class.rb b/data/plugins/combat/weapon_class.rb index c427644a..fd57921b 100644 --- a/data/plugins/combat/weapon_class.rb +++ b/data/plugins/combat/weapon_class.rb @@ -24,7 +24,7 @@ RANGE_COMBAT_STYLES = [ ] class WeaponClass - attr_reader :widget, :name + attr_reader :widget, :name, :special_bar_button, :special_bar_config include Combat::BonusContainer @@ -37,7 +37,7 @@ class WeaponClass @animations = {} end - def add_style(style, attack_type: nil, speed: nil, animation: nil, block_animation: nil, range: 1) + def add_style(style, button: nil, attack_type: nil, speed: nil, animation: nil, block_animation: nil, range: 1) raise 'Invalid combat style given' unless COMBAT_STYLES.include? style @styles[style] = { @@ -45,11 +45,12 @@ class WeaponClass :speed => speed, :animation => animation, :block_animation => block_animation, - :range => range + :range => range, + :button => button == nil ? @styles.size + 1 : button } - + @style_offsets.push style - + if MELEE_COMBAT_STYLES.include? style @style_attacks[style] = Attack.new(animation: animation) end @@ -67,16 +68,30 @@ class WeaponClass @styles[style][:block_animation] end + def button(style) + @styles[style][:button] + end + + def config(style) + @style_offsets.find_index {|v| v == style } + end + def other_animation(type) @animations[type] end - + def speed(style) @styles[style][:speed] || default_speed end - def style_at(offset) - @style_offsets[offset] + def style_at(button) + selected_style = @styles.select { |key, hash| hash[:button] == button }.keys[0] + + if selected_style == nil + selected_style = @styles.min_by { |key, hash| hash[:button] }.first + end + + selected_style end def default_speed(speed = nil) @@ -87,12 +102,13 @@ class WeaponClass @default_speed end - def special_bar(id = nil) - unless id.nil? - @special_bar = id - end + def special_bar(config, button) + @special_bar_config = config + @special_bar_button = button + end - @special_bar + def special_bar? + !@special_bar_button.nil? and !@special_bar_config.nil? end def animations(stand: nil, walk: nil, run: nil, idle_turn: nil, turn_around: nil, turn_left: nil, turn_right: nil) diff --git a/data/plugins/combat/weapons/daggers.rb b/data/plugins/combat/weapons/daggers.rb index e69de29b..0405148f 100644 --- a/data/plugins/combat/weapons/daggers.rb +++ b/data/plugins/combat/weapons/daggers.rb @@ -0,0 +1,37 @@ +DAGGER_WIDGET_ID = 89 +DAGGER_SPECIAL_CONFIG_ID = 12 +DAGGER_SPECIAL_BUTTON_ID = 10 + +create_weapon_class :dagger, widget: DAGGER_WIDGET_ID do + default_speed 4 + + attack_bonuses crush: -4, magic: 1 + defence_bonuses magic: 1 + + add_style :accurate, attack_type: :stab, animation: 7041, button: 2 + add_style :aggressive, attack_type: :stab, animation: 7041, button: 3 + add_style :alt_aggressive, attack_type: :slash, animation: 7048, button: 4 + add_style :defensive, attack_type: :stab, animation: 7049, button: 5 +end + +# Need a separate WeaponClass for the dragon dagger because +# of the differing animations +create_weapon_class :dragon_dagger, widget: DAGGER_WIDGET_ID do + default_speed 4 + special_bar DAGGER_SPECIAL_CONFIG_ID, DAGGER_SPECIAL_BUTTON_ID + + attack_bonuses crush: -4, magic: 1 + defence_bonuses magic: 1 + + add_style :accurate, attack_type: :stab, animation: 402, button: 2 + add_style :aggressive, attack_type: :stab, animation: 402, button: 3 + add_style :alt_aggressive, attack_type: :slash, animation: 402, button: 4 + add_style :defensive, attack_type: :stab, animation: 402, button: 5 +end + +create_weapon /(?:drag|dragon) dagger.*/, :dragon_dagger do + set_special_attack energy_requirement: 25, animation: 1062, graphic: {id: 252, height: 100} do |source, target| + damage! source, target, CombatUtil::calculate_hit(source, target) + damage! source, target, CombatUtil::calculate_hit(source, target), 1 + end +end \ No newline at end of file diff --git a/data/plugins/combat/weapons/scimitars.rb b/data/plugins/combat/weapons/scimitars.rb index 74e94692..f7f78b1f 100644 --- a/data/plugins/combat/weapons/scimitars.rb +++ b/data/plugins/combat/weapons/scimitars.rb @@ -1,17 +1,18 @@ -SCIMITAR_WIDGET_ID = 81 -SCIMITAR_SPECIAL_BAR_ID = 21 +SCIMITAR_WIDGET_ID = 81 +SCIMITAR_SPECIAL_BAR_CONFIG_ID = 21 +SCIMITAR_SPECIAL_BAR_BUTTON_ID = 21 create_weapon_class :scimitar, widget: SCIMITAR_WIDGET_ID do default_speed 4 - special_bar SCIMITAR_SPECIAL_BAR_ID + special_bar SCIMITAR_SPECIAL_BAR_CONFIG_ID, SCIMITAR_SPECIAL_BAR_BUTTON_ID attack_bonuses crush: -2 defence_bonuses slash: -1 - add_style :accurate, attack_type: :slash, animation: 390 - add_style :aggressive, attack_type: :slash, animation: 390 - add_style :alt_aggressive, attack_type: :stab, animation: 391 - add_style :defensive, attack_type: :slash, animation: 390 + add_style :accurate, attack_type: :slash, animation: 390, button: 2 + add_style :aggressive, attack_type: :slash, animation: 390, button: 3 + add_style :alt_aggressive, attack_type: :stab, animation: 391, button: 4 + add_style :defensive, attack_type: :slash, animation: 390, button: 5 end create_weapon :iron_scimitar do diff --git a/data/plugins/combat/weapons/two_handed_swords.rb b/data/plugins/combat/weapons/two_handed_swords.rb index a70efb1a..3fcf374f 100644 --- a/data/plugins/combat/weapons/two_handed_swords.rb +++ b/data/plugins/combat/weapons/two_handed_swords.rb @@ -1,19 +1,20 @@ TWO_HANDED_SWORD_WIDGET_ID = 82 -TWO_HANDED_SWORD_SPECIAL_ID = 12 +TWO_HANDED_SWORD_SPECIAL_CONFIG_ID = 12 +TWO_HANDED_SWORD_SPECIAL_BUTTON_ID = 10 create_weapon_class :two_handed_sword, widget: TWO_HANDED_SWORD_WIDGET_ID do default_speed 7 - special_bar TWO_HANDED_SWORD_SPECIAL_ID - + special_bar TWO_HANDED_SWORD_SPECIAL_CONFIG_ID, TWO_HANDED_SWORD_SPECIAL_BUTTON_ID + animations stand: 7047, walk: 7046, run: 7039, idle_turn: 7044, turn_around: 7044, turn_left: 7043, turn_right: 7044 - + attack_bonuses stab: -4, magic: -4 defence_bonuses range: -1 - add_style :accurate, attack_type: :slash, animation: 7041 - add_style :aggressive, attack_type: :crush, animation: 7041 - add_style :alt_aggressive, attack_type: :crush, animation: 7048 - add_style :defensive, attack_type: :slash, animation: 7049 + add_style :accurate, attack_type: :slash, animation: 7041, button: 2 + add_style :aggressive, attack_type: :crush, animation: 7041, button: 3 + add_style :alt_aggressive, attack_type: :crush, animation: 7048, button: 4 + add_style :defensive, attack_type: :slash, animation: 7049, button: 5 end create_weapon :iron_2h_sword do @@ -49,4 +50,8 @@ end create_weapon :dragon_2h_sword do attack_bonuses slash: 92, crush: 80 other_bonuses melee_strength: 70 + + set_special_attack energy_requirement: 60, animation: 3157, graphic: 1225 do |source, target| + damage! source, target, 5 + end end \ No newline at end of file diff --git a/data/plugins/combat/weapons/unarmed.rb b/data/plugins/combat/weapons/unarmed.rb index db15a953..dbee6cd6 100644 --- a/data/plugins/combat/weapons/unarmed.rb +++ b/data/plugins/combat/weapons/unarmed.rb @@ -1,4 +1,4 @@ -create_weapon_class :unarmed, widget: -1 do +create_weapon_class :no_weapon, widget: 92 do default_speed 4 add_style :accurate, animation: 422, block_animation: 424 @@ -6,6 +6,6 @@ create_weapon_class :unarmed, widget: -1 do add_style :defensive, animation: 422, block_animation: 424 end -create_weapon :no_weapon, :unarmed, named: true do +create_weapon :unarmed, :no_weapon, named: true do # Todo factor out empty blocks end \ No newline at end of file