GoodsManager.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Framework } from "../../framework/Framework";
  2. import { ObjectUtil } from "../../framework/util/ObjectUtil";
  3. import { AwardData, BaseItem, ItemEnum } from "../common/InterfaceAddEnum";
  4. import { MaterialConf } from "../config/MaterialConf";
  5. import { GameEvent } from "../data/GameEvent";
  6. import {GoodsData } from "../data/GoodsData";
  7. export class GoodsManager {
  8. static getBagGoods() {
  9. let _goodsData = GoodsData.getAllGoods();
  10. let bagList = [];
  11. for (const key in _goodsData) {
  12. if (Object.prototype.hasOwnProperty.call(_goodsData, key)) {
  13. const element = _goodsData[key];
  14. if (element.count > 0 && Number(element.conf['Showable'] == 1)) {
  15. bagList.push(element);
  16. }
  17. }
  18. }
  19. bagList.sort((a, b) => {
  20. return Number(a.id) > Number(b.id) ? -1 : 1;
  21. });
  22. return bagList;
  23. }
  24. static getGoodsById(id: string) {
  25. let _goodsData = GoodsData.getAllGoods();
  26. if (_goodsData[id]) {
  27. return _goodsData[id];
  28. } else {
  29. let mConf = MaterialConf.data[id];
  30. if (mConf) {
  31. let item:BaseItem = {
  32. id: id,
  33. count: 0,
  34. type: ItemEnum.material,
  35. conf: mConf,
  36. }
  37. return item;
  38. }
  39. }
  40. return null;
  41. }
  42. static addGoodsById(id: string, num: number):BaseItem {
  43. let _goodsData = GoodsData.getAllGoods();
  44. let mConf = MaterialConf.data[id];
  45. if (mConf) {
  46. if (_goodsData[id]) {
  47. let sumCount = _goodsData[id].count + num;
  48. if (mConf.MaxStoreLimit) {
  49. if (sumCount > mConf.MaxStoreLimit) {
  50. _goodsData[id].count = mConf.MaxStoreLimit
  51. } else {
  52. _goodsData[id].count = sumCount
  53. }
  54. } else {
  55. _goodsData[id].count = sumCount
  56. }
  57. } else {
  58. let item:BaseItem = {
  59. id: id,
  60. count: num,
  61. type: ItemEnum.material,
  62. conf: mConf,
  63. }
  64. _goodsData[id] = item;
  65. }
  66. Framework.event.fireEvent(GameEvent.MaterialChange, id);
  67. //後期可能有紅點邏輯
  68. let changeItem:BaseItem = ObjectUtil.deepCopy(_goodsData[id])
  69. changeItem.count = num
  70. return changeItem
  71. }
  72. }
  73. static getGoodsLocalInfo(id: string, num: number) {
  74. let _goodsData = GoodsData.getAllGoods();
  75. let mConf = MaterialConf.data[id];
  76. if (mConf) {
  77. let item:BaseItem = {
  78. id: id,
  79. count: num,
  80. type: ItemEnum.material,
  81. conf: mConf,
  82. }
  83. return item;
  84. }
  85. return null;
  86. }
  87. // //消息-讀郵件
  88. // static sendReadMailMsg(args: { id: string }, callback) {
  89. // LoginMgr.sendPost('user', 'read_mail', (data) => {
  90. // console.log(data);
  91. // // MailData.setMailReadById(args.id)
  92. // }, args)
  93. // }
  94. }