249 lines
9.3 KiB
TypeScript
249 lines
9.3 KiB
TypeScript
import { _decorator ,Vec3,v3, Prefab, instantiate,Node} 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 { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { BoxSet, GameSet } from "../common/config/BoxSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { MapViewScene } from "./view/MapViewScene";
|
|
import { MissionSet,MissionNum,MonsetList, BossList } from "../common/config/MissionSet";
|
|
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
import { Role } from "../Role/Role";
|
|
import { Hero } from "../hero/Hero";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { Mon } from "../mon/Mon";
|
|
import { MonModelComp } from "../mon/MonModelComp";
|
|
import { Boss} from "../Boss/Boss";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { Talents } from "../common/config/TalentSet";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { HeroSet } from "../common/config/heroSet";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MapMonsterComp')
|
|
@ecs.register('MapMonster', false)
|
|
export class MapMonsterComp extends CCComp {
|
|
scene: MapViewScene = null;
|
|
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
|
|
hero_index:number = 0
|
|
hero_x:number = 0;
|
|
@property(Node)
|
|
start_p: Node = null;
|
|
|
|
onLoad(){
|
|
// 监听全局事件
|
|
oops.message.on("other_add_monster", this.on_other_add_monster, this);
|
|
oops.message.on("do_add_hero", this.on_do_add_hero, this);
|
|
oops.message.on("mission_start", this.mission_start, this);
|
|
oops.message.on("mission_end", this.mission_end, this);
|
|
oops.message.on("normal_call", this.on_normal_call, this);
|
|
oops.message.on("better_call", this.on_better_call, this);
|
|
oops.message.on("mon_dead", this.on_mon_dead, this);
|
|
|
|
|
|
}
|
|
start() {
|
|
// this.scene = this.getComponent(MapViewScene);
|
|
// this.scene.node.active = true
|
|
// this.scene = this.getComponent(MapViewScene);
|
|
var scene = smc.map.MapView.scene;
|
|
this.start_p.parent=scene.mapLayer!.node!
|
|
this.set_start_point()
|
|
|
|
|
|
}
|
|
|
|
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.on_normal_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()
|
|
|
|
// if (this.game_timer.update(dt)) {
|
|
// smc.vm_data.game.g_time += 1;
|
|
// }
|
|
// this.shuaxin(dt)
|
|
}
|
|
mission_start(){
|
|
this.total=smc.vm_data.mission.m_less=smc.vm_data.mission.m_alive=smc.vm_data.mission.total;
|
|
this.hero_total=1
|
|
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)
|
|
this.hero_x=0
|
|
this.hero_index=0
|
|
smc.vm_data.mission.coin = 0
|
|
}
|
|
mission_end(){
|
|
smc.vm_data.mission.play=false
|
|
let heros:any= ecs.query(ecs.allOf(HeroViewComp));
|
|
for(let i=0;i<heros.length;i++){
|
|
heros[i].HeroView.ent.destroy()
|
|
}
|
|
}
|
|
on_mon_dead(){
|
|
let coin =(GameSet.MON_COIN_ADD*smc.vm_data.mission.coin_reward_add*(1+Talents[1006].bonus*smc.vm_data.talent[1006].lv)).toFixed(0)
|
|
smc.vm_data.mission.coin += parseFloat(coin)
|
|
smc.vm_data.mission.reward_num += 1;
|
|
smc.vm_data.mission.reward_gold +=10+(1-smc.vm_data.mission.mission_lv)*1
|
|
smc.vm_data.mission.reward_exp +=10+(1-smc.vm_data.mission.mission_lv)*1
|
|
smc.vm_data.mission.m_alive -= 1;
|
|
if(smc.vm_data.mission.m_alive <= 0){
|
|
smc.vm_data.mission.victory = 1;
|
|
oops.message.dispatchEvent("minssion_victory");
|
|
}
|
|
}
|
|
on_normal_call(){
|
|
let hero:any =RandomManager.instance.getRandomByObjectList(smc.cards, 1);
|
|
this.addHero(hero[0].uuid)
|
|
this.hero_total -= 1
|
|
}
|
|
on_better_call(){
|
|
let hero:any =RandomManager.instance.getRandomByObjectList(smc.cards, 1);
|
|
console.log("better_call:",hero)
|
|
this.addHero(hero[0].uuid)
|
|
}
|
|
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");
|
|
}
|
|
|
|
private on_other_add_monster(event: string, args: any) {
|
|
var scene = smc.map.MapView.scene;
|
|
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
|
|
let monster_layer = scene.entityLayer!.node!
|
|
this.addMonster(args.uuid)
|
|
}
|
|
set_start_point(){
|
|
// this.start_p.setPosition(-240,BoxSet.GAME_LINE+this.start_ys[this.hero_index]+30,0)
|
|
}
|
|
check_mon_count(){
|
|
let count = 0;
|
|
let list = ecs.query(ecs.allOf(MonModelComp));
|
|
count = list.length
|
|
return count;
|
|
}
|
|
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
|
|
}
|
|
}
|
|
|
|
private on_do_add_hero(event: string, args: any) {
|
|
this.addHero(args.uuid)
|
|
}
|
|
/** 添加玩家 */
|
|
private addHero(uuid:number=1001) {
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let pos:Vec3 = v3(HeroSet[smc.heros[uuid].type],BoxSet.GAME_LINE);
|
|
hero.load(pos,scale,uuid);
|
|
this.set_start_point()
|
|
}
|
|
private addMonster(uuid:number=1001) {
|
|
let monster = ecs.getEntity<Hero>(Hero);
|
|
let scale = -1
|
|
let index = -1
|
|
let pos:Vec3 = v3(-1*HeroSet[smc.heros[uuid].type],BoxSet.GAME_LINE);
|
|
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();
|
|
}
|
|
} |