BuffMgr.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const l = t("App"),
  6. a = t("GameConst"),
  7. r = t("IBuff"),
  8. h = {
  9. ADD_IDLE: 1,
  10. CUSTOMER_MOVE_SPEED: 0,
  11. WAITER_SPEED: 0,
  12. CHEF_SPEED: 0,
  13. COOK_SPEED: 0,
  14. FOOD_SELL_RATE: 1,
  15. ALL_EMPLOYEES_MOVE_SPEED: 0
  16. };
  17. class s {
  18. constructor() {
  19. (this._buffDataList = {}),
  20. (this._globalBuffList = {}),
  21. (this._regionBuffList = {}),
  22. (this._globalBuffAttrList = null),
  23. (this._regionBuffAttrList = {}),
  24. ObjectPool.registerClass(r.BuffAttr, "BuffAttr"),
  25. (this._globalBuffAttrList = r.BuffAttr.create(h)),
  26. (this.buffDataManager = l.default.ConfigManager.getConfig("BuffDataManager")),
  27. l.default.TimerManager.doTimer(500, 0, this.routine, this),
  28. l.default.SaveManage.add(this, "buff", !1, !0),
  29. l.default.SaveManage.load("buff");
  30. }
  31. checkBuff(t, e) {
  32. return !!(t.buffEndTime && t.buffEndTime < e);
  33. }
  34. routine(t) {
  35. var e,
  36. i,
  37. s = l.default.DateUtils.Now();
  38. for (e in this._globalBuffList) {
  39. var o = this._globalBuffList[e];
  40. o.buffEndTime && o.buffEndTime < s && this.removeGlobalBuff(o.buffIndex);
  41. }
  42. for (i in this._regionBuffList) {
  43. var a,
  44. n = this._regionBuffList[i];
  45. for (a in n) {
  46. var r = n[a];
  47. this.checkBuff(r, s) && this.removeRegionBuff(Number(i), r.buffIndex);
  48. }
  49. }
  50. }
  51. getGlobalBuffList() {
  52. return this._globalBuffList;
  53. }
  54. getGlobalBuffByIndex(t) {
  55. return this._globalBuffList[t];
  56. }
  57. addGlobalBuff(t) {
  58. t.buffType || (t.buffType = this.buffDataManager.getType(t.buffIndex));
  59. let e = this._globalBuffList[t.buffIndex];
  60. var i;
  61. e && e.buffValue == t.buffValue
  62. ? ((i = l.default.DateUtils.Now()),
  63. e.buffEndTime && e.buffEndTime > i
  64. ? (e.buffEndTime += t.buffEndTime - i)
  65. : e.buffEndTime && e.buffEndTime <= i
  66. ? (e.buffEndTime = t.buffEndTime)
  67. : (this._globalBuffList[t.buffIndex] = t))
  68. : (this._globalBuffList[t.buffIndex] = t),
  69. this.calGlobalBuffAttr(),
  70. l.default.NotificationCenter.dispatch(a.GameNotificationConst.UPDATE_BUFF, -1, -1, t.buffType);
  71. }
  72. removeGlobalBuff(t) {
  73. var e = this._globalBuffList[t];
  74. delete this._globalBuffList[t],
  75. this.calGlobalBuffAttr(),
  76. l.default.NotificationCenter.dispatch(a.GameNotificationConst.UPDATE_BUFF, -1, -1, e.buffType);
  77. }
  78. getKcBuffList() {
  79. return this._regionBuffList;
  80. }
  81. getKcBuffListById(t) {
  82. return this._regionBuffList[t];
  83. }
  84. getKcBuffByIndex(t, e) {
  85. return this._regionBuffList[t] || (this._regionBuffList[t] = {}), this._regionBuffList[t][e];
  86. }
  87. openNewRegion(t) {
  88. (this._regionBuffList[t] = this._regionBuffList[t] || {}),
  89. this._regionBuffAttrList[t] && (this._regionBuffAttrList[t] = r.BuffAttr.create(h)),
  90. this.calRegionBuffAttrById(t);
  91. }
  92. closeRegion(t) {
  93. delete this._regionBuffList[t];
  94. }
  95. addRegionBuff(t, e) {
  96. e.buffType || (e.buffType = this.buffDataManager.getType(e.buffIndex)),
  97. this._regionBuffList[t] || (this._regionBuffList[t] = {});
  98. let i = this._regionBuffList[t],
  99. s = i[e.buffIndex];
  100. var o;
  101. s && s.buffValue == e.buffValue
  102. ? ((o = l.default.DateUtils.Now()),
  103. s.buffEndTime && s.buffEndTime > o
  104. ? (s.buffEndTime += e.buffEndTime - o)
  105. : s.buffEndTime && s.buffEndTime <= o
  106. ? (s.buffEndTime = e.buffEndTime)
  107. : (i[e.buffIndex] = e))
  108. : (i[e.buffIndex] = e),
  109. this.calRegionBuffAttrById(t, !0),
  110. l.default.NotificationCenter.dispatch(a.GameNotificationConst.UPDATE_BUFF, t, -1, e.buffType);
  111. }
  112. removeRegionBuff(t, e) {
  113. this._regionBuffList[t] || (this._regionBuffList[t] = {});
  114. let i = this._regionBuffList[t];
  115. var s = i[e];
  116. delete i[e],
  117. this.calRegionBuffAttrById(t, !0),
  118. l.default.NotificationCenter.dispatch(a.GameNotificationConst.UPDATE_BUFF, t, -1, s.buffType);
  119. }
  120. calGlobalBuffAttr() {
  121. for (var t in (this._globalBuffAttrList.reset(), this._globalBuffList)) {
  122. var e = this._globalBuffList[t],
  123. t = e.buffType;
  124. this._globalBuffAttrList.addBuffValue(t, e.buffValue);
  125. }
  126. this._globalBuffAttrList.claFinish(), this.calRegionBuffAttr();
  127. }
  128. calRegionBuffAttrById(t, e = 0) {
  129. var i,
  130. s = this._regionBuffList[t];
  131. this._regionBuffAttrList[t] || (this._regionBuffAttrList[t] = r.BuffAttr.create(h));
  132. let o = this._regionBuffAttrList[t];
  133. for (i in (o.reset(), s)) {
  134. var a = s[i],
  135. n = a.buffType;
  136. o.addBuffValue(n, a.buffValue);
  137. }
  138. o.claFinish(), o.addBuffAttr(this._globalBuffAttrList);
  139. }
  140. calRegionBuffAttr() {
  141. for (var t in this._regionBuffList) this.calRegionBuffAttrById(t);
  142. }
  143. getRegionBuffAttrList(t) {
  144. return (
  145. (this._regionBuffAttrList[t] = this._regionBuffAttrList[t] || r.BuffAttr.create()),
  146. this._regionBuffAttrList[t]
  147. );
  148. }
  149. setMemento(t) {
  150. t
  151. ? ((this._globalBuffList = this._buffDataList[0] = t[0] || {}),
  152. (this._regionBuffList = this._buffDataList[1] = t[1] || {}))
  153. : ((this._globalBuffList = this._buffDataList[0] = this._buffDataList[0] || {}),
  154. (this._regionBuffList = this._buffDataList[1] = this._buffDataList[1] || {})),
  155. this.calGlobalBuffAttr();
  156. }
  157. createMemento() {
  158. return this._buffDataList;
  159. }
  160. save() {}
  161. }
  162. (i.default = s).ins = null;