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

Achievement task fixes #546

Merged
merged 7 commits into from
Jul 1, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package world.gregs.voidps.engine.data

import world.gregs.voidps.engine.client.ui.InterfaceOptions
import world.gregs.voidps.engine.client.ui.Interfaces
import world.gregs.voidps.engine.client.ui.open
import world.gregs.voidps.engine.client.update.view.Viewport
import world.gregs.voidps.engine.client.variable.PlayerVariables
import world.gregs.voidps.engine.data.definition.*
Expand Down Expand Up @@ -86,6 +87,7 @@ class AccountManager(
}
}
player.emit(RegionLoad)
player.open(player.interfaces.gameFrame)
player.emit(Spawn)
for (def in areaDefinitions.get(player.tile.zone)) {
if (player.tile in def.area) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.rsmod.game.pathfinder.collision.CollisionFlagMap
import org.rsmod.game.pathfinder.collision.CollisionStrategies
import org.rsmod.game.pathfinder.collision.CollisionStrategy
import world.gregs.voidps.engine.entity.character.Character
import world.gregs.voidps.engine.entity.character.size
import world.gregs.voidps.engine.get
import world.gregs.voidps.type.Area
import world.gregs.voidps.type.Tile
Expand Down Expand Up @@ -33,13 +34,13 @@ fun Collisions.clear(zone: Zone) {
deallocateIfPresent(zone.tile.x, zone.tile.y, zone.level)
}

fun Area.random(character: Character): Tile? = random(character.collision)
fun Area.random(character: Character): Tile? = random(character.collision, character.size)

fun Area.random(collision: CollisionStrategy = CollisionStrategies.Normal): Tile? {
fun Area.random(collision: CollisionStrategy = CollisionStrategies.Normal, size: Int = 1): Tile? {
val steps = get<StepValidator>()
var tile = random()
var exit = 100
while (!canTravel(steps, tile, collision)) {
while (!canFit(steps, tile, collision, size)) {
if (--exit <= 0) {
return null
}
Expand All @@ -48,9 +49,85 @@ fun Area.random(collision: CollisionStrategy = CollisionStrategies.Normal): Tile
return tile
}

private fun canTravel(steps: StepValidator, tile: Tile, collision: CollisionStrategy) =
steps.canTravel(x = tile.x, z = tile.y - 1, level = tile.level, size = 1, offsetX = 0, offsetZ = 1, extraFlag = 0, collision = collision) ||
steps.canTravel(x = tile.x, z = tile.y + 1, level = tile.level, size = 1, offsetX = 0, offsetZ = -1, extraFlag = 0, collision = collision) ||
steps.canTravel(x = tile.x - 1, z = tile.y, level = tile.level, size = 1, offsetX = 1, offsetZ = 0, extraFlag = 0, collision = collision) ||
steps.canTravel(x = tile.x + 1, z = tile.y, level = tile.level, size = 1, offsetX = -1, offsetZ = 0, extraFlag = 0, collision = collision)
private fun canFit(steps: StepValidator, tile: Tile, collision: CollisionStrategy, size: Int): Boolean {
val free = steps.canTravel(
x = tile.x,
z = tile.y - 1,
level = tile.level,
offsetX = 0,
offsetZ = 1,
size = size,
collision = collision
) || steps.canTravel(
x = tile.x,
z = tile.y + 1,
level = tile.level,
offsetX = 0,
offsetZ = -1,
size = size,
collision = collision
) || steps.canTravel(
x = tile.x - 1,
z = tile.y,
level = tile.level,
offsetX = 1,
offsetZ = 0,
size = size,
collision = collision
) || steps.canTravel(
x = tile.x + 1,
z = tile.y,
level = tile.level,
offsetX = -1,
offsetZ = 0,
size = size,
collision = collision
)
if (size == 1) {
return free
} else {
if (!free) {
return false
}
for (x in 0 until size) {
for (y in 0 until size) {
if (x != size - 1 && !steps.canTravel(
tile.level,
tile.x + x,
tile.y + y,
offsetX = 1,
offsetZ = 0,
collision = collision
)
) {
return false
}
if (y != size - 1 && !steps.canTravel(
tile.level,
tile.x + x,
tile.y + y,
offsetX = 0,
offsetZ = 1,
collision = collision
)
) {
return false
}
if (y != size - 1 && x != size - 1 && !steps.canTravel(
tile.level,
tile.x + x,
tile.y + y,
offsetX = 1,
offsetZ = 1,
collision = collision
)
) {
return false
}
}

}
return true
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AccountManagerTest : KoinMock() {

override val modules = listOf(module {
single { ItemDefinitions(emptyArray()) }
single { InterfaceDefinitions(emptyArray()) }
single { InterfaceDefinitions(emptyArray()).apply { ids = emptyMap() } }
single { AreaDefinitions(areas = mapOf(0 to setOf(AreaDefinition("area", Rectangle(Tile(0), 1, 1), emptySet())))) }
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.client.sendScript
import world.gregs.voidps.engine.client.variable.BitwiseValues
import world.gregs.voidps.engine.data.definition.VariableDefinitions
import world.gregs.voidps.engine.entity.World.name
import world.gregs.voidps.Main.name
import world.gregs.voidps.engine.entity.character.npc.NPCOption
import world.gregs.voidps.engine.entity.character.npc.npcOperate
import world.gregs.voidps.engine.entity.character.player.Player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import world.gregs.voidps.world.interact.entity.obj.teleportLand
import world.gregs.voidps.world.interact.entity.player.combat.prayer.prayerStart
import world.gregs.voidps.world.interact.entity.player.combat.range.ammo
import java.util.concurrent.TimeUnit

Check warning on line 31 in game/src/main/kotlin/world/gregs/voidps/world/activity/achievement/LumbridgeBeginnerTasks.kts

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive

move({ player.running && !player["on_the_run_task", false] }) {
player["on_the_run_task"] = true
Expand Down Expand Up @@ -168,7 +169,8 @@
}

itemAdded(inventory = "bank") { player ->
if (!player["hang_on_to_something_task", false]) {
val millis = System.currentTimeMillis() - player["creation", 0L]
if (millis > 1000 && !player["hang_on_to_something_task", false]) {
player["hang_on_to_something_task"] = true
player.addVarbit("task_reward_items", "magic_staff")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import world.gregs.voidps.engine.client.ui.event.interfaceOpen
import world.gregs.voidps.engine.client.ui.event.interfaceRefresh
import world.gregs.voidps.engine.client.ui.interfaceOption
import world.gregs.voidps.engine.client.ui.open
import world.gregs.voidps.engine.entity.playerSpawn
import world.gregs.voidps.engine.queue.weakQueue

val list = listOf(
Expand Down Expand Up @@ -37,10 +36,6 @@ val list = listOf(
"area_status_icon"
)

playerSpawn { player ->
player.open(player.interfaces.gameFrame)
}

Tab.entries.forEach { tab ->
val name = tab.name.toSnakeCase()
interfaceOption(name.toTitleCase(), name, "toplevel*") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fun teleport(player: Player, target: NPC) {
tile = abyss.random(player)
}
player.tele(tile!!)
player.levels.drain(Skill.Prayer, player.levels.get(Skill.Prayer))
player.clearAnimation()
}
}
Expand Down
Loading