2025-11-25 12:29:50 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/data/xmlres"
|
|
|
|
|
"blazing/common/socket/errorcode"
|
2026-01-10 03:14:23 +08:00
|
|
|
"blazing/modules/config/service"
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
"blazing/logic/service/item"
|
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-21 18:17:25 +00:00
|
|
|
// 防止封包通过领取来获取道具
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// BuyItem 购买单个道具
|
2025-12-25 12:26:18 +08:00
|
|
|
// data: 包含购买道具信息的输入数据
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
// 返回: 购买结果和错误码
|
|
|
|
|
func (h Controller) BuyItem(data *item.BuyInboundInfo, player *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
itemInfo, exists := xmlres.ItemsMAP[int(data.ItemId)]
|
|
|
|
|
if !exists {
|
2025-12-25 12:26:18 +08:00
|
|
|
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
2025-12-23 10:46:17 +08:00
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// 免费道具直接添加
|
|
|
|
|
if itemInfo.Price == 0 {
|
2025-12-25 12:26:18 +08:00
|
|
|
if player.ItemAdd(data.ItemId, data.Count) {
|
2025-11-25 12:29:50 +08:00
|
|
|
return &item.BuyOutboundInfo{
|
|
|
|
|
ItemId: data.ItemId,
|
|
|
|
|
Level: 1,
|
|
|
|
|
Count: data.Count,
|
2025-12-25 12:26:18 +08:00
|
|
|
Coins: player.Info.Coins,
|
2025-11-25 12:29:50 +08:00
|
|
|
}, 0
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
2025-12-23 10:46:17 +08:00
|
|
|
}
|
2025-12-08 21:11:12 +08:00
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// 需要付费的道具
|
2026-02-12 04:28:20 +08:00
|
|
|
totalCost := int64(data.Count) * int64(itemInfo.Price)
|
2026-01-03 13:53:38 +00:00
|
|
|
if !player.GetCoins(totalCost) {
|
2025-12-25 12:26:18 +08:00
|
|
|
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-25 12:29:50 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
if player.ItemAdd(data.ItemId, data.Count) {
|
|
|
|
|
player.Info.Coins -= totalCost
|
2025-12-23 10:46:17 +08:00
|
|
|
return &item.BuyOutboundInfo{
|
|
|
|
|
ItemId: data.ItemId,
|
|
|
|
|
Level: 1,
|
|
|
|
|
Count: data.Count,
|
2025-12-25 12:26:18 +08:00
|
|
|
Coins: player.Info.Coins,
|
2025-12-23 10:46:17 +08:00
|
|
|
}, 0
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// 购买失败,返还赛尔豆
|
2025-12-25 12:26:18 +08:00
|
|
|
player.Info.Coins += totalCost
|
|
|
|
|
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
2025-11-25 12:29:50 +08:00
|
|
|
}
|
2025-12-08 21:11:12 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
// BuyMultipleItems 批量购买道具
|
2025-12-25 12:26:18 +08:00
|
|
|
// data: 包含批量购买道具信息的输入数据
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
// 返回: 批量购买结果和错误码
|
|
|
|
|
func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, player *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
for _, itemID := range data.ItemIds {
|
|
|
|
|
itemInfo, exists := xmlres.ItemsMAP[int(itemID)]
|
|
|
|
|
if !exists {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// 免费道具直接添加
|
|
|
|
|
if itemInfo.Price == 0 {
|
2026-02-12 04:28:20 +08:00
|
|
|
player.ItemAdd(int64(itemID), 1)
|
2025-12-23 10:46:17 +08:00
|
|
|
continue
|
|
|
|
|
}
|
2025-12-08 21:11:12 +08:00
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// 需要付费的道具
|
2026-02-12 04:28:20 +08:00
|
|
|
if !player.GetCoins(int64(itemInfo.Price)) {
|
2025-12-23 10:46:17 +08:00
|
|
|
break
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
2026-02-12 04:28:20 +08:00
|
|
|
if player.ItemAdd(int64(itemID), 1) {
|
|
|
|
|
player.Info.Coins -= int64(itemInfo.Price)
|
2025-11-25 12:29:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &item.BuyMultiOutboundInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
Coins: player.Info.Coins,
|
2025-11-25 12:29:50 +08:00
|
|
|
}, 0
|
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
// BuyGoldItem 使用金豆购买商品
|
2025-12-25 12:26:18 +08:00
|
|
|
// data: 包含金豆购买商品信息的输入数据
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
// 返回: 金豆购买结果和错误码
|
2026-01-10 03:14:23 +08:00
|
|
|
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
|
|
|
|
//product, exists := xmlres.GoldProductMap[int(data.ProductID)]
|
|
|
|
|
pro := service.NewShopService().Get(data.ProductID)
|
|
|
|
|
if pro == nil {
|
2026-02-27 00:09:23 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrTooManyProducts
|
2026-01-10 03:14:23 +08:00
|
|
|
}
|
2026-03-27 12:56:29 +08:00
|
|
|
config := service.NewTalkConfigService().GetCache(int(data.ProductID))
|
|
|
|
|
if config != nil {
|
2026-03-28 01:46:52 +08:00
|
|
|
_, ok := player.Service.Talk.Cheak(0, int(data.ProductID))
|
|
|
|
|
if !ok {
|
2026-02-27 00:09:23 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrExceedStock
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 12:56:29 +08:00
|
|
|
// if pro.QuotaType != 0 {
|
|
|
|
|
// if data.Count > int64(pro.QuotaLimit) {
|
|
|
|
|
// return nil, errorcode.ErrorCodes.ErrExceedStock
|
|
|
|
|
// }
|
|
|
|
|
// if player.Service.Talk.Cheak(0, int(data.ProductID)) {
|
|
|
|
|
// return nil, errorcode.ErrorCodes.ErrExceedStock
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2026-01-10 03:14:23 +08:00
|
|
|
var usegold uint64
|
2026-03-28 01:46:52 +08:00
|
|
|
|
2026-01-10 03:14:23 +08:00
|
|
|
switch data.Type {
|
|
|
|
|
case 0:
|
|
|
|
|
if pro.SeerdouPrice == 0 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 04:28:20 +08:00
|
|
|
if !player.GetCoins(data.Count * int64(pro.SeerdouPrice)) {
|
2026-01-10 03:14:23 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
|
|
|
|
usegold = uint64(data.Count) * uint64(pro.SeerdouPrice)
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
if pro.JindouPrice == 0 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 22:09:15 +08:00
|
|
|
if !player.UseGold(int64(data.Count) * int64(pro.JindouPrice) * 100) {
|
2026-01-10 03:14:23 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
|
|
|
|
usegold = uint64(data.Count) * uint64(pro.JindouPrice*100)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
switch data.Type {
|
|
|
|
|
case 0:
|
2026-01-10 03:14:23 +08:00
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
if player.ItemAdd(pro.ProductID, data.Count) {
|
2026-02-12 04:28:20 +08:00
|
|
|
player.Info.Coins -= int64(usegold)
|
2026-03-28 01:46:52 +08:00
|
|
|
}
|
2026-01-10 03:14:23 +08:00
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
case 1:
|
2026-03-28 16:56:00 +08:00
|
|
|
if config != nil {
|
|
|
|
|
r := player.Service.Talk.Update(int(pro.ProductID), int(data.Count))
|
|
|
|
|
if !r {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrGoldBeanSingleLimit
|
|
|
|
|
}
|
2026-03-28 01:46:52 +08:00
|
|
|
}
|
2026-01-10 03:14:23 +08:00
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
if player.ItemAdd(pro.ProductID, data.Count) {
|
|
|
|
|
player.User.UpdateGold(player.Info.UserID, -int64(usegold))
|
2026-01-10 03:14:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
//购买成功,执行记录
|
|
|
|
|
|
2026-01-10 03:14:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 01:46:52 +08:00
|
|
|
player.SendPackCmd(1105, item.GoldOnlineRemainOutboundInfo{
|
|
|
|
|
Coin: player.Info.Coins,
|
|
|
|
|
GoldNumber: uint32(player.User.GetGold(uint(player.Info.UserID))),
|
|
|
|
|
})
|
2026-01-10 03:14:23 +08:00
|
|
|
return nil, -1
|
|
|
|
|
}
|