2025-11-25 12:29:50 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/data/xmlres"
|
|
|
|
|
"blazing/common/socket/errorcode"
|
|
|
|
|
|
|
|
|
|
"blazing/logic/service/item"
|
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-21 18:17:25 +00:00
|
|
|
// 防止封包通过领取来获取道具
|
|
|
|
|
|
|
|
|
|
// 领取道具包校验价格
|
2025-11-25 12:29:50 +08:00
|
|
|
func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
tt, ok := xmlres.ItemsMAP[int(data.ItemId)]
|
|
|
|
|
if ok && tt.Price != 0 && c.UseCoins(data.Count*uint32(tt.Price)) {
|
|
|
|
|
|
2025-12-08 21:11:12 +08:00
|
|
|
r := c.ItemAdd(data.ItemId, data.Count)
|
|
|
|
|
if r {
|
2025-11-25 12:29:50 +08:00
|
|
|
return &item.BuyOutboundInfo{
|
|
|
|
|
ItemId: data.ItemId,
|
|
|
|
|
Level: 1,
|
|
|
|
|
Count: data.Count,
|
|
|
|
|
Coins: c.Info.Coins,
|
|
|
|
|
}, 0
|
|
|
|
|
}
|
|
|
|
|
//购买失败,返还豆子
|
2025-12-08 21:11:12 +08:00
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
c.Info.Coins += data.Count * uint32(tt.Price)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &item.BuyOutboundInfo{
|
|
|
|
|
|
|
|
|
|
Coins: c.Info.Coins,
|
|
|
|
|
}, 0
|
|
|
|
|
}
|
|
|
|
|
func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-08 21:11:12 +08:00
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
for _, v := range data.ItemIds {
|
2025-12-08 21:11:12 +08:00
|
|
|
iteminfo, ok := xmlres.ItemsMAP[int(v)]
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
if ok {
|
2025-12-08 21:11:12 +08:00
|
|
|
if !c.UseCoins(uint32(iteminfo.Price)) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if c.ItemAdd(v, 1) {
|
|
|
|
|
c.Info.Coins -= uint32(iteminfo.Price)
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &item.BuyMultiOutboundInfo{
|
|
|
|
|
|
|
|
|
|
Coins: c.Info.Coins,
|
|
|
|
|
}, 0
|
|
|
|
|
}
|
|
|
|
|
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
|
|
|
|
r := xmlres.GoldProductMap[int(data.ProductID)]
|
2025-12-17 00:05:03 +08:00
|
|
|
usegold := uint32(data.Count) * uint32(gconv.Float64(r.Price)*100)
|
2025-12-08 21:11:12 +08:00
|
|
|
if !c.UseGold(usegold) {
|
2025-11-25 12:29:50 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
2025-12-06 23:59:00 +08:00
|
|
|
|
2025-12-08 21:11:12 +08:00
|
|
|
isbuycot := c.ItemAdd(uint32(gconv.Uint32(r.ItemID)), uint32(data.Count))
|
|
|
|
|
if isbuycot {
|
2025-12-17 00:05:03 +08:00
|
|
|
c.User.UpdateGold(c.Info.UserID, -int64(usegold))
|
2025-12-08 21:11:12 +08:00
|
|
|
result = &item.S2C_GoldBuyProductInfo{
|
|
|
|
|
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
|
|
|
|
PayGold: usegold,
|
|
|
|
|
Reserved: 0,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
result = &item.S2C_GoldBuyProductInfo{
|
2025-12-06 23:59:00 +08:00
|
|
|
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
2025-12-08 21:11:12 +08:00
|
|
|
PayGold: 0,
|
2025-11-25 12:29:50 +08:00
|
|
|
Reserved: 0,
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
}
|