From b07c014a6e8e82846fc8a3d227d5d270b565b9d0 Mon Sep 17 00:00:00 2001 From: GregHib Date: Thu, 23 Jan 2025 11:02:00 +0000 Subject: [PATCH] Move exactMoveDelay into SuspendableContext --- .../voidps/engine/entity/character/Visuals.kt | 10 ---------- .../voidps/engine/suspend/SuspendableContext.kt | 17 +++++++++++++++++ .../skill/agility/course/BarbarianAdvanced.kts | 1 - .../skill/agility/course/BarbarianOutpost.kts | 1 - .../skill/agility/course/GnomeStronghold.kts | 1 - .../skill/agility/course/WildernessCourse.kts | 1 - 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Visuals.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Visuals.kt index f4aa6965c..7c2e92e22 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Visuals.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Visuals.kt @@ -186,11 +186,6 @@ fun Character.exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delt setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction) } -context(SuspendableContext<*>) suspend fun Character.exactMoveDelay(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) { - character.exactMove(delta, delay, direction) - delay(delay / 30) -} - fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) { val start = tile tele(target) @@ -200,11 +195,6 @@ fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, setExactMovement(Delta.EMPTY, delay, start.delta(tile), startDelay, direction = direction) } -context(SuspendableContext<*>) suspend fun Character.exactMoveDelay(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) { - character.exactMove(target, delay, direction, startDelay) - delay((startDelay + delay) / 30) -} - val Character.turn: Delta get() = Tile(visuals.turn.targetX, visuals.turn.targetY, tile.level).delta(tile) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/suspend/SuspendableContext.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/suspend/SuspendableContext.kt index a7a4dcfb2..27c5d4993 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/suspend/SuspendableContext.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/suspend/SuspendableContext.kt @@ -2,7 +2,11 @@ package world.gregs.voidps.engine.suspend import kotlinx.coroutines.suspendCancellableCoroutine import world.gregs.voidps.engine.entity.character.Character +import world.gregs.voidps.engine.entity.character.exactMove import world.gregs.voidps.engine.event.Context +import world.gregs.voidps.type.Delta +import world.gregs.voidps.type.Direction +import world.gregs.voidps.type.Tile interface SuspendableContext : Context { /** @@ -25,4 +29,17 @@ interface SuspendableContext : Context { character.delay = it } } + + suspend fun Character.exactMoveDelay(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) { + character.exactMove(delta, delay, direction) + delay(delay / 30) + } + + /** + * Gradually move the characters appeared location over time + */ + suspend fun Character.exactMoveDelay(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) { + character.exactMove(target, delay, direction, startDelay) + delay((startDelay + delay) / 30) + } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianAdvanced.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianAdvanced.kts index 1b0435d65..bb452c4be 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianAdvanced.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianAdvanced.kts @@ -1,6 +1,5 @@ package world.gregs.voidps.world.activity.skill.agility.course -import world.gregs.voidps.engine.entity.character.exactMoveDelay import world.gregs.voidps.engine.entity.character.exactMove import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.move.tele diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianOutpost.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianOutpost.kts index f9a819532..2fa7c3ec7 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianOutpost.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/BarbarianOutpost.kts @@ -2,7 +2,6 @@ package world.gregs.voidps.world.activity.skill.agility.course import world.gregs.voidps.engine.client.message import world.gregs.voidps.engine.data.Settings -import world.gregs.voidps.engine.entity.character.exactMoveDelay import world.gregs.voidps.engine.entity.character.exactMove import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.move.tele diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/GnomeStronghold.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/GnomeStronghold.kts index 3aea59890..3a432aa0a 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/GnomeStronghold.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/GnomeStronghold.kts @@ -1,7 +1,6 @@ package world.gregs.voidps.world.activity.skill.agility.course import world.gregs.voidps.engine.client.message -import world.gregs.voidps.engine.entity.character.exactMoveDelay import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.move.tele import world.gregs.voidps.engine.entity.character.move.walkOver diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/WildernessCourse.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/WildernessCourse.kts index 578df681d..4550f8e66 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/WildernessCourse.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/agility/course/WildernessCourse.kts @@ -2,7 +2,6 @@ package world.gregs.voidps.world.activity.skill.agility.course import world.gregs.voidps.engine.client.message import world.gregs.voidps.engine.data.Settings -import world.gregs.voidps.engine.entity.character.exactMoveDelay import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.move.tele import world.gregs.voidps.engine.entity.character.move.walkOver