go_dreamfactory/modules/moonfantasy/modelDream.go
2022-09-15 15:56:39 +08:00

96 lines
2.7 KiB
Go

package moonfantasy
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/lego/sys/timewheel"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///论坛 数据组件
type modelDreamComp struct {
modules.MCompModel
module *Moonfantasy
}
//组件初始化接口
func (this *modelDreamComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Moonfantasy)
this.TableName = comm.TableMoonfantasy
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
///添加月之秘境记录
func (this *modelDreamComp) queryDreamData(uid string, mid string) (result *pb.DBMoonfantasy, err error) {
result = &pb.DBMoonfantasy{}
if err = this.GetListObj(uid, mid, result); err != nil && err != mongo.ErrNilDocument {
this.module.Errorln(err)
}
return
}
///添加月之秘境记录
func (this *modelDreamComp) addDreamData(uid string, boss *cfg.GameDreamlandBoosData) (result *pb.DBMoonfantasy, err error) {
result = &pb.DBMoonfantasy{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Monster: boss.Bossid,
Ctime: time.Now().Unix(),
Joinnum: 0,
Numup: boss.Challengenum,
Unitmup: boss.Fightnum,
Record: make(map[string]int32),
}
if err = this.AddList(uid, result.Id, result); err != nil {
this.module.Errorln(err)
}
return
}
///查询好友数据
func (this *modelDreamComp) noticeuserfriend(stag, uid string, chat *pb.DBChat) (code pb.ErrorCode) {
var (
err error
)
model := db.NewDBModel(comm.TableFriend, 0, db.ServerDBConn(stag))
friend := &pb.DBFriend{Uid: uid, FriendIds: make([]string, 0)}
if err = model.Get(uid, friend); err != nil && err != mgo.MongodbNil {
this.module.Errorln(err)
return
}
for _, v := range friend.FriendIds {
temp := *chat
temp.Id = primitive.NewObjectID().Hex()
temp.Channel = pb.ChatChannel_Private
temp.Ruid = v
this.module.chat.SendUserChat(&temp)
}
chat.Id = primitive.NewObjectID().Hex()
chat.Channel = pb.ChatChannel_World
// code = this.module.chat.SendWorldChat(stag, chat)
this.delaynoticeWorld(stag, chat)
return
}
//延迟推送到 世界聊天频道
func (this *modelDreamComp) delaynoticeWorld(stag string, chat *pb.DBChat) {
timewheel.Add(time.Minute*15, func(t *timewheel.Task, i ...interface{}) {
_chat := i[0].(*pb.DBChat)
this.module.chat.SendWorldChat(_chat)
}, chat)
}