go_dreamfactory/modules/moonfantasy/api_receive.go
2023-06-06 10:11:23 +08:00

53 lines
1.3 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 code = this.ReceiveCheck(session, req); errdata != nil {
return
}
if boss, err = this.module.configure.GetMonsterById(req.Mid); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
return
}
if !iswin {
if code = this.module.ConsumeRes(session, boss.PsMg, true); errdata != nil {
return
}
return
} else {
if code = this.module.ConsumeRes(session, boss.PsConsume, true); errdata != nil {
return
}
this.module.DispenseRes(session, boss.Prize, true)
}
session.SendMsg(string(this.module.GetType()), "receive", &pb.MoonfantasyReceiveResp{Issucc: true})
return
}