67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package island
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelHeroComp struct {
|
|
modules.MCompModel
|
|
module *IsLand
|
|
}
|
|
|
|
func (this *modelHeroComp) 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.TableIsLandHero
|
|
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 *modelHeroComp) getHeroList(uid string) (heros []*pb.DBHero, err error) {
|
|
heros = make([]*pb.DBHero, 0)
|
|
err = this.GetList(uid, &heros)
|
|
return
|
|
}
|
|
|
|
// 获取玩家的英雄
|
|
func (this *modelHeroComp) getHeros(uid string, ids []string) (heros []*pb.DBHero, err error) {
|
|
heros = make([]*pb.DBHero, 0)
|
|
if err = this.GetListObjs(uid, ids, &heros); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
//添加英雄
|
|
func (this *modelHeroComp) addheros(uid string, hero *pb.DBHero) (err error) {
|
|
if err = this.AddList(uid, hero.Id, hero); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 重新计算英雄属性
|
|
func (this *modelHeroComp) updateHeroProperty(uid string, hero *pb.DBHero) (err error) {
|
|
update := map[string]interface{}{
|
|
"star": hero.Star,
|
|
"juexingLv": hero.JuexingLv,
|
|
"property": hero.Property,
|
|
"juexProperty": hero.JuexProperty,
|
|
}
|
|
if err = this.ChangeList(uid, hero.Id, update); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|