diff --git a/common/data/xmlres/file.go b/common/data/xmlres/file.go index 87dc42696..dd5d0d95b 100644 --- a/common/data/xmlres/file.go +++ b/common/data/xmlres/file.go @@ -52,8 +52,8 @@ var ( ShopMap map[int]ShopItem SkillTypeMap map[int]SkillType RelationsMap map[int]Relation - GoldProductMap = make(map[int]GoldProductItem, 0) - EVOLVMAP map[int]Evolve + //GoldProductMap = make(map[int]GoldProductItem, 0) + EVOLVMAP map[int]Evolve ) func Initfile() { @@ -127,12 +127,12 @@ func Initfile() { } - GoldProductMap = utils.ToMap(getXml[GoldProductConfig](path+"30001.xml").Items, - func(m GoldProductItem) int { - return gconv.Int(m.ProductID) + // GoldProductMap = utils.ToMap(getXml[GoldProductConfig](path+"30001.xml").Items, + // func(m GoldProductItem) int { + // return gconv.Int(m.ProductID) - }, - ) + // }, + // ) } diff --git a/logic/controller/item_buy.go b/logic/controller/item_buy.go index 0be54ea45..20c05db28 100644 --- a/logic/controller/item_buy.go +++ b/logic/controller/item_buy.go @@ -3,9 +3,12 @@ package controller import ( "blazing/common/data/xmlres" "blazing/common/socket/errorcode" + "blazing/modules/config/service" "blazing/logic/service/item" "blazing/logic/service/player" + + "github.com/gogf/gf/v2/util/gconv" ) // 防止封包通过领取来获取道具 @@ -90,34 +93,54 @@ func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, player *pla // data: 包含金豆购买商品信息的输入数据 // player: 当前玩家对象 // 返回: 金豆购买结果和错误码 -// 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)] -// if !exists { -// return nil, errorcode.ErrorCodes.ErrSystemError -// } +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 { + return nil, errorcode.ErrorCodes.ErrSystemError + } + var usegold uint64 + var addSuccess bool + switch data.Type { + case 0: + if pro.SeerdouPrice == 0 { + return nil, errorcode.ErrorCodes.ErrSystemError + } -// useGold := uint32(data.Count) * uint32(gconv.Float64(product.Price)*100) -// if !player.UseGold(useGold) { -// return &item.S2C_GoldBuyProductInfo{ -// Gold: player.User.GetGold(uint(player.Info.UserID)), -// PayGold: 0, -// Reserved: 0, -// }, errorcode.ErrorCodes.ErrXinDouInsufficient -// } + if !player.GetCoins(data.Count * uint32(pro.SeerdouPrice)) { + return nil, errorcode.ErrorCodes.ErrSystemError + } + usegold = uint64(data.Count) * uint64(pro.SeerdouPrice) -// addSuccess := player.ItemAdd(uint32(gconv.Uint32(product.ItemID)), uint32(data.Count)) -// if addSuccess { -// player.User.UpdateGold(player.Info.UserID, -int64(useGold)) -// return &item.S2C_GoldBuyProductInfo{ -// Gold: player.User.GetGold(uint(player.Info.UserID)), -// PayGold: useGold, -// Reserved: 0, -// }, 0 -// } + case 1: + if pro.JindouPrice == 0 { + return nil, errorcode.ErrorCodes.ErrSystemError + } -// return &item.S2C_GoldBuyProductInfo{ -// Gold: player.User.GetGold(uint(player.Info.UserID)), -// PayGold: 0, -// Reserved: 0, -// }, errorcode.ErrorCodes.ErrSystemError -// } + if !player.UseGold(uint32(data.Count) * uint32(pro.JindouPrice) * 100) { + return nil, errorcode.ErrorCodes.ErrSystemError + } + usegold = uint64(data.Count) * uint64(pro.JindouPrice*100) + + } + + addSuccess = player.ItemAdd(uint32(gconv.Uint32(pro.ProductID)), uint32(data.Count)) + if addSuccess { + + switch data.Type { + case 0: + player.Info.Coins -= uint32(usegold) + + case 1: + player.User.UpdateGold(player.Info.UserID, -int64(usegold)) + + } + + player.SendPackCmd(1105, item.GoldOnlineRemainOutboundInfo{ + Coin: player.Info.Coins, + GoldNumber: player.User.GetGold(uint(player.Info.UserID)), + }) + } + + return nil, -1 +} diff --git a/logic/service/item/buy.go b/logic/service/item/buy.go index ed2005c69..37c6f08ae 100644 --- a/logic/service/item/buy.go +++ b/logic/service/item/buy.go @@ -32,13 +32,14 @@ type BuyMultiOutboundInfo struct { // C2S_GOLD_BUY_PRODUCT 客户端→服务端:金豆购买商品请求 type C2S_GOLD_BUY_PRODUCT struct { Head common.TomeeHeader `cmd:"1104" struc:"skip"` + Type uint32 `json:"type"` //购买类型,0是豆子购买,1是金豆购买 ProductID uint32 `json:"product_id"` // 金豆物品id对应的产品id - Count uint16 `json:"count"` // 购买数量(前端限制金豆物品只能1个1个买) + Count uint32 `json:"count"` // 购买数量(前端限制金豆物品只能1个1个买) } // S2C_GoldBuyProductInfo 服务端→客户端:金豆购买商品结果返回 type S2C_GoldBuyProductInfo struct { Reserved uint32 `json:"reserved"` // 0 空数据(预留字段) - PayGold uint32 `json:"pay_gold"` // 购买物品消耗的金豆数(后端返回值需*100) + Coins uint32 `json:"pay_gold"` // 购买物品消耗的金豆数(后端返回值需*100) Gold uint32 `json:"gold"` // 购买后剩余金豆数(后端返回值需*100) } diff --git a/modules/config/service/shop.go b/modules/config/service/shop.go index dab856955..2ed994c80 100644 --- a/modules/config/service/shop.go +++ b/modules/config/service/shop.go @@ -14,8 +14,16 @@ func NewShopService() *ShopService { &cool.Service{ Model: model.NewShopConfig(), PageQueryOp: &cool.QueryOp{ - KeyWordField: []string{"desc"}, + KeyWordField: []string{"desc", "product_name"}, }, }, } } +func (s *ShopService) Get(product_id uint32) *model.ShopConfig { + m := dbm(s.Model).Where("product_id", product_id) + var tt *model.ShopConfig + m.Scan(&tt) + + return tt + +}