mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
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.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
def get_combat_state(mob)
|
||||
mob.is_a?(Player) ? type = :player : type = :npc
|
||||
|
||||
unless MOB_COMBAT_STATE_CACHE[type].has_key? mob.index
|
||||
MOB_COMBAT_STATE_CACHE[type][mob.index] = CombatState.new(mob)
|
||||
end
|
||||
|
||||
MOB_COMBAT_STATE_CACHE[type][mob.index]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
class CombatState
|
||||
attr_accessor :state, :next_attack
|
||||
attr_reader :queued_attacks, :supports_weapon
|
||||
|
||||
def initialize(mob, supports_weapon = true)
|
||||
@mob = mob
|
||||
@supports_weapon = supports_weapon
|
||||
reset
|
||||
end
|
||||
|
||||
def reset
|
||||
@state = :idle
|
||||
@target = nil
|
||||
@next_attack = nil
|
||||
@queued_attacks = []
|
||||
@mob.reset_interacting_mob
|
||||
end
|
||||
|
||||
def target
|
||||
@target
|
||||
end
|
||||
|
||||
def target=(target)
|
||||
@mob.reset_interacting_mob
|
||||
@mob.interacting_mob = target
|
||||
@target = target
|
||||
end
|
||||
|
||||
def queue_attack(attack)
|
||||
@queued_attacks.push(attack)
|
||||
end
|
||||
end
|
||||
|
||||
MOB_COMBAT_STATE_CACHE = {
|
||||
:player => {},
|
||||
:npc => {}
|
||||
}
|
||||
Reference in New Issue
Block a user