77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package hero
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
// 英雄天赋组件
|
|
type ModelTalent struct {
|
|
modules.MCompModel
|
|
module *Hero
|
|
}
|
|
|
|
func (this *ModelTalent) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableTalent
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Hero)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
//获取用户天赋数据
|
|
func (this *ModelTalent) GetHerotalent(uid string) (result []*pb.DBHeroTalent, err error) {
|
|
result = make([]*pb.DBHeroTalent, 0)
|
|
if err = this.GetList(uid, &result); err != nil && err != redis.RedisNil {
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
//修改天赋数据
|
|
func (this *ModelTalent) ChangeHeroTalent(talent *pb.DBHeroTalent, update map[string]interface{}) (err error) {
|
|
if talent == nil || len(update) == 0 {
|
|
return errors.New("err")
|
|
}
|
|
if err := this.ChangeList(talent.Uid, talent.Id, update); err != nil {
|
|
this.module.Debugf("ChangeHeroTalent err %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 通过objId 查询天赋数据
|
|
func (this *ModelTalent) GetHerotalentByObjId(uid string, oid string) (talent *pb.DBHeroTalent, err error) {
|
|
talent = &pb.DBHeroTalent{}
|
|
err = this.GetListObj(uid, oid, talent)
|
|
return
|
|
}
|
|
|
|
// 创建一条新的英雄天赋数据
|
|
func (this *ModelTalent) CreateHeroTalent(uid, heroId string) (talent *pb.DBHeroTalent, err error) {
|
|
talent = &pb.DBHeroTalent{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
HeroId: heroId,
|
|
Talent: map[int32]int32{},
|
|
}
|
|
err = this.AddList(uid, talent.Id, talent)
|
|
return
|
|
}
|
|
|
|
// gm 专用 清除所有的天赋
|
|
func (this *ModelTalent) CleanAllHeroTalent(uid string) (talent *pb.DBHeroTalent, err error) {
|
|
err = this.DelByUId(uid)
|
|
return
|
|
}
|