310 lines
13 KiB
TypeScript
310 lines
13 KiB
TypeScript
import { _decorator, Component, Label, Node, resources, Sprite, SpriteAtlas } 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';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('EquipsComp')
|
|
export class EquipsComp extends Component {
|
|
weapon:any=null
|
|
armor:any=null
|
|
accessory: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.EquipAdd,this.equip_add,this)
|
|
oops.message.on(GameEvent.EquipRemove,this.equip_remove,this)
|
|
this.boxs=this.node.getChildByName("boxs")
|
|
oops.message.on(GameEvent.HeroLvUp,this.hero_lv_up,this)
|
|
|
|
}
|
|
hero_lv_up(e:GameEvent,data:any){
|
|
console.log("[EquipsComp]:hero_lv_up",data)
|
|
switch(data.lv){
|
|
case FightSet.WEAPON_LV:
|
|
this.show_equip_get("weapon")
|
|
break
|
|
case FightSet.ARMOR_LV:
|
|
this.show_equip_get("armor")
|
|
break
|
|
case FightSet.SHIELD_LV:
|
|
this.show_equip_get("shield")
|
|
break
|
|
case FightSet.ACCESSORY_LV:
|
|
this.show_equip_get("accessory")
|
|
break
|
|
}
|
|
}
|
|
equip_stone_up(e:GameEvent,data:any){
|
|
|
|
}
|
|
|
|
call_equip_card(e:any,data:any){
|
|
oops.message.dispatchEvent(GameEvent.EquipSelect,{slot:data})
|
|
|
|
}
|
|
up_equip_card(e:any,data:any){
|
|
oops.message.dispatchEvent(GameEvent.EquipSelect,{slot:data})
|
|
|
|
}
|
|
start(){
|
|
this.fight_ready()
|
|
}
|
|
fight_ready(){
|
|
this.hide_equip_get(null,"weapon")
|
|
this.hide_equip_get(null,"armor")
|
|
this.hide_equip_get(null,"accessory")
|
|
this.boxs.getChildByName("weapon").getChildByName("icon").active=false
|
|
this.boxs.getChildByName("armor").getChildByName("icon").active=false
|
|
this.boxs.getChildByName("accessory").getChildByName("icon").active=false
|
|
this.weapon={
|
|
uuid:0,
|
|
name:"weapon",
|
|
type:"weapon",
|
|
level:0,
|
|
}
|
|
this.armor={
|
|
uuid:0,
|
|
name:"armor",
|
|
type:"armor",
|
|
level:0,
|
|
}
|
|
this.accessory={
|
|
uuid:0,
|
|
name:"accessory",
|
|
type:"accessory",
|
|
level:0,
|
|
}
|
|
}
|
|
equip_add(e:GameEvent,data:any){
|
|
console.log("equip_add",data)
|
|
if(data.type==EquipType.WEAPON){
|
|
this.weapon.uuid=data.uuid
|
|
this.weapon.name=data.name
|
|
this.weapon.type=data.type
|
|
this.weapon.level=data.level
|
|
this.show_weapon(data.uuid)
|
|
}
|
|
if(data.type==EquipType.ARMOR){
|
|
this.armor.uuid=data.uuid
|
|
this.armor.name=data.name
|
|
this.armor.type=data.type
|
|
this.armor.level=data.level
|
|
this.show_armor(data.uuid)
|
|
}
|
|
if(data.type==EquipType.ACCESSORY){
|
|
this.accessory.uuid=data.uuid
|
|
this.accessory.name=data.name
|
|
this.accessory.type=data.type
|
|
this.accessory.level=data.level
|
|
this.show_accessory(data.uuid)
|
|
}
|
|
// this.count_attrs()
|
|
}
|
|
show_weapon(uuid:number){
|
|
let icon = this.boxs.getChildByName("weapon").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/heros/equips2"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(EquipInfo[uuid].path);
|
|
});
|
|
icon.getChildByName("q1").active=EquipInfo[uuid].quality==Quality.WHITE
|
|
icon.getChildByName("q2").active=EquipInfo[uuid].quality==Quality.GREEN
|
|
icon.getChildByName("q3").active=EquipInfo[uuid].quality==Quality.BLUE
|
|
icon.getChildByName("q4").active=EquipInfo[uuid].quality==Quality.PURPLE
|
|
icon.getChildByName("q5").active=EquipInfo[uuid].quality==Quality.ORANGE
|
|
|
|
}
|
|
show_armor(uuid:number){
|
|
let icon = this.boxs.getChildByName("armor").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/heros/equips2"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(EquipInfo[uuid].path);
|
|
});
|
|
|
|
|
|
icon.getChildByName("q1").active=EquipInfo[uuid].quality==Quality.WHITE
|
|
icon.getChildByName("q2").active=EquipInfo[uuid].quality==Quality.GREEN
|
|
icon.getChildByName("q3").active=EquipInfo[uuid].quality==Quality.BLUE
|
|
icon.getChildByName("q4").active=EquipInfo[uuid].quality==Quality.PURPLE
|
|
icon.getChildByName("q5").active=EquipInfo[uuid].quality==Quality.ORANGE
|
|
}
|
|
show_accessory(uuid:number){
|
|
let icon = this.boxs.getChildByName("accessory").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/heros/equips2"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(EquipInfo[uuid].path);
|
|
});
|
|
|
|
|
|
icon.getChildByName("q1").active=EquipInfo[uuid].quality==Quality.WHITE
|
|
icon.getChildByName("q2").active=EquipInfo[uuid].quality==Quality.GREEN
|
|
icon.getChildByName("q3").active=EquipInfo[uuid].quality==Quality.BLUE
|
|
icon.getChildByName("q4").active=EquipInfo[uuid].quality==Quality.PURPLE
|
|
icon.getChildByName("q5").active=EquipInfo[uuid].quality==Quality.ORANGE
|
|
|
|
|
|
}
|
|
// count_attrs(){
|
|
// // 重置所有属性
|
|
// this.reset_attrs();
|
|
// console.log("[EquipsComp]:重置后的属性", this.attrs);
|
|
|
|
// // 获取所有装备的属性
|
|
// let weapon_buffs = this.weapon.uuid ? EquipInfo[this.weapon.uuid]?.buff || [] : [];
|
|
// let armor_buffs = this.armor.uuid ? EquipInfo[this.armor.uuid]?.buff || [] : [];
|
|
// let accessory_buffs = this.accessory.uuid ? EquipInfo[this.accessory.uuid]?.buff || [] : [];
|
|
// let weapon_special_attr = this.weapon.uuid ? EquipInfo[this.weapon.uuid]?.special_attr : [];
|
|
// let armor_special_attr = this.armor.uuid ? EquipInfo[this.armor.uuid]?.special_attr : [];
|
|
// let accessory_special_attr = this.accessory.uuid ? EquipInfo[this.accessory.uuid]?.special_attr : [];
|
|
|
|
// console.log("[EquipsComp]:weapon_special_attr", weapon_special_attr);
|
|
// console.log("[EquipsComp]:armor_special_attr", armor_special_attr);
|
|
// console.log("[EquipsComp]:accessory_special_attr", accessory_special_attr);
|
|
// console.log("[EquipsComp]:weapon_buffs", weapon_buffs);
|
|
// console.log("[EquipsComp]:防具属性", armor_buffs);
|
|
// console.log("[EquipsComp]:饰品属性", accessory_buffs);
|
|
// const all_special_attr=[...weapon_special_attr,...armor_special_attr,...accessory_special_attr]
|
|
|
|
// let equip_special_attr=this.count_equip_special_attr(all_special_attr)
|
|
// oops.message.dispatchEvent(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,equip_special_attr)
|
|
|
|
// // 合并所有装备属性
|
|
// const allBuff = [...weapon_buffs, ...armor_buffs, ...accessory_buffs];
|
|
// console.log("[EquipsComp]:合并后的所有属性", allBuff);
|
|
// // 计算每个目标的属性加成
|
|
// allBuff.forEach(attr => {
|
|
// const target = attr.target || EquipAttrTarget.HERO;
|
|
// let targetKey = null;
|
|
// // 根据目标类型获取对应的key
|
|
// switch (target) {
|
|
// case EquipAttrTarget.HERO:
|
|
// targetKey = 'hero_buff';
|
|
// break;
|
|
// }
|
|
// this.add_attr(targetKey,attr)
|
|
// });
|
|
|
|
// console.log("[EquipsComp]:debuff buff attrs ", this.attrs);
|
|
// oops.message.dispatchEvent(GameEvent.EquipChange, this.attrs);
|
|
// }
|
|
|
|
// count_equip_special_attr(all_special_attr:any[]){
|
|
// //特殊属性附加 - 直接使用枚举值作为属性名
|
|
// let equip_special_attr = {
|
|
// [EquipSpecialAttr.ICE]: 0,
|
|
// [EquipSpecialAttr.FIRE]: 0,
|
|
// [EquipSpecialAttr.WIND]: 0,
|
|
// [EquipSpecialAttr.ATK_ADD_GLOD]: 0,
|
|
// [EquipSpecialAttr.ATK_ADD_MASTER_ATK]: 0,
|
|
// [EquipSpecialAttr.ATK_ADD_MASTER_HP]: 0,
|
|
// [EquipSpecialAttr.DOUBLE_ATKED]: 0,
|
|
// [EquipSpecialAttr.ATKED_ADD_SKILL_STONE]: 0,
|
|
// [EquipSpecialAttr.ATK_ADD_VALUE]: 0,
|
|
// };
|
|
|
|
// console.log("[EquipsComp]:all_special_attr",all_special_attr)
|
|
|
|
// // 直接使用枚举值累加属性
|
|
// all_special_attr.forEach(special_attr => {
|
|
// if (special_attr && equip_special_attr.hasOwnProperty(special_attr.special_attr)) {
|
|
// equip_special_attr[special_attr.special_attr] += special_attr.special_attr_value;
|
|
// }
|
|
// });
|
|
|
|
// console.log("[EquipsComp]:equip_special_attr",equip_special_attr)
|
|
// return equip_special_attr
|
|
// }
|
|
|
|
|
|
// add_attr(targetKey:string,attr:any){
|
|
// if(targetKey){
|
|
// this.attrs[targetKey][BuffAttr[attr.type]] += attr.value;
|
|
// }
|
|
// }
|
|
|
|
|
|
// 重置所有属性为0
|
|
private reset_attrs() {
|
|
// 创建新的属性对象
|
|
// const newAttrs = {
|
|
// hero_buff: getBuffNum(),
|
|
// enemy_buff: getBuffNum(),
|
|
// };
|
|
|
|
// // 替换整个 attrs 对象
|
|
// this.attrs = newAttrs;
|
|
|
|
// console.log("重置属性", {
|
|
// hero_buff: this.attrs.hero_buff,
|
|
// enemy_buff: this.attrs.enemy_buff,
|
|
// });
|
|
}
|
|
|
|
equip_remove(e:GameEvent,data:any){
|
|
console.log("equip_remove",data)
|
|
}
|
|
update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause) return
|
|
}
|
|
|
|
private show_equip_get(e:string){
|
|
switch(e){
|
|
case "weapon":
|
|
this.boxs.getChildByName("weapon").getChildByName("get").active =true
|
|
this.boxs.getChildByName("weapon").getChildByName("light").active=true
|
|
this.boxs.getChildByName("weapon").getChildByName("tip").active=true
|
|
this.boxs.getChildByName("weapon").getChildByName("tip").getComponent(Label).string="获取"
|
|
break
|
|
case "armor":
|
|
this.boxs.getChildByName("armor").getChildByName("get").active =true
|
|
this.boxs.getChildByName("armor").getChildByName("light").active=true
|
|
this.boxs.getChildByName("armor").getChildByName("tip").active=true
|
|
this.boxs.getChildByName("armor").getChildByName("tip").getComponent(Label).string="获取"
|
|
break
|
|
case "accessory":
|
|
this.boxs.getChildByName("accessory").getChildByName("get").active =true
|
|
this.boxs.getChildByName("accessory").getChildByName("light").active=true
|
|
this.boxs.getChildByName("accessory").getChildByName("tip").active=true
|
|
this.boxs.getChildByName("accessory").getChildByName("tip").getComponent(Label).string="获取"
|
|
break
|
|
}
|
|
}
|
|
|
|
private hide_equip_get(e:any,data:string){
|
|
this.scheduleOnce(()=>{
|
|
if(smc.vmdata.mission_data.equip_stone > smc.vmdata.mission_data.equip_stone_max) return
|
|
this.boxs.getChildByName("weapon").getChildByName("get").active =false
|
|
this.boxs.getChildByName("weapon").getChildByName("change").active =false
|
|
this.boxs.getChildByName("weapon").getChildByName("light").active=false
|
|
this.boxs.getChildByName("weapon").getChildByName("tip").active=false
|
|
this.boxs.getChildByName("armor").getChildByName("get").active =false
|
|
this.boxs.getChildByName("armor").getChildByName("change").active =false
|
|
this.boxs.getChildByName("armor").getChildByName("light").active=false
|
|
this.boxs.getChildByName("armor").getChildByName("tip").active=false
|
|
this.boxs.getChildByName("accessory").getChildByName("get").active =false
|
|
this.boxs.getChildByName("accessory").getChildByName("change").active =false
|
|
this.boxs.getChildByName("accessory").getChildByName("light").active=false
|
|
this.boxs.getChildByName("accessory").getChildByName("tip").active=false
|
|
},0.5)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|