|
|
|
|
package live_logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"dcg/app/user_center/usercenter"
|
|
|
|
|
"dcg/config"
|
|
|
|
|
"dcg/game/logic"
|
|
|
|
|
pbCommon "dcg/game/pb/common"
|
|
|
|
|
pbMq "dcg/game/pb/mq"
|
|
|
|
|
"dcg/game/svc"
|
|
|
|
|
"dcg/pkg/cmd"
|
|
|
|
|
"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(true, config.Config.Game.Common.Commands...)),
|
|
|
|
|
}
|
|
|
|
|
// 通用指令处理器
|
|
|
|
|
resp.RegisterCMDHandler(resp.handleQuery, "q", "查询")
|
|
|
|
|
resp.RegisterCMDHandler(resp.handleCheckIn, "打卡", "签到")
|
|
|
|
|
// 通用礼物处理器
|
|
|
|
|
resp.RegisterGiftHandler(resp.handleGift)
|
|
|
|
|
return resp.LiveGameLogic
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *commonGameLogic) handleCheckIn(roomId int64, _ string, user *pbCommon.PbUser) {
|
|
|
|
|
room, err := logic.GameLogic.RoomManager.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.UId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
respMsg.Msg = "打卡失败,UP主有罪。"
|
|
|
|
|
} else {
|
|
|
|
|
user.Integral = resp.Integral
|
|
|
|
|
respMsg.Success = resp.Success
|
|
|
|
|
respMsg.Msg = resp.Msg
|
|
|
|
|
respMsg.IntegralChange = resp.IntegralChange
|
|
|
|
|
respMsg.IsCritical = resp.IsCritical
|
|
|
|
|
}
|
|
|
|
|
room.PushToLiveRoom(roomId, "user.checkIn", respMsg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *commonGameLogic) handleQuery(roomId int64, _ string, user *pbCommon.PbUser) {
|
|
|
|
|
room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
room.PushToLiveRoom(roomId, "user.query", &pbCommon.UserQueryMsg{User: user})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *commonGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) {
|
|
|
|
|
room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 1. 发送通用礼物消息
|
|
|
|
|
room.PushToLiveRoom(roomId, "live.gift", &pbCommon.GiftMsg{
|
|
|
|
|
User: user,
|
|
|
|
|
GiftId: gift.GiftId,
|
|
|
|
|
Num: gift.Num,
|
|
|
|
|
GiftName: gift.GiftName,
|
|
|
|
|
Price: gift.Price,
|
|
|
|
|
IsPaid: gift.IsPaid,
|
|
|
|
|
})
|
|
|
|
|
// 2. RPC 记录送礼,积分变动
|
|
|
|
|
req := &usercenter.UserSendGiftReq{
|
|
|
|
|
Platform: gift.Platform,
|
|
|
|
|
UserId: user.UId,
|
|
|
|
|
PUid: strconv.FormatInt(gift.Uid, 10),
|
|
|
|
|
RoomId: strconv.FormatInt(roomId, 10),
|
|
|
|
|
GiftId: gift.GiftId,
|
|
|
|
|
GiftName: gift.GiftName,
|
|
|
|
|
Num: gift.Num,
|
|
|
|
|
Price: gift.Price,
|
|
|
|
|
IsPaid: gift.IsPaid,
|
|
|
|
|
}
|
|
|
|
|
giftResp, err := h.svcCtx.UserCenterRpc.UserSendGift(h.svcCtx.Ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.SLog.Info("rpc 用户送礼记录失败,积分变动不通知了...")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
user.Integral = giftResp.Integral.Integral // 更新最新积分
|
|
|
|
|
room.PushToLiveRoom(roomId, "user.integral.change", &pbCommon.UserIntegralChanged{
|
|
|
|
|
User: user,
|
|
|
|
|
Change: giftResp.Integral.Change,
|
|
|
|
|
Integral: giftResp.Integral.Integral,
|
|
|
|
|
})
|
|
|
|
|
}
|