From 73d65757f3c8610f9418ebb60b2e606a397f0721 Mon Sep 17 00:00:00 2001 From: GregHib Date: Thu, 23 Jan 2025 11:05:42 +0000 Subject: [PATCH] Move exactMove into Character --- .../engine/entity/character/Character.kt | 30 +++++++++++++++++++ .../voidps/engine/entity/character/Visuals.kt | 18 ----------- .../engine/suspend/SuspendableContext.kt | 6 ++-- .../dnd/shootingstar/ShootingStar.kts | 1 - .../agility/course/BarbarianAdvanced.kts | 1 - .../skill/agility/course/BarbarianOutpost.kts | 1 - .../combat/melee/special/SpearShove.kts | 1 - 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Character.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Character.kt index f82de29b1..e571da619 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Character.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/Character.kt @@ -6,15 +6,21 @@ import world.gregs.voidps.engine.client.variable.Variables import world.gregs.voidps.engine.entity.Entity import world.gregs.voidps.engine.entity.character.mode.Mode import world.gregs.voidps.engine.entity.character.mode.move.Steps +import world.gregs.voidps.engine.entity.character.move.tele import world.gregs.voidps.engine.entity.character.npc.NPC import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.appearance +import world.gregs.voidps.engine.entity.character.player.movementType import world.gregs.voidps.engine.entity.character.player.skill.level.Levels import world.gregs.voidps.engine.event.EventDispatcher import world.gregs.voidps.engine.queue.ActionQueue import world.gregs.voidps.engine.suspend.Suspension import world.gregs.voidps.engine.timer.Timers import world.gregs.voidps.network.login.protocol.visual.Visuals +import world.gregs.voidps.network.login.protocol.visual.update.player.MoveType +import world.gregs.voidps.type.Delta +import world.gregs.voidps.type.Direction +import world.gregs.voidps.type.Tile import kotlin.coroutines.Continuation interface Character : Entity, Variable, EventDispatcher, Comparable { @@ -34,6 +40,30 @@ interface Character : Entity, Variable, EventDispatcher, Comparable { return index.compareTo(other.index) } + /** + * Gradually move the characters appeared location to [delta] over [delay] time + */ + fun exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) { + val start = tile + tele(delta) + if (this is Player) { + movementType = MoveType.Walk + } + setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction) + } + + /** + * Gradually move the characters appeared location to [target] over [delay] time + */ + fun exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) { + val start = tile + tele(target) + if (this is Player) { + movementType = MoveType.Walk + } + setExactMovement(Delta.EMPTY, delay, start.delta(tile), startDelay, direction = direction) + } + fun say(message: String) { visuals.say.text = message flagSay() 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 7c2e92e22..b87af8af4 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 @@ -177,24 +177,6 @@ fun Character.setExactMovement( flagExactMovement() } -fun Character.exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) { - val start = tile - tele(delta) - if (this is Player) { - movementType = MoveType.Walk - } - setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction) -} - -fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) { - val start = tile - tele(target) - if (this is Player) { - movementType = MoveType.Walk - } - setExactMovement(Delta.EMPTY, delay, start.delta(tile), startDelay, direction = direction) -} - 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 27c5d4993..91378f66f 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,6 @@ 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 @@ -30,13 +29,16 @@ interface SuspendableContext : Context { } } + /** + * Delay until the appeared location of the character has moved [delta] in [delay] time + */ 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 + * Delay until the appeared location of the character has moved to [target] in [delay] 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) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/dnd/shootingstar/ShootingStar.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/dnd/shootingstar/ShootingStar.kts index 9e0ee7ad7..1918bd932 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/dnd/shootingstar/ShootingStar.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/dnd/shootingstar/ShootingStar.kts @@ -10,7 +10,6 @@ import world.gregs.voidps.engine.data.Settings import world.gregs.voidps.engine.data.definition.data.Rock import world.gregs.voidps.engine.data.settingsReload import world.gregs.voidps.engine.entity.World -import world.gregs.voidps.engine.entity.character.exactMove import world.gregs.voidps.engine.entity.character.mode.interact.Interact import world.gregs.voidps.engine.entity.character.move.walkTo import world.gregs.voidps.engine.entity.character.npc.NPC 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 bb452c4be..163bf4372 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.exactMove 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.walkTo 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 2fa7c3ec7..8d1f959ae 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.exactMove 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/interact/entity/player/combat/melee/special/SpearShove.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/SpearShove.kts index f6538efb0..0a4e5b93e 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/SpearShove.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/SpearShove.kts @@ -2,7 +2,6 @@ package world.gregs.voidps.world.interact.entity.player.combat.melee.special import world.gregs.voidps.engine.client.message import world.gregs.voidps.engine.client.variable.hasClock -import world.gregs.voidps.engine.entity.character.exactMove import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.entity.character.setGraphic