386 lines
14 KiB
TypeScript
386 lines
14 KiB
TypeScript
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,UITransform,v3, Vec3 } 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 { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
import { MSkills, MSkillset, MSlist, SkillSet } from "../common/config/SkillSet";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { RewardSet } from "../common/config/RewardSet";
|
|
import { BoxSet, GameSet } from "../common/config/BoxSet";
|
|
import { GameMap } from "./GameMap";
|
|
import { MapModelComp } from "./model/MapModelComp";
|
|
import { Talent } from "../Role/Talent";
|
|
import { Talents } from "../common/config/TalentSet";
|
|
import { MonViewComp } from "../mon/MonViewComp";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { RoleViewComp } from "../Role/RoleViewComp";
|
|
import { BossViewComp } from "../Boss/BossViewComp";
|
|
import { Hero } from "../hero/Hero";
|
|
import { HeroSet } from "../common/config/heroSet";
|
|
import { Boss } from "../Boss/Boss";
|
|
import { MonModelComp } from "../mon/MonModelComp";
|
|
import { BossList, MissionNum, MonsetList } from "../common/config/MissionSet";
|
|
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { HCard } from "./HCard";
|
|
import { HCardComp } from "./HCardComp";
|
|
import { MSkill } from "../skills/MSkill";
|
|
import { MSkillComp } from "../skills/MSkillComp";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionComp')
|
|
@ecs.register('Mission', false)
|
|
export class MissionComp extends CCComp {
|
|
max_count: number = 99 ; //最大波次
|
|
cur_count: number = 1; //波次
|
|
boss_count: number = 10; //boss波次间隔
|
|
monster_level:number = 1; //怪物池等级
|
|
max_monster_level:number = 4; //最高怪物次等级
|
|
min_monster_num:number = 1; ///最小每次刷新怪物数量
|
|
max_monster_num:number = 1; //最大每次刷新怪物数量
|
|
refresh_timer: Timer = new Timer(5); // 刷新怪物定时器
|
|
refresh_cd: Timer = new Timer(0.5);
|
|
mission_up_timer: Timer = new Timer(30); //波次增加
|
|
boss_timer: Timer = new Timer(10);
|
|
boss_num:number = 1;
|
|
cur_mission:number = 1; //当前关卡方案
|
|
mission_list:any = []
|
|
boss_list:any = []
|
|
setp_timer: Timer = new Timer(0.3);
|
|
call_hero_timer: Timer = new Timer(0.3);
|
|
target_timer: Timer = new Timer(0.1);
|
|
setp_num:number = smc.vm_data.mission.once;
|
|
total:number = 0;
|
|
hero_total:number = 0;
|
|
reward:number = 0;
|
|
reward_num:number = 0;
|
|
game_over:boolean = false;
|
|
start_ys:any[] = [0,70,-70];
|
|
mon_index:number = 0
|
|
msk:any={
|
|
on :false,
|
|
uuid:1001,
|
|
type:1,
|
|
lv: 1
|
|
}
|
|
mmsk:any={
|
|
on :false,
|
|
uuid:1001,
|
|
type:1,
|
|
lv: 1
|
|
}
|
|
onLoad(){
|
|
|
|
}
|
|
start() {
|
|
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if(!smc.vm_data.mission.play||smc.vm_data.pause){
|
|
return
|
|
}
|
|
if(this.setp_timer.update(dt)){
|
|
if(this.total<=0) return
|
|
this.monster_refresh()
|
|
}
|
|
if(this.call_hero_timer.update(dt)){
|
|
if(this.hero_total <= 0) return
|
|
this.heros_call()
|
|
}
|
|
if(this.boss_timer.update(dt)){
|
|
if(this.boss_num <=0 ) return
|
|
// this.load_boss()
|
|
}
|
|
this.is_reward()
|
|
if (this.refresh_timer.update(dt)) {
|
|
this.setp_num=smc.vm_data.mission.once
|
|
}
|
|
if (this.mission_up_timer.update(dt)) {
|
|
// 刷新怪物定时器
|
|
this.cur_count += 1;
|
|
}
|
|
this.count_hero_pos()
|
|
this.count_mon_pos()
|
|
this.check_exp()
|
|
this.check_m_exp()
|
|
// if (this.game_timer.update(dt)) {
|
|
// smc.vm_data.game.g_time += 1;
|
|
// }
|
|
// this.shuaxin(dt)
|
|
}
|
|
mission_start(){
|
|
/* todo 关卡设定完善*/
|
|
this.total=smc.vm_data.mission.m_less=smc.vm_data.mission.m_alive=smc.vm_data.mission.total;
|
|
this.hero_total=2
|
|
let num =RandomManager.instance.getRandomByObjectList(MissionNum,1)
|
|
this.cur_mission = num[0]
|
|
this.mission_list = MonsetList[this.cur_mission]
|
|
this.boss_list = BossList[this.cur_mission]
|
|
// console.log("当前关卡方案",this.cur_mission,this.mission_list)
|
|
this.refresh_timer= new Timer(smc.vm_data.mission.refresh_timer);
|
|
this.boss_num=1
|
|
this.boss_timer = new Timer(smc.vm_data.mission.boss_cd)
|
|
//局内数据初始化
|
|
smc.vm_data.mission.a_exp=0 //近战经验石
|
|
smc.vm_data.mission.b_exp=0 //远程经验石
|
|
smc.vm_data.mission.c_exp=0 //辅助经验石
|
|
smc.vm_data.mission.ma_exp=0 //敌方近战经验石
|
|
smc.vm_data.mission.mb_exp=0 //敌方远程经验石
|
|
smc.vm_data.mission.mc_exp=0 //敌方辅助经验石
|
|
this.msk={ on :false, uuid:1001,type:1,lv: 1}
|
|
this.mmsk={ on :false, uuid:1001,type:1,lv: 1}
|
|
this.node.getChildByName("exp").getChildByName("a_exp").active = true
|
|
this.node.getChildByName("exp").getChildByName("b_exp").active = true
|
|
this.node.getChildByName("exp").getChildByName("c_exp").active = true
|
|
this.node.getChildByName("mexp").getChildByName("a_exp").active = true
|
|
this.node.getChildByName("mexp").getChildByName("b_exp").active = true
|
|
this.node.getChildByName("mexp").getChildByName("c_exp").active = true
|
|
|
|
}
|
|
check_exp(){
|
|
if(!this.msk.on){
|
|
if(smc.vm_data.mission.a_exp >= MSkillset.confirm_exp){
|
|
this.msk.type = 1
|
|
this.msk.on = true
|
|
this.select_msk(1)
|
|
this.node.getChildByName("exp").getChildByName("b_exp").active = false
|
|
this.node.getChildByName("exp").getChildByName("c_exp").active = false
|
|
}
|
|
if(smc.vm_data.mission.b_exp >= MSkillset.confirm_exp){
|
|
this.msk.type = 2
|
|
this.msk.on = true
|
|
this.select_msk(2)
|
|
this.node.getChildByName("exp").getChildByName("a_exp").active = false
|
|
this.node.getChildByName("exp").getChildByName("c_exp").active = false
|
|
}
|
|
if(smc.vm_data.mission.c_exp >= MSkillset.confirm_exp){
|
|
this.msk.type = 3
|
|
this.msk.on = true
|
|
this.select_msk(3)
|
|
this.node.getChildByName("exp").getChildByName("a_exp").active = false
|
|
this.node.getChildByName("exp").getChildByName("b_exp").active = false
|
|
}
|
|
}else{
|
|
switch (this.msk.type){
|
|
case 1:
|
|
if(smc.vm_data.mission.a_exp >= MSkills[this.msk.uuid].up_exp){
|
|
this.msk.lv += 1
|
|
smc.vm_data.mission.a_exp = 0
|
|
}
|
|
break;
|
|
case 2:
|
|
if(smc.vm_data.mission.b_exp >= MSkills[this.msk.uuid].up_exp){
|
|
this.msk.lv += 1
|
|
smc.vm_data.mission.b_exp = 0
|
|
}
|
|
break;
|
|
case 3:
|
|
if(smc.vm_data.mission.c_exp >= MSkills[this.msk.uuid].up_exp){
|
|
this.msk.lv += 1
|
|
smc.vm_data.mission.c_exp = 0
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
check_m_exp(){
|
|
if(!this.mmsk.on){
|
|
if(smc.vm_data.mission.ma_exp >= MSkillset.confirm_exp){
|
|
this.mmsk.type = 1
|
|
this.mmsk.on = true
|
|
this.select_mmsk(1)
|
|
this.node.getChildByName("mexp").getChildByName("b_exp").active = false
|
|
this.node.getChildByName("mexp").getChildByName("c_exp").active = false
|
|
}
|
|
if(smc.vm_data.mission.mb_exp >= MSkillset.confirm_exp){
|
|
this.mmsk.type = 2
|
|
this.mmsk.on = true
|
|
this.select_mmsk(2)
|
|
this.node.getChildByName("mexp").getChildByName("a_exp").active = false
|
|
this.node.getChildByName("mexp").getChildByName("c_exp").active = false
|
|
}
|
|
if(smc.vm_data.mission.mc_exp >= MSkillset.confirm_exp){
|
|
this.mmsk.type = 3
|
|
this.mmsk.on = true
|
|
this.select_mmsk(3)
|
|
this.node.getChildByName("mexp").getChildByName("a_exp").active = false
|
|
this.node.getChildByName("mexp").getChildByName("b_exp").active = false
|
|
}
|
|
}else{
|
|
switch (this.mmsk.type){
|
|
case 1:
|
|
if(smc.vm_data.mission.ma_exp >= MSkills[this.mmsk.uuid].up_exp){
|
|
this.mmsk.lv += 1
|
|
smc.vm_data.mission.ma_exp = 0
|
|
}
|
|
break;
|
|
case 2:
|
|
if(smc.vm_data.mission.mb_exp >= MSkills[this.mmsk.uuid].up_exp){
|
|
this.mmsk.lv += 1
|
|
smc.vm_data.mission.mb_exp = 0
|
|
}
|
|
break;
|
|
case 3:
|
|
if(smc.vm_data.mission.mc_exp >= MSkills[this.mmsk.uuid].up_exp){
|
|
this.mmsk.lv += 1
|
|
smc.vm_data.mission.mc_exp = 0
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
select_msk(type:number){
|
|
smc.vm_data.mission.a_exp=0
|
|
smc.vm_data.mission.b_exp=0
|
|
smc.vm_data.mission.c_exp=0
|
|
let sk:any=RandomManager.instance.getRandomByObjectList(MSlist[type],1)
|
|
this.msk.uuid=sk[0]
|
|
let skill=ecs.getEntity<MSkill>(MSkill)
|
|
let praent = this.node.getChildByName("msk")
|
|
skill.load(this.msk.uuid,1,praent)
|
|
}
|
|
select_mmsk(type:number){
|
|
smc.vm_data.mission.ma_exp=0
|
|
smc.vm_data.mission.mb_exp=0
|
|
smc.vm_data.mission.mc_exp=0
|
|
let sk:any=RandomManager.instance.getRandomByObjectList(MSlist[type],1)
|
|
this.mmsk.uuid=sk[0]
|
|
let mskill=ecs.getEntity<MSkill>(MSkill)
|
|
let praent = this.node.getChildByName("mmsk")
|
|
mskill.load(this.msk.uuid,1,praent)
|
|
}
|
|
call_msk(){
|
|
|
|
}
|
|
|
|
mission_end(){
|
|
smc.vm_data.mission.play=false
|
|
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
|
|
let monsters:any= ecs.query(ecs.allOf(MonModelComp));
|
|
let hcards:any= ecs.query(ecs.allOf(HCardComp));
|
|
let mska:any= ecs.query(ecs.allOf(MSkillComp));
|
|
for(let i=0;i<mska.length;i++){
|
|
mska[i].MSkillComp.reset()
|
|
mska[i].MSkillComp.ent.destroy()
|
|
}
|
|
// let hcns=this.node.getChildByName("hcards")
|
|
// for(let i=0;i<hcns.children.length;i++){
|
|
// hcns.children[i].destroy()
|
|
// }
|
|
for(let i=0;i<heros.length;i++){
|
|
|
|
heros[i].HeroView.reset()
|
|
heros[i].HeroView.ent.destroy()
|
|
|
|
}
|
|
for(let i=0;i<hcards.length;i++){
|
|
hcards[i].HCardComp.reset()
|
|
hcards[i].HCardComp.ent.destroy()
|
|
}
|
|
for(let i=0;i<monsters.length;i++){
|
|
monsters[i].HeroView.reset()
|
|
monsters[i].HeroView.ent.destroy()
|
|
}
|
|
}
|
|
|
|
|
|
monster_refresh(){
|
|
if (this.setp_num <= 0){
|
|
return
|
|
}
|
|
let m:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],1)
|
|
this.addMonster(m[0])
|
|
this.mon_index += 1
|
|
if(this.mon_index>2){
|
|
this.mon_index = 0
|
|
}
|
|
smc.vm_data.mission.m_less=this.total -= 1
|
|
// this.setp_num -= 1
|
|
}
|
|
is_reward(){
|
|
if(smc.vm_data.mission.reward_num < smc.vm_data.mission.reward) return
|
|
// this.do_reward()
|
|
smc.vm_data.mission.reward_num = 0
|
|
}
|
|
do_reward(){
|
|
console.log("do_reward")
|
|
oops.message.dispatchEvent("do_reward");
|
|
}
|
|
|
|
count_mon_pos(){
|
|
let monsters:any= ecs.query(ecs.allOf(MonModelComp));
|
|
for(let i=0;i<monsters.length;i++){
|
|
if(monsters[i].HeroView == undefined) return
|
|
let mon:any = monsters[i].HeroView.node.position
|
|
smc.enemy_pos[i].x= mon.x
|
|
}
|
|
}
|
|
count_hero_pos(){
|
|
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
|
|
for(let i=0;i<heros.length;i++){
|
|
if(heros[i].HeroView == undefined) return
|
|
let ho:any = heros[i].HeroView.node.position
|
|
smc.hero_pos[i].x= ho.x
|
|
}
|
|
}
|
|
|
|
|
|
heros_call(){
|
|
let hero:any =RandomManager.instance.getRandomByObjectList(smc.cards, 1);
|
|
this.addHero(hero[0].uuid)
|
|
this.hero_total -= 1
|
|
if(this.hero_total <= 0){
|
|
console.log("heros_call")
|
|
this.hcard_call()
|
|
}
|
|
}
|
|
hcard_call(){
|
|
let node =this.node.getChildByName("hcards")
|
|
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
|
|
|
|
for(let i=0;i<heros.length;i++){
|
|
let hcard = ecs.getEntity<HCard>(HCard)
|
|
console.log("hcard:",hcard)
|
|
hcard.load(1001,i,node)
|
|
}
|
|
|
|
}
|
|
/** 添加玩家 */
|
|
private addHero(uuid:number=1001) {
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let pos:Vec3 = v3(HeroSet.StartPos[smc.heros[uuid].type],BoxSet.GAME_LINE);
|
|
console.log("addHero:",pos)
|
|
hero.load(pos,scale,uuid);
|
|
}
|
|
private addMonster(uuid:number=1001) {
|
|
let monster = ecs.getEntity<Hero>(Hero);
|
|
let scale = -1
|
|
let index = -1
|
|
let pos:Vec3 = v3(-1*HeroSet.StartPos[smc.heros[uuid].type],BoxSet.GAME_LINE);
|
|
console.log("addMonster:",pos)
|
|
monster.load(pos,scale,uuid,index,false);
|
|
}
|
|
|
|
load_boss(){
|
|
let bs:any = RandomManager.instance.getRandomByObjectList(this.boss_list[this.monster_level],1)
|
|
var scene = smc.map.MapView.scene;
|
|
let pos:Vec3 = v3(260,BoxSet.GAME_LINE)
|
|
let layer = scene.entityLayer!.node!
|
|
let b = ecs.getEntity<Boss>(Boss);
|
|
let scale = -1
|
|
b.load(pos,scale,bs[0],layer);
|
|
this.boss_num -= 1
|
|
}
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |