Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gg.rsmod.game.model.buffs
- import gg.rsmod.game.model.entity.Pawn
- import gg.rsmod.util.ticks
- import java.util.concurrent.TimeUnit
- class BuffHandler(val pawn: Pawn) {
- var timers = mutableListOf<BuffTimer>()
- fun add(buff: Buff, time: Int = -1) {
- val time = if (time == -1) buff.time else time
- if (time == 0) return
- timers.removeIf { it.buff.override && (it.buff.id == buff.id || it.buff.type == buff.type)}
- val timer = BuffTimer(buff, time.ticks(TimeUnit.SECONDS))
- timers.add(timer)
- TODO("Display buff for player with seconds remaining")
- }
- fun remove(buff: Buff) {
- buff.onEnd(pawn)
- timers.removeIf { it.buff.id == buff.id }
- TODO("Remove buff from displayed buffs for player")
- }
- fun reset() {
- timers.forEach { it.buff.onEnd(pawn) }
- timers.clear()
- TODO("Remove buffs from displayed buffs for player")
- }
- fun resetTransient() {
- timers.filterNot { it.buff.persistent }.forEach { it.buff.onEnd(pawn) }
- timers.retainAll { it.buff.persistent }
- TODO("Remove buffs from displayed buffs for player")
- }
- fun isActive(timer: BuffTimer): Boolean {
- return timers.contains(timer)
- }
- fun cycle() {
- timers.forEach {
- if (--it.ticks <= 0) {
- remove(it.buff)
- it.buff.onEnd(pawn)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement