package arena import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "math/rand" "go.mongodb.org/mongo-driver/bson/primitive" ) // 参数校验 func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.ArenaInfoReq) (errdata *pb.ErrorData) { return } // /获取自己的排行榜信息 func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (errdata *pb.ErrorData) { var ( global *cfg.GameGlobalData info *pb.DBArenaUser user *pb.DBUser err error ) if errdata = this.InfoCheck(session, req); errdata != nil { return } user, err = this.module.GetUserForSession(session) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if err == mgo.MongodbNil { global = this.module.ModuleTools.GetGlobalConf() info = &pb.DBArenaUser{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), Uinfo: comm.GetUserBaseInfo(user), Integral: global.ArenaInitiaIntegral, Streak: 0, Record: make([]*pb.DBArenaBattleRecord, 0), Lastrtickettime: 0, Isdef: false, Npc: make(map[int32]*pb.DBNpc), Title: user.Curtitle, } if info.Dan, err = this.module.modelArena.computedan(info.Integral); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } info.Loc = []float64{float64(info.Dan), float64(rand.Int31n(100)) / 1000.0} if err = this.module.modelArena.Add(session.GetUserId(), info); err != nil { this.module.Errorln(err) } } else { info.Uinfo = comm.GetUserBaseInfo(user) this.module.modelArena.recoverTicket(session, info) if err = this.module.modelArena.updateArenaUserInfo(info); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } } session.SendMsg(string(this.module.GetType()), "info", &pb.ArenaInfoResp{Info: info}) return }