191 lines
6.6 KiB
TypeScript
191 lines
6.6 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/MissionSet";
|
|
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
|
|
|
|
|
|
onLoad(){
|
|
// this.MSComp=this.node.getChildByName("msk").getComponent(MSkillComp)
|
|
// this.MMSComp=this.node.getChildByName("mmsk").getComponent(MSkillComp)
|
|
// this.MSComp.group=BoxSet.HERO
|
|
// this.MSComp.s_uuid=smc.mission.mskill
|
|
// this.MMSComp.group=BoxSet.MONSTER
|
|
// this.MMSComp.s_uuid=smc.mission.mmskill
|
|
}
|
|
start() {
|
|
// this.VictoryComp=this.node.getChildByName("victory").getComponent(VictoryComp)
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause){
|
|
return
|
|
}
|
|
if(this.fight_start){
|
|
this.check_mon_num()
|
|
}
|
|
this.count_hero_pos()
|
|
this.count_mon_pos()
|
|
// if (this.game_timer.update(dt)) {
|
|
// smc.vmdata.game.g_time += 1;
|
|
// }
|
|
// this.shuaxin(dt)
|
|
}
|
|
mission_start(){
|
|
/* todo 关卡设定完善*/
|
|
console.log("mission_start Missions mons:",Missions[smc.mission.lv])
|
|
smc.mission.status=1
|
|
this.colose_victory()
|
|
this.mission_init()
|
|
// this.mskill_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
|
|
|
|
}
|
|
|
|
mskill_init(){
|
|
this.MSComp.group=BoxSet.HERO
|
|
this.MMSComp.group=BoxSet.MONSTER
|
|
this.MSComp.init()
|
|
this.MMSComp.init()
|
|
}
|
|
check_mon_num(){
|
|
let mons:any = this.get_mons()
|
|
let heros:any= this.get_heros()
|
|
let h_alive=false
|
|
let m_alive=false
|
|
for (let i = 0; i < heros.length; i++) {
|
|
if ( !heros[i].HeroView.is_dead) {
|
|
h_alive=true
|
|
}
|
|
}
|
|
for (let i = 0; i < mons.length; i++) {
|
|
if ( !mons[i].HeroView.is_dead) {
|
|
m_alive=true
|
|
}
|
|
}
|
|
// if (!m_alive||!h_alive) this.mission_end()
|
|
}
|
|
|
|
get_mons(){
|
|
return ecs.query(ecs.allOf(MonModelComp));
|
|
}
|
|
get_heros(){
|
|
return ecs.query(ecs.allOf(HeroModelComp))
|
|
}
|
|
count_mon_pos(){
|
|
let right_x:number=360
|
|
let left_x:number=-360
|
|
let monsters:any= this.get_mons()
|
|
for(let i=0;i<monsters.length;i++){
|
|
if(monsters[i].HeroView == undefined) return
|
|
if(monsters[i].HeroView.node.position.x > 400) continue
|
|
let mon:any = monsters[i].HeroView.node.position
|
|
smc.enemy_pos[i]= mon
|
|
if(monsters[i].HeroView.node.position.x > left_x){
|
|
left_x = monsters[i].HeroView.node.position.x
|
|
}
|
|
if(monsters[i].HeroView.node.position.x < right_x){
|
|
right_x = monsters[i].HeroView.node.position.x
|
|
}
|
|
}
|
|
smc.mon_front_x=right_x
|
|
smc.mon_back_x=left_x
|
|
// console.log("count_mon_pos",smc.mon_pos,smc.mon_front_x,smc.mon_back_x)
|
|
}
|
|
count_hero_pos(){
|
|
let right_x:number=360
|
|
let left_x:number=-360
|
|
let heros:any= this.get_heros()
|
|
for(let i=0;i<heros.length;i++){
|
|
if(heros[i].HeroView == undefined) return
|
|
if(heros[i].HeroView.node.position.x < -400) continue
|
|
|
|
let ho:any = heros[i].HeroView.node.position
|
|
smc.hero_pos[i]= ho
|
|
if(heros[i].HeroView.node.position.x > left_x){
|
|
left_x = heros[i].HeroView.node.position.x
|
|
}
|
|
if(heros[i].HeroView.node.position.x < right_x){
|
|
right_x = heros[i].HeroView.node.position.x
|
|
}
|
|
}
|
|
smc.hero_front_x=left_x
|
|
smc.hero_back_x=right_x
|
|
// console.log("count_hero_pos",smc.hero_pos,smc.hero_front_x,smc.mon_front_x)
|
|
}
|
|
card_refresh(){
|
|
oops.message.dispatchEvent(GameEvent.CardRefresh)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |