Files
heros/assets/script/game/map/MissionComp.ts
2025-05-27 10:57:42 +08:00

119 lines
3.9 KiB
TypeScript

import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI } 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 { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { HeroModelComp } from "../hero/HeroModelComp";
import { BoxSet } from "../common/config/BoxSet";
import { MonModelComp } from "../hero/MonModelComp";
import { Missions} from "../common/config/Mission";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { VictoryComp } from "./VictoryComp";
import { MSkillComp } from "./MSkillComp";
import { CardControllerComp } from "./CardController";
import { GameEvent } from "../common/config/GameEvent";
import { HeroSkillsComp } from "../skill/heroSkillsComp";
import { HeroViewComp } from "../hero/HeroViewComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('MissionComp')
@ecs.register('Mission', false)
export class MissionComp extends CCComp {
VictoryComp:any = null;
mon_list:any = []
call_hero_timer: Timer = new Timer(0.3);
target_timer: Timer = new Timer(0.1);
reward:number = 0;
reward_num:number = 0;
game_over:boolean = false;
fight_start:boolean = false;
mission_buff_type:number = 1 // 1 攻击 2 防御 3 HP
m_mission_buff_type:number = 1 // 1 攻击 2 防御 3 HP
mission_buff_up_exp:number = 99999999
MSComp:MSkillComp=null
MMSComp:MSkillComp=null
heros_node:any=null
heros_node_pos:any=v3(0,0,0)
herosc_node:any=null
hero_args:any=null
onLoad(){
}
start() {
}
protected update(dt: number): void {
if(!smc.mission.play||smc.mission.pause){
return
}
// if (this.game_timer.update(dt)) {
// smc.vmdata.game.g_time += 1;
// }
}
call_hero(event: string, args: any){
console.log("call_hero",args)
oops.message.dispatchEvent(GameEvent.CallHero,{uuid:this.hero_args.uuid,pos:args})
this.hero_args=null
}
mission_start(){
/* todo 关卡设定完善*/
console.log("战斗开始 Missions mons:",Missions[smc.mission.lv])
smc.mission.status=1
this.colose_victory()
this.mission_init()
}
mission_end(){
oops.message.dispatchEvent(GameEvent.MissionEnd)
smc.mission.play=false
smc.mission.pause=false
this.cleanComponents()
// this.to_mission_home()
this.open_victory()
}
private cleanComponents() {
ecs.query(ecs.allOf(HeroSkillsComp)).forEach(entity => {entity.remove(HeroSkillsComp);entity.destroy()});
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
}
open_victory(){
this.node.getChildByName("victory").active=true
this.node.getChildByName("victory").getComponent(VictoryComp).open()
}
colose_victory(){
this.node.getChildByName("victory").active=false
}
to_mission_home(){
this.colose_victory()
let home =this.node.parent.getComponent(CardControllerComp);
home.mission_to_mission_home()
}
mission_init(){
//局内数据初始化
this.fight_start=false
smc.mission.is_victory=false
smc.mission.is_defeat=false
}
card_refresh(){
oops.message.dispatchEvent(GameEvent.CardRefresh)
}
/** 视图层逻辑代码分离演示 */
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}