Skip to content

Commit

Permalink
Fix npcs messing with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed May 30, 2024
1 parent c8b634a commit 4199947
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import kotlin.test.assertTrue

internal class LumbridgeBeginnerTasksTest : WorldTest() {

override var loadNpcs = true

@Test
fun `On the Run`() = runTest {
val player = createPlayer("adventurer", emptyTile)
Expand Down
26 changes: 20 additions & 6 deletions game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ abstract class WorldTest : KoinTest {

val extraProperties: MutableMap<String, Any> = mutableMapOf()

open var loadNpcs: Boolean = false

fun tick(times: Int = 1) = runBlocking(Contexts.Game) {
repeat(times) {
GameLoop.tick++
Expand Down Expand Up @@ -128,7 +130,15 @@ abstract class WorldTest : KoinTest {
return objects.add(id, tile, shape, rotation)
}

fun createFloorItem(id: String, tile: Tile = Tile.EMPTY, amount: Int = 1, revealTicks: Int = FloorItems.NEVER, disappearTicks: Int = FloorItems.NEVER, charges: Int = 0, owner: Player? = null): FloorItem {
fun createFloorItem(
id: String,
tile: Tile = Tile.EMPTY,
amount: Int = 1,
revealTicks: Int = FloorItems.NEVER,
disappearTicks: Int = FloorItems.NEVER,
charges: Int = 0,
owner: Player? = null
): FloorItem {
return floorItems.add(tile, id, amount, revealTicks, disappearTicks, charges, owner)
}

Expand Down Expand Up @@ -167,9 +177,11 @@ abstract class WorldTest : KoinTest {
single { objectCollisionAdd }
single { objectCollisionAdd }
single { objectCollisionRemove }
single { Hunting(get(), get(), get(), get(), get(), get(), object : FakeRandom() {
override fun nextBits(bitCount: Int) = 0
}) }
single {
Hunting(get(), get(), get(), get(), get(), get(), object : FakeRandom() {
override fun nextBits(bitCount: Int) = 0
})
}
})
}
loadScripts()
Expand Down Expand Up @@ -213,7 +225,9 @@ abstract class WorldTest : KoinTest {
@BeforeEach
fun beforeEach() {
loadItemSpawns(floorItems, get())
loadNpcSpawns(npcs)
if (loadNpcs) {
loadNpcSpawns(npcs)
}
loadObjectSpawns(objects)
setRandom(FakeRandom())
}
Expand Down Expand Up @@ -256,7 +270,7 @@ abstract class WorldTest : KoinTest {
private val objectCollisionAdd: GameObjectCollisionAdd by lazy { GameObjectCollisionAdd(collisions) }
private val objectCollisionRemove: GameObjectCollisionRemove by lazy { GameObjectCollisionRemove(collisions) }
private val gameObjects: GameObjects by lazy { GameObjects(objectCollisionAdd, objectCollisionRemove, ZoneBatchUpdates(), objectDefinitions, storeUnused = true) }
private val mapDefinitions: MapDefinitions by lazy { MapDefinitions(CollisionDecoder( collisions), objectDefinitions, gameObjects, cache).loadCache() }
private val mapDefinitions: MapDefinitions by lazy { MapDefinitions(CollisionDecoder(collisions), objectDefinitions, gameObjects, cache).loadCache() }
private val fontDefinitions: FontDefinitions by lazy { FontDefinitions(FontDecoder().load(cache)).load() }
val emptyTile = Tile(2655, 4640)
}
Expand Down

0 comments on commit 4199947

Please sign in to comment.