feat(物品系统): 添加物品使用功能及相关配置

- 在GameEvent枚举中添加UseItemCard事件
- 创建ItemSet物品配置表,包含8种不同效果的物品
- 在HeroAttrsComp中添加物品使用逻辑,处理物品效果应用
- 修改MissionCardComp支持物品购买界面和购买逻辑
- 添加物品购买后的视觉反馈和状态管理
This commit is contained in:
panw
2026-01-05 09:54:58 +08:00
parent 08487cd944
commit e576d19255
4 changed files with 218 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import { BuffConf } from "../common/config/SkillSet";
import { HeroInfo, AttrSet } from "../common/config/heroSet";
import { HeroSkillsComp } from "./HeroSkills";
import { smc } from "../common/SingletonModuleComp";
import { ItemSet } from "../common/config/ItemSet";
interface talTrigger{
@@ -78,10 +79,17 @@ export class HeroAttrsComp extends ecs.Comp {
onLoad() {
// 监听升级事件
oops.message.on(GameEvent.CanUpdateLv, this.onLevelUp, this);
oops.message.on(GameEvent.UseItemCard, this.onUseItemCard, this);
}
onDestroy() {
oops.message.off(GameEvent.CanUpdateLv, this.onLevelUp, this);
oops.message.off(GameEvent.UseItemCard, this.onUseItemCard, this);
}
onUseItemCard(event: string, args: any) {
if (!this.is_master) return;
this.useItem(args);
}
/**
@@ -579,9 +587,40 @@ export class HeroAttrsComp extends ecs.Comp {
useValueTalByUuid(t_uuid: number) {
const buff = this.BUFFS_TAL[t_uuid];
if (!buff) return;
const attrIndex = buff.attrIndex;
delete this.BUFFS_TAL[t_uuid];
buff.count--;
if (buff.count <= 0) {
delete this.BUFFS_TAL[t_uuid];
}
this.recalculateSingleAttr(buff.attrIndex);
}
/**
* 使用物品
* @param itemId 物品ID
*/
useItem(itemId: number) {
const item = ItemSet[itemId];
if (!item) return;
console.log(`[HeroAttrs] 使用物品: ${item.name} (${item.desc})`);
// 直接添加到 BUFFS_TEMP
const attrIndex = item.attr;
if (!this.BUFFS_TEMP[attrIndex]) {
this.BUFFS_TEMP[attrIndex] = [];
}
this.BUFFS_TEMP[attrIndex].push({
value: item.value,
BType: item.bType,
remainTime: item.duration
});
// 重新计算受影响的属性
this.recalculateSingleAttr(attrIndex);
oops.gui.toast(`使用了 ${item.name}`);
}
/**