package practice import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "math/rand" ) // 参数校验 func (this *apiComp) GymRefreshCheck(session comm.IUserSession, req *pb.PracticeGymRefreshReq) (errdata *pb.ErrorData) { return } // /刷新动作 func (this *apiComp) GymRefresh(session comm.IUserSession, req *pb.PracticeGymRefreshReq) (errdata *pb.ErrorData) { var ( err error room *pb.DBPracticeRoom confs []*cfg.GamePandamasMrylData temp []*cfg.GamePandamasMrylData refreshAtns []*cfg.Gameatn atn *cfg.Gameatn ) if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } refreshAtns = this.module.ModuleTools.GetGlobalConf().MrylFlushed if len(refreshAtns) == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if int(room.Gymrefresh) < len(refreshAtns) { atn = refreshAtns[room.Gymrefresh] } else { atn = refreshAtns[len(refreshAtns)-1] } if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{atn}, true); errdata != nil { return } if confs, err = this.module.configure.getGamePandamasMryls(); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } temp = make([]*cfg.GamePandamasMrylData, 0) //过滤掉当前的buff for _, v := range confs { if v.Id != room.Gymaction { temp = append(temp, v) } } if len(confs) == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigurationException, Title: pb.ErrorCode_ConfigurationException.ToString(), Message: err.Error(), } return } r := rand.New(rand.NewSource(configure.Now().Unix())) room.Gymaction = temp[r.Perm(len(temp))[0]].Id room.Gymrefresh++ room.Lastrefresh = configure.Now().Unix() this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{ "gymaction": room.Gymaction, "gymrefresh": room.Gymrefresh, "lastrefresh": room.Lastrefresh, }) session.SendMsg(string(this.module.GetType()), "gymrefresh", &pb.PracticeGymRefreshResp{Lastaction: room.Gymaction, Refreshnum: room.Gymrefresh}) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "PracticeGymRefreshReq", atn) }) return }