From 99425f09913a39a7cc3b380cd22430f1e713024a Mon Sep 17 00:00:00 2001 From: Ceikry Date: Sat, 22 Apr 2023 13:37:59 +0000 Subject: [PATCH] Reworked skill-based random event logic --- .../content/global/ame/RandomEventManager.kt | 25 ++++----- .../main/content/global/ame/RandomEvents.kt | 56 ++++++++++++------- .../core/game/node/entity/skill/Skills.java | 3 + 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Server/src/main/content/global/ame/RandomEventManager.kt b/Server/src/main/content/global/ame/RandomEventManager.kt index 5b37e039a..083dd7bf5 100644 --- a/Server/src/main/content/global/ame/RandomEventManager.kt +++ b/Server/src/main/content/global/ame/RandomEventManager.kt @@ -13,6 +13,7 @@ import core.game.world.GameWorld import core.game.world.repository.Repository import core.tools.Log import kotlin.random.Random +import content.global.ame.RandomEvents class RandomEventManager(val player: Player? = null) : LoginListener, EventHook, Commands { var event: content.global.ame.RandomEventNPC? = null @@ -39,22 +40,20 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook< return } if (player!!.zoneMonitor.isRestricted(ZoneRestriction.RANDOM_EVENTS)) { - nextSpawn = GameWorld.ticks + 3000 + rollNextSpawn() return } if (getAttribute(player, "re-npc", null) != null) return val currentAction = player.pulseManager.current?.toString() ?: "None" - val ame: content.global.ame.RandomEvents = if(currentAction.contains("WoodcuttingSkillPulse") && Random.nextBoolean()){ - content.global.ame.RandomEvents.TREE_SPIRIT - } else if(currentAction.contains("FishingPulse") && Random.nextBoolean()){ - content.global.ame.RandomEvents.RIVER_TROLL - } else if(currentAction.contains("MiningSkillPulse") && Random.nextBoolean()){ - content.global.ame.RandomEvents.ROCK_GOLEM - } else if(currentAction.contains("BoneBuryingOptionPlugin") && Random.nextBoolean()){ - content.global.ame.RandomEvents.SHADE - } else { - content.global.ame.RandomEvents.values().filter { it.type != "skill" }.random() - } + + //Give us a decent pool of events to pick from randomly, with the skill-based random event mixed in if applicable. + //This is just to provide a bit more randomization (you don't want to get the skill-based randoms EVERY TIME when training woodcutting, for example.) + val ame = listOf ( + RandomEvents.getSkillBasedRandomEvent (player.skills.lastTrainedSkill), + RandomEvents.getNonSkillRandom(), + RandomEvents.getNonSkillRandom() + ).filter{ it != null }.random() ?: RandomEvents.getNonSkillRandom() //Absolute cosmic bit-flip tier safety fallback + event = ame.npc.create(player,ame.loot,ame.type) if (event!!.spawnLocation == null) { nextSpawn = GameWorld.ticks + 3000 @@ -92,4 +91,4 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook< return getAttribute(player, "random-manager", null) } } -} \ No newline at end of file +} diff --git a/Server/src/main/content/global/ame/RandomEvents.kt b/Server/src/main/content/global/ame/RandomEvents.kt index 7c586596d..2318b403c 100644 --- a/Server/src/main/content/global/ame/RandomEvents.kt +++ b/Server/src/main/content/global/ame/RandomEvents.kt @@ -15,11 +15,12 @@ import content.global.ame.events.zombie.ZombieRENPC import core.api.utils.WeightBasedTable import core.api.utils.WeightedItem +import core.game.node.entity.skill.Skills -enum class RandomEvents(val npc: RandomEventNPC, val loot: WeightBasedTable? = null) { - SANDWICH_LADY(SandwichLadyRENPC()), - GENIE(GenieNPC()), - CERTER(CerterNPC(), WeightBasedTable.create( +enum class RandomEvents(val npc: RandomEventNPC, val loot: WeightBasedTable? = null, val skillId: Int = -1, val type: String = "") { + SANDWICH_LADY(npc = SandwichLadyRENPC()), + GENIE(npc = GenieNPC()), + CERTER(npc = CerterNPC(), loot = WeightBasedTable.create( WeightedItem(Items.UNCUT_SAPPHIRE_1623,1,1,3.4), WeightedItem(Items.KEBAB_1971,1,1,1.7), WeightedItem(Items.UNCUT_EMERALD_1621,1,1,1.7), @@ -36,25 +37,40 @@ enum class RandomEvents(val npc: RandomEventNPC, val loot: WeightBasedTable? = n WeightedItem(Items.TOOTH_HALF_OF_A_KEY_985,1,1,0.1), WeightedItem(Items.LOOP_HALF_OF_A_KEY_987,1,1,0.1) )), - DRILL_DEMON(SeargentDamienNPC()), - EVIL_CHICKEN(EvilChickenNPC()), - SURPRISE_EXAM(MysteriousOldManNPC(),"sexam"), - TREE_SPIRIT(TreeSpiritRENPC(),"skill"), - RIVER_TROLL(RiverTrollRENPC(),"skill"), - ROCK_GOLEM(RockGolemRENPC(),"skill"), - SHADE(ShadeRENPC(),"skill"), - ZOMBIE(ZombieRENPC(),"skill"); - - var type: String = "" - private set - - constructor(npc: RandomEventNPC, type: String) : this(npc,null){ - this.type = type - } + DRILL_DEMON(npc = SeargentDamienNPC()), + EVIL_CHICKEN(npc = EvilChickenNPC()), + SURPRISE_EXAM(npc = MysteriousOldManNPC(), type = "sexam"), + TREE_SPIRIT(npc = TreeSpiritRENPC(), skillId = Skills.WOODCUTTING), + RIVER_TROLL(RiverTrollRENPC(), skillId = Skills.FISHING), + ROCK_GOLEM(RockGolemRENPC(), skillId = Skills.MINING), + SHADE(ShadeRENPC(), skillId = Skills.PRAYER), + ZOMBIE(ZombieRENPC(), skillId = Skills.PRAYER); companion object { @JvmField val randomIDs = values().map { it.npc.id }.toList() + val skillMap = HashMap>() + val nonSkillList = ArrayList() + + init { populateMappings() } + + fun getSkillBasedRandomEvent (skill: Int) : RandomEvents? { + return skillMap[skill]?.random() + } + + fun getNonSkillRandom() : RandomEvents { + return nonSkillList.random() + } + + private fun populateMappings() { + for (event in values()) { + if (event.skillId != -1) { + val list = skillMap[event.skillId] ?: ArrayList().also { skillMap[event.skillId] = it } + list.add (event) + } + else nonSkillList.add (event) + } + } } -} \ No newline at end of file +} diff --git a/Server/src/main/core/game/node/entity/skill/Skills.java b/Server/src/main/core/game/node/entity/skill/Skills.java index e2502a07f..134ab86ff 100644 --- a/Server/src/main/core/game/node/entity/skill/Skills.java +++ b/Server/src/main/core/game/node/entity/skill/Skills.java @@ -125,6 +125,8 @@ public final class Skills { */ private int skillMilestone; + public int lastTrainedSkill = -1; + /** * Constructs a new {@code Skills} {@code Object}. * @param entity The entity. @@ -299,6 +301,7 @@ public final class Skills { lastUpdateXp = this.experience.clone(); lastUpdate = GameWorld.getTicks(); } + lastTrainedSkill = slot; } /**