From ae764c946a8b3fca47e20136ee40d56629375c90 Mon Sep 17 00:00:00 2001 From: xinian Date: Sun, 22 Feb 2026 00:49:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=E6=88=98=E6=96=97=E5=8A=A8?= =?UTF-8?q?=E4=BD=9C=E9=80=9A=E9=81=93=E6=B7=BB=E5=8A=A0=E9=9D=9E=E9=98=BB?= =?UTF-8?q?=E5=A1=9E=E5=8F=91=E9=80=81=E5=92=8C=E9=99=8D=E7=BA=A7=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/action.go | 45 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/logic/service/fight/action.go b/logic/service/fight/action.go index ca219f9d5..e2ce408b8 100644 --- a/logic/service/fight/action.go +++ b/logic/service/fight/action.go @@ -1,10 +1,12 @@ package fight import ( + "blazing/cool" "blazing/logic/service/common" "blazing/logic/service/fight/action" "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" + "context" "github.com/jinzhu/copier" ) @@ -71,8 +73,16 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) { BaseAction: action.NewBaseAction(c.GetInfo().UserID), Cid: id, } + select { + case f.actionChan <- ret: + // 发送成功,可选记录日志 + // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) + default: + // 通道满时的降级处理 + cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d", + c.GetInfo().UserID, id) + } - f.actionChan <- ret } // 玩家使用技能 @@ -104,7 +114,16 @@ func (f *FightC) UseSkill(c common.PlayerI, id uint32) { } } - f.actionChan <- ret + // 非阻塞发送,避免goroutine永久阻塞 + select { + case f.actionChan <- ret: + // 发送成功,可选记录日志 + // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) + default: + // 通道满时的降级处理 + cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d", + c.GetInfo().UserID, id) + } } // 玩家使用技能 @@ -113,7 +132,16 @@ func (f *FightC) Capture(c common.PlayerI, id uint32) { return } - f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id} + select { + case f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}: + // 发送成功,可选记录日志 + // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) + default: + // 通道满时的降级处理 + cool.Logger.Printf(context.Background(), "actionChan is full, failed to send Capture, userID: %d ", + c.GetInfo().UserID) + } + } func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) { @@ -121,7 +149,16 @@ func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) { return } - f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid} + + select { + case f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}: + // 发送成功,可选记录日志 + // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) + default: + // 通道满时的降级处理 + cool.Logger.Printf(context.Background(), "actionChan is full, failed to send UseItem, userID: %d, skillID: %d", + c.GetInfo().UserID, cacthid) + } } // ReadyFight 处理玩家战斗准备逻辑,当满足条件时启动战斗循环