mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add an await function to the AsyncActionRunner trait
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
plugin {
|
||||
name = "Apollo Plugin API"
|
||||
description = "Helpers and API for common plugin usecases"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.apollo.game.plugins.api
|
||||
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.cache.def.ObjectDefinition
|
||||
|
||||
object Definitions {
|
||||
fun item(id: Int): ItemDefinition? {
|
||||
return ItemDefinition.lookup(id)
|
||||
}
|
||||
|
||||
fun obj(id: Int): ObjectDefinition? {
|
||||
return ObjectDefinition.lookup(id)
|
||||
}
|
||||
|
||||
fun npc(id: Int): NpcDefinition? {
|
||||
return NpcDefinition.lookup(id)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.apollo.game.plugins.api
|
||||
|
||||
import org.apollo.game.model.entity.Skill
|
||||
import org.apollo.game.model.entity.SkillSet
|
||||
|
||||
val SkillSet.attack: Skill get() = getSkill(Skill.ATTACK)
|
||||
val SkillSet.defence: Skill get() = getSkill(Skill.DEFENCE)
|
||||
val SkillSet.strength: Skill get() = getSkill(Skill.STRENGTH)
|
||||
val SkillSet.hitpoints: Skill get() = getSkill(Skill.HITPOINTS)
|
||||
val SkillSet.ranged: Skill get() = getSkill(Skill.RANGED)
|
||||
val SkillSet.prayer: Skill get() = getSkill(Skill.PRAYER)
|
||||
val SkillSet.magic: Skill get() = getSkill(Skill.MAGIC)
|
||||
val SkillSet.cooking: Skill get() = getSkill(Skill.COOKING)
|
||||
val SkillSet.woodcutting: Skill get() = getSkill(Skill.WOODCUTTING)
|
||||
val SkillSet.fletching: Skill get() = getSkill(Skill.FLETCHING)
|
||||
val SkillSet.fishing: Skill get() = getSkill(Skill.FISHING)
|
||||
val SkillSet.firemaking: Skill get() = getSkill(Skill.FIREMAKING)
|
||||
val SkillSet.crafting: Skill get() = getSkill(Skill.CRAFTING)
|
||||
val SkillSet.smithing: Skill get() = getSkill(Skill.SMITHING)
|
||||
val SkillSet.mining: Skill get() = getSkill(Skill.MINING)
|
||||
val SkillSet.herblore: Skill get() = getSkill(Skill.HERBLORE)
|
||||
val SkillSet.agility: Skill get() = getSkill(Skill.AGILITY)
|
||||
val SkillSet.thieving: Skill get() = getSkill(Skill.THIEVING)
|
||||
val SkillSet.slayer: Skill get() = getSkill(Skill.SLAYER)
|
||||
val SkillSet.farming: Skill get() = getSkill(Skill.FARMING)
|
||||
val SkillSet.runecraft: Skill get() = getSkill(Skill.RUNECRAFT)
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.apollo.game.action
|
||||
|
||||
import kotlinx.coroutines.experimental.*
|
||||
import kotlinx.coroutines.experimental.CommonPool
|
||||
import kotlinx.coroutines.experimental.Job
|
||||
import kotlinx.coroutines.experimental.channels.Channel
|
||||
import kotlinx.coroutines.experimental.launch
|
||||
import kotlinx.coroutines.experimental.selects.select
|
||||
import org.apollo.game.model.entity.Mob
|
||||
import java.util.function.Supplier
|
||||
|
||||
class AsyncActionRunner(val actionSupplier: () -> Action<*>, val callback: suspend () -> Unit) {
|
||||
var job: Job? = null
|
||||
@@ -53,4 +53,15 @@ class AsyncActionRunner(val actionSupplier: () -> Action<*>, val callback: suspe
|
||||
remainingPulses -= numPulses
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(condition: () -> Boolean, timeout: Int = 15) {
|
||||
var remainingPulsesBeforeTimeout = timeout
|
||||
|
||||
while (!condition.invoke()) {
|
||||
remainingPulsesBeforeTimeout -= pulseChannel.receive()
|
||||
if (remainingPulsesBeforeTimeout <= 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user