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

Fix on_enter_region and on_exit_region not being fired while moving #170

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/MovementQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class MovementQueue(val pawn: Pawn) {
val collision = pawn.world.collision

var next = steps.poll()
var tile = pawn.tile
if (next != null) {
var tile = pawn.tile

var walkDirection: Direction?
var runDirection: Direction? = null
Expand Down Expand Up @@ -81,12 +81,12 @@ class MovementQueue(val pawn: Pawn) {

if (walkDirection != null && walkDirection != Direction.NONE) {
pawn.steps = StepDirection(walkDirection, runDirection)
pawn.tile = Tile(tile)
if (runDirection != null) {
pawn.addBlock(UpdateBlockType.MOVEMENT)
}
}
}
pawn.tile = Tile(tile)
}

private fun addStep(current: Tile, next: Tile, type: StepType, detectCollision: Boolean) {
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/kotlin/gg/rsmod/game/model/entity/Entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Entity {
/**
* The current 3D [Tile] that this [Pawn] is standing on in the [World].
*/
lateinit var tile: Tile
open lateinit var tile: Tile

abstract val entityType: EntityType

Expand Down
1 change: 1 addition & 0 deletions game/src/main/kotlin/gg/rsmod/game/model/entity/Npc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Npc private constructor(val id: Int, world: World, val spawnTile: Tile) :
timerCycle()
}
hitsCycle()
updateLastTile()
}

/**
Expand Down
12 changes: 12 additions & 0 deletions game/src/main/kotlin/gg/rsmod/game/model/entity/Pawn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ abstract class Pawn(val world: World) : Entity() {
*/
internal var blockBuffer = UpdateBlockBuffer()

override var tile: Tile = Tile(0, 0, 0)
set(value) {
lastTileBuffer = field
field = value
}

/**
* The 3D [Tile] that this pawn was standing on, in the last game cycle.
*/
internal var lastTile: Tile? = null

private var lastTileBuffer: Tile? = null

/**
* The last tile that was set for the pawn's [gg.rsmod.game.model.region.Chunk].
*/
Expand Down Expand Up @@ -151,6 +159,10 @@ abstract class Pawn(val world: World) : Entity() {
*/
abstract fun cycle()

fun updateLastTile() {
lastTile = lastTileBuffer
}

fun isDead(): Boolean = getCurrentHp() == 0

fun isAlive(): Boolean = !isDead()
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/kotlin/gg/rsmod/game/model/entity/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ open class Player(world: World) : Pawn(world) {
movementQueue.clear()
lock = LockState.DELAY_ACTIONS

lastTile = Tile(tile)
moveTo(movement.finalDestination)

forceMove(movement)
Expand Down Expand Up @@ -366,6 +365,7 @@ open class Player(world: World) : Pawn(world) {
* conditions if any logic may modify other [Pawn]s.
*/
fun postCycle() {
updateLastTile()
/*
* Flush the channel at the end.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ object NpcPostSynchronizationTask : SynchronizationTask<Npc> {
val oldTile = pawn.lastTile
val moved = oldTile == null || !oldTile.sameAs(pawn.tile)

if (moved) {
pawn.lastTile = Tile(pawn.tile)
}
pawn.moved = false
pawn.steps = null
pawn.blockBuffer.clean()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gg.rsmod.game.sync.task

import gg.rsmod.game.model.Tile
import gg.rsmod.game.model.entity.Player
import gg.rsmod.game.service.GameService
import gg.rsmod.game.sync.SynchronizationTask
Expand All @@ -16,9 +15,6 @@ object PlayerPostSynchronizationTask : SynchronizationTask<Player> {
val moved = oldTile == null || !oldTile.sameAs(pawn.tile)
val changedHeight = oldTile?.height != pawn.tile.height

if (moved) {
pawn.lastTile = Tile(pawn.tile)
}
pawn.moved = false
pawn.steps = null
pawn.blockBuffer.clean()
Expand Down