64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package moonfantasy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.MoonfantasyReceiveReq) (errdata *pb.ErrorData) {
|
|
if req.Bid == "" || req.Mid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///领取战斗奖励
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.MoonfantasyReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
boss *cfg.GameDreamlandBoosData
|
|
iswin bool
|
|
err error
|
|
)
|
|
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if boss, err = this.module.configure.GetMonsterById(req.Mid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
|
|
return
|
|
}
|
|
if !iswin {
|
|
if errdata = this.module.ConsumeRes(session, boss.PsMg, true); errdata != nil {
|
|
return
|
|
}
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "MoonfantasyReceiveReq", boss.PsMg)
|
|
})
|
|
return
|
|
} else {
|
|
if errdata = this.module.ConsumeRes(session, boss.PsConsume, true); errdata != nil {
|
|
return
|
|
}
|
|
this.module.DispenseRes(session, boss.Prize, true)
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "MoonfantasyReceiveReq", boss.Prize)
|
|
})
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "receive", &pb.MoonfantasyReceiveResp{Issucc: true})
|
|
return
|
|
}
|