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.
138 lines
3.8 KiB
Go
138 lines
3.8 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
|
|
}
|
|
|
|
func NewCommonLiveGameLogic(svcCtx *svc.ServiceContext) *CommonGameLogic {
|
|
return &CommonGameLogic{
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (h *CommonGameLogic) CmdParserPatterns() []cmd.Pattern {
|
|
return []cmd.Pattern{
|
|
{
|
|
Prefix: "打卡",
|
|
Alias: []string{"签到"},
|
|
ContentMaxLen: 0,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (h *CommonGameLogic) WithCmdHandler() LogicOption {
|
|
return func(logic LiveLogic) {
|
|
logic.RegisterCMDHandler(h.handleCheckIn, "打卡")
|
|
}
|
|
}
|
|
|
|
func (h *CommonGameLogic) GiftHandler() GiftHandler {
|
|
return func(next GiftHandlerFunc) GiftHandlerFunc {
|
|
return func(liveRoom *LiveRoom, user *pbCommon.PbUser, gift *pbMq.MqGift) {
|
|
h.handleGift(liveRoom, user, gift)
|
|
next(liveRoom, user, gift)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (h *CommonGameLogic) handleCheckIn(liveRoom *LiveRoom, _ string, _ []rune, user *pbCommon.PbUser) {
|
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
|
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(liveRoom *LiveRoom, user *pbCommon.PbUser, gift *pbMq.MqGift) {
|
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
|
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(liveRoom.RoomId, 10),
|
|
GiftId: gift.GiftId,
|
|
GiftName: gift.GiftName,
|
|
Num: gift.GiftNum,
|
|
Price: gift.Price,
|
|
IsPaid: gift.IsPaid,
|
|
BattleId: manager.GameManager.BattleIdByLiveRoom(liveRoom.RoomId, liveRoom.Platform),
|
|
}
|
|
_, err = h.svcCtx.UserCenterRpc.UserSendGift(h.svcCtx.Ctx, req)
|
|
if err != nil {
|
|
logger.SLog.Info("rpc 用户送礼记录失败,金币变动不通知了...")
|
|
return
|
|
}
|
|
}
|
|
|
|
func (h *CommonGameLogic) handleNobility(liveRoom *LiveRoom, user *pbCommon.PbUser, msg *pbMq.MqNobilityBuy) {
|
|
//room, err := manager.GameManager.RoomByLiveRoom(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.BattleIdByLiveRoom(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
|
|
//}
|
|
}
|