63 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import GameModel from "../ts/core/GameModel";
import ItemUtil from "../ts/core/ItemUtil";
class GoodsMgr {
constructor() {
// this.Init();
}
Init() {
cc.loader.loadRes(`Prefabs/WorkShopPanel`, cc.Prefab, (err, prefab) => {
this.WorkShopPanel = prefab;
});
}
getItem(itemid) {
let itemInfo = ItemUtil.getItemData(itemid);
if (!itemInfo){
return null;
}
let count = GameModel.player.itemList[itemid];
if (count == null) {
count = 0;
}
itemInfo.count = count;
return itemInfo;
}
subItem(itemid) {
let itemInfo = this.getItem(itemid);
if (itemInfo == null || itemInfo.count <= 0) {
return;
}
let params={
roleid: GameModel.player.roleid,
itemid: itemid,
count: itemInfo.count,
operation: 0
};
GameModel.send('c2s_update_bagitem',params);
}
addItem(itemid) {
let itemInfo = this.getItem(itemid);
if (itemInfo == null) {
return;
}
GameModel.send('c2s_update_bagitem', {
roleid: GameModel.player.roleid,
itemid: itemid,
count: 1,
operation: 1
});
}
}
let goodsmgr = null;
module.exports = (() => {
if (goodsmgr == null) {
goodsmgr = new GoodsMgr();
}
return goodsmgr;
})();