Reworked skill-based random event logic
This commit is contained in:
@@ -13,6 +13,7 @@ import core.game.world.GameWorld
|
|||||||
import core.game.world.repository.Repository
|
import core.game.world.repository.Repository
|
||||||
import core.tools.Log
|
import core.tools.Log
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
import content.global.ame.RandomEvents
|
||||||
|
|
||||||
class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<TickEvent>, Commands {
|
class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<TickEvent>, Commands {
|
||||||
var event: content.global.ame.RandomEventNPC? = null
|
var event: content.global.ame.RandomEventNPC? = null
|
||||||
@@ -39,22 +40,20 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (player!!.zoneMonitor.isRestricted(ZoneRestriction.RANDOM_EVENTS)) {
|
if (player!!.zoneMonitor.isRestricted(ZoneRestriction.RANDOM_EVENTS)) {
|
||||||
nextSpawn = GameWorld.ticks + 3000
|
rollNextSpawn()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (getAttribute<content.global.ame.RandomEventNPC?>(player, "re-npc", null) != null) return
|
if (getAttribute<content.global.ame.RandomEventNPC?>(player, "re-npc", null) != null) return
|
||||||
val currentAction = player.pulseManager.current?.toString() ?: "None"
|
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
|
//Give us a decent pool of events to pick from randomly, with the skill-based random event mixed in if applicable.
|
||||||
} else if(currentAction.contains("FishingPulse") && Random.nextBoolean()){
|
//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.)
|
||||||
content.global.ame.RandomEvents.RIVER_TROLL
|
val ame = listOf (
|
||||||
} else if(currentAction.contains("MiningSkillPulse") && Random.nextBoolean()){
|
RandomEvents.getSkillBasedRandomEvent (player.skills.lastTrainedSkill),
|
||||||
content.global.ame.RandomEvents.ROCK_GOLEM
|
RandomEvents.getNonSkillRandom(),
|
||||||
} else if(currentAction.contains("BoneBuryingOptionPlugin") && Random.nextBoolean()){
|
RandomEvents.getNonSkillRandom()
|
||||||
content.global.ame.RandomEvents.SHADE
|
).filter{ it != null }.random() ?: RandomEvents.getNonSkillRandom() //Absolute cosmic bit-flip tier safety fallback
|
||||||
} else {
|
|
||||||
content.global.ame.RandomEvents.values().filter { it.type != "skill" }.random()
|
|
||||||
}
|
|
||||||
event = ame.npc.create(player,ame.loot,ame.type)
|
event = ame.npc.create(player,ame.loot,ame.type)
|
||||||
if (event!!.spawnLocation == null) {
|
if (event!!.spawnLocation == null) {
|
||||||
nextSpawn = GameWorld.ticks + 3000
|
nextSpawn = GameWorld.ticks + 3000
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ import content.global.ame.events.zombie.ZombieRENPC
|
|||||||
|
|
||||||
import core.api.utils.WeightBasedTable
|
import core.api.utils.WeightBasedTable
|
||||||
import core.api.utils.WeightedItem
|
import core.api.utils.WeightedItem
|
||||||
|
import core.game.node.entity.skill.Skills
|
||||||
|
|
||||||
enum class RandomEvents(val npc: RandomEventNPC, val loot: WeightBasedTable? = null) {
|
enum class RandomEvents(val npc: RandomEventNPC, val loot: WeightBasedTable? = null, val skillId: Int = -1, val type: String = "") {
|
||||||
SANDWICH_LADY(SandwichLadyRENPC()),
|
SANDWICH_LADY(npc = SandwichLadyRENPC()),
|
||||||
GENIE(GenieNPC()),
|
GENIE(npc = GenieNPC()),
|
||||||
CERTER(CerterNPC(), WeightBasedTable.create(
|
CERTER(npc = CerterNPC(), loot = WeightBasedTable.create(
|
||||||
WeightedItem(Items.UNCUT_SAPPHIRE_1623,1,1,3.4),
|
WeightedItem(Items.UNCUT_SAPPHIRE_1623,1,1,3.4),
|
||||||
WeightedItem(Items.KEBAB_1971,1,1,1.7),
|
WeightedItem(Items.KEBAB_1971,1,1,1.7),
|
||||||
WeightedItem(Items.UNCUT_EMERALD_1621,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.TOOTH_HALF_OF_A_KEY_985,1,1,0.1),
|
||||||
WeightedItem(Items.LOOP_HALF_OF_A_KEY_987,1,1,0.1)
|
WeightedItem(Items.LOOP_HALF_OF_A_KEY_987,1,1,0.1)
|
||||||
)),
|
)),
|
||||||
DRILL_DEMON(SeargentDamienNPC()),
|
DRILL_DEMON(npc = SeargentDamienNPC()),
|
||||||
EVIL_CHICKEN(EvilChickenNPC()),
|
EVIL_CHICKEN(npc = EvilChickenNPC()),
|
||||||
SURPRISE_EXAM(MysteriousOldManNPC(),"sexam"),
|
SURPRISE_EXAM(npc = MysteriousOldManNPC(), type = "sexam"),
|
||||||
TREE_SPIRIT(TreeSpiritRENPC(),"skill"),
|
TREE_SPIRIT(npc = TreeSpiritRENPC(), skillId = Skills.WOODCUTTING),
|
||||||
RIVER_TROLL(RiverTrollRENPC(),"skill"),
|
RIVER_TROLL(RiverTrollRENPC(), skillId = Skills.FISHING),
|
||||||
ROCK_GOLEM(RockGolemRENPC(),"skill"),
|
ROCK_GOLEM(RockGolemRENPC(), skillId = Skills.MINING),
|
||||||
SHADE(ShadeRENPC(),"skill"),
|
SHADE(ShadeRENPC(), skillId = Skills.PRAYER),
|
||||||
ZOMBIE(ZombieRENPC(),"skill");
|
ZOMBIE(ZombieRENPC(), skillId = Skills.PRAYER);
|
||||||
|
|
||||||
var type: String = ""
|
|
||||||
private set
|
|
||||||
|
|
||||||
constructor(npc: RandomEventNPC, type: String) : this(npc,null){
|
|
||||||
this.type = type
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val randomIDs = values().map { it.npc.id }.toList()
|
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;
|
private int skillMilestone;
|
||||||
|
|
||||||
|
public int lastTrainedSkill = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new {@code Skills} {@code Object}.
|
* Constructs a new {@code Skills} {@code Object}.
|
||||||
* @param entity The entity.
|
* @param entity The entity.
|
||||||
@@ -299,6 +301,7 @@ public final class Skills {
|
|||||||
lastUpdateXp = this.experience.clone();
|
lastUpdateXp = this.experience.clone();
|
||||||
lastUpdate = GameWorld.getTicks();
|
lastUpdate = GameWorld.getTicks();
|
||||||
}
|
}
|
||||||
|
lastTrainedSkill = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user