360 lines
13 KiB
TypeScript
360 lines
13 KiB
TypeScript
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";
|
|
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, 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";
|
|
import { MSkill } from "../skills/MSkill";
|
|
import { MSkillComp } from "../skills/MSkillComp";
|
|
import { VictoryComp } from "./VictoryComp";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionComp')
|
|
@ecs.register('Mission', false)
|
|
export class MissionComp extends CCComp {
|
|
VictoryNode: any = null;
|
|
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;
|
|
msk:any={
|
|
on :false,
|
|
uuid:1001,
|
|
type:1,
|
|
lv: 1
|
|
}
|
|
mmsk:any={
|
|
on :false,
|
|
uuid:1001,
|
|
type:1,
|
|
lv: 1
|
|
}
|
|
onLoad(){
|
|
|
|
}
|
|
start() {
|
|
this.VictoryNode=this.node.getChildByName("victory")
|
|
this.VictoryNode.active=false
|
|
this.VictoryComp=this.VictoryNode.getComponent(VictoryComp)
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if(!smc.vm_data.mission.play||smc.vm_data.pause){
|
|
return
|
|
}
|
|
if(this.fight_start){
|
|
this.check_mon_num()
|
|
}
|
|
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 关卡设定完善*/
|
|
let mon_set=RandomManager.instance.getRandomByObjectList(MissionSet,1)
|
|
this.mon_list=mon_set[0]
|
|
console.log("mission_start:",this.mon_list)
|
|
//局内数据初始化
|
|
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
|
|
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
|
|
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){
|
|
if(smc.vm_data.mission.a_exp >= MSkillset.confirm_exp){
|
|
this.msk.type = 1
|
|
this.msk.on = true
|
|
this.select_msk(1)
|
|
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.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.exp_move(-100,-100,30)
|
|
}
|
|
}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.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.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.mexp_move(100,100,-30)
|
|
}
|
|
}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)
|
|
skill.load(BoxSet.HERO,this.msk.uuid)
|
|
}
|
|
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)
|
|
mskill.load(BoxSet.MONSTER,this.mmsk.uuid)
|
|
}
|
|
do_reward(){
|
|
console.log("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
|
|
this.to_end_mission()
|
|
}
|
|
to_end_mission(){
|
|
if (smc.vm_data.mission.is_victory){
|
|
this.VictoryNode.active=true
|
|
}
|
|
if (smc.vm_data.mission.is_defeat){
|
|
this.VictoryNode.active=true
|
|
}
|
|
}
|
|
get_mons(){
|
|
return ecs.query(ecs.allOf(MonModelComp));
|
|
}
|
|
get_heros(){
|
|
return ecs.query(ecs.allOf(HeroModelComp))
|
|
}
|
|
count_mon_pos(){
|
|
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]= mon
|
|
}
|
|
}
|
|
count_hero_pos(){
|
|
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]= ho
|
|
}
|
|
}
|
|
|
|
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= this.get_heros();
|
|
|
|
for(let i=0;i<heros.length;i++){
|
|
let hcard = ecs.getEntity<HCard>(HCard)
|
|
// console.log("hcard:",hcard)
|
|
hcard.load(1001,i,node)
|
|
}
|
|
this.fight_start= true
|
|
}
|
|
/** 添加玩家 */
|
|
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]-i*15,BoxSet.GAME_LINE);
|
|
// console.log("addHero:",pos)
|
|
hero.load(pos,scale,uuid);
|
|
}
|
|
private addMonster(uuid:number=1001,i:number=0) {
|
|
let monster = ecs.getEntity<Hero>(Hero);
|
|
let scale = -1
|
|
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,false);
|
|
}
|
|
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |