| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- package user
- import (
- "bet24.com/log"
- "bet24.com/servers/micros/audioroom/handler/config"
- "bet24.com/servers/micros/audioroom/handler/income"
- pb "bet24.com/servers/micros/audioroom/proto"
- "bet24.com/servers/micros/audioroom/transaction/database"
- badge "bet24.com/servers/micros/badge/proto"
- giftservice "bet24.com/servers/micros/giftservice/proto"
- task "bet24.com/servers/micros/task/proto"
- "fmt"
- )
- // 发送礼物
- func (this *UserRoom) SendGiving(roomId, roomOwner, toUserId, giftId, num int) (retCode int, message string) {
- log.Debug("user_giving.sendGiving userId=%d roomId=%d toUserId=%d giftId=%d num=%d", this.userId, roomId, toUserId, giftId, num)
- var (
- totalDiamond int // 总钻石数
- totalGold int // 总金币数
- sendDiamond int // 每人获得钻石数
- sendGold int // 每人获得金币数
- toUserIds []int // 接收礼物的id群
- )
- // 所有在线用户
- if toUserId == 1 {
- for _, v := range this.roomMgr.GetOnlineUsers(roomId) {
- if v.UserId == this.userId {
- continue
- }
- toUserIds = append(toUserIds, v.UserId)
- }
- } else if this.userId != toUserId {
- toUserIds = append(toUserIds, toUserId)
- }
- // 数量异常
- if len(toUserIds) <= 0 {
- message = fmt.Sprintf("user_giving.sendGiving userId=%d roomId=%d toUserId=%d giftId=%d num=%d is irregular",
- this.userId, roomId, toUserId, giftId, num)
- log.Debug(message)
- return
- }
- // 发送礼物
- retCode, message, result := giftservice.SendGiftBulk(this.userId, toUserIds, giftId, num)
- //log.Debug("user_giving.sendGiving userId=%d roomId=%d toUserId=%d giftId=%d num=%d retCode=%v message=%s result=%+v toUserIds=%+v",
- // this.userId, roomId, toUserId, giftId, num, retCode, message, result, toUserIds)
- // 判断是否成功
- if retCode != 1 {
- message = fmt.Sprintf("user_giving.sendGiving userId=%d roomId=%d toUserId=%d giftId=%d num=%d retCode=%d message=%s result=%+v",
- this.userId, roomId, toUserId, giftId, num, retCode, message, result)
- log.Debug(message)
- return
- }
- cfg := config.Mgr.GetRoomConfig()
- switch result.PayType {
- case giftservice.PayType_Diamond: // 赠送钻石
- sendDiamond = int(result.Price)
- totalDiamond = int(result.Price) * len(toUserIds)
- case giftservice.PayType_Gold: // 赠送金币
- sendGold = int(result.Price)
- totalGold = int(result.Price) * len(toUserIds)
- }
- log.Debug("user_giving.sendGiving userId=%d roomId=%d toUserId=%d giftId=%d num=%d retCode=%v message=%s result=%+v toUserIds=%+v totalDiamond=%d sendDiamond=%d",
- this.userId, roomId, toUserId, giftId, num, retCode, message, result, toUserIds, totalDiamond, sendDiamond)
- // 给所有在线用户赠送礼物
- for _, uid := range toUserIds {
- if uid == this.userId {
- continue
- }
- // 触发收益
- for _, v := range result.Items {
- income.TriggerGiftIncome(this.userId, pb.TriggerData{
- RoomId: roomId,
- Receiver: uid,
- RoomOwner: roomOwner,
- ItemType: v.ItemId,
- Amount: v.Count,
- })
- }
- if sendDiamond > 0 {
- go func(uid int) {
- // 触发用户任务
- this.roomMgr.DoUserTaskAction(uid, roomId, pb.UserTask_Action_AcceptGiving_Diamond, sendDiamond, 0)
- // 徽章进度
- badge.DoAction(uid, badge.Action_AudioRoom_ReceiveGivingDiamond, sendDiamond, badge.Scope{})
- badge.DoAction(uid, badge.Action_AudioRoom_ReceiveGivingNum, num, badge.Scope{GiftId: giftId})
- // 触发大厅任务
- task.DoTaskAction(uid, task.TaskAction_receiveGivingDiamond, sendDiamond, task.TaskScope{})
- }(uid)
- }
- // 添加礼物记录
- go database.AddGiftHistory(pb.GiftHistory{
- RoomId: roomId,
- Sender: this.userId,
- Receiver: uid,
- GiftId: giftId,
- GiftNum: num,
- DiamondAmount: sendDiamond,
- GoldAmount: sendGold,
- })
- }
- // 达到大礼物条件
- if totalDiamond >= cfg.GivingDiamondMax || result.AnimationType == giftservice.AnimationType_Global {
- // 发送礼物通知
- go this.givingNotify(roomId, toUserId, result.GiftId, num, totalDiamond >= cfg.GivingDiamondMax)
- }
- // 钻石
- if totalDiamond > 0 {
- go func() {
- // 触发房间任务
- this.roomMgr.DoRoomTaskAction(this.userId, roomId, pb.RoomTask_Action_Giving_Diamond, totalDiamond)
- // 触发用户任务
- this.roomMgr.DoUserTaskAction(this.userId, roomId, pb.UserTask_Action_SendGiving_Diamond, totalDiamond, 0)
- // 收集点数
- this.roomMgr.AddCollect(this.userId, roomId, totalDiamond)
- // 徽章进度
- badge.DoAction(this.userId, badge.Action_AudioRoom_SendGivingDiamond, totalDiamond, badge.Scope{})
- badge.DoAction(this.userId, badge.Action_AudioRoom_SendGivingNum, num, badge.Scope{GiftId: giftId})
- // 触发大厅任务
- task.DoTaskAction(this.userId, task.TaskAction_diamondGift, 1, task.TaskScope{})
- // 触发大厅任务
- task.DoTaskAction(this.userId, task.TaskAction_sendGivingDiamond, totalDiamond, task.TaskScope{})
- }()
- }
- // 金币
- if totalGold > 0 {
- go func() {
- // 触发任务
- this.roomMgr.DoRoomTaskAction(this.userId, roomId, pb.RoomTask_Action_Giving_Gold, totalGold)
- // 徽章进度
- badge.DoAction(this.userId, badge.Action_PropConsumeGold, totalGold, badge.Scope{})
- }()
- }
- retCode, message = 1, "success"
- return
- }
|