fix: 为战斗动作通道添加非阻塞发送和降级处理
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -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 处理玩家战斗准备逻辑,当满足条件时启动战斗循环
|
||||
|
||||
Reference in New Issue
Block a user