Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✅API BACK-COMPAT] Fixed TileCondition functionality #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions game/src/main/kotlin/gg/rsmod/game/model/queue/QueueTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ data class QueueTask(val ctx: Any, val priority: TaskPriority) : Continuation<Un
* of [Pawn] and that the height of the [tile] and [Pawn.tile] must be equal,
* as well as the x and z coordinates.
*/
suspend fun waitTile(tile: Tile): Unit = suspendCoroutine {
nextStep = SuspendableStep(TileCondition((ctx as Pawn).tile, tile), it)
suspend fun waitTile(tile: Tile, pawn: Pawn = ctx as Pawn): Unit = suspendCoroutine {
nextStep = SuspendableStep(TileCondition(pawn, tile), it)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gg.rsmod.game.model.queue.coroutine

import com.google.common.base.MoreObjects
import gg.rsmod.game.model.Tile
import gg.rsmod.game.model.entity.Pawn
import java.util.concurrent.atomic.AtomicInteger

/**
Expand Down Expand Up @@ -33,23 +34,23 @@ class WaitCondition(cycles: Int) : SuspendableCondition() {
}

/**
* A [SuspendableCondition] that waits for [src] to possess the exact same
* A [SuspendableCondition] that waits for [pawn] to possess the exact same
* coordinates as [dst] before permitting the coroutine to continue its logic.
*
* Note that the [src] and [dst] can't be the same coordinates if their height
* Note that the [pawn] and [dst] can't be the same coordinates if their height
* does not match as well as their x and z coordinates.
*
* @param src
* @param pawn
* The tile that must reach [dst] before the condition returns true.
*
* @param dst
* The tile that must be reached by [dst].
*/
class TileCondition(private val src: Tile, private val dst: Tile) : SuspendableCondition() {
class TileCondition(private val pawn: Pawn, private val dst: Tile) : SuspendableCondition() {

override fun resume(): Boolean = src.sameAs(dst)
override fun resume(): Boolean = pawn.tile.sameAs(dst)

override fun toString(): String = MoreObjects.toStringHelper(this).add("src", src).add("dst", dst).toString()
override fun toString(): String = MoreObjects.toStringHelper(this).add("pawn", pawn).add("dst", dst).toString()
}

/**
Expand Down