96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
package sys
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelSys struct {
|
|
modules.MCompModel
|
|
moduleSys *ModuleSys
|
|
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelSys) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableOpenCond
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleSys = module.(*ModuleSys)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *ModelSys) GetOpenCondList(uid string) (result *pb.DBOpenCond, err error) {
|
|
result = &pb.DBOpenCond{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if mongo.ErrNoDocuments == err { // 创建一条新的数据
|
|
result = &pb.DBOpenCond{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Cond: map[string]int32{},
|
|
Lv: 1,
|
|
Friend: 0,
|
|
Mline: map[int32]int32{},
|
|
Wtask: map[int32]int32{},
|
|
Pagoda: map[int32]int32{},
|
|
Sociaty: 1,
|
|
Moonlv: 1,
|
|
}
|
|
this.Add(uid, result)
|
|
err = nil
|
|
}
|
|
}
|
|
return result, err
|
|
}
|
|
|
|
// 修改OpenCond 数据
|
|
func (this *ModelSys) ChangeOpenCondData(uid string, value map[string]interface{}) (err error) {
|
|
if len(value) == 0 {
|
|
return nil
|
|
}
|
|
return this.Change(uid, value)
|
|
}
|
|
|
|
func (this *ModelSys) CheckValidCond(uid string, condData *cfg.GameOpencondData, open *pb.DBOpenCond) string {
|
|
for _, conf := range condData.Main {
|
|
switch comm.OpencondType(conf.Key) {
|
|
case comm.OpencondTypePlatlv: //等级
|
|
if open.Lv < conf.Param {
|
|
return ""
|
|
}
|
|
case comm.OpencondTypeMaxmapid: //关卡ID
|
|
if _, ok := open.Mline[conf.Param]; !ok {
|
|
return ""
|
|
}
|
|
case comm.OpencondTypeWorldtaskid: //世界任务ID
|
|
if _, ok := open.Wtask[conf.Param]; !ok {
|
|
return ""
|
|
}
|
|
|
|
case comm.OpencondTypeFriend: // 好友数量
|
|
if open.Friend < conf.Param {
|
|
return ""
|
|
}
|
|
case comm.OpencondTypePagoda:
|
|
if _, ok := open.Pagoda[conf.Param]; !ok {
|
|
return ""
|
|
}
|
|
case comm.OpencondTypeSociaty: // 查询工会等级
|
|
if open.Sociaty < conf.Param {
|
|
return ""
|
|
}
|
|
case comm.OpencondTypeMoonLv:
|
|
if open.Moonlv < conf.Param {
|
|
return ""
|
|
}
|
|
}
|
|
}
|
|
return condData.Id
|
|
}
|