Files
bl/logic/controller/item_sale.go

31 lines
898 B
Go
Raw Permalink Normal View History

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: 当前玩家对象
// 返回: 空结果和错误码
2026-04-05 07:24:36 +08:00
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
}