package island 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/utils" "math" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) type modelComp struct { modules.MCompModel module *IsLand } func (this *modelComp) 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.TableIsLand this.module = module.(*IsLand) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } // 读取数据 func (this *modelComp) getmodel(uid string) (result *pb.DBIsland, err error) { result = &pb.DBIsland{} if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) } if err == mgo.MongodbNil { result = &pb.DBIsland{ Id: primitive.NewObjectID().Hex(), Uid: uid, Opentime: utils.GetMonthStart(), Islands: make(map[int32]*pb.DBIslandItem), Nodes: make(map[int32]int32), } if err = this.Add(uid, result); err != nil { this.module.Errorln(err) return } } err = nil return } //计算属性 func (this *modelComp) compute(info *pb.DBIsland, heros []*pb.DBHero) (err error) { var ( node *cfg.GamePuggsySkillData property map[string]int32 = make(map[string]int32) ) for k, v := range info.Nodes { if node, err = this.module.configure.getGamePuggsySkilllvData(k, v); err != nil { this.module.Errorln(err) return } for _, v := range node.Upgrade { property[v.A] += v.N } } for _, hero := range heros { for k, v := range property { hero.Property[k] += v } for k, v := range hero.Property { switch k { case comm.AtkPro: hero.Property[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Atk]))) case comm.DefPro: hero.Property[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Def]))) case comm.HpPro: hero.Property[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Hp]))) case comm.SpeedPro: hero.Property[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Speed]))) } } } return }