157 lines
3.8 KiB
Go
157 lines
3.8 KiB
Go
package sys
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/event"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &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)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) GetType() core.M_Modules {
|
|
return comm.ModuleSys
|
|
}
|
|
|
|
func (this *ModuleSys) ValidCond(uid string, conf *cfg.GameOpencondData) string {
|
|
return this.modelSys.validCond(uid, conf)
|
|
}
|
|
|
|
func (this *ModuleSys) CheckLvUpCond(session comm.IUserSession, lv int32) {
|
|
if cond := this.configure.GetOpencondLv(lv); len(cond) > 0 {
|
|
this.AutoActivate(session, cond)
|
|
}
|
|
}
|
|
|
|
// 自动激活
|
|
func (this *ModuleSys) AutoActivate(session comm.IUserSession, cids []string) bool {
|
|
var (
|
|
szOpen []string
|
|
)
|
|
list, _ := this.modelSys.GetOpenCondList(session.GetUserId())
|
|
for _, cid := range cids {
|
|
opencfg := this.configure.getOpencondCfgByCid(cid)
|
|
if opencfg == nil {
|
|
continue
|
|
}
|
|
if id := this.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足
|
|
continue
|
|
} else {
|
|
if _, ok := list.Cond[cid]; !ok {
|
|
list.Cond[cid] = 1
|
|
szOpen = append(szOpen, cid)
|
|
}
|
|
}
|
|
|
|
}
|
|
if len(szOpen) > 0 {
|
|
this.modelSys.ChangeOpenCondData(session.GetUserId(), map[string]interface{}{
|
|
"cond": list.Cond,
|
|
})
|
|
}
|
|
// 推送变化
|
|
session.SendMsg(string(this.GetType()), "open", &pb.SysFuncOpnePush{
|
|
Cid: szOpen,
|
|
})
|
|
return true
|
|
}
|
|
|
|
// 功能开启条件校验
|
|
func (this *ModuleSys) CheckOpenCondCfgById(uid string, id string) (bOpen bool, errdata *pb.ErrorData) {
|
|
|
|
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 this.ValidCond(uid, conf) != "" {
|
|
bOpen = true
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) FriendCountChange(uid string, count int32) {
|
|
if cond := this.configure.getFriendTask(count); len(cond) > 0 {
|
|
if session, ok := this.GetUserSession(uid); ok {
|
|
this.AutoActivate(session, cond)
|
|
if err := session.Push(); err != nil {
|
|
this.Errorln(err)
|
|
}
|
|
this.PutUserSession(session)
|
|
} else {
|
|
this.PutUserSession(session)
|
|
}
|
|
}
|
|
}
|
|
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
|
|
}
|