go_dreamfactory/modules/moonlv/module.go
2024-03-07 10:17:08 +08:00

133 lines
3.3 KiB
Go

package moonlv
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
type Moonlv struct {
modules.ModuleBase
api *apiComp
configure *configureComp
modelMoonlv *modelMoonlv
service core.IService
}
func NewModule() core.IModule {
return &Moonlv{}
}
func (this *Moonlv) GetType() core.M_Modules {
return comm.ModuleMoonlv
}
func (this *Moonlv) 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
return
}
func (this *Moonlv) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelMoonlv = this.RegisterComp(new(modelMoonlv)).(*modelMoonlv)
}
func (this *Moonlv) GMCreateMoonlv(session comm.IUserSession, lv int32) {
if lv <= 0 {
return
}
if _, err := this.modelMoonlv.module.configure.GetMoonLvConf(lv + 1); err == nil {
this.modelMoonlv.modifyMoonlvList(session.GetUserId(), map[string]interface{}{"cid": lv + 1})
}
}
// 任务条件达成通知
func (this *Moonlv) BuriedsNotify(session comm.IUserSession, conds []*pb.ConIProgress) {
this.Debug("辉月任务通知",
log.Field{Key: "uid", Value: session.GetUserId()},
log.Field{Key: "condIds", Value: conds})
ok := false
for _, v := range conds {
if v.State == pb.BuriedItemFinishState_buried_finish {
ok = true
}
}
if ok {
session.SendMsg(string(comm.ModuleReddot), "change", &pb.ReddotChangePush{Rids: []*pb.ReddotItem{
{
Rid: int32(comm.Reddot36101),
Activated: true,
},
}})
}
}
// 红点需求
func (this *Moonlv) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
var (
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot36101}
info *pb.DBMoonLv
conf *cfg.GameMoonLvData
tconfs []*cfg.GameMoonTaskData
comdi []int32
condisProgress []*pb.ConIProgress
err error
ok bool
)
items = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range selfrid {
if _, ok = rid[v]; ok {
break
}
}
if !ok {
return
}
if info, err = this.modelMoonlv.getMoonlvList(session); err != nil {
return
}
if conf, err = this.configure.GetMoonLvConf(info.Cid); err != nil {
return
}
if tconfs, err = this.configure.GetMoonLvTaskConf(conf.TaskGroupId); err != nil {
return
}
for _, v := range selfrid {
if _, ok = rid[v]; ok {
switch v {
case comm.Reddot36101:
for _, v := range tconfs {
comdi = append(comdi, v.TaskId)
}
if _, condisProgress, err = this.ModuleBuried.CheckCondition(session, comdi...); err != nil {
this.Errorln(err)
return
}
for _, v := range condisProgress {
if v.State == pb.BuriedItemFinishState_buried_finish {
if value, ok := info.Tasks[v.Conid]; !ok || value == 0 {
items[comm.Reddot34101] = &pb.ReddotItem{
Rid: int32(comm.Reddot34101),
Activated: true,
}
break
}
}
}
break
}
}
}
return
}