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 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } 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 atno []*pb.UserAtno ) if errdata = this.PlotRewardCheck(session, req); errdata != nil { return } if npc, err = this.module.configure.getChallengenpc(req.Pid); 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 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_MoonfantasyBattleNoWin, Title: pb.ErrorCode_MoonfantasyBattleNoWin.ToString(), } return } if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if info.Npc[req.Pid] == nil { info.Npc[req.Pid] = &pb.DBNpc{ Id: req.Pid, Index: 0, } } if info.Npc[req.Pid].Index != 0 { if errdata, atno = this.module.DispenseAtno(session, npc.NpcReward, true); errdata != nil { return } } else { if errdata, atno = this.module.DispenseAtno(session, npc.NewNpcReward, true); errdata != nil { return } } 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.Uinfo.Uid, map[string]interface{}{ "npc": info.Npc, }); err != nil { this.module.Errorln(err) errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } session.SendMsg(string(this.module.GetType()), "plotreward", &pb.ArenaPlotRewardResp{ Issucc: true, Npc: info.Npc, }) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "ArenaPlotRewardReq", atno) }) return }