```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(item): 调整玄彩道具使用数量限制

玄彩道具检查逻辑从 items <= 0 修改为 items < 100,
确保玩家拥有至少100个道具才能使用。

fix(fight): 修复战斗操作通道阻塞问题

添加10秒超时机制到战斗操作通道发送逻辑中,
避免通道满载时的
This commit is contained in:
昔念
2026-02-23 10:21:58 +08:00
parent c78e8e13c3
commit 4fff047c4c
3 changed files with 27 additions and 8 deletions

View File

@@ -102,7 +102,7 @@ func (h Controller) handlexuancaiItem(currentPet *model.PetInfo, c *player.Playe
return errorcode.ErrorCodes.ErrItemUnusable return errorcode.ErrorCodes.ErrItemUnusable
} }
items := c.Service.Item.CheakItem(uint32(xmlres.PetMAP[int(currentPet.ID)].Type) + 400686) items := c.Service.Item.CheakItem(uint32(xmlres.PetMAP[int(currentPet.ID)].Type) + 400686)
if items <= 0 { if items < 100 {
return errorcode.ErrorCodes.ErrInsufficientItems return errorcode.ErrorCodes.ErrInsufficientItems
} }
c.Service.Item.UPDATE(uint32(items), -100) c.Service.Item.UPDATE(uint32(items), -100)

View File

@@ -7,6 +7,7 @@ import (
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/fight/input" "blazing/logic/service/fight/input"
"context" "context"
"time"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
) )
@@ -77,7 +78,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
case f.actionChan <- ret: case f.actionChan <- ret:
// 发送成功,可选记录日志 // 发送成功,可选记录日志
// log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id)
default: case <-time.After(time.Second * 10):
// 通道满时的降级处理 // 通道满时的降级处理
cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d", cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d",
c.GetInfo().UserID, id) c.GetInfo().UserID, id)
@@ -119,7 +120,7 @@ func (f *FightC) UseSkill(c common.PlayerI, id uint32) {
case f.actionChan <- ret: case f.actionChan <- ret:
// 发送成功,可选记录日志 // 发送成功,可选记录日志
// log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id) // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id)
default: case <-time.After(time.Second * 10):
// 通道满时的降级处理 // 通道满时的降级处理
cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d", cool.Logger.Printf(context.Background(), "actionChan is full, failed to send skill, userID: %d, skillID: %d",
c.GetInfo().UserID, id) c.GetInfo().UserID, id)
@@ -136,7 +137,7 @@ func (f *FightC) Capture(c common.PlayerI, id uint32) {
case f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}: 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) // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id)
default: case <-time.After(time.Second * 10):
// 通道满时的降级处理 // 通道满时的降级处理
cool.Logger.Printf(context.Background(), "actionChan is full, failed to send Capture, userID: %d ", cool.Logger.Printf(context.Background(), "actionChan is full, failed to send Capture, userID: %d ",
c.GetInfo().UserID) c.GetInfo().UserID)
@@ -154,7 +155,7 @@ func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) {
case f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}: 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) // log.Printf("send skill success, userID: %d, skillID: %d", c.GetInfo().UserID, id)
default: case <-time.After(time.Second * 10):
// 通道满时的降级处理 // 通道满时的降级处理
cool.Logger.Printf(context.Background(), "actionChan is full, failed to send UseItem, userID: %d, skillID: %d", cool.Logger.Printf(context.Background(), "actionChan is full, failed to send UseItem, userID: %d, skillID: %d",
c.GetInfo().UserID, cacthid) c.GetInfo().UserID, cacthid)

View File

@@ -3,24 +3,42 @@ package service
import ( import (
"blazing/cool" "blazing/cool"
"blazing/modules/player/model" "blazing/modules/player/model"
"time"
) )
type GoldService struct { type GoldService struct {
BaseService BaseService
} }
func (s *GoldService) Cheak(pid, count uint32) {
}
func (s *GoldService) Log(pid, count uint32) { func (s *GoldService) Log(pid, count uint32) {
if cool.Config.ServerInfo.IsVip != 0 { if cool.Config.ServerInfo.IsVip != 0 {
return return
} }
// 获取当前时间
now := time.Now()
// 提取年份
year := uint32(now.Year())
// 构造消费时间数组 [月, 周, 日]
// ISOWeek返回周数这里只取周数Day()返回当月的第几天
_, week := now.ISOWeek()
consumeTime := []uint32{
uint32(now.Month()), // 月份
uint32(week), // 周数
uint32(now.Day()), // 日期
}
record := &model.GoldBeanConsume{ record := &model.GoldBeanConsume{
PlayerID: uint64(s.userid), PlayerID: uint64(s.userid),
ConsumeNum: count, ConsumeNum: count,
BizID: pid, BizID: pid,
Year: year, // 补充年份
Consume: consumeTime, // 补充消费时间(月-周-日)
} }
s.dbm(s.Model).Data(record).Insert()
return
} }