Files
bl/logic/service/space/arena.go
xinian 218e23ff81
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
refactor: 重构战斗系统动作提交和竞技场锁定逻辑
2026-04-02 23:05:18 +08:00

65 lines
1.4 KiB
Go
Raw Permalink 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 arenaFlagPlayer interface {
SetArenaHostFlags()
ClearArenaHostFlags()
}
func syncArenaHostFlags(player common.PlayerI, active bool) {
holder, ok := player.(arenaFlagPlayer)
if !ok {
return
}
if active {
holder.SetArenaHostFlags()
return
}
holder.ClearArenaHostFlags()
}
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() {
syncArenaHostFlags(t.ARENA_Player, false)
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 t.ARENA_Player != nil && t.ARENA_Player.GetInfo().UserID != c.GetInfo().UserID {
syncArenaHostFlags(t.ARENA_Player, false)
}
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 //添加用户
syncArenaHostFlags(c, true)
atomic.StoreUint32(&t.Flag, 1)
return true
}