feat(player): 添加 UseCoins 方法统一处理玩家金币消耗逻辑

重构购买物品和变更外观功能,使用 UseCoins 方法替代手动操作 Coins 字段,
确保金币扣除的安全性和一致性。同时修复可能因并发导致的金币超扣问题。

此外,调整部分战斗系统接口参数传递方式,将 DamageZone 指
This commit is contained in:
2025-11-13 21:36:18 +08:00
parent 6e01848b04
commit 5e3d558d30
24 changed files with 306 additions and 114 deletions

View File

@@ -69,8 +69,12 @@ func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *
return nil, -1
}
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
c.Info.Coins -= 200
if !c.UseCoins(200) { //如果花不了200,直接返回
return
}
c.Info.Color = data.Color
c.Info.Texture = 0
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, v common.PlayerI) {
data.Head.Result = 0
@@ -86,7 +90,9 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
return nil, -1
}
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
c.Info.Coins -= 200
if !c.UseCoins(200) { //如果花不了200,直接返回
return
}
c.Info.Texture = data.Id
c.Info.Color = data.Color
defer space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, v common.PlayerI) {