Files
bl/logic/service/space/arena.go
昔念 f90581e0f6 ```
feat(fight): 优化擂台战斗逻辑与状态管理

- 修改了擂台主人设置逻辑,引入 `Set` 方法统一处理玩家信息更新
- 增加对擂主是否可战斗的判断,防止无效挑战
- 调整连胜计算和广播机制,确保数据一致性
- 修复擂台挑战失败时的状态回滚问题
- 引入错误码替代硬编码返回值,提高代码可读性与维护性
- 统一访问擂台玩家的方式,移除冗余字段
2025-11-28 00:16:51 +08:00

46 lines
918 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package space
import (
"blazing/logic/service/common"
"sync/atomic"
)
type ARENA struct {
ARENA_Player common.PlayerI `struc:"skip"`
Flag uint32 // 0=清除ArenaInfoflag为0时其他字段全为空 1=站上擂台的信息 2=挑战中的信息
UserID uint32
Nick string `struc:"[16]byte"`
HostWins uint32 // 应该是擂台人的连胜数
ChallengerID uint32 // 挑战者的userid
}
func (t *ARENA) Reset() {
t.Flag = 0
t.UserID = 0
t.Nick = ""
t.HostWins = 0
t.ChallengerID = 0
t.ARENA_Player = nil
}
func (t *ARENA) Set(c common.PlayerI) bool {
if c.GetInfo().UserID == atomic.LoadUint32(&t.UserID) {
t.HostWins += 1 //连胜+1
} else {
t.HostWins = 0 //连胜重置
t.UserID = c.GetInfo().UserID //添加用户ID
t.Nick = c.GetInfo().Nick
t.ARENA_Player = c //添加用户
}
atomic.StoreUint32(&t.Flag, 1)
return true
}