260 lines
6.5 KiB
Go
260 lines
6.5 KiB
Go
package sys
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"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
|
|
}
|
|
|
|
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) {
|
|
if err = this.ModuleBase.Init(service, module, options); err != nil {
|
|
return
|
|
}
|
|
this.service = service.(base.IRPCXService)
|
|
//event.Register(comm.EventFriendChange, this.FriendCountChange)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleWtask); err != nil {
|
|
return
|
|
}
|
|
this.wtask = module.(comm.IWtask)
|
|
|
|
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
|
|
// }
|
|
// case comm.OpencondTypeMoonLv:
|
|
// if list.Moonlv != value {
|
|
// list.Moonlv = value
|
|
// update["moonlv"] = list.Moonlv
|
|
// }
|
|
// default:
|
|
// return
|
|
// }
|
|
// if err = this.modelSys.ChangeOpenCondData(session.GetUserId(), update); err != nil {
|
|
// this.Errorf("ChangeOpenCondData error: %v", err)
|
|
// }
|
|
|
|
// }
|
|
|
|
// 功能开启条件校验
|
|
func (this *ModuleSys) CheckOpenCondCfgById(session comm.IUserSession, id string) (bOpen bool, errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameOpencondData
|
|
err error
|
|
)
|
|
if conf, err = this.configure.GetOpenCondCfgById(id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
bOpen, _, _ = this.ModuleBuried.CheckCondition(session, conf.Opencondi...)
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) QueryOpenCondData(session comm.IUserSession) (data map[string]int32, errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameOpencond
|
|
condlids []int32
|
|
condis []*pb.ConIProgress
|
|
condisMap map[int32]*pb.ConIProgress = make(map[int32]*pb.ConIProgress)
|
|
progress *pb.ConIProgress
|
|
err error
|
|
ok bool
|
|
)
|
|
if conf, err = this.configure.getOpencondCfg(); err != nil {
|
|
return
|
|
}
|
|
for _, v := range conf.GetDataList() {
|
|
condlids = append(condlids, v.Opencondi...)
|
|
}
|
|
if _, condis, err = this.ModuleBuried.CheckCondition(session, condlids...); err != nil {
|
|
return
|
|
}
|
|
for _, v := range condis {
|
|
condisMap[v.Conid] = v
|
|
}
|
|
for _, v := range conf.GetDataList() {
|
|
ok = true
|
|
for _, condi := range v.Opencondi {
|
|
if progress, ok = condisMap[condi]; !ok || progress.State != pb.BuriedItemFinishState_buried_finish {
|
|
ok = false
|
|
break
|
|
}
|
|
}
|
|
if ok {
|
|
data[v.Id] = 2
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModuleSys) GMOpenAllCondition(session comm.IUserSession) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameOpencond
|
|
condlids []int32
|
|
err error
|
|
)
|
|
if conf, err = this.configure.getOpencondCfg(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range conf.GetDataList() {
|
|
condlids = append(condlids, v.Opencondi...)
|
|
}
|
|
if err = this.ModuleBuried.CompleteCondition(session, condlids...); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ExternalModule,
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//功能开启
|
|
func (this *ModuleSys) BuriedsNotify(session comm.IUserSession, condis []*pb.ConIProgress) {
|
|
this.Debug("收到子任务进度变化推送", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condis", Value: condis})
|
|
var (
|
|
condlTask map[int32][]*cfg.GameOpencondData
|
|
condlidsMap map[int32]struct{} = make(map[int32]struct{})
|
|
confs map[string]*cfg.GameOpencondData
|
|
condlids []int32
|
|
condisSlice []*pb.ConIProgress
|
|
condisMap map[int32]*pb.ConIProgress
|
|
progress *pb.ConIProgress
|
|
notify []*cfg.GameOpencondData = make([]*cfg.GameOpencondData, 0)
|
|
ok bool
|
|
err error
|
|
)
|
|
condlTask = this.configure.condlTask
|
|
for _, v := range condis {
|
|
if _, ok = condlTask[v.Conid]; ok {
|
|
for _, cmd := range condlTask[v.Conid] {
|
|
if len(cmd.Notify) > 0 {
|
|
confs[cmd.Id] = cmd
|
|
for _, condi := range cmd.Opencondi {
|
|
condlidsMap[condi] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(condlidsMap) < 0 {
|
|
return
|
|
}
|
|
for k, _ := range condlidsMap {
|
|
condlids = append(condlids, k)
|
|
}
|
|
|
|
if _, condisSlice, err = this.ModuleBuried.CheckCondition(session, condlids...); err != nil {
|
|
this.Errorln(err)
|
|
}
|
|
for _, v := range condisSlice {
|
|
condisMap[v.Conid] = v
|
|
}
|
|
|
|
for _, conf := range confs {
|
|
ok = true
|
|
for _, v := range conf.Opencondi {
|
|
if progress, ok = condisMap[v]; !ok || progress.State == pb.BuriedItemFinishState_buried_unfinish {
|
|
ok = false
|
|
break
|
|
}
|
|
}
|
|
if ok {
|
|
notify = append(notify, conf)
|
|
}
|
|
}
|
|
if len(notify) > 0 {
|
|
for _, conf := range notify {
|
|
for _, v := range conf.Notify {
|
|
i, err := this.service.GetModule(core.M_Modules(v))
|
|
if err != nil {
|
|
this.Errorln(err)
|
|
continue
|
|
}
|
|
if ic, ok := i.(comm.IOpenCmdNotice); ok {
|
|
ic.OpenCmdNotice(session, conf.Id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|