Skip to content

Commit 9cece50

Browse files
GregHibTyluur
andauthored
Fix spell auto-casting and freezing movement (#959)
* Fix missing spell items clearing autocast instead of current spell closes #954 * Fix missing spell on player interaction * fix(combat): exclude caster from AoE magic splash damage - Add source parameter to multiTargets() to filter out attacker - Prevents ice barrage/burst from hitting self in multi when adjacent to target - Updates spell handler to pass caster reference * Reformat stepOut * Tidy up freeze timer name to reduce confusion * Make freeze effect command give message * Fix movement delay not stopping movement * Add test to test freeze stops players from moving * Fix no collision movement --------- Co-authored-by: Tyluur <contact@tyluur.com>
1 parent 53994b3 commit 9cece50

14 files changed

Lines changed: 83 additions & 39 deletions

File tree

data/area/misthalin/lumbridge/lumbridge.teles.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ option = "Enter"
44
tile = { x = 3184, y = 3164 }
55
to = { x = 3494, y = 4832 }
66

7-
[36768]
7+
[lumbridge_tower_ladder_south]
88
option = "Climb-up"
99
tile = { x = 3198, y = 3219 }
1010
delta = { level = 1 }
@@ -90,7 +90,7 @@ option = "Climb-down"
9090
tile = { x = 3207, y = 3223, level = 3 }
9191
delta = { y = 2, level = -1 }
9292

93-
[36768]
93+
[lumbridge_tower_ladder_south]
9494
option = "Climb-up"
9595
tile = { x = 3229, y = 3213 }
9696
delta = { level = 1 }
@@ -110,7 +110,7 @@ option = "Climb-down"
110110
tile = { x = 3229, y = 3213, level = 2 }
111111
delta = { level = -1 }
112112

113-
[36768]
113+
[lumbridge_tower_ladder_south]
114114
option = "Climb-up"
115115
tile = { x = 3229, y = 3224 }
116116
delta = { level = 1 }

data/area/misthalin/tutorial_island/tutorial_island.teles.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ option = "Climb-up"
44
tile = { x = 3043, y = 10328 }
55
delta = { y = -6400 }
66

7-
[36768]
7+
[lumbridge_tower_ladder_south]
88
option = "Climb-up"
99
tile = { x = 3126, y = 3124, level = 1 }
1010
delta = { level = 1 }
@@ -72,7 +72,7 @@ option = "Climb-up"
7272
tile = { x = 3088, y = 9971 }
7373
to = { x = 3089, y = 3571 }
7474

75-
[36768]
75+
[lumbridge_tower_ladder_south]
7676
option = "Climb-up"
7777
tile = { x = 3139, y = 3078 }
7878
delta = { level = 1 }

data/bot/lumbridge.nav-edges.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ edges = [
2727
{ from = { x = 3184, y = 3225 }, to = { x = 3168, y = 3221 } }, # lumbridge_castle_yew_trees_to_yew_trees_west
2828
{ from = { x = 3184, y = 3225 }, to = { x = 3195, y = 3236 } }, # lumbridge_castle_yew_trees_to_tree_patch
2929
{ from = { x = 3226, y = 3214 }, to = { x = 3227, y = 3214 }, cost = 3, actions = [{ object = { option = "Open", id = "door_627_closed", x = 3226, y = 3214, success = { object = { id = "door_627_opened", x = 3227, y = 3214 } } } }] }, # lumbridge_south_tower_to_ground_floor
30-
{ from = { x = 3227, y = 3214 }, to = { x = 3229, y = 3214, level = 1 }, cost = 1, actions = [{ object = { option = "Climb-up", id = "36768", x = 3229, y = 3213, success = { tile = { level = 1 } } } }] }, # lumbridge_south_tower_ground_floor_to_1st_floor
30+
{ from = { x = 3227, y = 3214 }, to = { x = 3229, y = 3214, level = 1 }, cost = 1, actions = [{ object = { option = "Climb-up", id = "lumbridge_tower_ladder_south", x = 3229, y = 3213, success = { tile = { level = 1 } } } }] }, # lumbridge_south_tower_ground_floor_to_1st_floor
3131
{ from = { x = 3229, y = 3214, level = 1 }, to = { x = 3229, y = 3214, level = 2 }, cost = 1, actions = [{ object = { option = "Climb-up", id = "36769", x = 3229, y = 3213, success = { tile = { level = 2 } } } }] }, # lumbridge_south_tower_1st_floor_to_2nd_floor
3232
{ from = { x = 3229, y = 3214, level = 1 }, to = { x = 3229, y = 3214 }, cost = 1, actions = [{ object = { option = "Climb-down", id = "36769", x = 3229, y = 3213, success = { tile = { level = 0 } } } }] }, # lumbridge_south_tower_1st_floor_to_ground_floor
3333
{ from = { x = 3229, y = 3214, level = 2 }, to = { x = 3229, y = 3214, level = 1 }, cost = 1, actions = [{ object = { option = "Climb-down", id = "36770", x = 3229, y = 3213, success = { tile = { level = 1 } } } }] }, # lumbridge_south_tower_2nd_floor_to_1st_floor

data/entity/obj/stairs_ladders.objs.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ examine = "I can climb this."
114114
id = 29355
115115
examine = "I can climb this."
116116

117-
[36768]
117+
[lumbridge_tower_ladder_south]
118118
id = 36768
119119
examine = "I can climb up this."
120120

engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ open class Interact(
8686
return
8787
}
8888
updateRange = false
89-
val target = target
9089
if (stepOut()) {
9190
super.tick()
9291
return

engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,24 @@ open class Movement(
5959
*/
6060
protected open fun stepOut(): Boolean {
6161
val strategy = strategy ?: return false
62-
if (strategy.shape != -2) return false
62+
if (strategy.shape != -2) {
63+
return false
64+
}
6365
val npc = character as? NPC ?: return false
64-
if (npc.def["allowed_under", false]) return false
65-
if (!Overlap.isUnder(npc.tile, npc.size, npc.size, strategy.tile, strategy.width, strategy.height)) return false
66+
if (npc.def["allowed_under", false]) {
67+
return false
68+
}
69+
if (!Overlap.isUnder(npc.tile, npc.size, npc.size, strategy.tile, strategy.width, strategy.height)) {
70+
return false
71+
}
6672
clearSteps()
67-
if (shouldQueueStepOut()) {
68-
for (direction in Direction.cardinal.shuffled(random)) {
69-
if (canStep(direction.delta.x, direction.delta.y)) {
70-
character.steps.queueStep(npc.tile.add(direction))
71-
break
72-
}
73+
if (!shouldQueueStepOut()) {
74+
return true
75+
}
76+
for (direction in Direction.cardinal.shuffled(random)) {
77+
if (canStep(direction.delta.x, direction.delta.y)) {
78+
character.steps.queueStep(npc.tile.add(direction))
79+
break
7380
}
7481
}
7582
return true
@@ -85,7 +92,7 @@ open class Movement(
8592
if (character is Player && character.viewport?.loaded == false) {
8693
return
8794
}
88-
if (hasDelay() && !canMove() && !character.steps.destination.noCollision) {
95+
if (!canMove()) {
8996
return
9097
}
9198
if (!stepOut()) {
@@ -101,17 +108,16 @@ open class Movement(
101108
}
102109

103110
private fun canMove(): Boolean {
104-
if (!hasDelay() && (character as? Player)?.menu == null) {
105-
return true
111+
if (character.hasClock("movement_delay")) {
112+
return false
106113
}
107-
if (character.queue.isEmpty()) {
108-
return true
114+
if (character.contains("delay")) {
115+
// Inactive delays block movement unless there's a queue in action
116+
return character.delay != null || !character.queue.isEmpty() || character.steps.destination.noCollision
109117
}
110-
return character.delay != null
118+
return true
111119
}
112120

113-
private fun hasDelay() = character.hasClock("movement_delay") || character.contains("delay")
114-
115121
/**
116122
* Applies one step
117123
* @return false if blocked by an obstacle or not [Character.steps] left to take

game/src/main/kotlin/content/entity/effect/EffectCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class EffectCommands(
5353
if (player.poisoned || ticks < 0) {
5454
target.softTimers.clear("movement_delay")
5555
} else {
56-
target.freeze(ticks, force = true)
56+
player.freeze(target, ticks, force = true)
5757
}
5858
}
5959

game/src/main/kotlin/content/entity/effect/Freeze.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ fun Character.freeze(target: Character, ticks: Int, force: Boolean = false): Boo
3838
fun Character.freeze(ticks: Int, force: Boolean = false) {
3939
val protect = praying("protect_from_magic") || praying("deflect_magic")
4040
movementDelay = if (force || !protect) ticks else ticks / 2
41-
softTimers.start("movement_delay")
41+
softTimers.start("frozen")
4242
}
4343

4444
fun Character.freezeImmune(ticks: Int) {
4545
movementDelay = -ticks
46-
softTimers.start("movement_delay")
46+
softTimers.start("frozen")
4747
}
4848

4949
class Freeze : Script {
5050

5151
init {
52-
timerStart("movement_delay", ::start)
53-
npcTimerStart("movement_delay", ::start)
54-
timerTick("movement_delay", ::tick)
55-
npcTimerTick("movement_delay", ::tick)
56-
timerStop("movement_delay", ::stop)
57-
npcTimerStop("movement_delay", ::stop)
52+
timerStart("frozen", ::start)
53+
npcTimerStart("frozen", ::start)
54+
timerTick("frozen", ::tick)
55+
npcTimerTick("frozen", ::tick)
56+
timerStop("frozen", ::stop)
57+
npcTimerStop("frozen", ::stop)
5858
}
5959

6060
fun start(character: Character, restart: Boolean): Int {

game/src/main/kotlin/content/entity/player/combat/Attack.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class Attack : Script {
102102
it.combatInteraction(target)
103103
}
104104

105+
onPlayerApproach("*_spellbook:*") {
106+
val (target, id) = it
107+
approachRange(8, update = false)
108+
spell = id.substringAfter(":")
109+
set("attack_speed", 5)
110+
set("one_time", true)
111+
attackRange = 8
112+
face(target)
113+
it.combatInteraction(target)
114+
}
115+
105116
combatPrepare {
106117
if (contains("one_time")) {
107118
mode = EmptyMode

game/src/main/kotlin/content/skill/magic/book/SpellRunes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SpellRunes : Script {
99
init {
1010
combatPrepare(style = "magic") { _ ->
1111
if (spell.isNotBlank() && !hasSpellItems(spell)) {
12-
clear("autocast")
12+
clear("spell")
1313
false
1414
} else {
1515
true

0 commit comments

Comments
 (0)