装备改为 buff 和 debuff 2种加成
This commit is contained in:
@@ -3,7 +3,7 @@ import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { EquipInfo, EquipType, EquipAttrTarget} from '../common/config/Equips';
|
||||
import { BuffAttr, getBuffNum } from '../common/config/SkillSet';
|
||||
import { BuffAttr, DebuffAttr, geDebuffNum, getBuffNum } from '../common/config/SkillSet';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('EquipsComp')
|
||||
@@ -16,10 +16,11 @@ export class EquipsComp extends Component {
|
||||
skill3:any=null
|
||||
boxs:Node=null
|
||||
attrs:any={
|
||||
hero:getBuffNum(),
|
||||
ally:getBuffNum(),
|
||||
enemy:getBuffNum(),
|
||||
friend:getBuffNum(),
|
||||
hero_buff:getBuffNum(),
|
||||
friend_buff:getBuffNum(),
|
||||
hero_debuff:geDebuffNum(),
|
||||
friend_debuff:geDebuffNum(),
|
||||
enemy_debuff:geDebuffNum(),
|
||||
}
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
@@ -114,106 +115,92 @@ export class EquipsComp extends Component {
|
||||
console.log("重置后的属性", this.attrs);
|
||||
|
||||
// 获取所有装备的属性
|
||||
let weapon_attrs = this.weapon.uuid ? EquipInfo[this.weapon.uuid]?.attributes || [] : [];
|
||||
let armor_attrs = this.armor.uuid ? EquipInfo[this.armor.uuid]?.attributes || [] : [];
|
||||
let accessory_attrs = this.accessory.uuid ? EquipInfo[this.accessory.uuid]?.attributes || [] : [];
|
||||
|
||||
console.log("武器属性", weapon_attrs);
|
||||
console.log("防具属性", armor_attrs);
|
||||
console.log("饰品属性", accessory_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_debuffs = this.weapon.uuid ? EquipInfo[this.weapon.uuid]?.debuff || [] : [];
|
||||
let armor_debuffs = this.armor.uuid ? EquipInfo[this.armor.uuid]?.debuff || [] : [];
|
||||
let accessory_debuffs = this.accessory.uuid ? EquipInfo[this.accessory.uuid]?.debuff || [] : [];
|
||||
console.log("武器属性", weapon_buffs);
|
||||
console.log("防具属性", armor_buffs);
|
||||
console.log("饰品属性", accessory_buffs);
|
||||
console.log("武器减益", weapon_debuffs);
|
||||
console.log("防具减益", armor_debuffs);
|
||||
console.log("饰品减益", accessory_debuffs);
|
||||
// 合并所有装备属性
|
||||
const allAttrs = [...weapon_attrs, ...armor_attrs, ...accessory_attrs];
|
||||
console.log("合并后的所有属性", allAttrs);
|
||||
|
||||
const allBuff = [...weapon_buffs, ...armor_buffs, ...accessory_buffs];
|
||||
const allDebuff = [...weapon_debuffs, ...armor_debuffs, ...accessory_debuffs];
|
||||
console.log("合并后的所有属性", allBuff);
|
||||
console.log("合并后的所有减益", allDebuff);
|
||||
// 计算每个目标的属性加成
|
||||
allAttrs.forEach(attr => {
|
||||
const target = attr.target || EquipAttrTarget.ALL;
|
||||
allBuff.forEach(attr => {
|
||||
const target = attr.target || EquipAttrTarget.HERO;
|
||||
let targetKey = null;
|
||||
|
||||
// 根据目标类型获取对应的key
|
||||
switch (target) {
|
||||
case EquipAttrTarget.ALL:
|
||||
targetKey = 'ally';
|
||||
break;
|
||||
case EquipAttrTarget.HERO:
|
||||
targetKey = 'hero';
|
||||
targetKey = 'hero_buff';
|
||||
break;
|
||||
case EquipAttrTarget.FRIEND:
|
||||
targetKey = 'friend';
|
||||
targetKey = 'friend_buff';
|
||||
break;
|
||||
}
|
||||
this.add_attr(targetKey,attr)
|
||||
});
|
||||
allDebuff.forEach(attr => {
|
||||
const target = attr.target || EquipAttrTarget.HERO;
|
||||
let targetKey = null;
|
||||
// 根据目标类型获取对应的key
|
||||
switch (target) {
|
||||
case EquipAttrTarget.HERO:
|
||||
targetKey = 'hero_debuff';
|
||||
break;
|
||||
case EquipAttrTarget.FRIEND:
|
||||
targetKey = 'friend_debuff';
|
||||
break;
|
||||
case EquipAttrTarget.ENEMY:
|
||||
targetKey = 'enemy';
|
||||
targetKey = 'enemy_debuff';
|
||||
break;
|
||||
}
|
||||
|
||||
console.log("处理属性加成", {
|
||||
target: target,
|
||||
targetKey: targetKey,
|
||||
attr: attr,
|
||||
beforeValue: targetKey ? this.attrs[targetKey][BuffAttr[attr.type]] : null
|
||||
});
|
||||
|
||||
if (targetKey) {
|
||||
switch (attr.type) {
|
||||
case BuffAttr.ATK:
|
||||
this.attrs[targetKey].ATK += attr.value;
|
||||
break;
|
||||
case BuffAttr.ATK_COUNT:
|
||||
this.attrs[targetKey].ATK_COUNT += attr.value;
|
||||
break;
|
||||
case BuffAttr.ATK_CD:
|
||||
this.attrs[targetKey].ATK_CD += attr.value;
|
||||
break;
|
||||
case BuffAttr.HP:
|
||||
this.attrs[targetKey].HP += attr.value;
|
||||
break;
|
||||
case BuffAttr.DEF:
|
||||
this.attrs[targetKey].DEF += attr.value;
|
||||
break;
|
||||
case BuffAttr.SKILL_DMG:
|
||||
this.attrs[targetKey].SKILL_DMG += attr.value;
|
||||
break;
|
||||
case BuffAttr.SKILL_CD:
|
||||
this.attrs[targetKey].SKILL_CD += attr.value;
|
||||
break;
|
||||
case BuffAttr.CARD_EFFECT:
|
||||
this.attrs[targetKey].CARD_EFFECT += attr.value;
|
||||
break;
|
||||
case BuffAttr.CARD_COUNT:
|
||||
this.attrs[targetKey].CARD_COUNT += attr.value;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log("属性加成后", {
|
||||
targetKey: targetKey,
|
||||
attrType: BuffAttr[attr.type],
|
||||
afterValue: this.attrs[targetKey][BuffAttr[attr.type]]
|
||||
});
|
||||
}
|
||||
this.add_debuff(targetKey,attr)
|
||||
});
|
||||
|
||||
console.log("最终属性加成", this.attrs);
|
||||
oops.message.dispatchEvent(GameEvent.EquipChange, this.attrs);
|
||||
}
|
||||
|
||||
add_attr(targetKey:string,attr:any){
|
||||
if(targetKey){
|
||||
this.attrs[targetKey][BuffAttr[attr.type]] += attr.value;
|
||||
}
|
||||
}
|
||||
|
||||
add_debuff(targetKey:string,attr:any){
|
||||
if(targetKey){
|
||||
this.attrs[targetKey][DebuffAttr[attr.type]] += attr.value;
|
||||
}
|
||||
}
|
||||
|
||||
// 重置所有属性为0
|
||||
private reset_attrs() {
|
||||
// 创建新的属性对象
|
||||
const newAttrs = {
|
||||
hero: getBuffNum(),
|
||||
ally: getBuffNum(),
|
||||
enemy: getBuffNum(),
|
||||
friend: getBuffNum()
|
||||
hero_buff: getBuffNum(),
|
||||
friend_buff: getBuffNum(),
|
||||
hero_debuff: geDebuffNum(),
|
||||
friend_debuff: geDebuffNum(),
|
||||
enemy_debuff: geDebuffNum(),
|
||||
};
|
||||
|
||||
// 替换整个 attrs 对象
|
||||
this.attrs = newAttrs;
|
||||
|
||||
console.log("重置属性", {
|
||||
hero: this.attrs.hero,
|
||||
ally: this.attrs.ally,
|
||||
enemy: this.attrs.enemy,
|
||||
friend: this.attrs.friend
|
||||
hero_buff: this.attrs.hero_buff,
|
||||
hero_debuff: this.attrs.hero_debuff,
|
||||
friend_buff: this.attrs.friend_buff,
|
||||
friend_debuff: this.attrs.friend_debuff,
|
||||
enemy_debuff: this.attrs.enemy_debuff,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user