123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import { Framework } from "../../framework/Framework";
- import { ItemEnum } from "../common/InterfaceAddEnum";
- import { MaterialConf } from "../config/MaterialConf";
- import { GameEvent } from "../data/GameEvent";
- import { GoodsData } from "../data/GoodsData";
- export class GoodsManager {
- static getBagGoods() {
- let _goodsData = GoodsData.getAllGoods();
- let bagList = [];
- for (const key in _goodsData) {
- if (Object.prototype.hasOwnProperty.call(_goodsData, key)) {
- const element = _goodsData[key];
- if (element.count > 0 && Number(element.conf['Showable'] == 1)) {
- bagList.push(element);
- }
- }
- }
- bagList.sort((a, b) => {
- return Number(a.id) > Number(b.id) ? -1 : 1;
- });
- return bagList;
- }
- static getGoodsById(id: string) {
- let _goodsData = GoodsData.getAllGoods();
- if (_goodsData[id]) {
- return _goodsData[id];
- } else {
- let mConf = MaterialConf.data[id];
- if (mConf) {
- let item = {
- id: id,
- count: 0,
- type: ItemEnum.material,
- conf: mConf,
- }
- return item;
- }
- }
- return null;
- }
- static addGoodsById(id: string, num: number) {
- let _goodsData = GoodsData.getAllGoods();
- let mConf = MaterialConf.data[id];
- if (mConf) {
- if (_goodsData[id]) {
- let sumCount = _goodsData[id].count + num;
- if (mConf.MaxStoreLimit) {
- if (sumCount > mConf.MaxStoreLimit) {
- _goodsData[id].count = mConf.MaxStoreLimit
- } else {
- _goodsData[id].count = sumCount
- }
- } else {
- _goodsData[id].count = sumCount
- }
- } else {
- let item = {
- id: id,
- count: num,
- type: ItemEnum.material,
- conf: mConf,
- }
- _goodsData[id] = item;
- }
- Framework.event.fireEvent(GameEvent.MaterialChange, id);
- //後期可能有紅點邏輯
- }
- }
- static getGoodsLocalInfo(id: string, num: number) {
- let _goodsData = GoodsData.getAllGoods();
- let mConf = MaterialConf.data[id];
- if (mConf) {
- let item = {
- id: id,
- count: num,
- type: ItemEnum.material,
- conf: mConf,
- }
- return item;
- }
- return null;
- }
- static parseServerAwards(data) {
- for (const element of data) {
- if (element[0] == 'material') {
- this.addGoodsById(element[1], element[2]);
- } else if (element[0] == 'equip') {
-
- }
- }
- }
- // //消息-讀郵件
- // static sendReadMailMsg(args: { id: string }, callback) {
- // LoginMgr.sendPost('user', 'read_mail', (data) => {
- // console.log(data);
- // // MailData.setMailReadById(args.id)
- // }, args)
- // }
- }
|