254 lines
14 KiB
TypeScript
254 lines
14 KiB
TypeScript
import { _decorator,Button,color,EventHandler,EventTouch,instantiate,Label,NodeEventType,Prefab,ProgressBar,resources,Sprite,SpriteAtlas,tween,UITransform,v3 } 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 { HeroCard } from "../hero/HeroCard";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { getUpChipByLv, getUpGoldByRange, LvUp, SlvUp, UpGold } from "../common/config/RoleSet";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HeroHomeComp')
|
|
@ecs.register('HeroHome', false)
|
|
export class HeroHomeComp extends CCComp {
|
|
h_uuid:number=0
|
|
role:any=null
|
|
hero:any=null
|
|
gold_need:number=9999
|
|
chip_need:number=9999
|
|
slv:number=0
|
|
protected onLoad(): void {
|
|
|
|
}
|
|
start() {
|
|
// this.load_talents()
|
|
console.log("hero_home start")
|
|
// this.h_uuid=5001
|
|
// this.hero_show(this.h_uuid)
|
|
this.loads()
|
|
this.node.getChildByName("show").active=false
|
|
}
|
|
loads(){
|
|
let hc:number =HeroList.length
|
|
let parent= this.node.getChildByName("heros").getChildByName("view").getChildByName("content")
|
|
parent.getComponent(UITransform).setContentSize(720,Math.ceil(HeroList.length/4)*230)
|
|
console.log("parent",parent)
|
|
for (let i = 0; i < hc; i++) {
|
|
let hcc =ecs.getEntity<HeroCard>(HeroCard)
|
|
hcc.load(HeroList[i],parent)
|
|
// if (HeroInfo[HeroList[i]].quality==3) {
|
|
// let hcc =ecs.getEntity<HeroCard>(HeroCard)
|
|
// hcc.load(HeroList[i],parent)
|
|
// }
|
|
}
|
|
// for (let i = 0; i < hc; i++) {
|
|
// if (HeroInfo[HeroList[i]].quality==2) {
|
|
// let hcc =ecs.getEntity<HeroCard>(HeroCard)
|
|
// hcc.load(HeroList[i],parent)
|
|
// }
|
|
// }
|
|
// for (let i = 0; i < hc; i++) {
|
|
// if (HeroInfo[HeroList[i]].quality==1) {
|
|
// let hcc =ecs.getEntity<HeroCard>(HeroCard)
|
|
// hcc.load(HeroList[i],parent)
|
|
// }
|
|
// }
|
|
}
|
|
hero_show(uuid:number) {
|
|
this.node.getChildByName("show").active=true
|
|
this.h_uuid=uuid
|
|
this.hero=HeroInfo[uuid]
|
|
console.log("hero_show",uuid)
|
|
// let skill1 = SkillSet[this.hero.skill[0]]
|
|
// let skill2 = SkillSet[this.hero.skill[1]]
|
|
// var sk_path = "game/skills/skill_icon"
|
|
// var icon_path = "game/heros/herois"
|
|
|
|
|
|
this.slv = Math.floor((smc.heros[uuid].lv) / 5);
|
|
let content=this.node.getChildByName("show").getChildByName("content")
|
|
content.getChildByName("name").getChildByName("value").getComponent(Label).string=this.hero.name
|
|
content.getChildByName("name").getChildByName("g1").active=HeroInfo[uuid].quality==1
|
|
content.getChildByName("name").getChildByName("g2").active=HeroInfo[uuid].quality==2
|
|
content.getChildByName("name").getChildByName("g3").active=HeroInfo[uuid].quality==3
|
|
this.clear_hero()
|
|
this.call_hero(uuid)
|
|
// resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = content.getChildByName("hero").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(this.hero.path);
|
|
// });
|
|
// resources.load(sk_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = content.getChildByName("bottom").getChildByName("sk").getChildByName("skicon").getChildByName("Mask").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(skill1.path);
|
|
// });
|
|
// content.getChildByName("bottom").getChildByName("sk").getChildByName("name").getComponent(Label).string = skill1.name;
|
|
// content.getChildByName("bottom").getChildByName("sk").getChildByName("info").getComponent(Label).string = skill1.info;
|
|
// resources.load(sk_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = content.getChildByName("bottom").getChildByName("sk2").getChildByName("skicon").getChildByName("Mask").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(skill2.path);
|
|
// });
|
|
// content.getChildByName("bottom").getChildByName("sk2").getChildByName("name").getComponent(Label).string = skill2.name;
|
|
// content.getChildByName("bottom").getChildByName("sk2").getChildByName("info").getComponent(Label).string = skill2.info;
|
|
|
|
// tal.getChildByName("slv1").getChildByName("val").getComponent(Label).string = this.hero.tals[0]
|
|
// tal.getChildByName("slv2").getChildByName("val").getComponent(Label).string = this.hero.tals[1]
|
|
// tal.getChildByName("slv3").getChildByName("val").getComponent(Label).string = this.hero.tals[2]
|
|
// tal.getChildByName("slv4").getChildByName("val").getComponent(Label).string = this.hero.tals[3]
|
|
// tal.getChildByName("slv5").getChildByName("val").getComponent(Label).string = this.hero.tals[4]
|
|
this.update_data()
|
|
}
|
|
update_data(){
|
|
let content=this.node.getChildByName("show").getChildByName("content")
|
|
this.slv = Math.floor((smc.heros[this.h_uuid].lv) / 5);
|
|
this.gold_need=(getUpGoldByRange(smc.heros[this.h_uuid].lv)*smc.heros[this.h_uuid].lv)
|
|
this.chip_need=getUpChipByLv(smc.heros[this.h_uuid].lv)-this.hero.lvexp
|
|
// let slv_node=content.getChildByName("name").getChildByName("slv");
|
|
let lvup=content.getChildByName("lvup");
|
|
// let slvup=content.getChildByName("slvup");
|
|
let attr = content.getChildByName("attr");
|
|
content.getChildByName("name").getChildByName("lv").getComponent(Label).string = smc.heros[this.h_uuid].lv.toString()+"级";
|
|
// slv_node.getChildByName("slv").getComponent(Label).string = smc.heros[uuid].slv.toString();
|
|
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("q1").active = this.hero.quality == 1;
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("q2").active = this.hero.quality == 2;
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("q3").active = this.hero.quality == 3;
|
|
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("k1").active = this.hero.kind == 1;
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("k2").active = this.hero.kind == 2;
|
|
// content.getChildByName("name").getChildByName("quality").getChildByName("k3").active = this.hero.kind == 3;
|
|
|
|
|
|
let lvnum=smc.heros[this.h_uuid].num
|
|
// lvup.getChildByName("gold").getChildByName("need").getComponent(Label).string = (UpGold.LvUp*smc.heros[uuid].lv).toString()
|
|
lvup.getChildByName("item").getChildByName("chip").getChildByName("need").getComponent(Label).string = this.chip_need.toString()
|
|
lvup.getChildByName("item").getChildByName("btn").getChildByName("gold").getChildByName("need").getComponent(Label).string = this.gold_need.toString()
|
|
lvup.getChildByName("item").getChildByName("chip").getChildByName("num").getComponent(Label).string = lvnum.toString()
|
|
if( lvnum >=this.chip_need) {
|
|
lvup.getChildByName("item").getChildByName("chip").getChildByName("num").getComponent(Label).color = color(0,255,0);
|
|
}else{
|
|
lvup.getChildByName("item").getChildByName("chip").getChildByName("num").getComponent(Label).color = color(255,0,0);
|
|
}
|
|
lvup.getChildByName("up").active=lvnum >= this.chip_need
|
|
lvup.getChildByName("item").getChildByName("chip").getChildByName("bar").getComponent(ProgressBar).progress = lvnum/this.chip_need
|
|
// lvup.getChildByName("info").getChildByName("ap").getComponent(Label).string = "+"+this.hero.ap_up
|
|
// lvup.getChildByName("info").getChildByName("def").getComponent(Label).string = "+"+this.hero.def_up
|
|
// lvup.getChildByName("info").getChildByName("hp").getComponent(Label).string = "+"+this.hero.hp_up
|
|
|
|
// lvup.getChildByName("info2").getChildByName("ap").getComponent(Label).string = "+"+this.hero.sap_up+"%"
|
|
// lvup.getChildByName("info2").getChildByName("def").getComponent(Label).string = "+"+this.hero.sdef_up+"%"
|
|
// lvup.getChildByName("info2").getChildByName("hp").getComponent(Label).string = "+"+this.hero.shp_up+"%"
|
|
|
|
// lvup.getChildByName("item").getChildByName("btn").getChildByName("bar").getComponent(ProgressBar).progress = smc.vmdata.exp.num/((LvUp[0]+this.hero.lvexp)*smc.heros[uuid].lv)
|
|
// slvup.getChildByName("gold").getChildByName("btn").getChildByName("need").getComponent(Label).string = (UpGold.SlvUp*(smc.heros[uuid].slv+1)).toString()
|
|
// let sthis.chip_need=HeroInfo[this.h_uuid].slvexp
|
|
// let slvnum=smc.heros[this.h_uuid].num
|
|
// slvup.getChildByName("up").active=slvnum>=sthis.chip_need
|
|
// if( slvnum>=sthis.chip_need) {
|
|
// slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(0,255,0);
|
|
// }else{
|
|
// slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(255,0,0);
|
|
// }
|
|
// slvup.getChildByName("cost").getChildByName("btn").getChildByName("need").getComponent(Label).string = sthis.chip_need.toString()
|
|
// slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).string = slvnum.toString()
|
|
// slvup.getChildByName("cost").getChildByName("btn").getChildByName("bar").getComponent(ProgressBar).progress = slvnum/sthis.chip_need
|
|
// let hchipcomp= slvup.getChildByName("cost").getChildByName("btn").getChildByName("hchip").getComponent(HChipComp)
|
|
// hchipcomp.update_data(this.h_uuid,0)
|
|
|
|
// if( smc.heros[uuid].slv==5) {
|
|
// slvup.getChildByName("btned").active=true
|
|
// }else{
|
|
// slvup.getChildByName("btned").active=false
|
|
// };
|
|
// if( smc.heros[uuid].slv==0) {
|
|
// content.getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("need").getComponent(Label).string = ((SlvUp[smc.heros[uuid].slv]-HeroInfo[this.h_uuid].slvexp)*(1+smc.heros[uuid].slv)).toString()
|
|
// content.getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("num").getComponent(Label).string = smc.heros[this.h_uuid].num.toString()
|
|
// content.getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("bar").getComponent(ProgressBar).progress = smc.heros[this.h_uuid].num/((SlvUp[smc.heros[uuid].slv]-HeroInfo[this.h_uuid].slvexp)*(1+smc.heros[uuid].slv))
|
|
// let hchipcomp= content.getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("hchip").getComponent(HChipComp)
|
|
// hchipcomp.update_data(this.h_uuid,0)
|
|
// content.getChildByName("call").active=true
|
|
// }else{
|
|
// content.getChildByName("call").active=false
|
|
// };
|
|
attr.getChildByName("ap").getChildByName("val").getComponent(Label).string = ((this.hero.ap+this.hero.ap_up* smc.heros[this.h_uuid].lv)*(1+this.hero.sap_up/100*this.slv)).toFixed(0).toString()
|
|
attr.getChildByName("hp").getChildByName("val").getComponent(Label).string = ((this.hero.hp+this.hero.hp_up* smc.heros[this.h_uuid].lv)*(1+this.hero.shp_up/100*this.slv)).toFixed(0).toString()
|
|
attr.getChildByName("def").getChildByName("val").getComponent(Label).string = ((this.hero.ap+this.hero.def_up* smc.heros[this.h_uuid].lv)*(1+this.hero.sdef_up/100*this.slv)).toFixed(0).toString()
|
|
attr.getChildByName("acd").getChildByName("val").getComponent(Label).string = this.hero.a_cd
|
|
attr.getChildByName("speed").getChildByName("val").getComponent(Label).string = this.hero.speed
|
|
attr.getChildByName("dis").getChildByName("val").getComponent(Label).string = this.hero.dis
|
|
|
|
|
|
|
|
oops.message.dispatchEvent("hero_card_update_info",{uuid:this.h_uuid})
|
|
}
|
|
lv_selcet(e:any,val:any){
|
|
|
|
}
|
|
|
|
|
|
call_hero(uuid:number){
|
|
var path = "game/heros/uiheros/"+HeroInfo[uuid].path;
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
var node = instantiate(prefab);
|
|
node.parent = this.node.getChildByName("show").getChildByName("content").getChildByName("hero").getChildByName("node")
|
|
}
|
|
clear_hero(){
|
|
this.node.getChildByName("show").getChildByName("content").getChildByName("hero").getChildByName("node").destroyAllChildren()
|
|
}
|
|
pre_hero(){
|
|
let hi= HeroList.indexOf(this.h_uuid)
|
|
if(hi==0){
|
|
oops.gui.toast("已经是第一个英雄");
|
|
return
|
|
}
|
|
this.h_uuid=HeroList[hi-1]
|
|
this.hero_show(this.h_uuid)
|
|
}
|
|
next_hero(){
|
|
let hi= HeroList.indexOf(this.h_uuid)
|
|
if(hi==HeroList.length-1){
|
|
oops.gui.toast("已经是最后一个英雄");
|
|
return
|
|
}
|
|
this.h_uuid=HeroList[hi+1]
|
|
this.hero_show(this.h_uuid)
|
|
}
|
|
// lv_up(){
|
|
// if(smc.vmdata.exp.num < ((this.hero.lvexp)*smc.heros[uuid].lv)){
|
|
// oops.gui.toast("资源不足,升级失败");
|
|
// return
|
|
// }
|
|
// smc.vmdata.exp.num -= ((this.hero.lvexp)*smc.heros[uuid].lv)
|
|
// smc.heros[uuid].lv++
|
|
// this.update_data()
|
|
// }
|
|
lv_up(){
|
|
// if(smc.heros[uuid].slv>=5){
|
|
// oops.gui.toast("已经满星,升阶失败");
|
|
// return
|
|
// }
|
|
if(smc.heros[this.h_uuid].num < this.chip_need){
|
|
oops.gui.toast("碎片不足,升级失败");
|
|
return
|
|
}
|
|
if(smc.vmdata.gold.num < this.gold_need){
|
|
oops.gui.toast("金币不足,升级失败");
|
|
return
|
|
}
|
|
smc.heros[this.h_uuid].num -= this.chip_need
|
|
smc.vmdata.gold.num -= (this.gold_need)
|
|
smc.heros[this.h_uuid].lv++
|
|
this.update_data()
|
|
}
|
|
item_show(e:any,val:any){
|
|
oops.gui.open(UIID.ItemInfo, {uuid:val,type:0});
|
|
}
|
|
close_show(){
|
|
this.node.getChildByName("show").active=false
|
|
}
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |