manager.lua 584 B

1234567891011121314151617181920212223242526272829303132
  1. local buffs = lib.object.create()
  2. function buffs:add(key, config)
  3. self.list = self.list or {}
  4. local buff = app.buffs[key]:new(util.merge({ owner = self.owner }, config))
  5. self.list[buff] = buff
  6. return buff
  7. end
  8. function buffs:remove(buff)
  9. if not self.list[buff] then return end
  10. self.list[buff]:remove()
  11. self.list[buff] = nil
  12. return buff
  13. end
  14. function buffs:withTag(tag)
  15. return util.filter(self.list or {}, function(buff)
  16. return util.find(buff.tags or {}, tag)
  17. end)
  18. end
  19. function buffs:getFear()
  20. return util.first(self:withTag('fear'))
  21. end
  22. return buffs