55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package stonehenge
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
// 世界buff
|
|
type MWorldBuff struct {
|
|
modules.MCompModel
|
|
module *Stonehenge
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *MWorldBuff) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableWorldBuff
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Stonehenge)
|
|
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
func (this *MWorldBuff) GetStonehengeData(uid string) *pb.DBStonehenge {
|
|
stone := &pb.DBStonehenge{}
|
|
if err := this.Get(uid, stone); err != nil && mgo.MongodbNil == err { // 创建一条初始的数据
|
|
stone.Id = primitive.NewObjectID().Hex()
|
|
stone.Uid = uid
|
|
stone.Rooms = nil // 注意初始房间为空
|
|
stone.Userbuff = make(map[int32]int32, 0)
|
|
stone.Reward = make(map[int32]bool, 0)
|
|
stone.Addweight = make(map[int32]int32, 0)
|
|
stone.Etime = utils.WeekIntervalTime(0)
|
|
this.Add(uid, stone)
|
|
return nil
|
|
}
|
|
return stone
|
|
}
|
|
|
|
// 修改石阵信息
|
|
func (this *MWorldBuff) ChangeStonehengeData(uid string, update map[string]interface{}) (err error) {
|
|
|
|
return this.Change(uid, update)
|
|
}
|