Skip to content

Commit 5789109

Browse files
committed
dragon2hSword.kts special attack
1 parent 0afd4d6 commit 5789109

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package game.combat.specialAttacks
2+
3+
import api.combat.specialAttack.SpecialAttackHandler.attack
4+
import io.luna.game.model.mob.Mob
5+
import io.luna.game.model.mob.Player
6+
import io.luna.game.model.mob.block.Graphic
7+
import io.luna.game.model.mob.combat.SpecialAttackType.DRAGON_2H_SWORD
8+
import io.luna.game.model.mob.combat.attack.CombatAttack
9+
import io.luna.game.model.mob.combat.damage.CombatDamageAction
10+
import io.luna.game.model.mob.combat.damage.CombatDamageRequest
11+
import io.luna.game.model.mob.combat.damage.CombatDamageType
12+
13+
/**
14+
* The maximum number of nearby secondary targets hit per mob category.
15+
*
16+
* This limit is applied separately to local players and local NPCs.
17+
*/
18+
val MAX_TARGETS = 14
19+
20+
/**
21+
* The animation played when performing the Dragon 2h sword special attack.
22+
*/
23+
val ANIMATION = 3157
24+
25+
/**
26+
* The graphic displayed when the Dragon 2h sword special attack is launched.
27+
*/
28+
val GRAPHIC = Graphic(559, 0, 0)
29+
30+
/**
31+
* Attempts to apply the Dragon 2h sword special attack's secondary hit to a nearby target.
32+
*
33+
* A hit is only applied if the supplied [victim] is within melee distance of [attacker]. When that condition is met,
34+
* a melee damage roll is resolved immediately and submitted as a [CombatDamageAction].
35+
*
36+
* @param attacker The player performing the special attack.
37+
* @param victim The nearby mob being checked for a secondary hit.
38+
* @param attack The parent combat attack associated with the special attack.
39+
* @return `true` if a secondary hit was submitted for the target, or `false` if the target was out of range.
40+
*/
41+
fun sendHit(attacker: Player, victim: Mob, attack: CombatAttack<Player>?): Boolean {
42+
if (victim.isWithinDistance(attacker, 1)) {
43+
val otherDamage = CombatDamageRequest.builder(attacker, victim, CombatDamageType.MELEE).build().resolve()
44+
victim.submitAction(CombatDamageAction(otherDamage, attack, true))
45+
return true
46+
}
47+
return false
48+
}
49+
50+
attack(type = DRAGON_2H_SWORD,
51+
drain = 60) {
52+
53+
// Override the primary melee animation.
54+
attack { melee(ANIMATION) }
55+
56+
// Hit nearby players and NPCs when applicable.
57+
launched {
58+
attacker.graphic(GRAPHIC)
59+
var playersHit = 0
60+
var npcsHit = 0
61+
// TODO Does it only damage mobs of the same type?
62+
// Apply potential damage to players.
63+
for (local in attacker.localMobs.localPlayers()) {
64+
if (playersHit >= MAX_TARGETS) {
65+
break
66+
}
67+
if (local != victim && sendHit(attacker, local, attack)) {
68+
playersHit++
69+
}
70+
}
71+
// Apply potential damage to NPCs.
72+
for (local in attacker.localMobs.localNpcs()) {
73+
if (npcsHit >= MAX_TARGETS) {
74+
break
75+
}
76+
if (local != victim && sendHit(attacker, local, attack)) {
77+
npcsHit++
78+
}
79+
}
80+
damage // Preserves the original primary hit result from the special attack DSL.
81+
}
82+
}

0 commit comments

Comments
 (0)