Files
heros/assets/script/game/map/VictoryComp.ts
2024-11-21 18:16:44 +08:00

64 lines
2.7 KiB
TypeScript

import { _decorator, Label } 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 { MonViewComp } from "../mon/MonViewComp";
import { HeroViewComp } from "../hero/HeroViewComp";
import { RoleViewComp } from "../Role/RoleViewComp";
import { BossViewComp } from "../Boss/BossViewComp";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { MissionReward } from "../common/config/MissionSet";
import { Items } from "../common/config/Items";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('VictoryComp')
@ecs.register('Victory', false)
export class VictoryComp extends CCComp {
reward_lv:number=1
reward_num:number=2
rerawd_item:any={}
/** 视图层逻辑代码分离演示 */
start() {
// console.log("VictoryComp start")
oops.message.on("minssion_victory", this.do_victiry, this);
oops.message.on("minssion_defeat", this.do_defeat, this);
console.log("VictoryComp start")
}
private do_victiry() {
smc.vm_data.mission.play=false
if(smc.vm_data.role.mission%10==0){
smc.vm_data.role.mission_finish == true
}else{
smc.vm_data.role.mission += 1
}
this.node.getChildByName("Node").active = true;
this.getReward()
this.node.getChildByName("Node").getChildByName("defeat").active = false
this.node.getChildByName("Node").getChildByName("victory").active = true;
}
private do_defeat() {
smc.vm_data.mission.play=false
this.node.getChildByName("Node").active = true;
this.getReward()
this.node.getChildByName("Node").getChildByName("victory").active = false;
this.node.getChildByName("Node").getChildByName("defeat").active = true
}
getReward(){
let reward:any = RandomManager.instance.getRandomByObjectList(MissionReward[this.reward_lv], 1);
this.rerawd_item =Items[reward[0]]
// console.log("getReward:",this.rerawd_item)
this.node.getChildByName("Node").getChildByName("item3").getChildByName("num").getComponent(Label).string=this.reward_num.toString()
}
end_mission(){
this.node.getChildByName("Node").active=false
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}