This commit is contained in:
meixiongfeng 2024-01-30 14:02:30 +08:00
commit 83170939c2
3 changed files with 10 additions and 7 deletions

View File

@ -67,7 +67,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.ArenaChallenge
})
if red.Attack != nil {
for i, v := range req.Battle.Format {
if (red.Attack.Formt[i] != nil && red.Attack.Formt[i].Id != v) || (red.Attack.Formt[i] == nil && v == "") {
if (red.Attack.Formt[i] != nil && red.Attack.Formt[i].Id != v) || (red.Attack.Formt[i] == nil && v != "") {
change = true
}
}

View File

@ -28,6 +28,10 @@ func (this *modelRank) Init(service core.IService, module core.IModule, comp cor
return
}
func (this *modelRank) rankey() string {
return fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName)
}
// 更新排名
func (this *modelRank) updateArenaRank(users ...*pb.ArenaPlayer) (err error) {
var (
@ -41,11 +45,11 @@ func (this *modelRank) updateArenaRank(users ...*pb.ArenaPlayer) (err error) {
for i, v := range users {
menbers[i] = &redis.Z{Score: float64(v.Integral), Member: v.Uinfo.Uid}
}
if cmd = pipe.ZAdd(this.TableName, menbers...); err != nil {
if cmd = pipe.ZAdd(this.rankey(), menbers...); err != nil {
this.module.Errorln(err)
}
for i, v := range users {
menbersCmd[i] = pipe.ZRevRank(this.TableName, v.Uinfo.Uid)
menbersCmd[i] = pipe.ZRevRank(this.rankey(), v.Uinfo.Uid)
}
if _, err = pipe.Exec(); err != nil {
this.module.Errorln(err)
@ -67,7 +71,7 @@ func (this *modelRank) updateArenaRank(users ...*pb.ArenaPlayer) (err error) {
//获取指定区间的玩家人数
func (this *modelRank) queryRankByScoreArea(min, max int32) (count int64, err error) {
if count, err = this.DBModel.Redis.ZCount(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), fmt.Sprintln(min), fmt.Sprintln(max)); err != nil {
if count, err = this.DBModel.Redis.ZCount(this.rankey(), fmt.Sprintln(min), fmt.Sprintln(max)); err != nil {
this.module.Errorln(err)
return
}
@ -79,7 +83,7 @@ func (this *modelRank) queryRankUser() (ranks []string, err error) {
var (
result []string
)
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), 0, 50).Result(); err != nil {
if result, err = this.DBModel.Redis.ZRevRange(this.rankey(), 0, 50).Result(); err != nil {
this.module.Errorln(err)
return
}
@ -93,6 +97,6 @@ func (this *modelRank) queryRankUser() (ranks []string, err error) {
// 比赛结算
func (this *modelRank) raceSettlement() {
if isopen := this.module.modelArena.isInMaintenance(); isopen {
this.DBModel.Del(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), db.SetDBMgoLog(false))
this.DBModel.Del(this.rankey(), db.SetDBMgoLog(false))
}
}

View File

@ -399,7 +399,6 @@ func (this *DBModel) ChangeLists(uid string, datas map[string]interface{}, opt .
func (this *DBModel) BatchChange(uids []string, datas map[string]interface{}, opt ...DBOption) (err error) {
pipe := this.Redis.RedisPipe(context.TODO())
for _, uid := range uids {
if err = pipe.HMSet(this.ukey(uid), datas); err != nil {
log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()})
return