Files
heros/assets/script/game/map/TalsComp.ts

193 lines
6.7 KiB
TypeScript

import { _decorator, Component, Label, Node, resources, Sprite, SpriteAtlas, tween, v3 } from 'cc';
import { oops } from 'db://oops-framework/core/Oops';
import { GameEvent } from '../common/config/GameEvent';
import { smc } from '../common/SingletonModuleComp';
import { EquipInfo, EquipType, EquipAttrTarget, EquipSpecialAttr} from '../common/config/Equips';
import { BuffAttr, DebuffAttr, geDebuffNum, getBuffNum } from '../common/config/SkillSet';
import { FightSet } from '../common/config/Mission';
import { Quality } from '../common/config/CardSet';
import { TalentList, TalentSlot } from '../common/config/TalentSet';
const { ccclass, property } = _decorator;
@ccclass('TalsComp')
export class TalsComp extends Component {
tal1:any=null
tal2:any=null
tal3:any=null
tal4:any=null
tal5:any=null
tal6:any=null
boxs:Node=null
// attrs:any={
// hero_buff:getBuffNum(),
// enemy_buff:getBuffNum(),
// }
/** 视图层逻辑代码分离演示 */
onLoad() {
oops.message.on(GameEvent.FightReady,this.fight_ready,this)
oops.message.on(GameEvent.UseTalentCard,this.tal_add,this)
this.boxs=this.node.getChildByName("boxs")
}
start(){
this.fight_ready()
}
fight_ready(){
this.boxs.getChildByName("tal1").getChildByName("icon").active=false
this.boxs.getChildByName("tal2").getChildByName("icon").active=false
this.boxs.getChildByName("tal3").getChildByName("icon").active=false
this.boxs.getChildByName("tal4").getChildByName("icon").active=false
this.boxs.getChildByName("tal5").getChildByName("icon").active=false
this.boxs.getChildByName("tal6").getChildByName("icon").active=false
this.boxs.getChildByName("tal1").getChildByName("light").active=false
this.boxs.getChildByName("tal2").getChildByName("light").active=false
this.boxs.getChildByName("tal3").getChildByName("light").active=false
this.boxs.getChildByName("tal4").getChildByName("light").active=false
this.boxs.getChildByName("tal5").getChildByName("light").active=false
this.boxs.getChildByName("tal6").getChildByName("light").active=false
this.reset_attrs()
}
tal_add(e:GameEvent,data:any){
console.log("[TalsComp]:tal_add",data)
switch(data.slot){
case TalentSlot[0]:
this.tal1.uuid=data.uuid
this.tal1.name=data.name
this.show_tal(data.uuid,TalentSlot[0])
break
case TalentSlot[1]:
this.tal2.uuid=data.uuid
this.tal2.name=data.name
this.show_tal(data.uuid,TalentSlot[1])
break
case TalentSlot[2]:
this.tal3.uuid=data.uuid
this.tal3.name=data.name
this.show_tal(data.uuid,TalentSlot[2])
break
case TalentSlot[3]:
this.tal4.uuid=data.uuid
this.tal4.name=data.name
this.show_tal(data.uuid,TalentSlot[3])
break
case TalentSlot[4]:
this.tal5.uuid=data.uuid
this.tal5.name=data.name
this.show_tal(data.uuid,TalentSlot[4])
break
case TalentSlot[5]:
this.tal6.uuid=data.uuid
this.tal6.name=data.name
this.show_tal(data.uuid,TalentSlot[5])
break
}
}
show_tal(uuid:number,slot:string="tal1"){
let icon = this.boxs.getChildByName(slot).getChildByName("icon")
icon.active=true
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = icon.getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(TalentList[uuid].path);
});
icon.getChildByName("q1").active=TalentList[uuid].quality==Quality.WHITE
icon.getChildByName("q2").active=TalentList[uuid].quality==Quality.GREEN
icon.getChildByName("q3").active=TalentList[uuid].quality==Quality.BLUE
icon.getChildByName("q4").active=TalentList[uuid].quality==Quality.PURPLE
icon.getChildByName("q5").active=TalentList[uuid].quality==Quality.ORANGE
}
to_change_tal(){
console.log("[TalsComp]:to_change_tal")
}
close_tal_info(){
console.log("[TalsComp]:close_tal_info")
let node= this.node.getChildByName("info")
tween(node).to(0.1,{position:v3(-1000,node.position.y,0)}).start()
}
show_tal_info(e:any,data:any){
console.log("[TalsComp]:show_tal_info",e,data)
let uuid=0
switch(data){
case TalentSlot[0]:
if(this.tal1.uuid==0) return
uuid=this.tal1.uuid
break
case TalentSlot[1]:
if(this.tal2.uuid==0) return
uuid=this.tal2.uuid
break
case TalentSlot[2]:
if(this.tal3.uuid==0) return
uuid=this.tal3.uuid
break
case TalentSlot[3]:
if(this.tal4.uuid==0) return
uuid=this.tal4.uuid
break
case TalentSlot[4]:
if(this.tal5.uuid==0) return
uuid=this.tal5.uuid
break
case TalentSlot[5]:
if(this.tal6.uuid==0) return
uuid=this.tal6.uuid
break
}
let node= this.node.getChildByName("info")
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = node.getChildByName("tal").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(TalentList[uuid].path);
});
node.getChildByName("info").getComponent(Label).string=TalentList[uuid].info
tween(node).to(0.1,{position:v3(0,node.position.y,0)}).start()
}
// 重置所有属性为0
private reset_attrs() {
this.tal1={
uuid:0,
name:"tal1",
slot:TalentSlot[0],
}
this.tal2={
uuid:0,
name:"tal2",
slot:TalentSlot[1],
}
this.tal3={
uuid:0,
name:"tal3",
slot:TalentSlot[2],
}
this.tal4={
uuid:0,
name:"tal4",
slot:TalentSlot[3],
}
this.tal5={
uuid:0,
name:"tal5",
slot:TalentSlot[4],
}
this.tal6={
uuid:0,
name:"tal6",
slot:TalentSlot[5],
}
}
update(dt: number): void {
if(!smc.mission.play||smc.mission.pause) return
}
}