refactor: 重构战斗系统动作提交和竞技场锁定逻辑
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
This commit is contained in:
@@ -5,6 +5,23 @@ import (
|
||||
"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=清除ArenaInfo(flag为0时其他字段全为空) 1=站上擂台的信息 2=挑战中的信息
|
||||
@@ -15,6 +32,7 @@ type ARENA struct {
|
||||
}
|
||||
|
||||
func (t *ARENA) Reset() {
|
||||
syncArenaHostFlags(t.ARENA_Player, false)
|
||||
|
||||
t.Flag = 0
|
||||
t.UserID = 0
|
||||
@@ -23,21 +41,22 @@ func (t *ARENA) Reset() {
|
||||
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 //添加用户
|
||||
}
|
||||
t.ARENA_Player = c //添加用户
|
||||
syncArenaHostFlags(c, true)
|
||||
|
||||
atomic.StoreUint32(&t.Flag, 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user