160 lines
5.9 KiB
TypeScript
160 lines
5.9 KiB
TypeScript
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI } 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 { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { MonModelComp } from "../hero/MonModelComp";
|
|
import { Missions,} from "../common/config/MissionSet";
|
|
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { VictoryComp } from "./VictoryComp";
|
|
import { MSkillComp } from "./MSkillComp";
|
|
import { CardControllerComp } from "./CardController";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
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
|
|
MSComp:MSkillComp=null
|
|
MMSComp:MSkillComp=null
|
|
heros_node:any=null
|
|
heros_node_pos:any=v3(0,0,0)
|
|
herosc_node:any=null
|
|
hero_args:any=null
|
|
onLoad(){
|
|
// this.on(GameEvent.UserHeroCard,this.show_herosc,this)
|
|
// this.MSComp=this.node.getChildByName("msk").getComponent(MSkillComp)
|
|
// this.MMSComp=this.node.getChildByName("mmsk").getComponent(MSkillComp)
|
|
// this.MSComp.group=BoxSet.HERO
|
|
// this.MSComp.s_uuid=smc.mission.mskill
|
|
// this.MMSComp.group=BoxSet.MONSTER
|
|
// this.MMSComp.s_uuid=smc.mission.mmskill
|
|
}
|
|
start() {
|
|
this.heros_node=this.node.getChildByName("heros")
|
|
// this.herosc_node=this.node.getChildByName("herosc")
|
|
// this.herosc_node.active=false
|
|
// this.node.getChildByName('hbg').active=false
|
|
this.heros_node_pos=v3(this.heros_node.position.x,this.heros_node.position.y,this.heros_node.position.z)
|
|
// this.VictoryComp=this.node.getChildByName("victory").getComponent(VictoryComp)
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause){
|
|
return
|
|
}
|
|
|
|
// if (this.game_timer.update(dt)) {
|
|
// smc.vmdata.game.g_time += 1;
|
|
// }
|
|
}
|
|
show_herosc(event: string, args: any){
|
|
// this.node.getChildByName('hbg').active=true
|
|
const screenSize = this.node.getComponent(UITransform).contentSize;
|
|
const centerY = screenSize.height / 2;
|
|
tween(this.heros_node).to(0.1,{position:v3(this.heros_node.position.x,centerY,0)}, // 这里以node的位置信息坐标缓动的目标
|
|
{ // ITweenOption 的接口实现:
|
|
onComplete:()=>{
|
|
|
|
this.herosc_node.active=true
|
|
this.heros_node.active=false
|
|
this.hero_args=args
|
|
}
|
|
}).start()
|
|
}
|
|
call_hero(event: string, args: any){
|
|
console.log("call_hero",args)
|
|
oops.message.dispatchEvent(GameEvent.CallHero,{uuid:this.hero_args.uuid,pos:args})
|
|
// this.herosc_node.active=false
|
|
this.heros_node.active=true
|
|
this.heros_node.position=this.heros_node_pos
|
|
this.hero_args=null
|
|
// this.node.getChildByName('hbg').active=false
|
|
}
|
|
mission_start(){
|
|
/* todo 关卡设定完善*/
|
|
console.log("战斗开始 Missions mons:",Missions[smc.mission.lv])
|
|
smc.mission.status=1
|
|
this.colose_victory()
|
|
this.mission_init()
|
|
// this.mskill_init()
|
|
}
|
|
|
|
mission_end(){
|
|
oops.message.dispatchEvent(GameEvent.MissionEnd)
|
|
smc.mission.play=false
|
|
smc.mission.pause=false
|
|
this.cleanComponents()
|
|
// this.to_mission_home()
|
|
this.open_victory()
|
|
}
|
|
private cleanComponents() {
|
|
ecs.query(ecs.allOf(HeroSkillsComp)).forEach(entity => {entity.remove(HeroSkillsComp);entity.destroy()});
|
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()});
|
|
}
|
|
|
|
open_victory(){
|
|
this.node.getChildByName("victory").active=true
|
|
this.node.getChildByName("victory").getComponent(VictoryComp).open()
|
|
}
|
|
colose_victory(){
|
|
this.node.getChildByName("victory").active=false
|
|
}
|
|
to_mission_home(){
|
|
this.colose_victory()
|
|
let home =this.node.parent.getComponent(CardControllerComp);
|
|
home.mission_to_mission_home()
|
|
}
|
|
mission_init(){
|
|
//局内数据初始化
|
|
this.fight_start=false
|
|
smc.mission.is_victory=false
|
|
smc.mission.is_defeat=false
|
|
|
|
}
|
|
|
|
mskill_init(){
|
|
this.MSComp.group=BoxSet.HERO
|
|
this.MMSComp.group=BoxSet.MONSTER
|
|
this.MSComp.init()
|
|
this.MMSComp.init()
|
|
}
|
|
|
|
get_mons(){
|
|
return ecs.query(ecs.allOf(MonModelComp));
|
|
}
|
|
get_heros(){
|
|
return ecs.query(ecs.allOf(HeroModelComp))
|
|
}
|
|
|
|
card_refresh(){
|
|
oops.message.dispatchEvent(GameEvent.CardRefresh)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |