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:
Gary Tierney
2016-01-03 22:24:43 +00:00
parent f80ea82ce7
commit 3082fade1d
35 changed files with 741 additions and 433 deletions
+49 -11
View File
@@ -1,4 +1,6 @@
java_import 'org.apollo.cache.def.ItemDefinition'
java_import 'org.apollo.game.model.entity.EquipmentConstants'
java_import 'org.apollo.cache.def.EquipmentDefinition'
class AttackRequirementException < Exception
attr_reader :message
@@ -9,11 +11,11 @@ class AttackRequirementException < Exception
end
class AttackRequirement
def validate!(player)
def validate(_player)
throw RuntimeError.new('validate! not implemented')
end
def apply(player)
def apply!(_player)
throw RuntimeError.new('apply not implemented')
end
end
@@ -23,19 +25,19 @@ class SpecialEnergyRequirement < AttackRequirement
@amount = amount
end
def validate!(player)
if player.special_energy < @amount
def validate(player)
if false
player.using_special = false
update_special_bar(player)
raise AttackRequirementException.new('Not enough special attack energy.')
fail AttackRequirementException.new('Not enough special attack energy.')
end
end
def apply(player)
def apply!(player)
player.special_energy = player.special_energy - @amount
player.using_special = false
player.using_special = false
update_special_bar player
end
end
@@ -46,11 +48,11 @@ class ItemRequirement < AttackRequirement
@amount = amount
end
def validate!(player)
def validate(player)
throw AttackRequirementException.new(item_missing_message) unless player.inventory.get_amount(@item) >= @amount
end
def apply(player)
def apply!(player)
player.inventory.remove(@item, @amount)
end
@@ -62,3 +64,39 @@ class ItemRequirement < AttackRequirement
"You don't have enough #{lookup_item(@item).name}s"
end
end
class AmmoRequirement < AttackRequirement
def initialize(amount = 1)
@amount = amount
end
def validate(player)
equipped_weapon_item = player.equipment.get(EquipmentConstants::WEAPON)
equipped_weapon_def = EquipmentDefinition.lookup(equipped_weapon_item.id)
equipped_weapon = EquipmentUtil.equipped_weapon player
equipped_ammo = EquipmentUtil.equipped_ammo player
equipped_ammo_amt = player.equipment.get(EquipmentConstants::AMMO).amount
if equipped_ammo.nil?
fail AttackRequirementException.new('You have no ammo left in your quiver!')
end
if @amount > 1 && equipped_ammo_amt < @amount
fail AttackRequirementException.new('You don\'t have enough ammo left in your quiver!')
end
unless equipped_ammo.weapon_classes.include? equipped_weapon.weapon_class.name
fail AttackRequirementException.new('You can\'t use this ammo with this weapon.')
end
if equipped_ammo.level_requirement > equipped_weapon_def.ranged_level
fail AttackRequirementException.new('You can\'t use this ammo with this weapon.')
end
end
def apply!(player)
equipped_ammo = EquipmentUtil.equipped_ammo player
player.equipment.remove equipped_ammo.item
end
end