添加 天赋设置
This commit is contained in:
434
assets/script/game/common/config/TalSet.ts
Normal file
434
assets/script/game/common/config/TalSet.ts
Normal file
@@ -0,0 +1,434 @@
|
||||
/**
|
||||
* 天赋系统配置文件
|
||||
* 支持定义英雄的特殊能力或特性
|
||||
*/
|
||||
|
||||
// ========== 枚举定义 ==========
|
||||
|
||||
/**
|
||||
* 天赋类型枚举
|
||||
*/
|
||||
export enum TalType {
|
||||
LEVEL_ATTR = 1, // 基于等级的属性增长
|
||||
ACTION_COUNT_ATTR = 2, // 基于行为计数的属性变化
|
||||
DAMAGE_COUNT_ATTR = 3, // 基于受伤次数的属性提升
|
||||
ACTION_TRIGGER_SKILL = 4, // 基于行为触发的技能释放
|
||||
}
|
||||
|
||||
/**
|
||||
* 属性类型枚举
|
||||
*/
|
||||
export enum TalAttrType {
|
||||
HP = "hp", // 最大生命值
|
||||
MP = "mp", // 最大魔力值
|
||||
AP = "ap", // 攻击力
|
||||
MAP = "map", // 魔法攻击力
|
||||
DEF = "def", // 防御力
|
||||
MDEF = "mdef", // 魔法防御力
|
||||
SPEED = "speed", // 移动速度
|
||||
DODGE = "dodge", // 闪避率
|
||||
CRIT = "crit", // 暴击率
|
||||
}
|
||||
|
||||
/**
|
||||
* 行为类型枚举
|
||||
*/
|
||||
export enum TalActionType {
|
||||
ATTACK = 1, // 攻击
|
||||
SKILL = 2, // 使用技能
|
||||
DAMAGED = 3, // 受伤
|
||||
}
|
||||
|
||||
// ========== 触发条件接口 ==========
|
||||
|
||||
/**
|
||||
* 触发条件基础接口
|
||||
*/
|
||||
export interface ITriggerCondition {
|
||||
type: "level" | "actionCount" | "damageCount";
|
||||
}
|
||||
|
||||
/**
|
||||
* 等级触发条件
|
||||
* 当英雄达到指定等级时触发
|
||||
*/
|
||||
export interface ILevelTrigger extends ITriggerCondition {
|
||||
type: "level";
|
||||
level: number; // 触发的等级阈值(如5级触发一次)
|
||||
}
|
||||
|
||||
/**
|
||||
* 行为计数触发条件
|
||||
* 当特定行为累计达到指定次数时触发
|
||||
*/
|
||||
export interface IActionCountTrigger extends ITriggerCondition {
|
||||
type: "actionCount";
|
||||
actionType: TalActionType; // 要计数的行为类型
|
||||
count: number; // 触发的计数阈值
|
||||
resetPerLevel?: boolean; // 是否每升一级重置计数(默认false,不重置)
|
||||
}
|
||||
|
||||
/**
|
||||
* 受伤次数触发条件
|
||||
* 当英雄累计受伤达到指定次数时触发
|
||||
*/
|
||||
export interface IDamageCountTrigger extends ITriggerCondition {
|
||||
type: "damageCount";
|
||||
count: number; // 触发的受伤次数阈值
|
||||
resetPerLevel?: boolean; // 是否每升一级重置计数(默认false,不重置)
|
||||
}
|
||||
|
||||
// ========== 效果接口 ==========
|
||||
|
||||
/**
|
||||
* 效果基础接口
|
||||
*/
|
||||
export interface ITalEffect {
|
||||
type: "attrModify" | "skillTrigger";
|
||||
}
|
||||
|
||||
/**
|
||||
* 属性修改效果
|
||||
* 对指定属性进行修改:增加/减少固定值或百分比
|
||||
*/
|
||||
export interface IAttrModifyEffect extends ITalEffect {
|
||||
type: "attrModify";
|
||||
attr: TalAttrType; // 修改的属性名
|
||||
value: number; // 修改值(正数增加,负数减少)
|
||||
percent?: boolean; // 是否为百分比修改(默认false,为固定值)
|
||||
}
|
||||
|
||||
/**
|
||||
* 技能触发效果
|
||||
* 自动触发指定的技能
|
||||
*/
|
||||
export interface ISkillTriggerEffect extends ITalEffect {
|
||||
type: "skillTrigger";
|
||||
skillId: number; // 要触发的技能ID
|
||||
}
|
||||
|
||||
// ========== 天赋配置接口 ==========
|
||||
|
||||
/**
|
||||
* 天赋配置接口
|
||||
* 定义一个完整的天赋效果
|
||||
*/
|
||||
export interface ItalConf {
|
||||
talId: number; // 天赋ID
|
||||
name: string; // 天赋名称
|
||||
desc: string; // 天赋描述(说明触发条件和效果)
|
||||
talType: TalType; // 天赋类型
|
||||
trigger: ITriggerCondition; // 触发条件
|
||||
effect: ITalEffect; // 效果
|
||||
stackable?: boolean; // 是否可堆叠效果(默认true)
|
||||
maxStack?: number; // 最大堆叠次数(不设置表示无限制)
|
||||
}
|
||||
|
||||
// ========== 天赋配置表 ==========
|
||||
|
||||
/**
|
||||
* 天赋配置表
|
||||
* 存储所有天赋的配置信息
|
||||
*
|
||||
* 使用说明:
|
||||
* 1. 等级类天赋:当英雄升级到指定等级时,每次都会触发效果
|
||||
* 2. 行为计数类:当特定行为累计达到阈值时触发,支持是否重置计数
|
||||
* 3. 受伤计数类:当受伤累计达到阈值时触发,支持是否重置计数
|
||||
* 4. 技能触发类:当特定条件满足时自动触发指定技能
|
||||
*/
|
||||
export const talConf: Record<number, ItalConf> = {
|
||||
// ========== 等级类天赋 ==========
|
||||
|
||||
/**
|
||||
* 剑意提升 - 刘邦专属
|
||||
* 每升5级,攻击力增加10%
|
||||
*/
|
||||
7001: {
|
||||
talId: 7001,
|
||||
name: "剑意提升",
|
||||
desc: "每升5级,攻击力增加10%",
|
||||
talType: TalType.LEVEL_ATTR,
|
||||
trigger: {
|
||||
type: "level",
|
||||
level: 5,
|
||||
} as ILevelTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.AP,
|
||||
value: 10,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20, // 最多堆叠到100级
|
||||
},
|
||||
|
||||
/**
|
||||
* 法力修炼 - 通用
|
||||
* 每升3级,最大魔力值增加15点
|
||||
*/
|
||||
7002: {
|
||||
talId: 7002,
|
||||
name: "法力修炼",
|
||||
desc: "每升3级,最大魔力值增加15点",
|
||||
talType: TalType.LEVEL_ATTR,
|
||||
trigger: {
|
||||
type: "level",
|
||||
level: 3,
|
||||
} as ILevelTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.MP,
|
||||
value: 15,
|
||||
percent: false,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 33,
|
||||
},
|
||||
|
||||
// ========== 行为计数类天赋 ==========
|
||||
|
||||
/**
|
||||
* 强化闪避 - 敏捷英雄
|
||||
* 每攻击10次,闪避率增加1%
|
||||
* 不按等级重置,持续累积
|
||||
*/
|
||||
7101: {
|
||||
talId: 7101,
|
||||
name: "强化闪避",
|
||||
desc: "每攻击10次,闪避率增加1%",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.DODGE,
|
||||
value: 1,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20,
|
||||
},
|
||||
|
||||
/**
|
||||
* 暴击强化 - 刺客
|
||||
* 每攻击15次,暴击率增加2%
|
||||
*/
|
||||
7102: {
|
||||
talId: 7102,
|
||||
name: "暴击强化",
|
||||
desc: "每攻击15次,暴击率增加2%",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 15,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.CRIT,
|
||||
value: 2,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 15,
|
||||
},
|
||||
|
||||
/**
|
||||
* 连击精通 - 战士
|
||||
* 每使用技能8次,攻击力增加5%
|
||||
*/
|
||||
7103: {
|
||||
talId: 7103,
|
||||
name: "连击精通",
|
||||
desc: "每使用技能8次,攻击力增加5%",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.SKILL,
|
||||
count: 8,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.AP,
|
||||
value: 5,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 18,
|
||||
},
|
||||
|
||||
// ========== 受伤计数类天赋 ==========
|
||||
|
||||
/**
|
||||
* 坚甲护体 - 重装战士
|
||||
* 每受伤10次,最大生命值增加100点
|
||||
*/
|
||||
7201: {
|
||||
talId: 7201,
|
||||
name: "坚甲护体",
|
||||
desc: "每受伤10次,最大生命值增加100点",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.HP,
|
||||
value: 100,
|
||||
percent: false,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 15,
|
||||
},
|
||||
|
||||
/**
|
||||
* 防御强化 - 防守型
|
||||
* 每受伤12次,防御力增加3%
|
||||
*/
|
||||
7202: {
|
||||
talId: 7202,
|
||||
name: "防御强化",
|
||||
desc: "每受伤12次,防御力增加3%",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 12,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.DEF,
|
||||
value: 3,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20,
|
||||
},
|
||||
|
||||
/**
|
||||
* 魔抗修炼 - 法系英雄
|
||||
* 每受伤15次,魔法防御增加5点
|
||||
*/
|
||||
7203: {
|
||||
talId: 7203,
|
||||
name: "魔抗修炼",
|
||||
desc: "每受伤15次,魔法防御增加5点",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 15,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.MDEF,
|
||||
value: 5,
|
||||
percent: false,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 12,
|
||||
},
|
||||
|
||||
// ========== 技能触发类天赋 ==========
|
||||
|
||||
/**
|
||||
* 连击反击 - 刺客
|
||||
* 每攻击15次,自动触发反击技能(假设技能ID为6010)
|
||||
*/
|
||||
7301: {
|
||||
talId: 7301,
|
||||
name: "连击反击",
|
||||
desc: "每攻击15次,自动触发反击技能",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 15,
|
||||
resetPerLevel: true, // 每升级重置计数
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6010,
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false, // 技能触发类天赋不堆叠
|
||||
},
|
||||
|
||||
/**
|
||||
* 受伤反制 - 防守型
|
||||
* 每受伤8次,自动触发反制护盾技能(假设技能ID为6011)
|
||||
*/
|
||||
7302: {
|
||||
talId: 7302,
|
||||
name: "受伤反制",
|
||||
desc: "每受伤8次,自动触发反制护盾技能",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 8,
|
||||
resetPerLevel: true,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6011,
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false,
|
||||
},
|
||||
|
||||
/**
|
||||
* 技能链接 - 法师
|
||||
* 每使用技能5次,自动触发增强魔法技能(假设技能ID为6012)
|
||||
*/
|
||||
7303: {
|
||||
talId: 7303,
|
||||
name: "技能链接",
|
||||
desc: "每使用技能5次,自动触发增强魔法技能",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.SKILL,
|
||||
count: 5,
|
||||
resetPerLevel: true,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6012,
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false,
|
||||
},
|
||||
};
|
||||
|
||||
// ========== 工具函数 ==========
|
||||
|
||||
/**
|
||||
* 根据天赋ID获取天赋配置
|
||||
* @param talId 天赋ID
|
||||
* @returns 天赋配置,不存在返回undefined
|
||||
*/
|
||||
export const getTalConf = (talId: number): ItalConf | undefined => {
|
||||
return talConf[talId];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取指定类型的所有天赋
|
||||
* @param talType 天赋类型
|
||||
* @returns 天赋配置数组
|
||||
*/
|
||||
export const getTalConfByType = (talType: TalType): ItalConf[] => {
|
||||
return Object.values(talConf).filter(tal => tal.talType === talType);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取所有天赋ID列表
|
||||
* @returns 天赋ID数组
|
||||
*/
|
||||
export const getAllTalIds = (): number[] => {
|
||||
return Object.keys(talConf).map(Number);
|
||||
};
|
||||
482
assets/script/game/common/config/TalSet_Example.ts
Normal file
482
assets/script/game/common/config/TalSet_Example.ts
Normal file
@@ -0,0 +1,482 @@
|
||||
/**
|
||||
* 天赋系统集成示例
|
||||
* 展示如何在实际游戏系统中使用 TalSet 配置
|
||||
*/
|
||||
|
||||
import {
|
||||
TalType,
|
||||
TalAttrType,
|
||||
TalActionType,
|
||||
ItalConf,
|
||||
getTalConf,
|
||||
getTalConfByType,
|
||||
getAllTalIds,
|
||||
talConf
|
||||
} from "./TalSet";
|
||||
|
||||
// ========== 天赋实时数据结构 ==========
|
||||
|
||||
/**
|
||||
* 英雄天赋实例数据
|
||||
* 记录单个英雄某个天赋的实时数据
|
||||
*/
|
||||
export interface HeroTalentInstance {
|
||||
talId: number; // 天赋ID
|
||||
stackCount: number; // 当前堆叠层数
|
||||
actionCounter: number; // 行为计数器(用于计数类天赋)
|
||||
damageCounter: number; // 受伤计数器(用于受伤类天赋)
|
||||
lastTriggerLevel: number; // 最后一次触发的等级(用于等级类天赋)
|
||||
isActive: boolean; // 是否激活
|
||||
}
|
||||
|
||||
/**
|
||||
* 英雄天赋管理数据
|
||||
* 记录一个英雄的所有天赋数据
|
||||
*/
|
||||
export interface HeroTalentManager {
|
||||
heroId: number;
|
||||
talents: Map<number, HeroTalentInstance>;
|
||||
}
|
||||
|
||||
// ========== 天赋触发系统 ==========
|
||||
|
||||
/**
|
||||
* 天赋触发管理器
|
||||
* 处理天赋的所有触发逻辑
|
||||
*/
|
||||
export class TalentTriggerManager {
|
||||
private talentInstances: Map<number, HeroTalentManager> = new Map();
|
||||
|
||||
/**
|
||||
* 初始化英雄的天赋系统
|
||||
* @param heroId 英雄ID
|
||||
* @param talentIds 天赋ID数组
|
||||
*/
|
||||
public initHeroTalents(heroId: number, talentIds: number[]): void {
|
||||
const talentManager: HeroTalentManager = {
|
||||
heroId,
|
||||
talents: new Map(),
|
||||
};
|
||||
|
||||
talentIds.forEach(talId => {
|
||||
const talConfig = getTalConf(talId);
|
||||
if (talConfig) {
|
||||
talentManager.talents.set(talId, {
|
||||
talId,
|
||||
stackCount: 0,
|
||||
actionCounter: 0,
|
||||
damageCounter: 0,
|
||||
lastTriggerLevel: 0,
|
||||
isActive: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.talentInstances.set(heroId, talentManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理英雄等级提升事件
|
||||
* @param heroId 英雄ID
|
||||
* @param newLevel 新等级
|
||||
*/
|
||||
public onHeroLevelUp(heroId: number, newLevel: number): void {
|
||||
const talentManager = this.talentInstances.get(heroId);
|
||||
if (!talentManager) return;
|
||||
|
||||
talentManager.talents.forEach((instance, talId) => {
|
||||
const talConfig = getTalConf(talId);
|
||||
if (!talConfig || talConfig.talType !== TalType.LEVEL_ATTR) return;
|
||||
|
||||
const levelTrigger = talConfig.trigger as any;
|
||||
const triggerInterval = levelTrigger.level;
|
||||
|
||||
// 检查是否应该触发
|
||||
if (newLevel % triggerInterval === 0) {
|
||||
// 检查是否还能堆叠
|
||||
if (talConfig.maxStack && instance.stackCount >= talConfig.maxStack) {
|
||||
console.warn(`天赋 ${talConfig.name} 已达到最大堆叠次数`);
|
||||
return;
|
||||
}
|
||||
|
||||
instance.stackCount++;
|
||||
instance.lastTriggerLevel = newLevel;
|
||||
|
||||
console.log(`[天赋触发] ${talConfig.name}: 堆叠层数 ${instance.stackCount}`);
|
||||
this.applyTalentEffect(heroId, talConfig, instance);
|
||||
}
|
||||
|
||||
// 处理 resetPerLevel 选项
|
||||
if ((talConfig.trigger as any).resetPerLevel) {
|
||||
instance.actionCounter = 0;
|
||||
instance.damageCounter = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理攻击事件
|
||||
* @param heroId 英雄ID
|
||||
* @param damage 造成的伤害值
|
||||
*/
|
||||
public onHeroAttack(heroId: number, damage: number): void {
|
||||
this.handleActionCounter(heroId, TalActionType.ATTACK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理技能释放事件
|
||||
* @param heroId 英雄ID
|
||||
* @param skillId 技能ID
|
||||
*/
|
||||
public onHeroSkillCast(heroId: number, skillId: number): void {
|
||||
this.handleActionCounter(heroId, TalActionType.SKILL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理受伤事件
|
||||
* @param heroId 英雄ID
|
||||
* @param damage 受到的伤害值
|
||||
*/
|
||||
public onHeroDamaged(heroId: number, damage: number): void {
|
||||
const talentManager = this.talentInstances.get(heroId);
|
||||
if (!talentManager) return;
|
||||
|
||||
talentManager.talents.forEach((instance, talId) => {
|
||||
const talConfig = getTalConf(talId);
|
||||
if (!talConfig || talConfig.talType !== TalType.DAMAGE_COUNT_ATTR) return;
|
||||
|
||||
const damageTrigger = talConfig.trigger as any;
|
||||
instance.damageCounter++;
|
||||
|
||||
// 检查是否应该触发
|
||||
if (instance.damageCounter % damageTrigger.count === 0) {
|
||||
// 检查是否还能堆叠
|
||||
if (talConfig.maxStack && instance.stackCount >= talConfig.maxStack) {
|
||||
console.warn(`天赋 ${talConfig.name} 已达到最大堆叠次数`);
|
||||
return;
|
||||
}
|
||||
|
||||
instance.stackCount++;
|
||||
console.log(`[天赋触发] ${talConfig.name}: 堆叠层数 ${instance.stackCount}`);
|
||||
this.applyTalentEffect(heroId, talConfig, instance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理行为计数
|
||||
* @private
|
||||
*/
|
||||
private handleActionCounter(heroId: number, actionType: TalActionType): void {
|
||||
const talentManager = this.talentInstances.get(heroId);
|
||||
if (!talentManager) return;
|
||||
|
||||
talentManager.talents.forEach((instance, talId) => {
|
||||
const talConfig = getTalConf(talId);
|
||||
if (!talConfig || talConfig.talType !== TalType.ACTION_COUNT_ATTR) return;
|
||||
|
||||
const actionTrigger = talConfig.trigger as any;
|
||||
if (actionTrigger.actionType !== actionType) return;
|
||||
|
||||
instance.actionCounter++;
|
||||
|
||||
// 检查是否应该触发
|
||||
if (instance.actionCounter % actionTrigger.count === 0) {
|
||||
// 检查是否还能堆叠
|
||||
if (talConfig.maxStack && instance.stackCount >= talConfig.maxStack) {
|
||||
console.warn(`天赋 ${talConfig.name} 已达到最大堆叠次数`);
|
||||
return;
|
||||
}
|
||||
|
||||
instance.stackCount++;
|
||||
console.log(`[天赋触发] ${talConfig.name}: 堆叠层数 ${instance.stackCount}`);
|
||||
this.applyTalentEffect(heroId, talConfig, instance);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用天赋效果
|
||||
* @private
|
||||
*/
|
||||
private applyTalentEffect(
|
||||
heroId: number,
|
||||
talConfig: ItalConf,
|
||||
instance: HeroTalentInstance
|
||||
): void {
|
||||
const effect = talConfig.effect;
|
||||
|
||||
switch (effect.type) {
|
||||
case "attrModify":
|
||||
this.applyAttrModify(heroId, talConfig);
|
||||
break;
|
||||
case "skillTrigger":
|
||||
this.triggerSkill(heroId, talConfig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用属性修改效果
|
||||
* @private
|
||||
*/
|
||||
private applyAttrModify(heroId: number, talConfig: ItalConf): void {
|
||||
const effect = talConfig.effect as any;
|
||||
const { attr, value, percent } = effect;
|
||||
|
||||
console.log(
|
||||
`应用属性修改: 英雄${heroId}, 属性${attr}, ` +
|
||||
`${percent ? '百分比' : '固定值'}: ${value}`
|
||||
);
|
||||
|
||||
// 这里应该调用实际的英雄属性修改系统
|
||||
// 示例:
|
||||
// const hero = getHeroData(heroId);
|
||||
// hero.modifyAttribute(attr, value, percent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发技能效果
|
||||
* @private
|
||||
*/
|
||||
private triggerSkill(heroId: number, talConfig: ItalConf): void {
|
||||
const effect = talConfig.effect as any;
|
||||
const { skillId } = effect;
|
||||
|
||||
console.log(`自动释放技能: 英雄${heroId}, 技能ID: ${skillId}`);
|
||||
|
||||
// 这里应该调用实际的技能释放系统
|
||||
// 示例:
|
||||
// const hero = getHeroData(heroId);
|
||||
// hero.castSkill(skillId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取英雄的天赋实例信息
|
||||
*/
|
||||
public getHeroTalentInfo(heroId: number): HeroTalentManager | undefined {
|
||||
return this.talentInstances.get(heroId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取英雄特定天赋的实例数据
|
||||
*/
|
||||
public getHeroTalentInstance(
|
||||
heroId: number,
|
||||
talId: number
|
||||
): HeroTalentInstance | undefined {
|
||||
const talentManager = this.talentInstances.get(heroId);
|
||||
return talentManager?.talents.get(talId);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 天赋查询工具 ==========
|
||||
|
||||
/**
|
||||
* 天赋查询助手
|
||||
*/
|
||||
export class TalentQueryHelper {
|
||||
/**
|
||||
* 获取某类型英雄的所有天赋
|
||||
*/
|
||||
public static getTalentsByType(talType: TalType): ItalConf[] {
|
||||
return getTalConfByType(talType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某属性的所有相关天赋
|
||||
*/
|
||||
public static getTalentsByAttribute(attr: TalAttrType): ItalConf[] {
|
||||
return Object.values(talConf).filter(tal => {
|
||||
const effect = tal.effect as any;
|
||||
return effect.type === "attrModify" && effect.attr === attr;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基于某行为的所有天赋
|
||||
*/
|
||||
public static getTalentsByAction(actionType: TalActionType): ItalConf[] {
|
||||
return Object.values(talConf).filter(tal => {
|
||||
const trigger = tal.trigger as any;
|
||||
return (
|
||||
(trigger.type === "actionCount" && trigger.actionType === actionType) ||
|
||||
(trigger.type === "damageCount")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可堆叠的天赋
|
||||
*/
|
||||
public static getStackableTalents(): ItalConf[] {
|
||||
return Object.values(talConf).filter(tal => tal.stackable !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有技能触发类天赋
|
||||
*/
|
||||
public static getSkillTriggerTalents(): ItalConf[] {
|
||||
return getTalConfByType(TalType.ACTION_TRIGGER_SKILL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印所有天赋信息(调试用)
|
||||
*/
|
||||
public static printAllTalents(): void {
|
||||
console.log("========== 所有天赋配置 ==========");
|
||||
|
||||
Object.values(talConf).forEach(tal => {
|
||||
console.log(`[${tal.talId}] ${tal.name}`);
|
||||
console.log(` 类型: ${this.getTalTypeString(tal.talType)}`);
|
||||
console.log(` 描述: ${tal.desc}`);
|
||||
console.log(` 可堆叠: ${tal.stackable !== false ? "是" : "否"}`);
|
||||
if (tal.maxStack) {
|
||||
console.log(` 最大堆叠: ${tal.maxStack}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取天赋类型的字符串表示
|
||||
* @private
|
||||
*/
|
||||
private static getTalTypeString(talType: TalType): string {
|
||||
const typeMap: Record<number, string> = {
|
||||
[TalType.LEVEL_ATTR]: "等级属性",
|
||||
[TalType.ACTION_COUNT_ATTR]: "行为计数属性",
|
||||
[TalType.DAMAGE_COUNT_ATTR]: "受伤计数属性",
|
||||
[TalType.ACTION_TRIGGER_SKILL]: "技能触发",
|
||||
};
|
||||
return typeMap[talType] || "未知";
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 使用示例 ==========
|
||||
|
||||
/**
|
||||
* 示例:初始化和使用天赋系统
|
||||
*/
|
||||
export class TalentSystemExample {
|
||||
private triggerManager = new TalentTriggerManager();
|
||||
|
||||
/**
|
||||
* 示例:初始化英雄刘邦的天赋
|
||||
*/
|
||||
public initLiuBangTalents(): void {
|
||||
const liuBangId = 5001;
|
||||
const talentIds = [7001, 7202]; // 剑意提升 + 防御强化
|
||||
|
||||
console.log("初始化刘邦的天赋系统...");
|
||||
this.triggerManager.initHeroTalents(liuBangId, talentIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 示例:模拟刘邦升级流程
|
||||
*/
|
||||
public simulateLevelUp(): void {
|
||||
const liuBangId = 5001;
|
||||
|
||||
console.log("\n--- 刘邦升级模拟 ---");
|
||||
for (let level = 1; level <= 20; level++) {
|
||||
this.triggerManager.onHeroLevelUp(liuBangId, level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 示例:模拟战斗中的天赋触发
|
||||
*/
|
||||
public simulateCombat(): void {
|
||||
const liuBangId = 5001;
|
||||
|
||||
console.log("\n--- 战斗模拟 ---");
|
||||
|
||||
// 模拟攻击
|
||||
for (let i = 0; i < 25; i++) {
|
||||
this.triggerManager.onHeroAttack(liuBangId, 50);
|
||||
}
|
||||
|
||||
// 模拟受伤
|
||||
for (let i = 0; i < 15; i++) {
|
||||
this.triggerManager.onHeroDamaged(liuBangId, 30);
|
||||
}
|
||||
|
||||
// 查询当前天赋状态
|
||||
const talentInfo = this.triggerManager.getHeroTalentInfo(liuBangId);
|
||||
if (talentInfo) {
|
||||
console.log("\n当前天赋状态:");
|
||||
talentInfo.talents.forEach((instance, talId) => {
|
||||
const talConfig = getTalConf(talId);
|
||||
console.log(
|
||||
`${talConfig?.name}: 堆叠 ${instance.stackCount}` +
|
||||
` (计数: 行为${instance.actionCounter}, 受伤${instance.damageCounter})`
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 示例:查询天赋信息
|
||||
*/
|
||||
public queryTalentInfo(): void {
|
||||
console.log("\n--- 天赋查询示例 ---");
|
||||
|
||||
// 查询所有等级类天赋
|
||||
const levelTals = TalentQueryHelper.getTalentsByType(TalType.LEVEL_ATTR);
|
||||
console.log(`\n等级类天赋 (${levelTals.length}个):`);
|
||||
levelTals.forEach(tal => console.log(` - ${tal.name}`));
|
||||
|
||||
// 查询与攻击相关的天赋
|
||||
const attackTals = TalentQueryHelper.getTalentsByAction(TalActionType.ATTACK);
|
||||
console.log(`\n与攻击相关的天赋 (${attackTals.length}个):`);
|
||||
attackTals.forEach(tal => console.log(` - ${tal.name}`));
|
||||
|
||||
// 查询所有技能触发类天赋
|
||||
const skillTals = TalentQueryHelper.getSkillTriggerTalents();
|
||||
console.log(`\n技能触发类天赋 (${skillTals.length}个):`);
|
||||
skillTals.forEach(tal => console.log(` - ${tal.name}`));
|
||||
|
||||
// 打印所有天赋
|
||||
TalentQueryHelper.printAllTalents();
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 全局单例 ==========
|
||||
|
||||
/** 全局天赋触发管理器实例 */
|
||||
export const globalTalentManager = new TalentTriggerManager();
|
||||
|
||||
/**
|
||||
* 快捷函数:初始化英雄天赋
|
||||
*/
|
||||
export function initHeroTalents(heroId: number, talentIds: number[]): void {
|
||||
globalTalentManager.initHeroTalents(heroId, talentIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷函数:处理英雄升级
|
||||
*/
|
||||
export function onHeroLevelUp(heroId: number, newLevel: number): void {
|
||||
globalTalentManager.onHeroLevelUp(heroId, newLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷函数:处理英雄攻击
|
||||
*/
|
||||
export function onHeroAttack(heroId: number, damage: number): void {
|
||||
globalTalentManager.onHeroAttack(heroId, damage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷函数:处理技能释放
|
||||
*/
|
||||
export function onHeroSkillCast(heroId: number, skillId: number): void {
|
||||
globalTalentManager.onHeroSkillCast(heroId, skillId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷函数:处理英雄受伤
|
||||
*/
|
||||
export function onHeroDamaged(heroId: number, damage: number): void {
|
||||
globalTalentManager.onHeroDamaged(heroId, damage);
|
||||
}
|
||||
445
assets/script/game/common/config/TalSet_QuickRef.md
Normal file
445
assets/script/game/common/config/TalSet_QuickRef.md
Normal file
@@ -0,0 +1,445 @@
|
||||
# 天赋系统快速参考
|
||||
|
||||
## 📋 文件导览
|
||||
|
||||
| 文件 | 用途 |
|
||||
|------|------|
|
||||
| `TalSet.ts` | 核心配置文件 - 定义所有天赋类型、接口和配置表 |
|
||||
| `TalSet_USAGE.md` | 详细使用文档 - 包含各天赋类型的详解和最佳实践 |
|
||||
| `TalSet_Example.ts` | 集成示例 - 完整的天赋系统实现代码 |
|
||||
| `TalSet_QuickRef.md` | 快速参考(本文件) - 常用代码片段速查 |
|
||||
|
||||
---
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 1. 初始化英雄天赋
|
||||
|
||||
```typescript
|
||||
import { initHeroTalents } from "./TalSet_Example";
|
||||
|
||||
// 为英雄 ID=5001 初始化天赋 [7001, 7202]
|
||||
initHeroTalents(5001, [7001, 7202]);
|
||||
```
|
||||
|
||||
### 2. 监听英雄事件
|
||||
|
||||
```typescript
|
||||
import {
|
||||
onHeroLevelUp,
|
||||
onHeroAttack,
|
||||
onHeroDamaged
|
||||
} from "./TalSet_Example";
|
||||
|
||||
// 英雄升级到新等级
|
||||
onHeroLevelUp(5001, 10);
|
||||
|
||||
// 英雄发动攻击
|
||||
onHeroAttack(5001, 50);
|
||||
|
||||
// 英雄受到伤害
|
||||
onHeroDamaged(5001, 30);
|
||||
```
|
||||
|
||||
### 3. 查询天赋信息
|
||||
|
||||
```typescript
|
||||
import { getTalConf, getTalConfByType, TalType } from "./TalSet";
|
||||
|
||||
// 获取单个天赋配置
|
||||
const talConfig = getTalConf(7001);
|
||||
|
||||
// 获取某类型的所有天赋
|
||||
const levelTals = getTalConfByType(TalType.LEVEL_ATTR);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 天赋类型速查
|
||||
|
||||
### 等级类天赋 (LEVEL_ATTR)
|
||||
|
||||
**ID范围**: 7001-7099
|
||||
|
||||
| ID | 名称 | 描述 | 触发条件 |
|
||||
|---|------|------|--------|
|
||||
| 7001 | 剑意提升 | 攻击力 +10% | 每5级 |
|
||||
| 7002 | 法力修炼 | 魔力 +15 | 每3级 |
|
||||
|
||||
**配置模板**:
|
||||
```typescript
|
||||
{
|
||||
talId: 7001,
|
||||
name: "天赋名",
|
||||
desc: "效果描述",
|
||||
talType: TalType.LEVEL_ATTR,
|
||||
trigger: { type: "level", level: 5 } as ILevelTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.AP,
|
||||
value: 10,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20,
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 行为计数类天赋 (ACTION_COUNT_ATTR)
|
||||
|
||||
**ID范围**: 7101-7199
|
||||
|
||||
| ID | 名称 | 描述 | 触发条件 |
|
||||
|---|------|------|--------|
|
||||
| 7101 | 强化闪避 | 闪避率 +1% | 每10次攻击 |
|
||||
| 7102 | 暴击强化 | 暴击率 +2% | 每15次攻击 |
|
||||
| 7103 | 连击精通 | 攻击力 +5% | 每8次技能 |
|
||||
|
||||
**配置模板**:
|
||||
```typescript
|
||||
{
|
||||
talId: 7101,
|
||||
name: "天赋名",
|
||||
desc: "效果描述",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.DODGE,
|
||||
value: 1,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20,
|
||||
}
|
||||
```
|
||||
|
||||
**行为类型**:
|
||||
- `TalActionType.ATTACK` - 攻击
|
||||
- `TalActionType.SKILL` - 技能
|
||||
- `TalActionType.DAMAGED` - 受伤
|
||||
|
||||
---
|
||||
|
||||
### 受伤计数类天赋 (DAMAGE_COUNT_ATTR)
|
||||
|
||||
**ID范围**: 7201-7299
|
||||
|
||||
| ID | 名称 | 描述 | 触发条件 |
|
||||
|---|------|------|--------|
|
||||
| 7201 | 坚甲护体 | 生命 +100 | 每10次受伤 |
|
||||
| 7202 | 防御强化 | 防御 +3% | 每12次受伤 |
|
||||
| 7203 | 魔抗修炼 | 魔防 +5 | 每15次受伤 |
|
||||
|
||||
**配置模板**:
|
||||
```typescript
|
||||
{
|
||||
talId: 7201,
|
||||
name: "天赋名",
|
||||
desc: "效果描述",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.HP,
|
||||
value: 100,
|
||||
percent: false,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 15,
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 技能触发类天赋 (ACTION_TRIGGER_SKILL)
|
||||
|
||||
**ID范围**: 7301-7399
|
||||
|
||||
| ID | 名称 | 描述 | 触发条件 |
|
||||
|---|------|------|--------|
|
||||
| 7301 | 连击反击 | 释放技能6010 | 每15次攻击 |
|
||||
| 7302 | 受伤反制 | 释放技能6011 | 每8次受伤 |
|
||||
| 7303 | 技能链接 | 释放技能6012 | 每5次技能 |
|
||||
|
||||
**配置模板**:
|
||||
```typescript
|
||||
{
|
||||
talId: 7301,
|
||||
name: "天赋名",
|
||||
desc: "效果描述",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 15,
|
||||
resetPerLevel: true,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6010,
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false,
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 属性类型速查
|
||||
|
||||
```typescript
|
||||
TalAttrType.HP // 最大生命值
|
||||
TalAttrType.MP // 最大魔力值
|
||||
TalAttrType.AP // 攻击力
|
||||
TalAttrType.MAP // 魔法攻击力
|
||||
TalAttrType.DEF // 防御力
|
||||
TalAttrType.MDEF // 魔法防御力
|
||||
TalAttrType.SPEED // 移动速度
|
||||
TalAttrType.DODGE // 闪避率
|
||||
TalAttrType.CRIT // 暴击率
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 💡 常见代码片段
|
||||
|
||||
### 获取所有某类型天赋
|
||||
|
||||
```typescript
|
||||
import { getTalConfByType, TalType } from "./TalSet";
|
||||
|
||||
const levelTals = getTalConfByType(TalType.LEVEL_ATTR);
|
||||
const actionTals = getTalConfByType(TalType.ACTION_COUNT_ATTR);
|
||||
const damageTals = getTalConfByType(TalType.DAMAGE_COUNT_ATTR);
|
||||
const skillTals = getTalConfByType(TalType.ACTION_TRIGGER_SKILL);
|
||||
```
|
||||
|
||||
### 获取某属性相关的所有天赋
|
||||
|
||||
```typescript
|
||||
import { TalentQueryHelper, TalAttrType } from "./TalSet_Example";
|
||||
|
||||
const hpTals = TalentQueryHelper.getTalentsByAttribute(TalAttrType.HP);
|
||||
const apTals = TalentQueryHelper.getTalentsByAttribute(TalAttrType.AP);
|
||||
```
|
||||
|
||||
### 获取某行为相关的所有天赋
|
||||
|
||||
```typescript
|
||||
import { TalentQueryHelper, TalActionType } from "./TalSet_Example";
|
||||
|
||||
const attackTals = TalentQueryHelper.getTalentsByAction(TalActionType.ATTACK);
|
||||
const skillTals = TalentQueryHelper.getTalentsByAction(TalActionType.SKILL);
|
||||
```
|
||||
|
||||
### 获取英雄的天赋状态
|
||||
|
||||
```typescript
|
||||
import { globalTalentManager } from "./TalSet_Example";
|
||||
|
||||
const talentInfo = globalTalentManager.getHeroTalentInfo(5001);
|
||||
if (talentInfo) {
|
||||
talentInfo.talents.forEach((instance, talId) => {
|
||||
console.log(`天赋${talId}: 堆叠${instance.stackCount}`);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### 获取英雄的特定天赋实例
|
||||
|
||||
```typescript
|
||||
import { globalTalentManager } from "./TalSet_Example";
|
||||
|
||||
const talInstance = globalTalentManager.getHeroTalentInstance(5001, 7001);
|
||||
if (talInstance) {
|
||||
console.log(`堆叠层数: ${talInstance.stackCount}`);
|
||||
console.log(`行为计数: ${talInstance.actionCounter}`);
|
||||
console.log(`受伤计数: ${talInstance.damageCounter}`);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 添加新天赋步骤
|
||||
|
||||
### 步骤 1: 确定天赋类型
|
||||
|
||||
选择以下之一:
|
||||
- `LEVEL_ATTR` - 等级触发
|
||||
- `ACTION_COUNT_ATTR` - 行为计数触发
|
||||
- `DAMAGE_COUNT_ATTR` - 受伤次数触发
|
||||
- `ACTION_TRIGGER_SKILL` - 技能自动释放
|
||||
|
||||
### 步骤 2: 分配 ID
|
||||
|
||||
遵循命名规范:
|
||||
- `70xx` - 等级类
|
||||
- `71xx` - 行为计数类
|
||||
- `72xx` - 受伤计数类
|
||||
- `73xx` - 技能触发类
|
||||
|
||||
### 步骤 3: 配置天赋
|
||||
|
||||
在 `TalSet.ts` 的 `talConf` 中添加配置:
|
||||
|
||||
```typescript
|
||||
// 示例:新增"生命吸取"天赋
|
||||
7104: {
|
||||
talId: 7104,
|
||||
name: "生命吸取",
|
||||
desc: "每使用技能10次,最大生命值增加50点",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.SKILL,
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.HP,
|
||||
value: 50,
|
||||
percent: false,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 10,
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔍 调试技巧
|
||||
|
||||
### 打印所有天赋信息
|
||||
|
||||
```typescript
|
||||
import { TalentQueryHelper } from "./TalSet_Example";
|
||||
|
||||
TalentQueryHelper.printAllTalents();
|
||||
```
|
||||
|
||||
### 获取所有天赋ID
|
||||
|
||||
```typescript
|
||||
import { getAllTalIds } from "./TalSet";
|
||||
|
||||
const allIds = getAllTalIds();
|
||||
console.log(allIds); // [7001, 7002, 7101, ...]
|
||||
```
|
||||
|
||||
### 获取所有可堆叠天赋
|
||||
|
||||
```typescript
|
||||
import { TalentQueryHelper } from "./TalSet_Example";
|
||||
|
||||
const stackableTals = TalentQueryHelper.getStackableTalents();
|
||||
```
|
||||
|
||||
### 获取所有技能触发类天赋
|
||||
|
||||
```typescript
|
||||
import { TalentQueryHelper } from "./TalSet_Example";
|
||||
|
||||
const skillTriggerTals = TalentQueryHelper.getSkillTriggerTalents();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ 配置最佳实践
|
||||
|
||||
### 等级间隔建议
|
||||
|
||||
| 间隔 | 用途 | 示例 |
|
||||
|------|------|------|
|
||||
| 1 级 | 极高频触发(谨慎使用) | 特殊被动 |
|
||||
| 2-3 级 | 高频触发 | 关键属性增长 |
|
||||
| 4-5 级 | 常规触发 | 通用属性增长 |
|
||||
| 6-10 级 | 低频触发 | 强力效果 |
|
||||
|
||||
### 堆叠层数建议
|
||||
|
||||
| 效果类型 | 建议上限 | 原因 |
|
||||
|---------|---------|------|
|
||||
| 固定值 (+100 HP) | 10-20 | 总收益 1000-2000 |
|
||||
| 小百分比 (+1%) | 15-30 | 防止过度膨胀 |
|
||||
| 大百分比 (+5%) | 5-10 | 数值平衡 |
|
||||
| 技能触发 | 1 (false) | 防止无限触发 |
|
||||
|
||||
### 数值平衡公式
|
||||
|
||||
```
|
||||
最终增益 = 基础值 × 最大堆叠 × 触发频率
|
||||
|
||||
例: 攻击力 +10% × 20 堆叠 = 200% 增加
|
||||
调整建议: 减少堆叠 maxStack 或增加触发频率
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📦 导入速览
|
||||
|
||||
### 基础导入
|
||||
|
||||
```typescript
|
||||
import {
|
||||
TalType, // 天赋类型枚举
|
||||
TalAttrType, // 属性类型枚举
|
||||
TalActionType, // 行为类型枚举
|
||||
getTalConf, // 获取单个天赋
|
||||
getTalConfByType, // 按类型获取天赋
|
||||
getAllTalIds, // 获取所有天赋ID
|
||||
} from "./TalSet";
|
||||
```
|
||||
|
||||
### 高级导入
|
||||
|
||||
```typescript
|
||||
import {
|
||||
TalentTriggerManager, // 天赋触发管理器
|
||||
TalentQueryHelper, // 天赋查询助手
|
||||
globalTalentManager, // 全局管理器实例
|
||||
initHeroTalents, // 初始化天赋
|
||||
onHeroLevelUp, // 升级事件
|
||||
onHeroAttack, // 攻击事件
|
||||
onHeroSkillCast, // 技能事件
|
||||
onHeroDamaged, // 受伤事件
|
||||
} from "./TalSet_Example";
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐛 常见问题速答
|
||||
|
||||
| 问题 | 答案 |
|
||||
|------|------|
|
||||
| 如何禁用某个天赋? | 在初始化时不添加该天赋ID |
|
||||
| 天赋可以堆叠多少次? | 看 `maxStack` 配置,不设则无限 |
|
||||
| 如何重置计数器? | 设置 `resetPerLevel: true` 按等级重置 |
|
||||
| 如何添加新的属性类型? | 在 `TalAttrType` 枚举中添加 |
|
||||
| 如何添加新的行为类型? | 在 `TalActionType` 枚举中添加 |
|
||||
| 技能触发如何防止无限循环? | 设置 `stackable: false` |
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关文件链接
|
||||
|
||||
- [详细使用文档](./TalSet_USAGE.md) - 完整的天赋系统说明
|
||||
- [集成示例代码](./TalSet_Example.ts) - 天赋系统实现示例
|
||||
- [核心配置文件](./TalSet.ts) - 所有类型定义和配置表
|
||||
|
||||
---
|
||||
|
||||
**版本**: 1.0
|
||||
**最后更新**: 2025-10-27
|
||||
**维护者**: 开发团队
|
||||
454
assets/script/game/common/config/TalSet_USAGE.md
Normal file
454
assets/script/game/common/config/TalSet_USAGE.md
Normal file
@@ -0,0 +1,454 @@
|
||||
# 天赋系统配置文档
|
||||
|
||||
## 概述
|
||||
|
||||
`TalSet.ts` 定义了一个灵活、可扩展的天赋系统,用于为游戏中的英雄定义特殊能力或特性。该系统支持四种主要的天赋类型,每种类型都有其独特的触发条件和效果机制。
|
||||
|
||||
## 核心概念
|
||||
|
||||
### 天赋系统的三个层次
|
||||
|
||||
1. **触发条件 (Trigger)** - 何时激发天赋效果
|
||||
2. **效果 (Effect)** - 天赋产生的具体效果
|
||||
3. **堆叠规则 (Stack Rules)** - 多次触发时的行为
|
||||
|
||||
---
|
||||
|
||||
## 四种天赋类型详解
|
||||
|
||||
### 1. 等级类天赋 (LEVEL_ATTR)
|
||||
|
||||
**触发机制**:当英雄达到指定等级时触发
|
||||
|
||||
**使用场景**:
|
||||
- 角色成长里程碑
|
||||
- 等级解锁的被动能力
|
||||
- 固定间隔的属性增强
|
||||
|
||||
**配置示例**:
|
||||
```typescript
|
||||
7001: {
|
||||
talId: 7001,
|
||||
name: "剑意提升",
|
||||
desc: "每升5级,攻击力增加10%",
|
||||
talType: TalType.LEVEL_ATTR,
|
||||
trigger: {
|
||||
type: "level",
|
||||
level: 5, // 触发间隔为5级
|
||||
} as ILevelTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.AP,
|
||||
value: 10,
|
||||
percent: true, // 百分比增长
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20, // 最多触发20次(到100级)
|
||||
}
|
||||
```
|
||||
|
||||
**工作流程**:
|
||||
- 等级 5 → 触发,攻击力 +10%
|
||||
- 等级 10 → 再次触发,攻击力 +10%(可堆叠)
|
||||
- 等级 15 → 继续触发...
|
||||
- 最高到等级 100(20×5)
|
||||
|
||||
---
|
||||
|
||||
### 2. 行为计数类天赋 (ACTION_COUNT_ATTR)
|
||||
|
||||
**触发机制**:当特定行为累计达到指定次数时触发
|
||||
|
||||
**支持的行为类型**:
|
||||
- `ATTACK` - 攻击动作
|
||||
- `SKILL` - 技能释放
|
||||
- `DAMAGED` - 受到伤害
|
||||
|
||||
**配置示例**:
|
||||
```typescript
|
||||
7101: {
|
||||
talId: 7101,
|
||||
name: "强化闪避",
|
||||
desc: "每攻击10次,闪避率增加1%",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 10,
|
||||
resetPerLevel: false, // 升级后不重置计数
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.DODGE,
|
||||
value: 1,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 20,
|
||||
}
|
||||
```
|
||||
|
||||
**工作流程**(假设 resetPerLevel: false):
|
||||
- 攻击 10 次 → 闪避率 +1%
|
||||
- 攻击 20 次 → 闪避率 +1%(累计 +2%)
|
||||
- 攻击 30 次 → 闪避率 +1%(累计 +3%)
|
||||
- 持续堆叠到 maxStack
|
||||
|
||||
**resetPerLevel 选项说明**:
|
||||
- `true`:每升一级重置计数器
|
||||
- 适合每个等级独立计算的天赋
|
||||
- 示例:每升级后重新开始计数
|
||||
- `false`:计数持续累积,不因升级而重置
|
||||
- 适合全程累积的天赋
|
||||
- 示例:整个游戏过程中累积攻击次数
|
||||
|
||||
---
|
||||
|
||||
### 3. 受伤计数类天赋 (DAMAGE_COUNT_ATTR)
|
||||
|
||||
**触发机制**:当英雄累计受伤达到指定次数时触发
|
||||
|
||||
**配置示例**:
|
||||
```typescript
|
||||
7201: {
|
||||
talId: 7201,
|
||||
name: "坚甲护体",
|
||||
desc: "每受伤10次,最大生命值增加100点",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 10,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.HP,
|
||||
value: 100,
|
||||
percent: false, // 固定值增长
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 15,
|
||||
}
|
||||
```
|
||||
|
||||
**工作流程**:
|
||||
- 受伤 10 次 → 生命值 +100
|
||||
- 受伤 20 次 → 生命值 +100
|
||||
- 受伤 30 次 → 生命值 +100
|
||||
- ...最多到 15 堆叠(150 次受伤)
|
||||
|
||||
**应用场景**:
|
||||
- 坦克英雄通过受伤变强
|
||||
- 防御系统的成长机制
|
||||
- 反伤/反制类的天赋基础
|
||||
|
||||
---
|
||||
|
||||
### 4. 技能触发类天赋 (ACTION_TRIGGER_SKILL)
|
||||
|
||||
**触发机制**:当特定条件达成时自动释放指定的技能
|
||||
|
||||
**配置示例**:
|
||||
```typescript
|
||||
7301: {
|
||||
talId: 7301,
|
||||
name: "连击反击",
|
||||
desc: "每攻击15次,自动触发反击技能",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.ATTACK,
|
||||
count: 15,
|
||||
resetPerLevel: true, // 每升级重置计数
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6010, // 反击技能的ID
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false, // 技能触发不堆叠
|
||||
}
|
||||
```
|
||||
|
||||
**工作流程**:
|
||||
- 升级 1:每攻击 15 次 → 自动释放技能 6010
|
||||
- 升级 2:计数重置,再每攻击 15 次 → 释放技能 6010
|
||||
- 持续每个等级都能触发
|
||||
|
||||
**关键特性**:
|
||||
- `stackable: false` - 通常技能触发不堆叠(防止过于强大)
|
||||
- 结合 `resetPerLevel` 控制触发频率
|
||||
- 可用于创建连锁反应和特殊战斗机制
|
||||
|
||||
---
|
||||
|
||||
## 属性类型速查表
|
||||
|
||||
| 属性类型 | 枚举值 | 说明 |
|
||||
|---------|-------|------|
|
||||
| HP | "hp" | 最大生命值 |
|
||||
| MP | "mp" | 最大魔力值 |
|
||||
| AP | "ap" | 攻击力 |
|
||||
| MAP | "map" | 魔法攻击力 |
|
||||
| DEF | "def" | 防御力 |
|
||||
| MDEF | "mdef" | 魔法防御力 |
|
||||
| SPEED | "speed" | 移动速度 |
|
||||
| DODGE | "dodge" | 闪避率 |
|
||||
| CRIT | "crit" | 暴击率 |
|
||||
|
||||
---
|
||||
|
||||
## 扩展天赋系统
|
||||
|
||||
### 添加新的等级类天赋
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* 坚韧意志 - 全系列
|
||||
* 每升4级,防御力增加5%
|
||||
*/
|
||||
7003: {
|
||||
talId: 7003,
|
||||
name: "坚韧意志",
|
||||
desc: "每升4级,防御力增加5%",
|
||||
talType: TalType.LEVEL_ATTR,
|
||||
trigger: {
|
||||
type: "level",
|
||||
level: 4,
|
||||
} as ILevelTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.DEF,
|
||||
value: 5,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 25,
|
||||
},
|
||||
```
|
||||
|
||||
### 添加新的行为计数类天赋
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* 技能精通 - 法师系
|
||||
* 每使用技能12次,魔法攻击增加8%
|
||||
*/
|
||||
7104: {
|
||||
talId: 7104,
|
||||
name: "技能精通",
|
||||
desc: "每使用技能12次,魔法攻击增加8%",
|
||||
talType: TalType.ACTION_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.SKILL,
|
||||
count: 12,
|
||||
resetPerLevel: false,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.MAP,
|
||||
value: 8,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 12,
|
||||
},
|
||||
```
|
||||
|
||||
### 添加新的受伤计数类天赋
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* 越战越强 - 战士系
|
||||
* 每受伤8次,攻击力增加4%
|
||||
*/
|
||||
7204: {
|
||||
talId: 7204,
|
||||
name: "越战越强",
|
||||
desc: "每受伤8次,攻击力增加4%",
|
||||
talType: TalType.DAMAGE_COUNT_ATTR,
|
||||
trigger: {
|
||||
type: "damageCount",
|
||||
count: 8,
|
||||
resetPerLevel: false,
|
||||
} as IDamageCountTrigger,
|
||||
effect: {
|
||||
type: "attrModify",
|
||||
attr: TalAttrType.AP,
|
||||
value: 4,
|
||||
percent: true,
|
||||
} as IAttrModifyEffect,
|
||||
stackable: true,
|
||||
maxStack: 18,
|
||||
},
|
||||
```
|
||||
|
||||
### 添加新的技能触发类天赋
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* 治疗链 - 辅助系
|
||||
* 每使用技能6次,自动释放治疗技能
|
||||
*/
|
||||
7304: {
|
||||
talId: 7304,
|
||||
name: "治疗链",
|
||||
desc: "每使用技能6次,自动释放治疗技能",
|
||||
talType: TalType.ACTION_TRIGGER_SKILL,
|
||||
trigger: {
|
||||
type: "actionCount",
|
||||
actionType: TalActionType.SKILL,
|
||||
count: 6,
|
||||
resetPerLevel: true,
|
||||
} as IActionCountTrigger,
|
||||
effect: {
|
||||
type: "skillTrigger",
|
||||
skillId: 6020, // 治疗技能ID
|
||||
} as ISkillTriggerEffect,
|
||||
stackable: false,
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 使用工具函数
|
||||
|
||||
### 1. 获取单个天赋配置
|
||||
|
||||
```typescript
|
||||
import { getTalConf } from "./TalSet";
|
||||
|
||||
const talConfig = getTalConf(7001);
|
||||
console.log(talConfig?.name); // "剑意提升"
|
||||
```
|
||||
|
||||
### 2. 获取指定类型的所有天赋
|
||||
|
||||
```typescript
|
||||
import { getTalConfByType, TalType } from "./TalSet";
|
||||
|
||||
// 获取所有等级类天赋
|
||||
const levelTals = getTalConfByType(TalType.LEVEL_ATTR);
|
||||
|
||||
// 获取所有行为计数类天赋
|
||||
const actionCountTals = getTalConfByType(TalType.ACTION_COUNT_ATTR);
|
||||
```
|
||||
|
||||
### 3. 获取所有天赋ID
|
||||
|
||||
```typescript
|
||||
import { getAllTalIds } from "./TalSet";
|
||||
|
||||
const allIds = getAllTalIds();
|
||||
console.log(allIds); // [7001, 7002, 7101, 7102, ...]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 1. ID 命名规范
|
||||
|
||||
采用 **XYZZ** 的格式:
|
||||
- **X** - 天赋类型(7表示天赋)
|
||||
- **Y** - 具体分类(0=等级,1=行为计数,2=受伤计数,3=技能触发)
|
||||
- **ZZ** - 序列号(01-99)
|
||||
|
||||
示例:
|
||||
- `7001` - 第一个等级类天赋
|
||||
- `7101` - 第一个行为计数类天赋
|
||||
- `7201` - 第一个受伤计数类天赋
|
||||
- `7301` - 第一个技能触发类天赋
|
||||
|
||||
### 2. 堆叠配置原则
|
||||
|
||||
- **属性增强类天赋** - 通常可堆叠,设置合理的 maxStack
|
||||
- **技能触发类天赋** - 通常不堆叠(stackable: false)
|
||||
- **百分比效果** - 堆叠次数要控制,防止无限膨胀
|
||||
|
||||
### 3. 触发计数的重置策略
|
||||
|
||||
- **持续累积** - resetPerLevel: false
|
||||
- 用于全程成长的天赋
|
||||
- 例如:攻击次数计数
|
||||
|
||||
- **按等级重置** - resetPerLevel: true
|
||||
- 用于每个等级独立计算的天赋
|
||||
- 例如:技能连锁、特殊触发
|
||||
|
||||
### 4. 数值平衡
|
||||
|
||||
建议遵循以下原则:
|
||||
- 固定值增长 - 根据角色等级调整数值
|
||||
- 百分比增长 - 通常 1-15% 范围较合理
|
||||
- 触发频率 - 越高频越小效果,越低频越大效果
|
||||
|
||||
---
|
||||
|
||||
## 与英雄系统的集成
|
||||
|
||||
### 在 heroSet.ts 中添加天赋
|
||||
|
||||
```typescript
|
||||
export interface heroInfo {
|
||||
uuid: number;
|
||||
name: string;
|
||||
// ... 其他属性 ...
|
||||
talents?: number[]; // 天赋ID数组
|
||||
}
|
||||
|
||||
// 示例:为刘邦添加天赋
|
||||
5001: {
|
||||
uuid: 5001,
|
||||
name: "刘邦",
|
||||
// ... 其他属性 ...
|
||||
talents: [7001, 7202], // 剑意提升 + 防御强化
|
||||
}
|
||||
```
|
||||
|
||||
### 在游戏系统中使用天赋
|
||||
|
||||
```typescript
|
||||
import { getTalConf, TalType } from "./TalSet";
|
||||
|
||||
// 为英雄应用天赋
|
||||
function applyHeroTalents(heroId: number, heroTalents: number[]) {
|
||||
heroTalents.forEach(talId => {
|
||||
const talConfig = getTalConf(talId);
|
||||
if (talConfig) {
|
||||
// 根据天赋配置应用效果
|
||||
console.log(`应用天赋: ${talConfig.name}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q: 如何创建一个多条件触发的天赋?
|
||||
**A**: 当前系统每个天赋只支持一种触发条件。如需复杂条件,建议在实现层面组合多个简单天赋。
|
||||
|
||||
### Q: 堆叠次数达到上限后会发生什么?
|
||||
**A**: 这由实现层面决定。建议:
|
||||
- 停止触发
|
||||
- 显示通知提示
|
||||
- 或记录日志便于调试
|
||||
|
||||
### Q: 如何实现基于时间的天赋触发?
|
||||
**A**: 当前系统不直接支持时间触发。建议:
|
||||
- 创建一个新的触发条件类型 `ITimeTrigger`
|
||||
- 在系统中添加相应的时间检查逻辑
|
||||
|
||||
### Q: 如何让天赋在战斗中实时反应?
|
||||
**A**: 天赋的实际效果应该在战斗系统中实现,配置只是定义。建议:
|
||||
- 在战斗系统中监听相关事件
|
||||
- 检查英雄的天赋配置
|
||||
- 根据配置应用对应的效果
|
||||
|
||||
---
|
||||
|
||||
## 总结
|
||||
|
||||
`TalSet.ts` 提供了一个强大而灵活的天赋系统框架,支持多种触发条件和效果类型。通过合理的配置和组合,可以创建出丰富多样的英雄特性,为游戏增添深度和可玩性。
|
||||
Reference in New Issue
Block a user