feat(attrs): 新增英雄基础属性及其对战斗属性影响的计算

- 在 Attrs 中添加力量、智力、敏捷、精神、幸运基本属性
- 为新增属性配置属性类型为数值型(BType.VALUE)
- 新增 HeroBaseAttributes,定义不同英雄类型的基础属性初始值
- 设计 AttributeInfluence,定义基础属性对战斗属性的影响系数
- 实现 calculateBaseAttributes 方法,根据英雄类型和等级计算基础属性值
- 实现 calculateAttributeInfluences 方法,计算基础属性对战斗属性的具体影响值
- 在 heroSet.ts 中增加相关类型导入和类型定义,完善属性系统逻辑
This commit is contained in:
2025-10-24 16:54:19 +08:00
parent c03a655f15
commit 2cf554b124
5 changed files with 218 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
"ver": "1.0.1",
"importer": "text",
"imported": true,
"uuid": "a34c8fe6-ba55-4bcb-b918-14c046cd5ef2",
"uuid": "6bb4bf9c-f8e4-448d-9590-510bc141a52a",
"files": [
".json"
],

View File

@@ -124,7 +124,12 @@ export enum Attrs {
DEBURN = 30, //被攻击易伤
PUNCTURE=31, // 穿刺次数
PUNCTURE_DMG=32, //穿刺伤害加成
// 基础属性
STRENGTH = 33, //力量
INTELLIGENCE = 34, //智力
AGILITY = 35, //敏捷
SPIRIT = 36, //精神
LUCK = 37, //幸运
}
@@ -168,6 +173,11 @@ export const AttrsType: Record<Attrs, BType> = {
[Attrs.BURN]: BType.VALUE, // 易伤 - 数值型
[Attrs.DEBURN]: BType.VALUE, // 被攻击易伤 - 数值型
[Attrs.PUNCTURE]: BType.VALUE, // 穿刺次数 - 数值型
[Attrs.STRENGTH]: BType.VALUE, // 力量 - 数值型
[Attrs.INTELLIGENCE]: BType.VALUE, // 智力 - 数值型
[Attrs.AGILITY]: BType.VALUE, // 敏捷 - 数值型
[Attrs.SPIRIT]: BType.VALUE, // 精神 - 数值型
[Attrs.LUCK]: BType.VALUE, // 幸运 - 数值型
// ========== 百分比型属性 ==========
[Attrs.CRITICAL]: BType.RATIO, // 暴击率 - 百分比型

View File

@@ -1,7 +1,7 @@
import { v3 } from "cc"
import { FacSet } from "./BoxSet"
import { smc } from "../SingletonModuleComp"
import { BuffConf, DbuffConf } from "./SkillSet"
import { BuffConf, DbuffConf, Attrs } from "./SkillSet"
import { debuff } from "../../skills/debuff"
export enum AttrSet {
@@ -14,6 +14,138 @@ export enum HType {
support = 3,
assassin = 4,
}
// 英雄基础属性配置表
// 定义每种英雄类型的力量、智力、敏捷、精神、幸运基础值
export const HeroBaseAttributes: Record<HType, { strength: number; intelligence: number; agility: number; spirit: number; luck: number }> = {
[HType.warrior]: { strength: 10, intelligence: 3, agility: 5, spirit: 4, luck: 3 },
[HType.remote]: { strength: 5, intelligence: 6, agility: 10, spirit: 4, luck: 5 },
[HType.mage]: { strength: 3, intelligence: 10, agility: 4, spirit: 8, luck: 5 },
[HType.support]: { strength: 4, intelligence: 8, agility: 5, spirit: 10, luck: 3 },
[HType.assassin]: { strength: 7, intelligence: 5, agility: 10, spirit: 3, luck: 5 },
}
// 基础属性对战斗属性的影响配置
// 定义基础属性如何影响其他战斗属性的系数
export const AttributeInfluence: Record<string, { attribute: Attrs; ratio: number }> = {
// 力量影响
"strength_to_ap": { attribute: Attrs.AP, ratio: 2 }, // 力量影响攻击力 (每点力量增加2点攻击力)
"strength_to_hp": { attribute: Attrs.HP_MAX, ratio: 10 }, // 力量影响生命值 (每点力量增加10点生命值)
// 智力影响
"intelligence_to_map": { attribute: Attrs.MAP, ratio: 3 }, // 智力影响魔法攻击力 (每点智力增加3点魔法攻击力)
"intelligence_to_mp": { attribute: Attrs.MP_MAX, ratio: 15 }, // 智力影响魔法值 (每点智力增加15点魔法值)
"intelligence_to_mdef": { attribute: Attrs.MDEF, ratio: 1 }, // 智力影响魔法防御 (每点智力增加1点魔法防御)
// 敏捷影响
"agility_to_as": { attribute: Attrs.AS, ratio: 0.5 }, // 敏捷影响攻击速度 (每点敏捷增加0.5%攻击速度)
"agility_to_dodge": { attribute: Attrs.DODGE, ratio: 0.4 }, // 敏捷影响闪避 (每点敏捷增加0.4%闪避)
"agility_to_hit": { attribute: Attrs.HIT, ratio: 0.3 }, // 敏捷影响命中 (每点敏捷增加0.3%命中)
// 精神影响
"spirit_to_mdef": { attribute: Attrs.MDEF, ratio: 2 }, // 精神影响魔法防御 (每点精神增加2点魔法防御)
"spirit_to_hp": { attribute: Attrs.HP_MAX, ratio: 5 }, // 精神影响生命值 (每点精神增加5点生命值)
"spirit_to_mp": { attribute: Attrs.MP_MAX, ratio: 10 }, // 精神影响魔法值 (每点精神增加10点魔法值)
// 幸运影响
"luck_to_critical": { attribute: Attrs.CRITICAL, ratio: 0.6 }, // 幸运影响暴击率 (每点幸运增加0.6%暴击率)
"luck_to_lifesteal": { attribute: Attrs.LIFESTEAL, ratio: 0.2 }, // 幸运影响吸血比率 (每点幸运增加0.2%吸血比率)
};
/**
* 根据英雄类型和等级计算基础属性值
* @param heroType 英雄类型
* @param level 英雄等级
* @returns 包含所有基础属性值的对象
*/
export function calculateBaseAttributes(heroType: HType, level: number): { strength: number; intelligence: number; agility: number; spirit: number; luck: number } {
const baseAttrs = HeroBaseAttributes[heroType];
// 简单的等级成长公式每级增加1点基础属性
const growth = level - 1;
return {
strength: baseAttrs.strength + growth,
intelligence: baseAttrs.intelligence + growth,
agility: baseAttrs.agility + growth,
spirit: baseAttrs.spirit + growth,
luck: baseAttrs.luck + growth
};
}
/**
* 根据基础属性计算对战斗属性的影响
* @param baseAttributes 基础属性值
* @returns 属性影响映射表
*/
export function calculateAttributeInfluences(baseAttributes: { strength: number; intelligence: number; agility: number; spirit: number; luck: number }): Record<Attrs, number> {
// 初始化所有属性影响值为0
const influences: Record<Attrs, number> = {
[Attrs.HP_MAX]: 0,
[Attrs.MP_MAX]: 0,
[Attrs.SHIELD_MAX]: 0,
[Attrs.AP]: 0,
[Attrs.MAP]: 0,
[Attrs.DEF]: 0,
[Attrs.MDEF]: 0,
[Attrs.CRITICAL]: 0,
[Attrs.CRITICAL_DMG]: 0,
[Attrs.DODGE]: 0,
[Attrs.HIT]: 0,
[Attrs.WFUNY]: 0,
[Attrs.AS]: 0,
[Attrs.REFLICT]: 0,
[Attrs.LIFESTEAL]: 0,
[Attrs.BACK]: 0,
[Attrs.DEBACK]: 0,
[Attrs.CON_RES]: 0,
[Attrs.ICE_RES]: 0,
[Attrs.FIRE_RES]: 0,
[Attrs.WIND_RES]: 0,
[Attrs.ICE_POWER]: 0,
[Attrs.FIRE_POWER]: 0,
[Attrs.WIND_POWER]: 0,
[Attrs.BUFF_UP]: 0,
[Attrs.DBUFF_UP]: 0,
[Attrs.DIS]: 0,
[Attrs.SPEED]: 0,
[Attrs.SHIELD_UP]: 0,
[Attrs.BURN]: 0,
[Attrs.DEBURN]: 0,
[Attrs.PUNCTURE]: 0,
[Attrs.PUNCTURE_DMG]: 0,
[Attrs.STRENGTH]: 0,
[Attrs.INTELLIGENCE]: 0,
[Attrs.AGILITY]: 0,
[Attrs.SPIRIT]: 0,
[Attrs.LUCK]: 0
};
// 计算力量的影响
influences[Attrs.AP] += baseAttributes.strength * (AttributeInfluence["strength_to_ap"]?.ratio || 0);
influences[Attrs.HP_MAX] += baseAttributes.strength * (AttributeInfluence["strength_to_hp"]?.ratio || 0);
// 计算智力的影响
influences[Attrs.MAP] += baseAttributes.intelligence * (AttributeInfluence["intelligence_to_map"]?.ratio || 0);
influences[Attrs.MP_MAX] += baseAttributes.intelligence * (AttributeInfluence["intelligence_to_mp"]?.ratio || 0);
influences[Attrs.MDEF] += baseAttributes.intelligence * (AttributeInfluence["intelligence_to_mdef"]?.ratio || 0);
// 计算敏捷的影响
influences[Attrs.AS] += baseAttributes.agility * (AttributeInfluence["agility_to_as"]?.ratio || 0);
influences[Attrs.DODGE] += baseAttributes.agility * (AttributeInfluence["agility_to_dodge"]?.ratio || 0);
influences[Attrs.HIT] += baseAttributes.agility * (AttributeInfluence["agility_to_hit"]?.ratio || 0);
// 计算精神的影响
influences[Attrs.MDEF] += baseAttributes.spirit * (AttributeInfluence["spirit_to_mdef"]?.ratio || 0);
influences[Attrs.HP_MAX] += baseAttributes.spirit * (AttributeInfluence["spirit_to_hp"]?.ratio || 0);
influences[Attrs.MP_MAX] += baseAttributes.spirit * (AttributeInfluence["spirit_to_mp"]?.ratio || 0);
// 计算幸运的影响
influences[Attrs.CRITICAL] += baseAttributes.luck * (AttributeInfluence["luck_to_critical"]?.ratio || 0);
influences[Attrs.LIFESTEAL] += baseAttributes.luck * (AttributeInfluence["luck_to_lifesteal"]?.ratio || 0);
return influences;
}
export const HTypeName ={
0:"战士",
1:"远程",

View File

@@ -0,0 +1,63 @@
import { HType, calculateBaseAttributes, calculateAttributeInfluences } from "../common/config/heroSet";
import { Attrs } from "../common/config/SkillSet";
/**
* 英雄属性计算器使用示例
*/
export class AttributeExample {
/**
* 示例:计算指定类型和等级的英雄属性
* @param heroType 英雄类型
* @param level 英雄等级
*/
static calculateHeroAttributes(heroType: HType, level: number) {
// 1. 计算基础属性值
const baseAttributes = calculateBaseAttributes(heroType, level);
console.log("基础属性:", baseAttributes);
// 2. 计算基础属性对战斗属性的影响
const attributeInfluences = calculateAttributeInfluences(baseAttributes);
console.log("属性影响:", attributeInfluences);
// 3. 输出特定属性的影响值
console.log(`攻击力加成: ${attributeInfluences[Attrs.AP]}`);
console.log(`生命值加成: ${attributeInfluences[Attrs.HP_MAX]}`);
console.log(`魔法攻击力加成: ${attributeInfluences[Attrs.MAP]}`);
return {
baseAttributes,
attributeInfluences
};
}
/**
* 示例:为英雄应用属性影响
* @param hero 英雄对象
* @param level 英雄等级
*/
static applyAttributesToHero(hero: any, level: number) {
// 计算基础属性
const baseAttributes = calculateBaseAttributes(hero.type, level);
// 计算属性影响
const attributeInfluences = calculateAttributeInfluences(baseAttributes);
// 应用属性影响到英雄
hero.ap += attributeInfluences[Attrs.AP];
hero.hp += attributeInfluences[Attrs.HP_MAX];
hero.map += attributeInfluences[Attrs.MAP];
hero.mp += attributeInfluences[Attrs.MP_MAX];
hero.mdef += attributeInfluences[Attrs.MDEF];
hero.as += attributeInfluences[Attrs.AS];
hero.dodge += attributeInfluences[Attrs.DODGE];
hero.hit += attributeInfluences[Attrs.HIT];
hero.critical += attributeInfluences[Attrs.CRITICAL];
hero.lifesteal += attributeInfluences[Attrs.LIFESTEAL];
return hero;
}
}
// 使用示例
// const warriorAttrs = AttributeExample.calculateHeroAttributes(HType.warrior, 10);
// const mageAttrs = AttributeExample.calculateHeroAttributes(HType.mage, 10);

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ac54946f-ff4d-4d34-b1a3-234efe61f2fc",
"files": [],
"subMetas": {},
"userData": {}
}