You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.5 KiB
Go

package live_logic
import (
"dcg/app/user_center/usercenter"
"dcg/game/manager"
"dcg/game/pb"
pbCommon "dcg/game/pb/common"
pbMq "dcg/game/pb/mq"
"dcg/game/svc"
"dcg/pkg/cmd"
"dcg/pkg/grpcx"
"git.noahlan.cn/northlan/ntools-go/logger"
"strconv"
)
type commonGameLogic struct {
svcCtx *svc.ServiceContext
*LiveGameLogic
}
func NewCommonLiveGameLogic(svcCtx *svc.ServiceContext) *LiveGameLogic {
resp := &commonGameLogic{
svcCtx: svcCtx,
LiveGameLogic: NewLiveGameLogic(-1, cmd.NewCMDParser(cmd.Pattern{
Prefix: "打卡",
Alias: []string{"签到"},
ContentMaxLen: 0,
})),
}
// 通用指令处理器
resp.RegisterCMDHandler(resp.handleCheckIn, "打卡")
// 通用礼物处理器
resp.RegisterGiftHandler(resp.handleGift)
resp.RegisterNobilityHandler(resp.handleNobility)
return resp.LiveGameLogic
}
func (h *commonGameLogic) handleCheckIn(roomId int64, _ string, _ []rune, user *pbCommon.PbUser) {
room, err := manager.GameManager.RoomByLiveRoomId(roomId)
if err != nil {
return
}
respMsg := &pbCommon.CheckInMsg{User: user}
// RPC - 签到
resp, err := h.svcCtx.UserCenterRpc.UserCheckIn(h.svcCtx.Ctx, &usercenter.UserIdReq{UserId: user.UserId})
if err != nil {
respMsg.Code, respMsg.Msg, _ = grpcx.WrapGrpcErr(err)
} else {
respMsg.Code = 200
respMsg.Msg = "打卡成功"
respMsg.CoinChange = resp.CoinChange
respMsg.IsCritical = resp.IsCritical
}
room.Broadcast(pb.PushCheckIn, respMsg)
}
func (h *commonGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) {
room, err := manager.GameManager.RoomByLiveRoomId(roomId)
if err != nil {
return
}
// 1. 发送通用礼物消息
room.Broadcast(pb.PushGift, &pbCommon.GiftMsg{
User: user,
GiftId: gift.GiftId,
Num: gift.GiftNum,
GiftName: gift.GiftName,
Price: gift.Price,
IsPaid: gift.IsPaid,
})
// 2. RPC 记录送礼,积分变动
req := &usercenter.UserSendGiftReq{
Platform: gift.Platform,
UserId: user.UserId,
PUid: strconv.FormatInt(gift.Uid, 10),
RoomId: strconv.FormatInt(roomId, 10),
GiftId: gift.GiftId,
GiftName: gift.GiftName,
Num: gift.GiftNum,
Price: gift.Price,
IsPaid: gift.IsPaid,
BattleId: manager.GameManager.BattleIdByLiveRoomId(roomId),
}
_, err = h.svcCtx.UserCenterRpc.UserSendGift(h.svcCtx.Ctx, req)
if err != nil {
logger.SLog.Info("rpc 用户送礼记录失败,积分变动不通知了...")
return
}
}
func (h *commonGameLogic) handleNobility(roomId int64, user *pbCommon.PbUser, msg *pbMq.MqNobilityBuy) {
//room, err := manager.GameManager.RoomByLiveRoomId(roomId)
//if err != nil {
// return
//}
//// 1. 发送通用礼物消息
//room.Broadcast(pb.PushGiftNobility, &pbCommon.GiftMsg{
// User: user,
// GiftId: msg.GiftId,
// Num: int64(msg.Num),
// GiftName: msg.GiftName,
// Price: msg.Price,
// IsPaid: true,
//})
// 2. rpc
//_, err := h.svcCtx.UserCenterRpc.UserBuyNobility(h.svcCtx.Ctx, &usercenter.UserBuyNobilityReq{
// Platform: msg.Platform,
// UserId: user.UserId,
// PUid: strconv.FormatInt(msg.Uid, 10),
// BattleId: manager.GameManager.BattleIdByLiveRoomId(roomId),
// RoomId: strconv.FormatInt(roomId, 10),
// GiftId: msg.GiftId,
// GiftName: msg.GiftName,
// Num: int64(msg.Num),
// Price: msg.Price,
// Level: int64(msg.GuardLevel),
// StartTime: msg.StartTime,
// EndTime: msg.EndTime,
//})
//if err != nil {
// logger.SLog.Info("rpc 购买舰长记录失败,积分变动不通知了...")
// return
//}
}