Brand.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Brand = Buff:New()
  2. --初始化Buff,通过传入一些自定义参数控制成长相关的数值
  3. function Brand:SetData(...)
  4. self.flag, self.endFunc = ... --标记,结束回调
  5. self.cover = true
  6. self.layer = 1
  7. self.maxLayer = 0
  8. -- 刷新排序等级
  9. self.sort = 4
  10. end
  11. --初始化后调用一次
  12. function Brand:OnStart()
  13. end
  14. --间隔N帧触发,返回true时表示继续触发,返回false立刻触发OnEnd
  15. function Brand:OnTrigger()
  16. return true
  17. end
  18. --效果结束时调用一次
  19. function Brand:OnEnd()
  20. if self.endFunc then
  21. self.endFunc()
  22. self.endFunc = nil
  23. end
  24. self.coverFunc = nil
  25. end
  26. --只有当cover字段为true时触发,返回true则被新效果覆盖
  27. function Brand:OnCover(newBuff)
  28. local b = newBuff.flag == self.flag
  29. if b then
  30. if newBuff.maxLayer == 0 then
  31. newBuff.layer = newBuff.layer + self.layer
  32. else
  33. newBuff.layer = math.min(newBuff.layer + self.layer, newBuff.maxLayer)
  34. end
  35. if newBuff.coverFunc then
  36. newBuff.coverFunc(self)
  37. end
  38. end
  39. return b
  40. end
  41. -- 比较buff
  42. function Brand:OnCompare(buff)
  43. return buff.flag == self.flag
  44. end
  45. return Brand