From 7a0500c5eb12c6ea2f77a38ca978207348666a91 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 9 Jul 2024 15:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=85=B7=E8=AE=B0=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B6=88=E8=80=97=E9=81=93=E5=85=B7=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/itemdatalog.go | 23 +++++++++++++---------- worldsrv/action_welfare.go | 21 +++++++++++++++++++-- worldsrv/bagmgr.go | 35 ++++++++++++++++++++++++++++++++--- worldsrv/welfmgr.go | 18 +++++++++++++++++- 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/model/itemdatalog.go b/model/itemdatalog.go index 2aac2d3..aecc757 100644 --- a/model/itemdatalog.go +++ b/model/itemdatalog.go @@ -24,6 +24,7 @@ type ItemLog struct { TypeId int32 // 变化类型 GameId int32 // 游戏id,游戏中获得时有值 GameFreeId int32 // 场次id,游戏中获得时有值 + Cost []*ItemInfo // 消耗的道具 } func NewItemLog() *ItemLog { @@ -32,16 +33,17 @@ func NewItemLog() *ItemLog { } type ItemParam struct { - Platform string // 平台 - SnId int32 // 玩家id - LogType int32 // 记录类型 0.获取 1.消耗 - ItemId int32 // 道具id - ItemName string // 道具名称 - Count int64 // 个数 - Remark string // 备注 - TypeId int32 // 变化类型 - GameId int64 // 游戏id,游戏中获得时有值 - GameFreeId int64 // 场次id,游戏中获得时有值 + Platform string // 平台 + SnId int32 // 玩家id + LogType int32 // 记录类型 0.获取 1.消耗 + ItemId int32 // 道具id + ItemName string // 道具名称 + Count int64 // 个数 + Remark string // 备注 + TypeId int32 // 变化类型 + GameId int64 // 游戏id,游戏中获得时有值 + GameFreeId int64 // 场次id,游戏中获得时有值 + Cost []*ItemInfo // 消耗的道具 } func NewItemLogEx(param ItemParam) *ItemLog { @@ -57,5 +59,6 @@ func NewItemLogEx(param ItemParam) *ItemLog { itemLog.TypeId = param.TypeId itemLog.GameId = int32(param.GameId) itemLog.GameFreeId = int32(param.GameFreeId) + itemLog.Cost = param.Cost return itemLog } diff --git a/worldsrv/action_welfare.go b/worldsrv/action_welfare.go index 15c7575..98e11e5 100644 --- a/worldsrv/action_welfare.go +++ b/worldsrv/action_welfare.go @@ -1029,6 +1029,7 @@ func CSPermitExchange(s *netlib.Session, packetid int, data interface{}, sid int var items []*Item var costItems []*Item var cost, gain []model.AwardItem + var cost1 []*model.ItemInfo for _, v := range exchangeConfig.GetCost() { item := BagMgrSingleton.GetItem(p.SnId, v.GetItemId()) if item == nil || item.ItemNum < v.GetItemNum() { @@ -1046,6 +1047,10 @@ func CSPermitExchange(s *netlib.Session, packetid int, data interface{}, sid int Id: v.GetItemId(), Num: v.GetItemNum(), }) + cost1 = append(cost1, &model.ItemInfo{ + ItemId: v.GetItemId(), + ItemNum: v.GetItemNum(), + }) } } for _, v := range exchangeConfig.GetGain() { @@ -1064,10 +1069,22 @@ func CSPermitExchange(s *netlib.Session, packetid int, data interface{}, sid int } // 扣除背包物品 for _, item := range costItems { - BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWayPermitExchangeCost, "system", "赛季通行证兑换消耗", 0, 0, false) + BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, + common.GainWayPermitExchangeCost, "system", "赛季通行证兑换消耗", 0, 0, false) } // 增加背包物品 - BagMgrSingleton.AddItems(p, items, 0, common.GainWayPermitExchangeGain, "system", "赛季通行证兑换获得", 0, 0, false) + BagMgrSingleton.AddItemsV2(&ItemParam{ + P: p, + Change: items, + Cost: cost1, + Add: 0, + GainWay: common.GainWayPermitExchangeGain, + Operator: "system", + Remark: "赛季通行证兑换获得", + gameId: 0, + gameFreeId: 0, + noLog: false, + }) p.WelfData.PermitExchange[msg.GetId()] = append(p.WelfData.PermitExchange[msg.GetId()], now.Unix()) // 兑换记录 LogChannelSingleton.WriteLog(&model.BackendPermitExchange{ diff --git a/worldsrv/bagmgr.go b/worldsrv/bagmgr.go index 5e8a688..0a15755 100644 --- a/worldsrv/bagmgr.go +++ b/worldsrv/bagmgr.go @@ -139,6 +139,27 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item { return item } +type ItemParam struct { + P *Player + Change []*Item // 道具变化数量 + Cost []*model.ItemInfo // 获得道具时消耗的道具数量 + Add int64 // 加成数量 + GainWay int32 // 记录类型 + Operator, Remark string // 操作人,备注 + gameId, gameFreeId int64 // 游戏id,场次id + noLog bool // 是否不记录日志 +} + +type AddItemParam struct { + Cost []*model.ItemInfo // 获得道具时消耗的道具数量 +} + +func (this *BagMgr) AddItemsV2(args *ItemParam) (*BagInfo, bag.OpResultCode, bool) { + return this.AddItems(args.P, args.Change, args.Add, args.GainWay, args.Operator, args.Remark, args.gameId, args.gameFreeId, args.noLog, AddItemParam{ + Cost: args.Cost, + }) +} + // AddItems 给玩家背包添加道具 // add 加成数量 // gainWay 记录类型 @@ -147,8 +168,14 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item { // gameId 游戏id // gameFreeId 场次id // noLog 是否不记录日志 +// Deprecated: use [ AddItemsV2 ] instead func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int32, operator, remark string, - gameId, gameFreeId int64, noLog bool) (*BagInfo, bag.OpResultCode, bool) { + gameId, gameFreeId int64, noLog bool, params ...AddItemParam) (*BagInfo, bag.OpResultCode, bool) { + var cost []*model.ItemInfo + if len(params) > 0 { + cost = params[0].Cost + } + longItem := this.GetItem(p.SnId, common.ItemIDPermit) var items []*Item for _, v := range addItems { @@ -278,6 +305,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int TypeId: gainWay, GameId: gameId, GameFreeId: gameFreeId, + Cost: cost, }) if log != nil { LogChannelSingleton.WriteLog(log) @@ -340,9 +368,10 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int } +// Deprecated: use [ AddItemsV2 ] instead func (this *BagMgr) AddItem(p *Player, itemId, itemNum int64, add int64, gainWay int32, operator, remark string, - gameId, gameFreeId int64, noLog bool) (*BagInfo, bag.OpResultCode, bool) { - return this.AddItems(p, []*Item{{ItemId: int32(itemId), ItemNum: itemNum}}, add, gainWay, operator, remark, gameId, gameFreeId, noLog) + gameId, gameFreeId int64, noLog bool, params ...AddItemParam) (*BagInfo, bag.OpResultCode, bool) { + return this.AddItems(p, []*Item{{ItemId: int32(itemId), ItemNum: itemNum}}, add, gainWay, operator, remark, gameId, gameFreeId, noLog, params...) } func (this *BagMgr) AddItemsOffline(platform string, snid int32, addItems []*Item, gainWay int32, operator, remark string, diff --git a/worldsrv/welfmgr.go b/worldsrv/welfmgr.go index a410ca7..13a203e 100644 --- a/worldsrv/welfmgr.go +++ b/worldsrv/welfmgr.go @@ -840,6 +840,7 @@ func (this *WelfareMgr) GetAddUp2Award(p *Player, day int32) { } typeId := addUpDate2Type[0].Id addUpDate2Num := addUpDate2Type[0].Num + var cost []*model.ItemInfo if typeId == 1 { Num += 1 //看广告任务 @@ -855,6 +856,10 @@ func (this *WelfareMgr) GetAddUp2Award(p *Player, day int32) { p.AddDiamond(int64(-addUpDate2Num), 0, common.GainWaySign7Con, "system", "累计签到进阶奖励钻石消耗") logger.Logger.Trace("累计签到进阶奖励,扣除钻石uid = ", p.SnId) EndTime = -1 + cost = append(cost, &model.ItemInfo{ + ItemId: common.ItemIDDiamond, + ItemNum: int64(addUpDate2Num), + }) } p.WelfData.Sign7.Addup2Data[day] = make(map[int32]int64) p.WelfData.Sign7.Addup2Data[day][Num+1] = EndTime @@ -873,7 +878,18 @@ func (this *WelfareMgr) GetAddUp2Award(p *Player, day int32) { items = append(items, item) } } - BagMgrSingleton.AddItems(p, items, 0, common.GainWaySign7Add, "system", "累计签到进阶奖励获得", 0, 0, false) + BagMgrSingleton.AddItemsV2(&ItemParam{ + P: p, + Change: items, + Cost: cost, + Add: 0, + GainWay: common.GainWaySign7Add, + Operator: "system", + Remark: "累计签到进阶奖励获得", + gameId: 0, + gameFreeId: 0, + noLog: false, + }) } //通知客户端 this.UpdateAddUp2Date(p, Num, day, EndTime)