package horoscope import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "math" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) ///星座图 数据组件 type modelHoroscope struct { modules.MCompModel module *Horoscope } //组件初始化接口 func (this *modelHoroscope) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { this.TableName = comm.TableHoroscope this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Horoscope) // 通过uid创建索引 this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } //查询用户装备数据 func (this *modelHoroscope) queryInfo(uid string) (result *pb.DBHoroscope, err error) { result = &pb.DBHoroscope{ Uid: uid, Nodes: make(map[int32]int32), } if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } if err == mgo.MongodbNil { result = &pb.DBHoroscope{ Id: primitive.NewObjectID().Hex(), Uid: uid, Nodes: make(map[int32]int32), } err = this.Add(uid, result) } return } ///保存用户竞技场信息 func (this *modelHoroscope) updateInfo(session comm.IUserSession, info *pb.DBHoroscope) (err error) { var ( model *db.DBModel ) err = this.Change(info.Uid, map[string]interface{}{ "nodes": info.Nodes, "lastrest": info.Lastrest, }) if model, err = this.module.GetDBModelByUid(info.Uid, this.TableName); err != nil { this.module.Errorln(err) return } if heros := this.module.ModuleHero.GetHeroListByUse(info.Uid); heros != nil && len(heros) > 0 { for _, v := range heros { if err = this.compute(info, v); err != nil { return } if err = model.ChangeList(info.Uid, v.Id, map[string]interface{}{ "horoscopeProperty": v.HoroscopeProperty, }); err != nil { this.module.Errorln(err) return } } this.module.ModuleHero.PushHeroProperty(session, heros) } return } //计算英雄属性 func (this *modelHoroscope) computeHeroNumeric(uid string, hero ...*pb.DBHero) (err error) { var ( info *pb.DBHoroscope ) if info, err = this.queryInfo(uid); err != nil { return } for _, v := range hero { err = this.compute(info, v) } return } //计算属性 func (this *modelHoroscope) compute(info *pb.DBHoroscope, hero *pb.DBHero) (err error) { var ( heroconf *cfg.GameHeroData node *cfg.GameHoroscopeData ) hero.HoroscopeProperty = make(map[string]int32) if heroconf, err = this.module.configure.getHeroConfig(hero.HeroID); err != nil { this.module.Errorln(err) return } for k, v := range info.Nodes { if node, err = this.module.configure.getHoroscopebylv(k, v); err != nil { this.module.Errorln(err) return } switch node.AddGroup { case full: //全员加成 for _, v := range node.Upgrade { hero.HoroscopeProperty[v.A] = v.N } break case camp: //指定阵营 if heroconf.Race == node.AddClassify { for _, v := range node.Upgrade { hero.HoroscopeProperty[v.A] = v.N } } break case job: //指定职业 if heroconf.Job == node.AddClassify { for _, v := range node.Upgrade { hero.HoroscopeProperty[v.A] = v.N } } break } } for k, v := range hero.HoroscopeProperty { switch k { case comm.AtkPro: hero.HoroscopeProperty[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.HoroscopeProperty[comm.Atk]))) case comm.DefPro: hero.HoroscopeProperty[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.HoroscopeProperty[comm.Def]))) case comm.HpPro: hero.HoroscopeProperty[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.HoroscopeProperty[comm.Hp]))) case comm.SpeedPro: hero.HoroscopeProperty[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.HoroscopeProperty[comm.Speed]))) } } return } func (this *modelHoroscope) reddot(session comm.IUserSession) bool { var ( info *pb.DBHoroscope horoscope *cfg.GameHoroscope errdata *pb.ErrorData err error ) if info, err = this.queryInfo(session.GetUserId()); err != nil { return false } if horoscope, err = this.module.configure.getHoroscopes(); err != nil { return false } for _, v := range horoscope.GetDataList() { if lv, ok := info.Nodes[v.NodeId]; !ok && v.Lv > lv { if errdata = this.module.CheckRes(session, v.CostItem); errdata == nil { return true } } } return false }