关卡设置基本完成

This commit is contained in:
2024-11-21 17:41:10 +08:00
parent 76d7e6677c
commit 3d9469eb10
10 changed files with 380 additions and 453 deletions

View File

@@ -1,4 +1,4 @@
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,UITransform,v3, Vec3 } from "cc";
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,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";
@@ -20,7 +20,7 @@ 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 { BossList, MissionNum, MissionSet, 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";
@@ -32,32 +32,14 @@ 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);
mon_list:any = []
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
fight_start:boolean = false;
msk:any={
on :false,
uuid:1001,
@@ -71,36 +53,20 @@ export class MissionComp extends CCComp {
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;
if(this.fight_start){
this.check_mon_num()
}
this.do_reward()
this.count_hero_pos()
this.count_mon_pos()
this.check_exp()
@@ -112,23 +78,19 @@ export class MissionComp extends CCComp {
}
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)
let mon_set=RandomManager.instance.getRandomByObjectList(MissionSet,1)
this.mon_list=mon_set[0]
console.log("mission_start:",this.mon_list)
//局内数据初始化
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.fight_start=false
smc.vm_data.mission.is_victory=false
smc.vm_data.mission.is_defeat=false
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
@@ -137,7 +99,54 @@ export class MissionComp extends CCComp {
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
this.mon_refresh()
this.heros_call()
}
mission_end(){
smc.vm_data.mission.play=false
let heros:any= this.get_heros();;
let monsters:any= this.get_mons();
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()
}
}
exp_move(ap: number,bp: number,cp: number){
let a_pos=v3(ap,this.node.getChildByName("exp").getChildByName("a_exp").position.y)
let b_pos=v3(bp,this.node.getChildByName("exp").getChildByName("b_exp").position.y)
let c_pos=v3(cp,this.node.getChildByName("exp").getChildByName("c_exp").position.y)
tween(this.node.getChildByName("exp").getChildByName("a_exp")).to(0.5,{position:a_pos}).start()
tween(this.node.getChildByName("exp").getChildByName("b_exp")).to(0.5,{position:b_pos}).start()
tween(this.node.getChildByName("exp").getChildByName("c_exp")).to(0.5,{position:c_pos}).start()
}
mexp_move(ap: number,bp: number,cp: number){
let a_pos=v3(ap,this.node.getChildByName("mexp").getChildByName("a_exp").position.y)
let b_pos=v3(bp,this.node.getChildByName("mexp").getChildByName("b_exp").position.y)
let c_pos=v3(cp,this.node.getChildByName("mexp").getChildByName("c_exp").position.y)
tween(this.node.getChildByName("mexp").getChildByName("a_exp")).to(0.5,{position:a_pos}).start()
tween(this.node.getChildByName("mexp").getChildByName("b_exp")).to(0.5,{position:b_pos}).start()
tween(this.node.getChildByName("mexp").getChildByName("c_exp")).to(0.5,{position:c_pos}).start()
}
check_exp(){
if(!this.msk.on){
@@ -145,22 +154,19 @@ export class MissionComp extends CCComp {
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
this.exp_move(30,-100,-100)
}
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
this.exp_move(-100,30,-100)
}
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
this.exp_move(-100,-100,30)
}
}else{
switch (this.msk.type){
@@ -184,7 +190,6 @@ export class MissionComp extends CCComp {
break;
}
}
}
check_m_exp(){
if(!this.mmsk.on){
@@ -192,22 +197,19 @@ export class MissionComp extends CCComp {
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
this.mexp_move(-30,100,100)
}
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
this.mexp_move(100,-30,100)
}
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
this.mexp_move(100,100,-30)
}
}else{
switch (this.mmsk.type){
@@ -249,129 +251,94 @@ export class MissionComp extends CCComp {
let sk:any=RandomManager.instance.getRandomByObjectList(MSlist[type],1)
this.mmsk.uuid=sk[0]
let mskill=ecs.getEntity<MSkill>(MSkill)
mskill.load(BoxSet.MONSTER,this.msk.uuid)
}
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
mskill.load(BoxSet.MONSTER,this.mmsk.uuid)
}
do_reward(){
console.log("do_reward")
oops.message.dispatchEvent("do_reward");
}
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) smc.vm_data.mission.is_victory = true
if (!h_alive) smc.vm_data.mission.is_defeat = true
console.log("check_end m_alive: "+m_alive+" h_alive:"+h_alive+" victory:"+smc.vm_data.mission.is_victory+" defeat:"+smc.vm_data.mission.is_defeat)
}
get_mons(){
return ecs.query(ecs.allOf(MonModelComp));
}
get_heros(){
return ecs.query(ecs.allOf(HeroModelComp))
}
count_mon_pos(){
let monsters:any= ecs.query(ecs.allOf(MonModelComp));
let monsters:any= this.get_mons()
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
smc.enemy_pos[i]= mon
}
}
count_hero_pos(){
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
let heros:any= this.get_heros()
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
smc.hero_pos[i]= ho
}
}
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()
mon_refresh(){
let mons=this.mon_list
for(let i=0;i<mons.length;i++){
this.addMonster(mons[i],i)
}
}
heros_call(){
let heros=smc.vm_data.role.fight_heros
for(let i=0;i<heros.length;i++){
this.addHero(heros[i],i)
}
this.hcard_call()
}
hcard_call(){
let node =this.node.getChildByName("hcards")
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
let heros:any= this.get_heros();
for(let i=0;i<heros.length;i++){
let hcard = ecs.getEntity<HCard>(HCard)
console.log("hcard:",hcard)
// console.log("hcard:",hcard)
hcard.load(1001,i,node)
}
this.fight_start= true
}
/** 添加玩家 */
private addHero(uuid:number=1001) {
private addHero(uuid:number=1001,i:number=0) {
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)
let pos:Vec3 = v3(HeroSet.StartPos[smc.heros[uuid].type]-i*15,BoxSet.GAME_LINE);
// console.log("addHero:",pos)
hero.load(pos,scale,uuid);
}
private addMonster(uuid:number=1001) {
private addMonster(uuid:number=1001,i:number=0) {
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);
let pos:Vec3 = v3(-1*HeroSet.StartPos[smc.heros[uuid].type]+i*15,BoxSet.GAME_LINE);
console.log("addMonster:",pos)
monster.load(pos,scale,uuid,index,false);
monster.load(pos,scale,uuid,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
}
/** 视图层逻辑代码分离演示 */