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) (code pb.ErrorCode) { return } ///练功请求 func (this *apiComp) GymRefresh(session comm.IUserSession, req *pb.PracticeGymRefreshReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( err error room *pb.DBPracticeRoom confs []*cfg.GamePandamasMrylData refreshAtns []*cfg.Gameatn atn *cfg.Gameatn ) if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError return } refreshAtns = this.module.ModuleTools.GetGlobalConf().MrylFlushed if len(refreshAtns) == 0 { code = pb.ErrorCode_ConfigNoFound return } if int(room.Gymrefresh) < len(refreshAtns) { atn = refreshAtns[room.Gymrefresh] } else { atn = refreshAtns[len(refreshAtns)-1] } if code = this.module.ConsumeRes(session, []*cfg.Gameatn{atn}, true); code != pb.ErrorCode_Success { return } if confs, err = this.module.configure.getGamePandamasMryls(); err != nil { code = pb.ErrorCode_ConfigNoFound return } r := rand.New(rand.NewSource(configure.Now().Unix())) room.Gymaction = confs[r.Perm(len(confs))[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}) return }