package arena import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" 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 isopen bool err error ) if errdata = this.InfoCheck(session, req); errdata != nil { return } if isopen = this.module.modelArena.isInMaintenance(); isopen { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ArenaInMaintenance, Message: "InMaintenance!", } 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), Lastweektime: configure.Now().Unix(), Settlementtime: this.module.modelArena.settlementTime().Unix(), Tasks: make(map[int32]int32), Danaward: make(map[int32]int32), Weekaward: make([]*pb.DBWeekAward, 0), } 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) if info.Defend != nil { //有防守阵型 var ( ids []string heros []*pb.DBHero ) ids = make([]string, len(info.Defend.Formt)) for i, v := range info.Defend.Formt { if v != nil { ids[i] = v.Id } } if heros, err = this.module.modelArena.queryUserHeros(session.GetUserId(), ids); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } info.Defend.Formt = heros } this.module.modelArena.weeksettlement(session, info) this.module.modelArena.raceSettlement(session, info) 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 }