还有好多错误
This commit is contained in:
@@ -5,16 +5,71 @@ import { HeroSpine } from "./HeroSpine";
|
||||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { Attrs, DBuff, geDebuffNum, getAttrs, SkillSet, TGroup, TType, BType, BuffConf, DbuffConf } from "../common/config/SkillSet";
|
||||
import { Attrs, DBuff, SkillSet, BType, BuffConf, DbuffConf, getAttrFieldFromDebuff } from "../common/config/SkillSet";
|
||||
import { BuffComp } from "./BuffComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { FightSet, getExpDrops, getStoneDrops, TooltipTypes } from "../common/config/Mission";
|
||||
import { FightSet, TooltipTypes } from "../common/config/Mission";
|
||||
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
||||
import { HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
/**
|
||||
* ==================== BUFF 系统使用说明 ====================
|
||||
*
|
||||
* 1. 系统架构:
|
||||
* - V_BUFF/V_BUFFS: 数值型 buff(持久/临时)
|
||||
* - R_BUFF/R_BUFFS: 百分比型 buff(持久/临时)
|
||||
* - V_DBUFF/V_DBUFFS: 数值型 debuff(持久/临时)
|
||||
* - R_DBUFF/R_DBUFFS: 百分比型 debuff(持久/临时)
|
||||
*
|
||||
* 2. 初始化(在英雄加载时自动调用):
|
||||
* - initBuffsDebuffs(): 从 HeroInfo 读取初始配置
|
||||
*
|
||||
* 3. 添加 buff(技能调用):
|
||||
* const buffConf: BuffConf = {
|
||||
* buff: Attrs.AP, // 增加攻击力
|
||||
* BType: BType.VALUE, // 数值型
|
||||
* buV: 10, // 增加值
|
||||
* buC: 0, // 持久(0=持久, >0=持续时间)
|
||||
* buR: 100 // 触发概率(100%)
|
||||
* };
|
||||
* heroView.addBuff(buffConf);
|
||||
*
|
||||
* 4. 添加 debuff(技能调用):
|
||||
* const dbuffConf: DbuffConf = {
|
||||
* debuff: DBuff.STUN, // 眩晕
|
||||
* BType: BType.VALUE, // 数值型
|
||||
* dev: 20, // 减少值
|
||||
* deC: 3, // 持续3秒
|
||||
* deR: 100 // 触发概率(100%)
|
||||
* };
|
||||
* heroView.addDebuff(dbuffConf);
|
||||
*
|
||||
* 5. 百分比型示例:
|
||||
* // 增加20%攻击力
|
||||
* heroView.addBuff({
|
||||
* buff: Attrs.AP,
|
||||
* BType: BType.RATIO, // 百分比型
|
||||
* buV: 20, // 20%
|
||||
* buC: 5, // 持续5秒
|
||||
* buR: 100
|
||||
* });
|
||||
*
|
||||
* 6. 移除 buff/debuff:
|
||||
* heroView.removeBuff(Attrs.AP, false); // 移除持久 AP buff
|
||||
* heroView.removeDebuff(DBuff.STUN, true); // 移除临时眩晕
|
||||
*
|
||||
* 7. 属性计算:
|
||||
* - 每次 buff/debuff 变动时自动调用 recalculateAttrs()
|
||||
* - 重新计算基础属性 + 所有 buff/debuff 的结果
|
||||
* - 临时 buff/debuff 在 update 中按时间递减
|
||||
*
|
||||
* 8. 初始值属性:
|
||||
* - base_hp, base_mp, base_def, base_ap, base_map 是初始值
|
||||
* - 百分比 buff/debuff 基于这些初始值计算
|
||||
* - 其他属性默认为 0,无初始值
|
||||
*/
|
||||
/** 角色显示组件 */
|
||||
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
|
||||
@ecs.register('HeroView', false) // 定义为 ECS 组件
|
||||
@@ -107,6 +162,347 @@ export class HeroViewComp extends CCComp {
|
||||
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||||
}
|
||||
|
||||
// ==================== BUFF系统初始化 ====================
|
||||
/**
|
||||
* 初始化角色的 buff 和 debuff
|
||||
* 从 HeroInfo 读取初始配置,建立属性系统
|
||||
*/
|
||||
initBuffsDebuffs() {
|
||||
// 获取英雄配置
|
||||
const heroInfo = HeroInfo[this.hero_uuid];
|
||||
if (!heroInfo) return;
|
||||
|
||||
// 清空现有 buff/debuff
|
||||
this.V_BUFF = [];
|
||||
this.V_BUFFS = [];
|
||||
this.R_BUFF = [];
|
||||
this.R_BUFFS = [];
|
||||
this.V_DBUFF = [];
|
||||
this.V_DBUFFS = [];
|
||||
this.R_DBUFF = [];
|
||||
this.R_DBUFFS = [];
|
||||
|
||||
// 加载初始 buff
|
||||
if (heroInfo.buff && heroInfo.buff.length > 0) {
|
||||
for (const buffConf of heroInfo.buff) {
|
||||
this.addBuff(buffConf);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载初始 debuff
|
||||
if (heroInfo.debuff && heroInfo.debuff.length > 0) {
|
||||
for (const dbuffConf of heroInfo.debuff) {
|
||||
this.addDebuff(dbuffConf);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新计算所有属性
|
||||
this.recalculateAttrs();
|
||||
}
|
||||
|
||||
// ==================== BUFF管理 ====================
|
||||
/**
|
||||
* 添加 buff 效果
|
||||
* @param buffConf buff 配置 (来自 SkillSet.BuffConf 或 heroSet.buff)
|
||||
*/
|
||||
addBuff(buffConf: BuffConf) {
|
||||
// 基于类型和持续时间分类存储
|
||||
if (buffConf.BType === BType.VALUE) {
|
||||
// 数值型 buff
|
||||
if (buffConf.buC === 0) {
|
||||
// 持久型
|
||||
this.V_BUFF.push({...buffConf});
|
||||
} else {
|
||||
// 临时型 - 添加剩余时间属性
|
||||
this.V_BUFFS.push({
|
||||
...buffConf,
|
||||
remainTime: buffConf.buC
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 百分比型 buff
|
||||
if (buffConf.buC === 0) {
|
||||
// 持久型
|
||||
this.R_BUFF.push({...buffConf});
|
||||
} else {
|
||||
// 临时型 - 添加剩余时间属性
|
||||
this.R_BUFFS.push({
|
||||
...buffConf,
|
||||
remainTime: buffConf.buC
|
||||
});
|
||||
}
|
||||
}
|
||||
// 立即重新计算属性
|
||||
this.recalculateAttrs();
|
||||
}
|
||||
|
||||
// ==================== DEBUFF管理 ====================
|
||||
/**
|
||||
* 添加 debuff 效果
|
||||
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf 或 heroSet.debuff)
|
||||
*
|
||||
* 支持两种 debuff:
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs)
|
||||
* 2. 状态型 debuff:只缓存状态(无对应的 Attrs,用于状态检查)
|
||||
*/
|
||||
addDebuff(dbuffConf: DbuffConf) {
|
||||
// 获取 debuff 对应的属性字段
|
||||
// attrField = -1 表示状态类 debuff(只缓存,不修改属性)
|
||||
// attrField >= 0 表示属性类 debuff(会修改属性)
|
||||
const attrField = getAttrFieldFromDebuff(dbuffConf.debuff);
|
||||
|
||||
// 基于类型和持续时间分类存储
|
||||
if (dbuffConf.BType === BType.VALUE) {
|
||||
// 数值型 debuff
|
||||
if (dbuffConf.deC === 0) {
|
||||
// 持久型
|
||||
this.V_DBUFF.push({
|
||||
...dbuffConf,
|
||||
attrField: attrField
|
||||
});
|
||||
} else {
|
||||
// 临时型 - 添加剩余时间属性
|
||||
this.V_DBUFFS.push({
|
||||
...dbuffConf,
|
||||
attrField: attrField,
|
||||
remainTime: dbuffConf.deC
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 百分比型 debuff
|
||||
if (dbuffConf.deC === 0) {
|
||||
// 持久型
|
||||
this.R_DBUFF.push({
|
||||
...dbuffConf,
|
||||
attrField: attrField
|
||||
});
|
||||
} else {
|
||||
// 临时型 - 添加剩余时间属性
|
||||
this.R_DBUFFS.push({
|
||||
...dbuffConf,
|
||||
attrField: attrField,
|
||||
remainTime: dbuffConf.deC
|
||||
});
|
||||
}
|
||||
}
|
||||
// 立即重新计算属性
|
||||
this.recalculateAttrs();
|
||||
}
|
||||
|
||||
// ==================== 属性计算系统 ====================
|
||||
/**
|
||||
* 重新计算所有角色属性
|
||||
* 基于基础属性 + 所有有效的 buff/debuff 计算
|
||||
* 注意:某些属性有初始值(HP_MAX, MP_MAX, DEF, AP, MAP)
|
||||
*/
|
||||
recalculateAttrs() {
|
||||
// 1. 重置为基础值
|
||||
this.Attrs[Attrs.HP_MAX] = this.base_hp;
|
||||
this.Attrs[Attrs.MP_MAX] = this.base_mp;
|
||||
this.Attrs[Attrs.DEF] = this.base_def;
|
||||
this.Attrs[Attrs.AP] = this.base_ap;
|
||||
this.Attrs[Attrs.MAP] = this.base_map;
|
||||
this.Attrs[Attrs.SHIELD_MAX] = 0; // 护盾默认为 0
|
||||
|
||||
// 2. 初始化其他属性(无初始值的)
|
||||
for (let i = 0; i <= 26; i++) {
|
||||
if (!(i in this.Attrs) ||
|
||||
(i !== Attrs.HP_MAX && i !== Attrs.MP_MAX && i !== Attrs.DEF &&
|
||||
i !== Attrs.AP && i !== Attrs.MAP && i !== Attrs.SHIELD_MAX)) {
|
||||
this.Attrs[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 应用数值型 buff (持久 + 临时)
|
||||
this.applyValueBuffs();
|
||||
|
||||
// 4. 应用百分比型 buff (持久 + 临时)
|
||||
this.applyRatioBuffs();
|
||||
|
||||
// 5. 应用数值型 debuff (持久 + 临时)
|
||||
this.applyValueDebuffs();
|
||||
|
||||
// 6. 应用百分比型 debuff (持久 + 临时)
|
||||
this.applyRatioDebuffs();
|
||||
|
||||
// 7. 确保关键属性不为负数
|
||||
this.clampAttrs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用数值型 buff
|
||||
*/
|
||||
private applyValueBuffs() {
|
||||
// 持久型 buff
|
||||
for (const buff of this.V_BUFF) {
|
||||
if (buff.buff !== undefined) {
|
||||
this.Attrs[buff.buff] += buff.buV;
|
||||
}
|
||||
}
|
||||
|
||||
// 临时型 buff
|
||||
for (const buff of this.V_BUFFS) {
|
||||
if (buff.buff !== undefined) {
|
||||
this.Attrs[buff.buff] += buff.buV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用百分比型 buff
|
||||
* 百分比型 buff 是基于基础属性的百分比增加
|
||||
*/
|
||||
private applyRatioBuffs() {
|
||||
// 获取基础值映射
|
||||
const baseValues: Record<number, number> = {};
|
||||
baseValues[Attrs.HP_MAX] = this.base_hp;
|
||||
baseValues[Attrs.MP_MAX] = this.base_mp;
|
||||
baseValues[Attrs.DEF] = this.base_def;
|
||||
baseValues[Attrs.AP] = this.base_ap;
|
||||
baseValues[Attrs.MAP] = this.base_map;
|
||||
|
||||
// 持久型 buff
|
||||
for (const buff of this.R_BUFF) {
|
||||
if (buff.buff !== undefined) {
|
||||
const baseVal = baseValues[buff.buff] || this.Attrs[buff.buff];
|
||||
this.Attrs[buff.buff] += Math.floor(baseVal * (buff.buV / 100));
|
||||
}
|
||||
}
|
||||
|
||||
// 临时型 buff
|
||||
for (const buff of this.R_BUFFS) {
|
||||
if (buff.buff !== undefined) {
|
||||
const baseVal = baseValues[buff.buff] || this.Attrs[buff.buff];
|
||||
this.Attrs[buff.buff] += Math.floor(baseVal * (buff.buV / 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用数值型 debuff
|
||||
*/
|
||||
private applyValueDebuffs() {
|
||||
// 持久型 debuff
|
||||
for (const debuff of this.V_DBUFF) {
|
||||
// 跳过状态类 debuff(attrField === -1)
|
||||
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
|
||||
this.Attrs[debuff.attrField] -= debuff.dev;
|
||||
}
|
||||
}
|
||||
|
||||
// 临时型 debuff
|
||||
for (const debuff of this.V_DBUFFS) {
|
||||
// 跳过状态类 debuff(attrField === -1)
|
||||
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
|
||||
this.Attrs[debuff.attrField] -= debuff.dev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用百分比型 debuff
|
||||
* 百分比型 debuff 是基于基础属性的百分比减少
|
||||
*/
|
||||
private applyRatioDebuffs() {
|
||||
// 获取基础值映射
|
||||
const baseValues: Record<number, number> = {};
|
||||
baseValues[Attrs.HP_MAX] = this.base_hp;
|
||||
baseValues[Attrs.MP_MAX] = this.base_mp;
|
||||
baseValues[Attrs.DEF] = this.base_def;
|
||||
baseValues[Attrs.AP] = this.base_ap;
|
||||
baseValues[Attrs.MAP] = this.base_map;
|
||||
|
||||
// 持久型 debuff
|
||||
for (const debuff of this.R_DBUFF) {
|
||||
// 跳过状态类 debuff(attrField === -1)
|
||||
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
|
||||
const baseVal = baseValues[debuff.attrField] || this.Attrs[debuff.attrField];
|
||||
this.Attrs[debuff.attrField] -= Math.floor(baseVal * (debuff.dev / 100));
|
||||
}
|
||||
}
|
||||
|
||||
// 临时型 debuff
|
||||
for (const debuff of this.R_DBUFFS) {
|
||||
// 跳过状态类 debuff(attrField === -1)
|
||||
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
|
||||
const baseVal = baseValues[debuff.attrField] || this.Attrs[debuff.attrField];
|
||||
this.Attrs[debuff.attrField] -= Math.floor(baseVal * (debuff.dev / 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保关键属性不为负数
|
||||
*/
|
||||
private clampAttrs() {
|
||||
// HP_MAX 最少 1
|
||||
this.Attrs[Attrs.HP_MAX] = Math.max(1, this.Attrs[Attrs.HP_MAX]);
|
||||
// MP_MAX 最少 1
|
||||
this.Attrs[Attrs.MP_MAX] = Math.max(1, this.Attrs[Attrs.MP_MAX]);
|
||||
// DEF 最少 0
|
||||
this.Attrs[Attrs.DEF] = Math.max(0, this.Attrs[Attrs.DEF]);
|
||||
// AP 最少 0
|
||||
this.Attrs[Attrs.AP] = Math.max(0, this.Attrs[Attrs.AP]);
|
||||
// MAP 最少 0
|
||||
this.Attrs[Attrs.MAP] = Math.max(0, this.Attrs[Attrs.MAP]);
|
||||
// 百分比属性限制在 0-100 之间
|
||||
this.Attrs[Attrs.CRITICAL] = Math.max(0, Math.min(85, this.Attrs[Attrs.CRITICAL]));
|
||||
this.Attrs[Attrs.DODGE] = Math.max(0, Math.min(85, this.Attrs[Attrs.DODGE]));
|
||||
this.Attrs[Attrs.HIT] = Math.max(0, Math.min(85, this.Attrs[Attrs.HIT]));
|
||||
}
|
||||
|
||||
// ==================== 临时 BUFF/DEBUFF 更新 ====================
|
||||
/**
|
||||
* 更新临时 buff/debuff 的剩余时间
|
||||
* 应在 update 中定期调用
|
||||
* @param dt 时间差
|
||||
*/
|
||||
updateTemporaryBuffsDebuffs(dt: number) {
|
||||
let needRecalculate = false;
|
||||
|
||||
// 更新临时型数值 buff
|
||||
for (let i = this.V_BUFFS.length - 1; i >= 0; i--) {
|
||||
this.V_BUFFS[i].remainTime -= dt;
|
||||
if (this.V_BUFFS[i].remainTime <= 0) {
|
||||
this.V_BUFFS.splice(i, 1);
|
||||
needRecalculate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型百分比 buff
|
||||
for (let i = this.R_BUFFS.length - 1; i >= 0; i--) {
|
||||
this.R_BUFFS[i].remainTime -= dt;
|
||||
if (this.R_BUFFS[i].remainTime <= 0) {
|
||||
this.R_BUFFS.splice(i, 1);
|
||||
needRecalculate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型数值 debuff
|
||||
for (let i = this.V_DBUFFS.length - 1; i >= 0; i--) {
|
||||
this.V_DBUFFS[i].remainTime -= dt;
|
||||
if (this.V_DBUFFS[i].remainTime <= 0) {
|
||||
this.V_DBUFFS.splice(i, 1);
|
||||
needRecalculate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型百分比 debuff
|
||||
for (let i = this.R_DBUFFS.length - 1; i >= 0; i--) {
|
||||
this.R_DBUFFS[i].remainTime -= dt;
|
||||
if (this.R_DBUFFS[i].remainTime <= 0) {
|
||||
this.R_DBUFFS.splice(i, 1);
|
||||
needRecalculate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有 buff/debuff 过期,重新计算属性
|
||||
if (needRecalculate) {
|
||||
this.recalculateAttrs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
update(dt: number){
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
// if(this.is_dead) {
|
||||
@@ -119,7 +515,8 @@ export class HeroViewComp extends CCComp {
|
||||
this.in_stop(dt);
|
||||
// 处理伤害队列
|
||||
this.processDamageQueue();
|
||||
|
||||
// 更新临时 buff/debuff 时间
|
||||
this.updateTemporaryBuffsDebuffs(dt);
|
||||
}
|
||||
BaseUp(dt:number){
|
||||
this.mp += HeroUpSet.MP*dt
|
||||
|
||||
Reference in New Issue
Block a user