177 lines
6.2 KiB
TypeScript
177 lines
6.2 KiB
TypeScript
import { _decorator, instantiate, Prefab ,Node, Label, Sprite, resources, SpriteAtlas, v3} from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { Item } from "./Item";
|
|
import { Items } from "../common/config/Items";
|
|
import { HChipComp } from "../hero/HChipComp";
|
|
import { BoxDrop } from "../common/config/RewardSet";
|
|
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
|
import { SChipComp } from "../hero/SChipComp";
|
|
import { ItemComp } from "./ItemComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('LuckHomeCompComp')
|
|
@ecs.register('LuckHomeComp', false)
|
|
export class LuckHomeCompComp extends CCComp {
|
|
@property({ type: Node })
|
|
sbn: Node = null;
|
|
@property({ type: Node })
|
|
mbn: Node | null = null;
|
|
@property({ type: Node })
|
|
lbn: Node | null = null;
|
|
@property({ type: Node })
|
|
btnno: Node | null = null;
|
|
@property({ type: Node })
|
|
itmes: Node | null = null;
|
|
selected: string = "";
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
// this.frist();
|
|
}
|
|
frist(){
|
|
this.colse_reward()
|
|
}
|
|
|
|
open_sb() {
|
|
smc.vmdata.box.num--;
|
|
this.open_reward()
|
|
this.get_reward(1)
|
|
}
|
|
open_mb() {
|
|
if (smc.vmdata.box.num < 5) {oops.gui.toast("宝箱数量不足");return;}
|
|
smc.vmdata.box.num=smc.vmdata.box.num-5;
|
|
this.open_reward()
|
|
for (let x = 0; x < 5; x++) {
|
|
this.get_reward(2)
|
|
}
|
|
}
|
|
open_lb() {
|
|
if (smc.vmdata.box.num < 15) {oops.gui.toast("宝箱数量不足");return;}
|
|
smc.vmdata.box.num=smc.vmdata.box.num-15;
|
|
this.open_reward()
|
|
for (let x = 0; x < 15; x++) {
|
|
this.get_reward(2)
|
|
}
|
|
}
|
|
colse_reward() {
|
|
this.node.getChildByName("reward").setScale(0,0,0);
|
|
this.node.getChildByName("reward").getChildByName("items").removeAllChildren();
|
|
}
|
|
open_reward() {
|
|
this.node.getChildByName("reward").setScale(1,1,1);
|
|
}
|
|
get_reward(reward:number){
|
|
console.log("get_reward",reward)
|
|
let list =BoxDrop[reward];
|
|
let uuid= 0
|
|
let num =1
|
|
let i=0
|
|
while (uuid==0) {
|
|
for (let x = 0; x < list.length; x++) {
|
|
let rate = Math.random()*100
|
|
if(rate < list[x].dropRate){
|
|
uuid=list[x].uuid;
|
|
num =RandomManager.instance.getRandomInt(list[x].num_max/2,list[x].num_max);
|
|
break;
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
switch(reward){
|
|
case 3:
|
|
this.show_hero_chip(uuid,num)
|
|
smc.heros[uuid].num += num
|
|
oops.message.dispatchEvent("hero_card_update_info")
|
|
break;
|
|
case 2:
|
|
this.show_hero_chip(uuid,num)
|
|
smc.heros[uuid].num += num
|
|
oops.message.dispatchEvent("hero_card_update_info")
|
|
// this.show_skill_chip(uuid,num)
|
|
// smc.skills[uuid].num += num
|
|
break;
|
|
case 1:
|
|
this.show_item(uuid,num)
|
|
if(uuid ==9001){
|
|
smc.vmdata.gold.num+=num
|
|
}
|
|
if(uuid ==9003){
|
|
smc.vmdata.exp.num+=num
|
|
}
|
|
if(uuid < 9000){
|
|
smc.items[uuid].num+=num
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
show_hero_chip(uuid:number,num:number){
|
|
console.log("show_hero_chip",uuid,num)
|
|
let path = "game/gui/hchip";
|
|
let prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
let node = instantiate(prefab);
|
|
let hc= node.getComponent(HChipComp)
|
|
hc.update_data(uuid,num)
|
|
node.parent = this.node.getChildByName("reward").getChildByName("items");
|
|
}
|
|
show_item(uuid:number,num:number){
|
|
var path = "game/gui/item";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
let ic= node.getComponent(ItemComp)
|
|
ic.update_data(uuid,num)
|
|
node.parent = this.node.getChildByName("reward").getChildByName("items");
|
|
|
|
}
|
|
show_skill_chip(uuid:number,num:number){
|
|
let path = "game/gui/schip";
|
|
let prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
let node = instantiate(prefab);
|
|
let sc= node.getComponent(SChipComp)
|
|
sc.update_data(uuid,num)
|
|
node.parent = this.node.getChildByName("reward").getChildByName("items");
|
|
}
|
|
show_bbox() {
|
|
var parent = this.node.getChildByName("bbox")
|
|
var path = "game/gui/bbox";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
let box = instantiate(prefab);
|
|
box.parent = parent;
|
|
parent.getChildByName("light").active = true;
|
|
this.scheduleOnce(()=>{
|
|
parent.getChildByName("light").active = false;
|
|
}, 0.5)
|
|
this.scheduleOnce(()=>{
|
|
box.destroy();
|
|
}, 0.7)
|
|
}
|
|
to_open(){
|
|
if(this.selected==""){return;}
|
|
switch(this.selected){
|
|
case "sb":
|
|
if(smc.items[1001].num <=0){oops.gui.toast("宝箱数量不足"); this.btnno.active = true;return;}
|
|
this.open_sb();
|
|
break;
|
|
case "mb":
|
|
if(smc.items[1002].num <=0){oops.gui.toast("宝箱数量不足");this.btnno.active = true;return;}
|
|
this.open_mb();
|
|
break;
|
|
case "lb":
|
|
if(smc.items[1003].num <=0){oops.gui.toast("宝箱数量不足");this.btnno.active = true;return;}
|
|
this.open_lb();
|
|
break;
|
|
}
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |