package uniongve import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) type ModelUniongve struct { modules.MCompModel module *UnionGve conflock sync.RWMutex bossconf *pb.DBUnionGveBossConf } func (this *ModelUniongve) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompModel.Init(service, module, comp, options) this.TableName = comm.TableUniongve this.module = module.(*UnionGve) return } // 获取用户全部的埋点数据 func (this *ModelUniongve) getUnionGve(unionid string) (results *pb.DBUnionGve, err error) { results = &pb.DBUnionGve{} if err = this.Get(unionid, results); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } if err == mgo.MongodbNil { err = nil results = &pb.DBUnionGve{ Unionid: unionid, Currstage: 0, Boos: make([]*pb.DBUnionGveBoss, 0), } err = this.Add(unionid, results) } return } // 刷新全局配置 func (this *ModelUniongve) refreshGlobalBoos() (err error) { var ( bossconf *pb.DBUnionGveBossConf booss []*cfg.GameGuildBossData rands []int ) if booss, err = this.module.configure.getguildboss(); err != nil { return } if len(booss) < 5 { err = fmt.Errorf("guildboss no data!") return } rands = comm.RandShuffle(len(booss)) bossconf = &pb.DBUnionGveBossConf{ Rtime: configure.Now().Unix(), Boos: make([]int32, 5), } for i := 0; i < 5; i++ { bossconf.Boos[i] = booss[rands[i]].BossId } this.conflock.Lock() this.bossconf = bossconf this.conflock.Unlock() return }