Files
heros/assets/script/game/map/MissionHomeComp.ts
2025-01-03 16:43:03 +08:00

299 lines
11 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 { MSklist, SkillSet } from "../common/config/SkillSet";
import { MSCard } from "./MSCard";
import { CardControllerComp } from "./CardController";
import { MissionComp } from "./MissionComp";
import { MSCardComp } from "./MSCardComp";
import { HeroSelectComp } from "../hero/HeroSelectComp";
import { MBSet } from "../common/config/MissionSet";
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},
]
/** 视图层逻辑代码分离演示 */
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()
}
start_mission() {
console.log("mission_home : start_mission")
if (this.heros.length <=0 ) {
oops.gui.toast("请先选择英雄")
return
}
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},
]
let home =this.node.parent.getComponent(CardControllerComp);
home.node.getChildByName("bar").active=false;
let mission=home.node.getChildByName("mission").getComponent(MissionComp)
mission.node.active = true;
mission.mission_start()
smc.mission.play = true;
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)*140 +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(){
let ms_num:number =MSklist.length
let parent= this.node.getChildByName("skills").getChildByName("view").getChildByName("content")
let height=ms_num*135
parent.getComponent(UITransform).height=height
for (let i = 0; i < ms_num; i++) {
let msc =ecs.getEntity<MSCard>(MSCard)
msc.load(MSklist[i],parent,2)
}
}
load_ui_heros(){
for(let i=0;i<smc.fight_heros.length;i++){
this.select_hero(smc.fight_heros[i])
}
}
select_skill(){
if(SkillSet[smc.mission.mskill]==undefined) return
var icon_path = "game/skills/skill_icon"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("msk").getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[smc.mission.mskill].path);
});
}
select_hero(h_uuid:number){
for(let i=0;i<GameSet.HERO_NUM;i++){
if(this.heros_pos[i].uuid==0){
this.heros_pos[i].uuid=h_uuid
this.call_hero(h_uuid,i)
break
}
}
}
cancel_hero(h_uuid:number){
for(let i=0;i<GameSet.HERO_NUM;i++){
if(this.heros_pos[i].uuid==h_uuid){
this.heros_pos[i].uuid=0
this.destory_hero(h_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)
}
show_buff_set(){
this.node.getChildByName("buffset").setPosition(0,400)
}
hide_buff_set(){
this.node.getChildByName("buffset").setPosition(0,-800)
}
add_ap(){
if(smc.vmdata.buff_num_less < MBSet.ap_cost){
oops.gui.toast("成长点数不足")
return
}
smc.vmdata.buff_num_less -= MBSet.ap_cost
smc.vmdata.buff_num[0] += MBSet.ap_cost
smc.vmdata.mission.ap_up=MBSet.ap_add*smc.vmdata.buff_num[0]/MBSet.ap_cost
}
less_ap(){
if(smc.vmdata.buff_num[0] <= 0){
return
}
smc.vmdata.buff_num_less += MBSet.ap_cost
smc.vmdata.buff_num[0] -= MBSet.ap_cost
smc.vmdata.mission.ap_up=MBSet.ap_add*smc.vmdata.buff_num[0]/MBSet.ap_cost
}
add_def(){
if(smc.vmdata.buff_num_less < MBSet.def_cost){
oops.gui.toast("成长点数不足")
return
}
smc.vmdata.buff_num_less -= MBSet.def_cost
smc.vmdata.buff_num[1] += MBSet.def_cost
smc.vmdata.mission.def_up=MBSet.def_add*smc.vmdata.buff_num[1]/MBSet.def_cost
}
less_def(){
if(smc.vmdata.buff_num[1] <= 0){
return
}
smc.vmdata.buff_num_less += MBSet.def_cost
smc.vmdata.buff_num[1] -= MBSet.def_cost
smc.vmdata.mission.def_up=MBSet.def_add*smc.vmdata.buff_num[1]/MBSet.def_cost
}
add_hp(){
if(smc.vmdata.buff_num_less < MBSet.hp_cost){
oops.gui.toast("成长点数不足")
return
}
smc.vmdata.buff_num_less -= MBSet.hp_cost
smc.vmdata.buff_num[2] += MBSet.hp_cost
smc.vmdata.mission.hp_up=MBSet.hp_add*smc.vmdata.buff_num[2]/MBSet.hp_cost
}
less_hp(){
if(smc.vmdata.buff_num[2] <= 0){
return
}
smc.vmdata.buff_num_less += MBSet.hp_cost
smc.vmdata.buff_num[2] -= MBSet.hp_cost
smc.vmdata.mission.hp_up=MBSet.hp_add*smc.vmdata.buff_num[2]/MBSet.hp_cost
}
add_crit(){
if(smc.vmdata.buff_num_less < MBSet.crit_cost){
oops.gui.toast("成长点数不足")
return
}
smc.vmdata.buff_num_less -= MBSet.crit_cost
smc.vmdata.buff_num[3] += MBSet.crit_cost
smc.vmdata.mission.crit_up=MBSet.crit_add*smc.vmdata.buff_num[3]/MBSet.crit_cost
}
less_crit(){
if(smc.vmdata.buff_num[3] <= 0){
return
}
smc.vmdata.buff_num_less += MBSet.crit_cost
smc.vmdata.buff_num[3] -= MBSet.crit_cost
smc.vmdata.mission.crit_up=MBSet.crit_add*smc.vmdata.buff_num[3]/MBSet.crit_cost
}
add_dodge(){
if(smc.vmdata.buff_num_less < MBSet.dodge_cost){
oops.gui.toast("成长点数不足")
return
}
smc.vmdata.buff_num_less -= MBSet.dodge_cost
smc.vmdata.buff_num[4] += MBSet.dodge_cost
smc.vmdata.mission.dodge_up=MBSet.dodge_add*smc.vmdata.buff_num[4]/MBSet.dodge_cost
}
less_dodge(){
if(smc.vmdata.buff_num[4] <= 0){
return
}
smc.vmdata.buff_num_less += MBSet.dodge_cost
smc.vmdata.buff_num[4] -= MBSet.dodge_cost
smc.vmdata.mission.dodge_up=MBSet.dodge_add*smc.vmdata.buff_num[4]/MBSet.dodge_cost
}
show_skills(){
this.node.getChildByName("skills").setPosition(0,400)
}
hide_skills(){
this.node.getChildByName("skills").setPosition(0,-800)
let mscards:any= ecs.query(ecs.allOf(MSCardComp));
for(let i=0;i<mscards.length;i++){
mscards[i].MSCardComp.is_select=true
mscards[i].MSCardComp.is_update=false
mscards[i].MSCardComp.change()
}
this.node.getChildByName("skills").getChildByName("noset").active=false
this.node.getChildByName("skills").getChildByName("set").active=true
}
set_skills(){
let mscards:any= ecs.query(ecs.allOf(MSCardComp));
for(let i=0;i<mscards.length;i++){
mscards[i].MSCardComp.change_set()
}
this.node.getChildByName("skills").getChildByName("set").active=!this.node.getChildByName("skills").getChildByName("set").active
this.node.getChildByName("skills").getChildByName("noset").active=!this.node.getChildByName("skills").getChildByName("noset").active
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}