168 lines
3.9 KiB
Go
168 lines
3.9 KiB
Go
package sys
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
var _ comm.ISys = (*ModuleSys)(nil)
|
|
|
|
type ModuleSys struct {
|
|
modules.ModuleBase
|
|
wtask comm.IWtask
|
|
api *apiComp
|
|
configure *configureComp
|
|
service base.IRPCXService
|
|
modelSys *ModelSys
|
|
mainline comm.IMainline
|
|
pagoda comm.IPagoda
|
|
sociaty comm.ISociaty
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &ModuleSys{}
|
|
}
|
|
|
|
func (this *ModuleSys) GetType() core.M_Modules {
|
|
return comm.ModuleSys
|
|
}
|
|
|
|
func (this *ModuleSys) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelSys = this.RegisterComp(new(ModelSys)).(*ModelSys)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 模块初始化
|
|
func (this *ModuleSys) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service.(base.IRPCXService)
|
|
//event.Register(comm.EventFriendChange, this.FriendCountChange)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleWtask); err != nil {
|
|
return
|
|
}
|
|
this.wtask = module.(comm.IWtask)
|
|
|
|
if module, err = this.service.GetModule(comm.ModuleMainline); err != nil {
|
|
|
|
return
|
|
}
|
|
this.mainline = module.(comm.IMainline)
|
|
|
|
if module, err = this.service.GetModule(comm.ModulePagoda); err != nil {
|
|
|
|
return
|
|
}
|
|
this.pagoda = module.(comm.IPagoda)
|
|
|
|
if module, err = this.service.GetModule(comm.ModuleSociaty); err != nil {
|
|
|
|
return
|
|
}
|
|
this.sociaty = module.(comm.ISociaty)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) CheckOpenCond(session comm.IUserSession, itype comm.OpencondType, value int32) {
|
|
var (
|
|
list *pb.DBOpenCond
|
|
err error
|
|
update map[string]interface{}
|
|
)
|
|
if list, err = this.modelSys.GetOpenCondList(session.GetUserId()); err != nil {
|
|
return
|
|
}
|
|
update = make(map[string]interface{})
|
|
switch itype {
|
|
case comm.OpencondTypePlatlv:
|
|
if list.Lv != value {
|
|
list.Lv = value
|
|
update["lv"] = list.Lv
|
|
}
|
|
case comm.OpencondTypeMaxmapid:
|
|
list.Mline[value] = 1
|
|
update["mline"] = list.Mline
|
|
case comm.OpencondTypeWorldtaskid:
|
|
list.Wtask[value] = 1
|
|
update["wtask"] = list.Wtask
|
|
case comm.OpencondTypeFriend:
|
|
if list.Friend != value {
|
|
list.Friend = value
|
|
update["friend"] = list.Friend
|
|
}
|
|
case comm.OpencondTypePagoda:
|
|
list.Pagoda[value] = 1
|
|
update["pagoda"] = list.Pagoda
|
|
case comm.OpencondTypeSociaty:
|
|
if list.Sociaty != value {
|
|
list.Sociaty = value
|
|
update["friend"] = list.Friend
|
|
}
|
|
default:
|
|
return
|
|
}
|
|
if err = this.modelSys.ChangeOpenCondData(session.GetUserId(), update); err != nil {
|
|
this.Errorf("ChangeOpenCondData error: %v", err)
|
|
}
|
|
}
|
|
|
|
// 功能开启条件校验
|
|
func (this *ModuleSys) CheckOpenCondCfgById(uid string, id string) (bOpen bool, errdata *pb.ErrorData) {
|
|
var (
|
|
list *pb.DBOpenCond
|
|
)
|
|
conf, err := this.configure.GetOpenCondCfgById(id)
|
|
if err != nil {
|
|
bOpen = false
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if list, err = this.modelSys.GetOpenCondList(uid); err != nil {
|
|
return
|
|
}
|
|
if _, ok := list.Cond[id]; ok { // 数据过滤
|
|
if list.Cond[id] > 0 {
|
|
bOpen = true
|
|
return
|
|
}
|
|
}
|
|
if this.modelSys.CheckValidCond(uid, conf, list) != "" {
|
|
bOpen = true
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) QueryOpenCondData(uid string) (data map[string]int32, errdata *pb.ErrorData) {
|
|
data = make(map[string]int32, 0)
|
|
list, err := this.modelSys.GetOpenCondList(uid)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for k, v := range list.Cond {
|
|
if v == 2 { // 已经开启的功能
|
|
data[k] = v
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|