mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
3082fade1d
* Clean up the CombatAction and Attack code to make it easier to use for range. * Add collision detection to the distance checks before attacking in the CombatAction. * Create a Ruby DSL for defining projectile types and fix the ProjectileUpdateOperation so it uses the correct position offset. * Fix the packet structure of the HintIconMessageEncoder.
70 lines
1.4 KiB
Ruby
70 lines
1.4 KiB
Ruby
def get_combat_state(mob)
|
|
mob.is_a?(Player) ? type = :player : type = :npc
|
|
|
|
unless MOB_COMBAT_STATE_CACHE[type].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_reader :target
|
|
|
|
def initialize(mob, supports_weapon = true)
|
|
@mob = mob
|
|
@supports_weapon = supports_weapon
|
|
reset
|
|
end
|
|
|
|
def reset
|
|
@target = nil
|
|
@next_attack = nil
|
|
@queued_attacks = []
|
|
end
|
|
|
|
def will_attack?
|
|
is_attacking? && next_attack(true).speed >= @mob.attack_timer
|
|
end
|
|
|
|
def is_attacking?
|
|
!target.nil? && @mob.attacking
|
|
end
|
|
|
|
def target=(target)
|
|
@mob.reset_interacting_mob
|
|
@mob.interacting_mob = target unless target.nil?
|
|
@target = target
|
|
end
|
|
|
|
def queue_attack(attack)
|
|
@queued_attacks.push(attack)
|
|
end
|
|
|
|
def next_attack(peek = false)
|
|
if @queued_attacks.size > 0
|
|
peek ? @queued_attacks.last : @queued_attacks.pop
|
|
else
|
|
weapon = EquipmentUtil.equipped_weapon @mob
|
|
|
|
if @mob.using_special && weapon.special_attack?
|
|
weapon.special_attack
|
|
else
|
|
combat_style = weapon.weapon_class.selected_style @mob
|
|
combat_style.attack
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
MOB_COMBAT_STATE_CACHE = {
|
|
player: {},
|
|
npc: {}
|
|
}
|
|
|
|
on :logout do |event|
|
|
MOB_COMBAT_STATE_CACHE[:player].delete event.player.index
|
|
end
|