go_dreamfactory/modules/hunting/model_rank.go

111 lines
2.8 KiB
Go

package hunting
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ModelRank struct {
modules.MCompModel
moduleHunting *Hunting
}
func (this *ModelRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableHuntingRank
err = this.MCompModel.Init(service, module, comp, options)
this.moduleHunting = module.(*Hunting)
return
}
func (this *ModelRank) AddRank(uId string, data *pb.DBHuntingRank) (err error) {
if err = this.Add(uId, data); err != nil {
return
}
return nil
}
// 更新排行榜数据
func (this *ModelRank) ChangeUserRank(uid string, objId string, value map[string]interface{}) (err error) {
if len(value) == 0 {
return nil
}
return this.ChangeList(uid, objId, value)
}
// 获取排行榜数据
func (this *ModelRank) GetRankData(bossType int32) (data []*pb.DBHuntingRank, err error) {
tmpdata := make([]*pb.DBHuntingRank, 0)
data = make([]*pb.DBHuntingRank, 0)
err = this.Redis.LRange(comm.TableVikingRankList, 0, -1, &tmpdata)
if err == nil {
for _, v := range tmpdata {
if v.Bosstype == bossType {
data = append(data, v)
}
}
}
return
}
func (this *ModelRank) getHuntingRankList(uid string) []*pb.DBHuntingRank {
ranks := make([]*pb.DBHuntingRank, 0)
err := this.GetList(uid, &ranks)
if err != nil {
return nil
}
return ranks
}
func (this *ModelRank) updatehuntingRankList(session comm.IUserSession, difficulty int32, boosType int32, Leadpos int32, line []*pb.LineUp) {
// 查询是不是更新数据
ranks := this.getHuntingRankList(session.GetUserId())
bfind := false
for _, v := range ranks {
if v.Bosstype == boosType {
mapRankData := make(map[string]interface{}, 0)
mapRankData["difficulty"] = difficulty
mapRankData["bosstype"] = boosType
mapRankData["Leadpos"] = Leadpos
mapRankData["line"] = line
mapRankData["costTime"] = 123
this.ChangeUserRank(session.GetUserId(), v.Id, mapRankData)
bfind = true
break
}
}
if !bfind {
userinfo := this.moduleHunting.ModuleUser.GetUser(session.GetUserId())
new := &pb.DBVikingRank{
Id: primitive.NewObjectID().Hex(),
Uid: session.GetUserId(),
Difficulty: difficulty,
Bosstype: boosType,
Nickname: userinfo.Name,
Icon: "",
Lv: userinfo.Lv,
Leadpos: Leadpos,
Line: line,
CostTime: 12,
}
this.AddList(session.GetUserId(), new.Id, new)
}
return
}
func (this *ModelRank) getHuntingRankListByBossType(uid string, bossType int32) *pb.DBHuntingRank {
ranks := make([]*pb.DBHuntingRank, 0)
err := this.GetList(uid, &ranks)
if err != nil {
return nil
}
for _, v := range ranks {
if v.Bosstype == bossType {
return v
}
}
return nil
}