From 2d1e8f14952171c3aa12cb9ceca7a60b0150f573 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 13 Oct 2023 18:21:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20fight.Round=20?= =?UTF-8?q?=E5=9C=A8=E5=9B=9E=E5=90=88=E5=86=85=E6=89=A7=E8=A1=8C=20Action?= =?UTF-8?q?Refresh=20=E7=AD=89=E6=93=8D=E4=BD=9C=E7=9A=84=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/fight/round.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/game/fight/round.go b/game/fight/round.go index 4baa9f7..bd68adb 100644 --- a/game/fight/round.go +++ b/game/fight/round.go @@ -5,6 +5,7 @@ import ( "github.com/kercylan98/minotaur/utils/random" "github.com/kercylan98/minotaur/utils/slice" "github.com/kercylan98/minotaur/utils/timer" + "sync" "time" ) @@ -65,6 +66,8 @@ type Round[Data RoundData] struct { changeEventHandles []RoundChangeEvent[Data] // 游戏回合变更事件 actionTimeoutEventHandles []RoundActionTimeoutEvent[Data] // 行动超时事件 actionRefreshEventHandles []RoundActionRefreshEvent[Data] // 行动刷新事件 + + actionMutex sync.Mutex } // GetData 获取游戏数据 @@ -77,6 +80,8 @@ func (slf *Round[Data]) GetData() Data { func (slf *Round[Data]) Start() { slf.currentEntity = -1 slf.round = 1 + slf.actionMutex.Lock() + defer slf.actionMutex.Unlock() slf.loop(false) } @@ -157,7 +162,11 @@ func (slf *Round[Data]) SkipCamp() { // ActionRefresh 刷新行动超时时间 func (slf *Round[Data]) ActionRefresh() { slf.actionTimeoutTime = time.Now().Add(slf.actionTimeout).Unix() - slf.ticker.After(slf.actionTimeoutTickerName, slf.actionTimeout, slf.loop, true) + slf.ticker.After(slf.actionTimeoutTickerName, slf.actionTimeout, func(timeout bool) { + slf.actionMutex.Lock() + defer slf.actionMutex.Unlock() + slf.loop(timeout) + }, true) } // ActionFinish 结束行动 @@ -166,6 +175,8 @@ func (slf *Round[Data]) ActionFinish() { if slf.shareAction { slf.currentEntity = -1 } + slf.actionMutex.Lock() + defer slf.actionMutex.Unlock() slf.loop(false) }