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:
Gary Tierney
2016-02-29 21:24:34 +00:00
parent 7731eedf3d
commit 348e5cc8dc
21 changed files with 895 additions and 80 deletions
+70
View File
@@ -0,0 +1,70 @@
java_import 'org.apollo.game.model.entity.EquipmentConstants'
class CombatUtil
def self.calculate_max_hit(source)
strength = source.skill_set.get_skill(Skill::STRENGTH)
strength_stat = 5 #source.bonus_stat(:other, :strength)
effective_strength_damage = (strength.current_level) #* prayer_multiplier
if [:aggressive, :alt_aggressive].include? source.combat_style
effective_strength_damage += 3
end
(1.3 + (effective_strength_damage / 10) + (strength_stat / 80) +
((effective_strength_damage * strength_stat) / 640))
end
def self.calculate_accuracy(source, target)
weapon = EquipmentUtil.equipped_weapon source
weapon_class = weapon.weapon_class
combat_style = weapon_class.style_at source.combat_style
attack_type = weapon.weapon_class.attack_type combat_style
attack_stat = [1, 1].max
defence_stat = [1, 1].max
attack = source.skill_set.get_skill(Skill::ATTACK).current_level.to_f
defence = target.skill_set.get_skill(Skill::DEFENCE).current_level.to_f
attack_prayer_multiplier = 1 #TODO: Prayer
attack_accuracy = attack_stat * attack * attack_prayer_multiplier
attack_accuracy = 0.1 if attack_accuracy < 0
defence_prayer_multiplier = 1 #TODO: Prayer
defence_accuracy = defence_stat * defence * defence_prayer_multiplier
defence_accuracy = 1 if defence_accuracy < 0
base = attack_accuracy / defence_accuracy
base > 1 ? 0.9 : base * 0.9
end
# Calculates a hit for the given <i>Mob</i> and special attack flag.
def self.calculate_hit(source, target)
accuracy = calculate_accuracy source, target
max_hit = calculate_max_hit(source) + 1
if rand <= accuracy
return rand(max_hit)
else
return 0
end
end
end
class EquipmentUtil
def self.equipped_weapon(source)
item = source.equipment.get(EquipmentConstants::WEAPON)
if item.nil?
return NAMED_WEAPONS[:no_weapon]
end
WEAPONS[item.id]
end
def self.equipped_projectile(source)
item = source.equipment.get(EquipmentConstants::ARROWS)
end
end