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.
This commit is contained in:
Gary Tierney
2015-12-24 05:02:54 +00:00
parent 348e5cc8dc
commit c9592c38df
7 changed files with 101 additions and 48 deletions
-2
View File
@@ -100,7 +100,5 @@ class CombatAction < Action
@combat_state.reset @combat_state.reset
mob.attacking = false mob.attacking = false
puts 'stopped combat action'
end end
end end
+11 -15
View File
@@ -8,14 +8,6 @@ java_import 'org.apollo.game.model.inv.SynchronizationInventoryListener'
WEAPONS = {} WEAPONS = {}
NAMED_WEAPONS = {} NAMED_WEAPONS = {}
COMBAT_STYLES = [
:accurate,
:aggressive,
:defensive,
:controlled,
:alt_aggressive
]
def create_weapon(identifier, class_name = nil, named: false, &block) def create_weapon(identifier, class_name = nil, named: false, &block)
if named if named
create_named_weapon(identifier, class_name, &block) create_named_weapon(identifier, class_name, &block)
@@ -28,7 +20,7 @@ end
private private
def create_normal_weapon(item_matcher, class_name = nil, &block) 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| items.each do |item_id|
definition = ItemDefinition.lookup(item_id) definition = ItemDefinition.lookup(item_id)
definition_name = definition.name.downcase.to_s definition_name = definition.name.downcase.to_s
@@ -40,18 +32,20 @@ def create_normal_weapon(item_matcher, class_name = nil, &block)
:two_handed_sword :two_handed_sword
when /[a-zA-Z]+ scimitar/ when /[a-zA-Z]+ scimitar/
:scimitar :scimitar
when /[a-zA-Z]+ dagger/
:dagger
else else
raise "Couldn't find a suitable weapon class for the given weapon." raise "Couldn't find a suitable weapon class for the given weapon."
end end
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 WEAPONS[item_id].instance_eval &block
end end
end end
def create_named_weapon(name, class_name, &block) 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 NAMED_WEAPONS[name].instance_eval &block
end end
@@ -60,11 +54,12 @@ end
# * has an optional special_attack # * has an optional special_attack
# * belongs to a certain WeaponClass, and inherits bonuses from it. # * belongs to a certain WeaponClass, and inherits bonuses from it.
class Weapon class Weapon
attr_reader :weapon_class, :special_attack attr_reader :name, :weapon_class, :special_attack
include Combat::BonusContainer include Combat::BonusContainer
def initialize(weapon_class) def initialize(name, weapon_class)
@name = name
@weapon_class = weapon_class @weapon_class = weapon_class
@special_attack = nil @special_attack = nil
end end
@@ -74,7 +69,10 @@ class Weapon
end end
def set_special_attack(energy_requirement:, animation:, graphic: nil, &block) 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
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| [:stand, :walk, :run, :idle_turn, :turn_around, :turn_left, :turn_right].each do |key|
animation = weapon_class.other_animation(key) animation = weapon_class.other_animation(key)
puts animation
puts key
unless animation.nil? unless animation.nil?
case key case key
when :stand when :stand
+26 -10
View File
@@ -24,7 +24,7 @@ RANGE_COMBAT_STYLES = [
] ]
class WeaponClass class WeaponClass
attr_reader :widget, :name attr_reader :widget, :name, :special_bar_button, :special_bar_config
include Combat::BonusContainer include Combat::BonusContainer
@@ -37,7 +37,7 @@ class WeaponClass
@animations = {} @animations = {}
end 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 raise 'Invalid combat style given' unless COMBAT_STYLES.include? style
@styles[style] = { @styles[style] = {
@@ -45,7 +45,8 @@ class WeaponClass
:speed => speed, :speed => speed,
:animation => animation, :animation => animation,
:block_animation => block_animation, :block_animation => block_animation,
:range => range :range => range,
:button => button == nil ? @styles.size + 1 : button
} }
@style_offsets.push style @style_offsets.push style
@@ -67,6 +68,14 @@ class WeaponClass
@styles[style][:block_animation] @styles[style][:block_animation]
end end
def button(style)
@styles[style][:button]
end
def config(style)
@style_offsets.find_index {|v| v == style }
end
def other_animation(type) def other_animation(type)
@animations[type] @animations[type]
end end
@@ -75,8 +84,14 @@ class WeaponClass
@styles[style][:speed] || default_speed @styles[style][:speed] || default_speed
end end
def style_at(offset) def style_at(button)
@style_offsets[offset] 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 end
def default_speed(speed = nil) def default_speed(speed = nil)
@@ -87,12 +102,13 @@ class WeaponClass
@default_speed @default_speed
end end
def special_bar(id = nil) def special_bar(config, button)
unless id.nil? @special_bar_config = config
@special_bar = id @special_bar_button = button
end end
@special_bar def special_bar?
!@special_bar_button.nil? and !@special_bar_config.nil?
end end
def animations(stand: nil, walk: nil, run: nil, idle_turn: nil, turn_around: nil, turn_left: nil, turn_right: nil) def animations(stand: nil, walk: nil, run: nil, idle_turn: nil, turn_around: nil, turn_left: nil, turn_right: nil)
+37
View File
@@ -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
+8 -7
View File
@@ -1,17 +1,18 @@
SCIMITAR_WIDGET_ID = 81 SCIMITAR_WIDGET_ID = 81
SCIMITAR_SPECIAL_BAR_ID = 21 SCIMITAR_SPECIAL_BAR_CONFIG_ID = 21
SCIMITAR_SPECIAL_BAR_BUTTON_ID = 21
create_weapon_class :scimitar, widget: SCIMITAR_WIDGET_ID do create_weapon_class :scimitar, widget: SCIMITAR_WIDGET_ID do
default_speed 4 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 attack_bonuses crush: -2
defence_bonuses slash: -1 defence_bonuses slash: -1
add_style :accurate, attack_type: :slash, animation: 390 add_style :accurate, attack_type: :slash, animation: 390, button: 2
add_style :aggressive, attack_type: :slash, animation: 390 add_style :aggressive, attack_type: :slash, animation: 390, button: 3
add_style :alt_aggressive, attack_type: :stab, animation: 391 add_style :alt_aggressive, attack_type: :stab, animation: 391, button: 4
add_style :defensive, attack_type: :slash, animation: 390 add_style :defensive, attack_type: :slash, animation: 390, button: 5
end end
create_weapon :iron_scimitar do create_weapon :iron_scimitar do
@@ -1,19 +1,20 @@
TWO_HANDED_SWORD_WIDGET_ID = 82 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 create_weapon_class :two_handed_sword, widget: TWO_HANDED_SWORD_WIDGET_ID do
default_speed 7 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 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 attack_bonuses stab: -4, magic: -4
defence_bonuses range: -1 defence_bonuses range: -1
add_style :accurate, attack_type: :slash, animation: 7041 add_style :accurate, attack_type: :slash, animation: 7041, button: 2
add_style :aggressive, attack_type: :crush, animation: 7041 add_style :aggressive, attack_type: :crush, animation: 7041, button: 3
add_style :alt_aggressive, attack_type: :crush, animation: 7048 add_style :alt_aggressive, attack_type: :crush, animation: 7048, button: 4
add_style :defensive, attack_type: :slash, animation: 7049 add_style :defensive, attack_type: :slash, animation: 7049, button: 5
end end
create_weapon :iron_2h_sword do create_weapon :iron_2h_sword do
@@ -49,4 +50,8 @@ end
create_weapon :dragon_2h_sword do create_weapon :dragon_2h_sword do
attack_bonuses slash: 92, crush: 80 attack_bonuses slash: 92, crush: 80
other_bonuses melee_strength: 70 other_bonuses melee_strength: 70
set_special_attack energy_requirement: 60, animation: 3157, graphic: 1225 do |source, target|
damage! source, target, 5
end
end end
+2 -2
View File
@@ -1,4 +1,4 @@
create_weapon_class :unarmed, widget: -1 do create_weapon_class :no_weapon, widget: 92 do
default_speed 4 default_speed 4
add_style :accurate, animation: 422, block_animation: 424 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 add_style :defensive, animation: 422, block_animation: 424
end end
create_weapon :no_weapon, :unarmed, named: true do create_weapon :unarmed, :no_weapon, named: true do
# Todo factor out empty blocks # Todo factor out empty blocks
end end