158 lines
7.2 KiB
TypeScript
158 lines
7.2 KiB
TypeScript
import { _decorator, Animation, AnimationClip, Component, Label, Node, resources, Sprite, SpriteFrame } from 'cc';
|
|
import { oops } from 'db://oops-framework/core/Oops';
|
|
import { UIID } from '../common/config/GameUIConfig';
|
|
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType, unlockHeroCost } from '../common/config/heroSet';
|
|
import { smc } from '../common/SingletonModuleComp';
|
|
import { GameEvent } from '../common/config/GameEvent';
|
|
import { NumberFormatter } from '../common/config/BoxSet';
|
|
import { Items } from '../common/config/Items';
|
|
import { finishCurrGuide, GuideConfig } from '../common/config/Guide';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('HInfoComp')
|
|
export class HInfoComp extends Component {
|
|
h_uuid:number=0
|
|
private guides:any=[0,1]
|
|
private guideends:any=[3,5]
|
|
start() {
|
|
|
|
}
|
|
|
|
onAdded(args: any) {
|
|
// console.log("[HInfoComp]:onAdded",args)
|
|
this.endGuide()
|
|
this.startNextGuide()
|
|
this.update_data(args)
|
|
}
|
|
startNextGuide(){
|
|
this.guides.forEach(guide_key=>{
|
|
if(smc.guides[guide_key]==0){
|
|
console.log("[HInfoComp]:推送启动引导:key",guide_key)
|
|
oops.message.dispatchEvent(GameEvent.GuideStart, guide_key)
|
|
return
|
|
}
|
|
})
|
|
}
|
|
endGuide(){
|
|
finishCurrGuide(3)
|
|
}
|
|
update(deltaTime: number) {
|
|
|
|
}
|
|
update_data(uuid:number){
|
|
this.h_uuid=uuid
|
|
let hero_data = HeroInfo[uuid]
|
|
console.log("[HInfoComp]:update_data",uuid,hero_data,this.node)
|
|
let lv=smc.heros[uuid]?.lv??1
|
|
let anm_path=hero_data.path
|
|
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
|
|
this.node.getChildByName("hero").getComponent(Animation).addClip(clip);
|
|
this.node.getChildByName("hero").getComponent(Animation).play("idle");
|
|
});
|
|
this.node.getChildByName("name").getComponent(Label).string=hero_data.name
|
|
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=lv.toString()
|
|
this.node.getChildByName("skills").getChildByName("list2").getChildByName("lock").active= lv <5
|
|
this.node.getChildByName("skills").getChildByName("list3").getChildByName("lock").active= lv <10
|
|
this.node.getChildByName("skills").getChildByName("list4").getChildByName("lock").active= lv <15
|
|
let {hp,ap,def}=getHeroStatsByLevel(uuid,lv)
|
|
this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=hp.toString()
|
|
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=ap.toString()
|
|
this.node.getChildByName("info").getChildByName("def").getChildByName("num").getComponent(Label).string=def.toString()
|
|
let {experience,gold}=getUpgradeResources(lv)
|
|
this.updata_need(experience,gold)
|
|
this.node.getChildByName("upBtn").active=smc.data.exp>=experience&&smc.data.gold>=gold
|
|
this.node.getChildByName("type").getChildByName("w").active=hero_data.type==HType.warrior
|
|
this.node.getChildByName("type").getChildByName("r").active=hero_data.type==HType.remote
|
|
this.node.getChildByName("type").getChildByName("m").active=hero_data.type==HType.mage
|
|
this.show_lock(smc.heros[uuid]?.lv??0)
|
|
}
|
|
updata_need(experience:number,gold:number){
|
|
let need_node=this.node.getChildByName("upNeed").getChildByName("need")
|
|
need_node.getChildByName("exp").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(experience)
|
|
need_node.getChildByName("gold").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(gold)
|
|
need_node.getChildByName("exp").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.exp)
|
|
need_node.getChildByName("gold").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.gold)
|
|
}
|
|
show_lock(lv:number){
|
|
this.node.getChildByName("upBtn").active=lv > 0
|
|
this.node.getChildByName("upNeed").active=lv > 0
|
|
this.node.getChildByName("lock").active=lv == 0
|
|
this.node.getChildByName("unLock").active=lv == 0
|
|
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
|
// console.log("[HInfoComp]:show_lock item:item_uuid:hero_uuid:hero_data",Items[need_item.i_uuid],need_item.i_uuid,this.h_uuid,HeroInfo[this.h_uuid])
|
|
|
|
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("has").getComponent(Label).string=smc.items[need_item.i_uuid]??0
|
|
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(need_item.num)
|
|
let path="gui/items/"+Items[need_item.i_uuid].path
|
|
resources.load(path,SpriteFrame, (err, clip) => {
|
|
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("icon").getComponent(Sprite).spriteFrame=clip
|
|
});
|
|
this.node.getChildByName("unLockNeed").active=lv == 0
|
|
}
|
|
uplockhero(){
|
|
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
|
if(!smc.items[need_item.i_uuid]||smc.items[need_item.i_uuid]<need_item.num){
|
|
oops.gui.toast("["+Items[need_item.i_uuid].name+"]数量不足")
|
|
return
|
|
}
|
|
if(!smc.spendItem(need_item.i_uuid,need_item.num)){
|
|
smc.error()
|
|
return
|
|
}
|
|
if(!smc.addHero(this.h_uuid)){
|
|
smc.addItem(need_item.i_uuid,need_item.num,false)
|
|
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >解锁失败")
|
|
return
|
|
}
|
|
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >解锁成功")
|
|
this.update_data(this.h_uuid)
|
|
oops.message.dispatchEvent(GameEvent.GuideEnd,GuideConfig[3].key)
|
|
oops.message.dispatchEvent(GameEvent.HeroUnlock, {uuid:this.h_uuid})
|
|
}
|
|
uplevel(){
|
|
let lv=smc.heros[this.h_uuid].lv
|
|
let {experience,gold}=getUpgradeResources(lv)
|
|
if(smc.data.exp<experience||smc.data.gold<gold){
|
|
oops.gui.toast("经验或金币不足")
|
|
return
|
|
}
|
|
if(!smc.spendGameProperty({exp:experience,gold:gold},false)){
|
|
smc.error()
|
|
return
|
|
}
|
|
if(!smc.levelUpHero(this.h_uuid)){
|
|
smc.addExp(experience,false)
|
|
smc.addGold(gold,false)
|
|
smc.error()
|
|
return
|
|
}
|
|
this.update_data(this.h_uuid)
|
|
oops.gui.toast(`英雄< ${HeroInfo[this.h_uuid].name} >升级成功`)
|
|
oops.message.dispatchEvent(GameEvent.HeroLvUp, {uuid:this.h_uuid})
|
|
}
|
|
next_hero(){
|
|
let heros=getHeroList()
|
|
let index = heros.indexOf(this.h_uuid);
|
|
index++
|
|
if(index==heros.length) index=0
|
|
let nextHero = heros[index];
|
|
this.update_data(nextHero)
|
|
}
|
|
prev_hero(){
|
|
let heros=getHeroList()
|
|
let index = heros.indexOf(this.h_uuid);
|
|
index--
|
|
if(index==-1) index=heros.length-1
|
|
let prevHero = heros[index];
|
|
this.update_data(prevHero)
|
|
}
|
|
close(){
|
|
oops.gui.removeByNode(this.node)
|
|
}
|
|
reset() {
|
|
this.node.destroy()
|
|
}
|
|
}
|
|
|
|
|