86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) JoinRoomCheck(session comm.IUserSession, req *pb.EntertainJoinRoomReq) (errdata *pb.ErrorData) {
|
|
if req.Roomid == "" || req.Idcard == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 房主创建房间
|
|
func (this *apiComp) JoinRoom(session comm.IUserSession, req *pb.EntertainJoinRoomReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
conf *cfg.GameConsumeHeroData
|
|
user *pb.DBUser
|
|
)
|
|
if errdata = this.JoinRoomCheck(session, req); err != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.GetGameConsumeHero(req.Idcard); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Type != 1 { // 校验数量够不够
|
|
if list, err := this.module.model.getEntertainmList(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
if list.Card[req.Idcard] <= 0 { // 需要购买
|
|
if errdata = this.module.ConsumeRes(session, conf.Consume, true); errdata != nil {
|
|
return
|
|
}
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "EntertainJoinRoomReq", conf.Consume)
|
|
})
|
|
list.Card[req.Idcard] += 1
|
|
this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
|
|
"card": list.Card,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
user, err = this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if err != nil {
|
|
return
|
|
}
|
|
p := &pb.PlayerData{
|
|
Userinfo: comm.GetUserBaseInfo(user),
|
|
Cardid: req.Idcard,
|
|
Consumeexp: user.Consumeexp,
|
|
}
|
|
|
|
if _, err = this.module.gameMgr.JoinMasterRoom(req.Roomid, p); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EntertainCreateFailed,
|
|
Title: pb.ErrorCode_EntertainCreateFailed.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "joinroom", &pb.EntertainJoinRoomResp{
|
|
BJoin: true,
|
|
})
|
|
return
|
|
}
|