package arena import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "time" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) PlotRewardCheck(session comm.IUserSession, req *pb.ArenaPlotRewardReq) (code pb.ErrorCode) { if req.Pid == 0 || req.Report == nil { code = pb.ErrorCode_ReqParameterError } return } ///领取战斗奖励 func (this *apiComp) PlotReward(session comm.IUserSession, req *pb.ArenaPlotRewardReq) (code pb.ErrorCode, data proto.Message) { 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 return } if code, iswin = this.module.battle.CheckBattleReport(session, req.Report); code != pb.ErrorCode_Success { return } if !iswin { code = pb.ErrorCode_MoonfantasyBattleNoWin return } if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError 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 = time.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 return } this.module.DispenseRes(session, npc.NpcReward, true) session.SendMsg(string(this.module.GetType()), "plotreward", &pb.ArenaPlotRewardResp{ Issucc: true, Npc: info.Npc, }) return }