feat: 优化游戏事件日志显示逻辑,优先使用 event.message 并完善 isMe 判断。
This commit is contained in:
parent
0367a8db8c
commit
83377543f8
@ -718,23 +718,26 @@ export default {
|
||||
},
|
||||
handleEvent(event) {
|
||||
if (event.type === 'damage' || event.type === 'heal' || event.type === 'item' || event.type === 'ability') {
|
||||
const isMe = event.targetUserId === this.myUserId;
|
||||
const iAmTarget = isMe;
|
||||
const attackerName = event.playerName || '对手';
|
||||
const isMe = event.playerID === this.myUserId || event.targetUserId === this.myUserId;
|
||||
const iAmTarget = event.targetUserId === this.myUserId;
|
||||
const attackerName = event.playerName || '系统';
|
||||
const itemDisplayName = this.guideItems.find(i => i.i === event.itemId)?.n || event.itemId;
|
||||
|
||||
let msg = '';
|
||||
if (event.type === 'item') msg = `发现了 ${itemDisplayName}`;
|
||||
else if (event.type === 'damage') msg = `受到了 ${event.value} 点伤害`;
|
||||
else if (event.type === 'heal') msg = `回复了 ${event.value} 点生命`;
|
||||
// 优先使用服务端传来的 message 字段
|
||||
let msg = event.message;
|
||||
if (!msg) {
|
||||
if (event.type === 'item') msg = `发现了 ${itemDisplayName}`;
|
||||
else if (event.type === 'damage') msg = `受到了 ${event.value} 点伤害`;
|
||||
else if (event.type === 'heal') msg = `回复了 ${event.value} 点生命制`;
|
||||
}
|
||||
|
||||
if (isMe) this.addLog('effect', `指令提示: ${msg}`);
|
||||
if (isMe) this.addLog('effect', msg);
|
||||
else this.addLog('effect', `${attackerName.substring(0,8)}: ${msg}`);
|
||||
|
||||
if (event.type === 'damage' || event.type === 'item') {
|
||||
if (iAmTarget && event.value) this.spawnLabel(0, 0, `-${event.value}`, 'damage', undefined, this.myUserId);
|
||||
}
|
||||
// 对于 opCode 5 的 damage 事件,也触发特效(通常 opCode 2 会覆盖,但多触发一次无妨,作为保险)
|
||||
// 对于 opCode 5 的 damage 事件,也触发特效
|
||||
if (event.type === 'damage' && iAmTarget) this.triggerDamageEffect(this.myUserId, event.value);
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user