清理smc

This commit is contained in:
2025-03-18 16:00:04 +08:00
parent f7f9849d14
commit 3a7b0e4762
10 changed files with 20 additions and 347 deletions

View File

@@ -24,63 +24,15 @@ export class GoodsComp extends CCComp {
// this.on(ModuleEvent.Cmd, this.onHandler, this);
}
update_data(){
let goods:any=smc.goods[this.smc_index]
let gnode=this.node.getChildByName("item")
switch (goods.type) {
default:
let item=ecs.getEntity<Item>(Item)
item.load(goods.uuid,goods.num,gnode)
this.node.getChildByName("inventory").getComponent(Label).string="库存:"+goods.inventory.toString()
console.log("item",item)
break;
case 3:
let path = "game/gui/hchip";
let prefab: Prefab = oops.res.get(path, Prefab)!;
let node = instantiate(prefab);
node.parent=gnode
let hc= node.getComponent(HChipComp)
hc.update_data(goods.uuid,goods.num)
break
}
if(goods.cost > 0){
this.node.getChildByName("free").active=false
this.node.getChildByName("buy").getChildByName("cost").getComponent(Label).string=goods.cost.toString()
}else{
this.node.getChildByName("free").active=true
}
}
buy(){
console.log("购买商品"+this.smc_index)
let goods:any=smc.goods[this.smc_index]
if(smc.vmdata.gold.num <= goods.cost){
oops.gui.toast("金币不足");
return
}
if(goods.inventory <= 0){
oops.gui.toast("库存不足");
return
}
switch (goods.type) {
case 0:
smc.vmdata.gold.num+=goods.num
break;
case 1:
smc.vmdata.exp.num+=goods.num
break;
case 2:
smc.items[goods.uuid].num+=goods.num
break;
case 3:
smc.heros[goods.uuid].num += goods.num
break;
}
goods.inventory--
smc.vmdata.gold.num-=goods.cost
this.update_inventory()
}
update_inventory(){
this.node.getChildByName("inventory").getComponent(Label).string="库存:"+smc.goods[this.smc_index].inventory
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {