Advertisement
fiveriverflow

BuffHandler Kotlin

Aug 30th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.27 KB | None | 0 0
  1. package gg.rsmod.game.model.buffs
  2.  
  3. import gg.rsmod.game.model.entity.Pawn
  4. import gg.rsmod.util.ticks
  5. import java.util.concurrent.TimeUnit
  6.  
  7. class BuffHandler(val pawn: Pawn) {
  8.  
  9.     var timers = mutableListOf<BuffTimer>()
  10.  
  11.     fun add(buff: Buff, time: Int = -1) {
  12.         val time = if (time == -1) buff.time else time
  13.  
  14.         if (time == 0) return
  15.  
  16.         timers.removeIf { it.buff.override && (it.buff.id == buff.id || it.buff.type == buff.type)}
  17.  
  18.         val timer = BuffTimer(buff, time.ticks(TimeUnit.SECONDS))
  19.         timers.add(timer)
  20.         TODO("Display buff for player with seconds remaining")
  21.     }
  22.  
  23.     fun remove(buff: Buff) {
  24.         buff.onEnd(pawn)
  25.         timers.removeIf { it.buff.id == buff.id }
  26.         TODO("Remove buff from displayed buffs for player")
  27.     }
  28.  
  29.     fun reset() {
  30.         timers.forEach { it.buff.onEnd(pawn) }
  31.         timers.clear()
  32.         TODO("Remove buffs from displayed buffs for player")
  33.     }
  34.  
  35.     fun resetTransient() {
  36.         timers.filterNot { it.buff.persistent }.forEach { it.buff.onEnd(pawn) }
  37.         timers.retainAll { it.buff.persistent }
  38.         TODO("Remove buffs from displayed buffs for player")
  39.     }
  40.  
  41.     fun isActive(timer: BuffTimer): Boolean {
  42.         return timers.contains(timer)
  43.     }
  44.  
  45.     fun cycle() {
  46.         timers.forEach {
  47.             if (--it.ticks <= 0) {
  48.                 remove(it.buff)
  49.                 it.buff.onEnd(pawn)
  50.             }
  51.         }
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement