mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Add ranged combat support
* 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.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
def get_combat_state(mob)
|
||||
mob.is_a?(Player) ? type = :player : type = :npc
|
||||
|
||||
unless MOB_COMBAT_STATE_CACHE[type].has_key? mob.index
|
||||
unless MOB_COMBAT_STATE_CACHE[type].key? mob.index
|
||||
MOB_COMBAT_STATE_CACHE[type][mob.index] = CombatState.new(mob)
|
||||
end
|
||||
|
||||
@@ -11,8 +11,7 @@ end
|
||||
private
|
||||
|
||||
class CombatState
|
||||
attr_accessor :state
|
||||
attr_reader :queued_attacks, :supports_weapon
|
||||
attr_reader :target
|
||||
|
||||
def initialize(mob, supports_weapon = true)
|
||||
@mob = mob
|
||||
@@ -21,20 +20,22 @@ class CombatState
|
||||
end
|
||||
|
||||
def reset
|
||||
@state = :idle
|
||||
@target = nil
|
||||
@next_attack = nil
|
||||
@queued_attacks = []
|
||||
@mob.reset_interacting_mob
|
||||
end
|
||||
|
||||
def target
|
||||
@target
|
||||
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
|
||||
@mob.interacting_mob = target unless target.nil?
|
||||
@target = target
|
||||
end
|
||||
|
||||
@@ -44,23 +45,25 @@ class CombatState
|
||||
|
||||
def next_attack(peek = false)
|
||||
if @queued_attacks.size > 0
|
||||
peek ? @queued_attacks.first : @queued_attacks.pop
|
||||
peek ? @queued_attacks.last : @queued_attacks.pop
|
||||
else
|
||||
weapon = EquipmentUtil.equipped_weapon @mob
|
||||
|
||||
if @mob.using_special and weapon.special_attack?
|
||||
if @mob.using_special && weapon.special_attack?
|
||||
weapon.special_attack
|
||||
else
|
||||
weapon_class = weapon.weapon_class
|
||||
combat_style = weapon_class.style_at @mob.combat_style
|
||||
|
||||
weapon_class.attack combat_style
|
||||
combat_style = weapon.weapon_class.selected_style @mob
|
||||
combat_style.attack
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MOB_COMBAT_STATE_CACHE = {
|
||||
:player => {},
|
||||
:npc => {}
|
||||
player: {},
|
||||
npc: {}
|
||||
}
|
||||
|
||||
on :logout do |event|
|
||||
MOB_COMBAT_STATE_CACHE[:player].delete event.player.index
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user