Fixed issue where eggs would occasionally spawn out-of-bounds

Added admin command to test egg spawning ::eggspawntest
This commit is contained in:
Ceikry 2024-04-02 11:49:37 +00:00 committed by Ryan
parent 68cf133955
commit 0ade8bdf02
2 changed files with 40 additions and 16 deletions

View file

@ -26,7 +26,7 @@ import core.tools.colorize
import org.rs09.consts.Items
import java.util.*
class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, LoginListener {
class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, LoginListener, Commands {
private val spawnedItems = ArrayList<GroundItem>()
private var timeUntilNextEggSpawn = 0
private var currentLoc = ""
@ -65,6 +65,13 @@ class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, Log
player.hook(Event.XpGained, xpEventHook)
}
override fun defineCommands() {
define("eggspawntest") {player, _ ->
notify(player, "Spawning 10 eggs nearby...")
repeat(10) { spawnEggFor(player) }
}
}
object xpEventHook : EventHook<XPGainEvent>
{
override fun process(entity: Entity, event: XPGainEvent) {
@ -76,17 +83,12 @@ class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, Log
val activeEggRate = if (GameWorld.settings!!.isDevMode) EGG_RATE_DEV else EGG_RATE
if (RandomFunction.roll(activeEggRate)) {
val dirs = Direction.values()
val dir = dirs[RandomFunction.random(dirs.size)]
val loc = entity.location.transform(dir, 3)
if (!Pathfinder.find(entity, loc).isSuccessful) return
GroundItemManager.create(Item(eggs.random()), loc, entity)
sendMessage(entity, colorize("%RAn egg has appeared nearby."))
}
if (RandomFunction.roll(activeEggRate))
spawnEggFor(entity)
}
}
fun getRandomLocations() : Pair<String, List<Location>>
{
val toReturn = ArrayList<Location>()
@ -251,7 +253,7 @@ class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, Log
Location.create(3089, 3481, 0),Location.create(3084, 3479, 0),Location.create(3108, 3499, 0),
Location.create(3110, 3517, 0),Location.create(3091, 3512, 0),Location.create(3092, 3507, 0),
Location.create(3081, 3513, 0),Location.create(3079, 3513, 1),Location.create(3080, 3508, 1),
Location.create(3108, 3499, 0),Location.create(3093, 3467, 0))
Location.create(3093, 3467, 0))
val TREE_GNOME_STRONGHOLD_SPOTS = arrayOf(
Location.create(2480, 3507, 0),Location.create(2486, 3513, 0),Location.create(2453, 3512, 0),
@ -288,6 +290,17 @@ class EasterEvent : WorldEvent("easter"), TickListener, InteractionListener, Log
}
}
fun spawnEggFor (player: Player)
{
val dirs = Direction.values()
val dir = dirs[RandomFunction.random(dirs.size)]
var loc = player.location.transform(dir, 3)
val path = Pathfinder.find(player, loc)
loc = Location.create(path.points.last.x, path.points.last.y, loc.z)
GroundItemManager.create(Item(eggs.random()), loc, player)
sendMessage(player, colorize("%RAn egg has appeared nearby."))
}
val lootTable = WeightBasedTable.create(
WeightedItem(Items.EASTER_EGG_1962, 1, 15, 0.10),
WeightedItem(Items.PURPLE_SWEETS_10476, 5, 15, 0.10),

View file

@ -62,14 +62,25 @@ class EasterEventTests {
sampleB = inst.getRandomLocations()
}
Assertions.assertEquals(true, similarityTolerance > 0)
}
val usedLocations = ArrayList<Location>()
for (loc in sampleB.second)
@Test fun eachLocationGroupShouldContainNoDuplicateLocations() {
for (locSet in arrayOf(
EasterEvent.FALADOR_SPOTS,
EasterEvent.EDGEVILLE_SPOTS,
EasterEvent.DRAYNOR_SPOTS,
EasterEvent.LUMBRIDGE_SPOTS,
EasterEvent.TREE_GNOME_STRONGHOLD_SPOTS
))
{
if (!usedLocations.contains(loc))
usedLocations.add(loc)
else
Assertions.fail("Loc $loc appeared more than once!")
val usedLocations = ArrayList<Location>()
for (loc in locSet)
{
if (!usedLocations.contains(loc))
usedLocations.add(loc)
else
Assertions.fail("Loc $loc appeared more than once!")
}
}
}