Skip to content

Commit

Permalink
Move exactMove into Character
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed Jan 23, 2025
1 parent b07c014 commit 73d6575
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Character> {
Expand All @@ -34,6 +40,30 @@ interface Character : Entity, Variable, EventDispatcher, Comparable<Character> {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,13 +29,16 @@ interface SuspendableContext<C : Character> : Context<C> {
}
}

/**
* 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73d6575

Please sign in to comment.