feat(attrs): 新增英雄基础属性及其对战斗属性影响的计算
- 在 Attrs 中添加力量、智力、敏捷、精神、幸运基本属性 - 为新增属性配置属性类型为数值型(BType.VALUE) - 新增 HeroBaseAttributes,定义不同英雄类型的基础属性初始值 - 设计 AttributeInfluence,定义基础属性对战斗属性的影响系数 - 实现 calculateBaseAttributes 方法,根据英雄类型和等级计算基础属性值 - 实现 calculateAttributeInfluences 方法,计算基础属性对战斗属性的具体影响值 - 在 heroSet.ts 中增加相关类型导入和类型定义,完善属性系统逻辑
This commit is contained in:
63
assets/script/game/hero/AttributeExample.ts
Normal file
63
assets/script/game/hero/AttributeExample.ts
Normal 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);
|
||||
9
assets/script/game/hero/AttributeExample.ts.meta
Normal file
9
assets/script/game/hero/AttributeExample.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ac54946f-ff4d-4d34-b1a3-234efe61f2fc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user