Reworked skill-based random event logic

This commit is contained in:
Ceikry
2023-04-22 13:37:59 +00:00
committed by Ryan
parent 9619f5b3a7
commit 99425f0991
3 changed files with 51 additions and 33 deletions
@@ -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<TickEvent>, 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<content.global.ame.RandomEventNPC?>(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
@@ -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<Int, ArrayList<RandomEvents>>()
val nonSkillList = ArrayList<RandomEvents>()
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<RandomEvents>().also { skillMap[event.skillId] = it }
list.add (event)
}
else nonSkillList.add (event)
}
}
}
}
@@ -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;
}
/**