Files
bl/logic/controller/item_sale.go
xinian c9b5f8569f
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
fix: 修复道具扣除和宠物融合事务处理问题
2026-04-14 13:06:28 +08:00

31 lines
898 B
Go

package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/fight"
"blazing/logic/service/player"
"github.com/gogf/gf/v2/util/gconv"
)
// ItemSale 出售道具
// data: 包含道具ID和数量的输入信息
// c: 当前玩家对象
// 返回: 空结果和错误码
func (h Controller) ItemSale(data *C2S_ITEM_SALE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.Service.Item.CheakItem(data.ItemId) < int64(data.Amount) {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if err := c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount)); err != nil {
return nil, errorcode.ErrorCodes.ErrInsufficientItems
}
itemConfig := xmlres.ItemsMAP[int(data.ItemId)]
if itemConfig.SellPrice != 0 {
c.Info.Coins += int64(int64(data.Amount) * int64(itemConfig.SellPrice))
}
return result, 0
}