
Originally Posted by
SilverNova
Yes, I purged the existing combat system as it was poorly done (not by myself). I have since completely rewritten it from scratch to be far more extensible. Melee, ranged and magic strategies are finished, with just special attacks and prayer effects remaining. It is still a WIP and some refactoring is required, but I am pleased with how it has turned out so far.
Code:
object DarkBowCombatStrategy : RangedCombatStrategy() {
override fun Mob.hasAmmunition(): Boolean {
val player = this as? Player ?: return false
val weapon = tryGetWeapon() ?: return false
val ammo = player.tryGetAmmunition(weapon)
if (ammo == null) {
player msg "You do not have any ammunition for this weapon."
return false
}
if (player.equipment[weapon.ammoSlot].amount < 2) {
player msg "You do not have enough ammunition for this weapon."
return false
}
return true
}
override fun doPreAttack(context: CombatContext) {
val player = context.mob as? Player ?: return
val target = context.target ?: return
val weapon = player.tryGetWeapon() ?: return
val ammo = player.tryGetAmmunition(weapon) ?: return
player.decrementAmmo(weapon, target.position, amount = 2)
player.performAnimation(context.attackAnimation)
player.performGraphic(ammo.graphic)
ammo.projectile.copy(speed = 70).send(player, target)
ammo.projectile.copy(startHeight = 48, delay = 34, speed = 74).send(player, target)
}
override fun doRollHits(context: CombatContext): List<Hit> {
val first = super.doRollHits(context).first()
val second = super.doRollHits(context).first().apply { delay += 1 }
return listOf(first, second) // Fire two arrows per attack
}
}
Thanks for all the support everyone