Files
heros/assets/script/game/map/MIssionController.ts
2024-12-09 09:25:35 +08:00

328 lines
12 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 { HeroViewComp } from "../hero/HeroViewComp";
import { BossViewComp } from "../Boss/BossViewComp";
import { Hero } from "../hero/Hero";
import { HeroInfo, HeroSet } from "../common/config/heroSet";
import { Boss } from "../Boss/Boss";
import { MonModelComp } from "../hero/MonModelComp";
import { BossList, MBSet, 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";
import { ItemComp } from "./ItemComp";
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
msk:any={
on :false,
uuid:1001,
type:1,
lv: 1
}
mmsk:any={
on :false,
uuid:1001,
type:1,
lv: 1
}
onLoad(){
}
start() {
this.VictoryComp=this.node.getChildByName("victory").getComponent(VictoryComp)
}
protected update(dt: number): void {
if(!smc.vmdata.mission.play||smc.vmdata.mission.pause){
return
}
if(this.fight_start){
this.check_mon_num()
}
this.count_hero_pos()
this.count_mon_pos()
this.check_buff()
// if (this.game_timer.update(dt)) {
// smc.vmdata.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,smc.vmdata.mission.mbt ,smc.vmdata.mission.mmbt)
//局内数据初始化
this.fight_start=false
smc.vmdata.mission.is_victory=false
smc.vmdata.mission.is_defeat=false
smc.vmdata.mission.exp=0 //局内经验
smc.vmdata.mission.m_exp=0 //敌方局内经验
smc.vmdata.mission.ap=0
smc.vmdata.mission.hp=0
smc.vmdata.mission.def=0
smc.vmdata.mission.map=0
smc.vmdata.mission.mhp=0
smc.vmdata.mission.mdef=0
this.msk={ on :false, uuid:1001,type:1,lv: 1}
this.mmsk={ on :false, uuid:1001,type:1,lv: 1}
let exp_n=this.node.getChildByName("exp")
let nexp_n=this.node.getChildByName("mexp")
exp_n.getChildByName("ap").active = false;
nexp_n.getChildByName("ap").active = false;
exp_n.getChildByName("def").active = false;
nexp_n.getChildByName("def").active = false;
exp_n.getChildByName("hp").active = false;
nexp_n.getChildByName("hp").active = false;
switch(smc.vmdata.mission.mbt){
case 1:
exp_n.getChildByName("ap").active = true;
smc.vmdata.mission.exp_max=MBSet.ap_exp-smc.vmdata.mission.ap_exp;
break;
case 2:
exp_n.getChildByName("def").active = true;
smc.vmdata.mission.exp_max=MBSet.def_exp-smc.vmdata.mission.def_exp;
break;
case 3:
exp_n.getChildByName("hp").active = true;
smc.vmdata.mission.exp_max=MBSet.hp_exp-smc.vmdata.mission.hp_exp;
break;
}
switch(smc.vmdata.mission.mmbt){
case 1:
nexp_n.getChildByName("ap").active = true;
smc.vmdata.mission.m_exp_max=MBSet.ap_exp+smc.vmdata.mission.map_exp;
break;
case 2:
nexp_n.getChildByName("def").active = true;
smc.vmdata.mission.m_exp_max=MBSet.def_exp+smc.vmdata.mission.mdef_exp;
break;
case 3:
nexp_n.getChildByName("hp").active = true;
smc.vmdata.mission.m_exp_max=MBSet.hp_exp+smc.vmdata.mission.mhp_exp;
break;
}
this.mon_refresh()
this.heros_call()
}
mission_end(){
smc.vmdata.mission.play=false
smc.vmdata.mission.pause=false
smc.vmdata.mission.mmbt=1
smc.vmdata.mission.mbt=1
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));
let res:any= ecs.query(ecs.allOf(ItemComp));
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()
}
for(let i=0;i<res.length;i++){
res[i].ItemComp.reset()
res[i].ItemComp.ent.destroy()
}
}
check_buff(){
if(smc.vmdata.mission.exp >= smc.vmdata.mission.exp_max){
smc.vmdata.mission.exp-=smc.vmdata.mission.exp_max
switch(smc.vmdata.mission.mbt){
case 1:
smc.vmdata.mission.ap+=smc.vmdata.mission.ap_up+MBSet.ap_add
console.log("mission ap",smc.vmdata.mission.ap)
this.node.getChildByName("exp").getChildByName("ap").getChildByName("data").setScale(1.3,1.3)
this.scheduleOnce(function(){
this.node.getChildByName("exp").getChildByName("ap").getChildByName("data").setScale(1,1)
},0.2)
break;
case 2:
smc.vmdata.mission.def+=smc.vmdata.mission.def_up+MBSet.def_add
this.node.getChildByName("exp").getChildByName("def").getChildByName("data").setScale(1.3,1.3)
this.scheduleOnce(function(){
this.node.getChildByName("exp").getChildByName("def").getChildByName("data").setScale(1,1)
},0.2)
break;
case 3:
smc.vmdata.mission.hp+=smc.vmdata.mission.hp_up+MBSet.hp_add
this.node.getChildByName("exp").getChildByName("hp").getChildByName("data").setScale(1.3,1.3)
this.scheduleOnce(function(){
this.node.getChildByName("exp").getChildByName("hp").getChildByName("data").setScale(1,1)
},0.2)
break;
}
}
if(smc.vmdata.mission.m_exp >= smc.vmdata.mission.m_exp_max){
smc.vmdata.mission.m_exp-=smc.vmdata.mission.m_exp_max
// this.node.getChildByName("mexp").setScale(1.2,1.2)
// this.scheduleOnce(function(){
// this.node.getChildByName("mexp").setScale(1,1)
// },0.2)
switch(smc.vmdata.mission.mmbt){
case 1:
smc.vmdata.mission.map+=smc.vmdata.mission.map_up+MBSet.ap_add
console.log("mission map",smc.vmdata.mission.map)
break;
case 2:
smc.vmdata.mission.mdef+=smc.vmdata.mission.mdef_up+MBSet.def_add
break;
case 3:
smc.vmdata.mission.mhp+=smc.vmdata.mission.mhp_up+MBSet.hp_add
break;
}
}
}
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.vmdata.mission.is_victory = true
if (!h_alive) smc.vmdata.mission.is_defeat = true
this.to_end_mission()
}
to_end_mission(){
if (smc.vmdata.mission.is_victory){
this.VictoryComp.do_victiry(true)
smc.vmdata.mission.pause=true
}
if (smc.vmdata.mission.is_defeat){
this.VictoryComp.do_victiry(false)
smc.vmdata.mission.pause=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.vmdata.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[HeroInfo[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[HeroInfo[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();
}
}