Files
apollo/data/plugins/combat/weapon_class.rb
T
Gary Tierney 348e5cc8dc Build a framework for a maintainable combat plugin
* Uses a hierarchy of WeaponClasses -> Weapons for performing attacks,
  with WeaponClass having a set of styles and associated Attacks for
  those styles. Weapons and their classes are built with an easy to use
  and clean DSL.

* Adds a BonusContainer mixin, so that Equipment, Weapons, and
  WeaponClasses can all have their own set of bonuses which apply to the
  player.

* Allows attacks to be queued to the Mobs CombatState instance from
  external code, allowing e.g., NPCs or auto-cast to queue attacks to be
  executed.
2016-02-29 21:27:17 +00:00

120 lines
2.3 KiB
Ruby

COMBAT_STYLES = [
:accurate,
:aggressive,
:defensive,
:controlled,
:alt_aggressive,
:accurate_ranged,
:rapid,
:long_range
]
MELEE_COMBAT_STYLES = [
:accurate,
:aggressive,
:alt_aggressive,
:controlled,
:defensive
]
RANGE_COMBAT_STYLES = [
:accurate_ranged,
:rapid,
:long_range
]
class WeaponClass
attr_reader :widget, :name
include Combat::BonusContainer
def initialize(name, widget)
@name = name
@widget = widget
@styles = {}
@style_attacks = {}
@style_offsets = []
@animations = {}
end
def add_style(style, attack_type: nil, speed: nil, animation: nil, block_animation: nil, range: 1)
raise 'Invalid combat style given' unless COMBAT_STYLES.include? style
@styles[style] = {
:attack_type => attack_type,
:speed => speed,
:animation => animation,
:block_animation => block_animation,
:range => range
}
@style_offsets.push style
if MELEE_COMBAT_STYLES.include? style
@style_attacks[style] = Attack.new(animation: animation)
end
end
def attack(style)
@style_attacks[style]
end
def attack_type(style)
@styles[style][:attack_type]
end
def block_animation(style)
@styles[style][:block_animation]
end
def other_animation(type)
@animations[type]
end
def speed(style)
@styles[style][:speed] || default_speed
end
def style_at(offset)
@style_offsets[offset]
end
def default_speed(speed = nil)
unless speed.nil?
@default_speed = speed
end
@default_speed
end
def special_bar(id = nil)
unless id.nil?
@special_bar = id
end
@special_bar
end
def animations(stand: nil, walk: nil, run: nil, idle_turn: nil, turn_around: nil, turn_left: nil, turn_right: nil)
@animations = {
:stand => stand,
:walk => walk,
:run => run,
:idle_turn => idle_turn,
:turn_around => turn_around,
:turn_left => turn_left,
:turn_right => turn_right
}
end
end
WEAPON_CLASSES = {}
WEAPON_CLASS_INTERFACE_MAP = {}
def create_weapon_class(name, widget:, &block)
weapon_class = WeaponClass.new(name, widget)
weapon_class.instance_eval &block
WEAPON_CLASSES[name.to_sym] = weapon_class
end