87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) PlotRewardCheck(session comm.IUserSession, req *pb.ArenaPlotRewardReq) (errdata *pb.ErrorData) {
|
|
if req.Pid == 0 || req.Report == nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///领取战斗奖励
|
|
func (this *apiComp) PlotReward(session comm.IUserSession, req *pb.ArenaPlotRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
npc *cfg.GameArenaChallengeNpcData
|
|
info *pb.DBArenaUser
|
|
iswin bool
|
|
err error
|
|
)
|
|
|
|
if code = this.PlotRewardCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if npc, err = this.module.configure.getChallengenpc(req.Pid); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if code, iswin = this.module.battle.CheckBattleReport(session, req.Report); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if !iswin {
|
|
code = pb.ErrorCode_MoonfantasyBattleNoWin
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: "战斗校验失败",
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info.Npc[req.Pid] == nil {
|
|
info.Npc[req.Pid] = &pb.DBNpc{
|
|
Id: req.Pid,
|
|
Index: 0,
|
|
}
|
|
}
|
|
if len(npc.MonsterformatId) > int(info.Npc[req.Pid].Index+1) {
|
|
info.Npc[req.Pid].Index++
|
|
}
|
|
info.Npc[req.Pid].Cd = configure.Now().Add(time.Minute * time.Duration(npc.ReviveCd)).Unix()
|
|
if err = this.module.modelArena.Change(info.Uid, map[string]interface{}{
|
|
"npc": info.Npc,
|
|
}); err != nil {
|
|
this.module.Errorln(err)
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
this.module.DispenseRes(session, npc.NpcReward, true)
|
|
session.SendMsg(string(this.module.GetType()), "plotreward", &pb.ArenaPlotRewardResp{
|
|
Issucc: true,
|
|
Npc: info.Npc,
|
|
})
|
|
return
|
|
}
|