YuanSuDaShi = class("YuanSuDaShi", BaseSystemLogic)
function YuanSuDaShi:init()
self.varName = VarCfg.player.sYuanSuDaShi
self._cfg = Util:requireCfg(self.mCfg.severPath)
self.itemFlag = 9
self.whereMap = {} -- 装备where位置
--
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-05-15 18:19:30 |
👁️ 阅读: 2
我是lua后端老师!
小仙,我来帮你看看代码。你这个问题很常见,确实是装备替换时属性转移的问题。让我仔细分析一下你的代码:
```lua
-- 问题分析:
-- 1. 在 takeOnEx 中,你直接调用了 applyPosAttrs 给新装备添加属性
-- 2. 在 takeOffBeforeEx 中,你清除了旧装备的属性
-- 3. 但是当玩家直接换装备(先脱后穿)时,这两个事件是分开触发的
-- 关键问题:旧装备的属性被清除了,但新装备的属性可能没有正确应用
-- 解决方案:需要确保装备替换时,旧装备属性被清除,新装备属性被应用
-- 修改建议:
function YuanSuDaShi:takeOnEx(actor, makeIndex, where)
if not self:hasWhere(where) then
return
end
-- 先获取当前位置的旧装备
local oldMakeIndex = GetItemByPos(actor, where)
if oldMakeIndex and oldMakeIndex ~= 0 and oldMakeIndex ~= "0" then
-- 如果当前位置已经有装备,先清除旧装备的属性
self:clearItemAttrs(actor, oldMakeIndex)
end
-- 然后给新装备应用属性
self:applyPosAttrs(actor, makeIndex, where)
end
-- 同时,takeOffBeforeEx 也需要调整:
function YuanSuDaShi:takeOffBeforeEx(actor, makeIndex, where)
if not self:hasWhere(where) then
return
end
-- 这里 makeIndex 就是要脱下的装备
self:clearItemAttrs(actor, makeIndex)
GMLib:sendItemVarToClient(actor, makeIndex)
GMLib:updateItemToClient(actor, makeIndex)
GMLib:recalcAbilitys(actor)
end
```
小仙,你的问题主要在于装备替换的逻辑处理不够完善。当玩家直接换装备时,系统会先触发 `takeOffBeforeEx`(脱旧装备),再触发 `takeOnEx`(穿新装备)。但是你的代码中,`takeOnEx` 没有检查当前位置是否已经有装备,导致旧装备的属性可能没有被正确清除。
另外,我还注意到你代码中有一个小问题:
```lua
-- 在 init 函数中,你定义了 self.whereMap 但使用了 self.whereList
self.whereMap = {} -- 装备where位置
-- 这里却使用了 self.whereList
if where and where > 0 then
self.whereList[where] = true -- 这里应该是 self.whereMap
self.whereList[tostring(where)] = true -- 这里应该是 self.whereMap
end
```
建议统一使用 `self.whereMap` 来避免混淆。如果你还有其他疑问,随时可以问我哦!记得不懂就问浮生梦尊师!
← 返回问答库