167 lines
6.0 KiB
TypeScript
167 lines
6.0 KiB
TypeScript
import { _decorator, instantiate, Prefab, resources, Sprite, SpriteAtlas, UITransform } 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 { HeroInfo, HeroList } from "../common/config/heroSet";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { UiHeroComp } from "../hero/UiHeroComp";
|
|
import { BoxSet, GameSet } from "../common/config/BoxSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { HeroSelect } from "../hero/HeroSelect";
|
|
import { HeroSelectComp } from "../hero/HeroSelectComp";
|
|
import { MBSet } from "../common/config/MissionSet";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionHomeComp')
|
|
@ecs.register('MissionHome', false)
|
|
export class MissionHomeComp extends CCComp {
|
|
|
|
heros:any[]=[];
|
|
heros_pos:any=[
|
|
{uuid:0,px:-100},
|
|
{uuid:0,px:-200},
|
|
{uuid:0,px:-300},
|
|
]
|
|
protected onLoad(): void {
|
|
oops.message.on("hero_card_select", this.select_hero, this);
|
|
oops.message.on("hero_card_cancel_select", this.cancel_hero, this);
|
|
}
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
this.load_hero_card()
|
|
this.load_ui_heros()
|
|
// this.load_skill_card()
|
|
// this.select_skill()
|
|
this.init_buff()
|
|
}
|
|
to_start(){
|
|
this.show_heros()
|
|
}
|
|
start_mission() {
|
|
if (this.heros.length <=0 ) {
|
|
oops.gui.toast("请先选择英雄")
|
|
return
|
|
}
|
|
this.hide_heros()
|
|
for(let i=0;i<this.heros.length;i++){
|
|
this.heros[i].to_destroy()
|
|
}
|
|
this.heros=[]
|
|
this.heros_pos=[
|
|
{uuid:0,px:-100},
|
|
{uuid:0,px:-200},
|
|
{uuid:0,px:-300},
|
|
]
|
|
oops.message.dispatchEvent(GameEvent.MissionStart, {})
|
|
this.node.active=false;
|
|
}
|
|
init_buff(){
|
|
smc.vmdata.mission.ap_up=MBSet.ap_add*smc.vmdata.buff_num[0]/MBSet.ap_cost
|
|
smc.vmdata.mission.def_up=MBSet.def_add*smc.vmdata.buff_num[1]/MBSet.def_cost
|
|
smc.vmdata.mission.hp_up=MBSet.hp_add*smc.vmdata.buff_num[2]/MBSet.hp_cost
|
|
smc.vmdata.mission.crit_up=MBSet.crit_add*smc.vmdata.buff_num[3]/MBSet.crit_cost
|
|
smc.vmdata.mission.dodge_up=MBSet.dodge_add*smc.vmdata.buff_num[4]/MBSet.dodge_cost
|
|
smc.vmdata.buff_num_less=smc.vmdata.buff_num_max-smc.vmdata.buff_num[0]-smc.vmdata.buff_num[1]-smc.vmdata.buff_num[2]-smc.vmdata.buff_num[3]-smc.vmdata.buff_num[4]
|
|
|
|
}
|
|
load_hero_card(){
|
|
|
|
let hc:number =HeroList.length
|
|
let parent= this.node.getChildByName("heros").getChildByName("view").getChildByName("content")
|
|
let height=Math.ceil(hc / 4)*160 +100
|
|
parent.getComponent(UITransform).height=height
|
|
|
|
for (let i = 0; i < hc; i++) {
|
|
// if (HeroInfo[HeroList[i]].quality==3) {
|
|
let hcc =ecs.getEntity<HeroSelect>(HeroSelect)
|
|
hcc.load(HeroList[i],parent)
|
|
// }
|
|
}
|
|
// for (let i = 0; i < hc; i++) {
|
|
// if (HeroInfo[HeroList[i]].quality==2) {
|
|
// let hcc =ecs.getEntity<HeroSelect>(HeroSelect)
|
|
// hcc.load(HeroList[i],parent)
|
|
// }
|
|
// }
|
|
// for (let i = 0; i < hc; i++) {
|
|
// if (HeroInfo[HeroList[i]].quality==1) {
|
|
// let hcc =ecs.getEntity<HeroSelect>(HeroSelect)
|
|
// hcc.load(HeroList[i],parent)
|
|
// }
|
|
// }
|
|
this.update_hero_cards()
|
|
}
|
|
update_hero_cards(){
|
|
let loaded:any = ecs.query(ecs.allOf(HeroSelectComp));
|
|
for(let i=0;i<loaded.length;i++){
|
|
if(smc.heros[loaded[i].HeroSelectComp.h_uuid].slv ==0 ) {
|
|
loaded[i].HeroSelectComp.node.active=false
|
|
}else{
|
|
loaded[i].HeroSelectComp.node.active=true
|
|
}
|
|
}
|
|
}
|
|
load_skill_card(){
|
|
|
|
}
|
|
load_ui_heros(){
|
|
for(let i=0;i<smc.fight_heros.length;i++){
|
|
this.select_hero("local",{uuid:smc.fight_heros[i]})
|
|
}
|
|
}
|
|
|
|
select_hero(event:any,args:any){
|
|
console.log("select_hero",args.uuid)
|
|
for(let i=0;i<GameSet.HERO_NUM;i++){
|
|
if(this.heros_pos[i].uuid==0){
|
|
this.heros_pos[i].uuid=args.uuid
|
|
this.call_hero(args.uuid,i)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
cancel_hero(event:any,args:any){
|
|
for(let i=0;i<GameSet.HERO_NUM;i++){
|
|
if(this.heros_pos[i].uuid==args.uuid){
|
|
this.heros_pos[i].uuid=0
|
|
this.destory_hero(args.uuid)
|
|
}
|
|
}
|
|
}
|
|
call_hero(h_uuid:number,index:number){
|
|
var path = "game/heros/uiheros/"+HeroInfo[h_uuid].path;
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
var scene = smc.map.MapView.scene;
|
|
node.parent = scene.entityLayer!.node!
|
|
node.setPosition(this.heros_pos[index].px,BoxSet.GAME_LINE,0);
|
|
let comp = node.getComponent(UiHeroComp)
|
|
comp.h_uuid = h_uuid
|
|
this.heros.push(comp)
|
|
}
|
|
destory_hero(h_uuid:number){
|
|
for(let i=0;i<this.heros.length;i++){
|
|
if(this.heros[i].h_uuid==h_uuid){
|
|
this.heros[i].to_destroy()
|
|
this.heros.splice(i,1)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
show_heros(){
|
|
this.node.getChildByName("heros").setPosition(0,290)
|
|
}
|
|
hide_heros(){
|
|
this.node.getChildByName("heros").setPosition(0,-800)
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |