go_dreamfactory/modules/dispatch/module.go
2024-02-26 15:10:55 +08:00

119 lines
2.5 KiB
Go

package dispatch
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
// 默认6条公告数量
const noticeNum int = 6
// 派遣
type Dispatch struct {
modules.ModuleBase
api *apiComp
configure *configureComp
modelDispatch *modelDispatch
}
func NewModule() core.IModule {
return &Dispatch{}
}
func (this *Dispatch) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
if err = this.ModuleBase.Init(service, module, options); err != nil {
return
}
return
}
func (this *Dispatch) GetType() core.M_Modules {
return comm.ModuleDispatch
}
func (this *Dispatch) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelDispatch = this.RegisterComp(new(modelDispatch)).(*modelDispatch)
}
//红点查询
func (this *Dispatch) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
var (
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot18105, comm.Reddot18112}
info *pb.DBDispatch
mintime int64
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.modelDispatch.getDBDispatch(session.GetUserId()); err != nil {
this.Errorln(err)
return
}
for _, v := range selfrid {
if _, ok = rid[v]; ok {
switch v {
case comm.Reddot18105:
ok = false
for _, v := range info.Nb.Tasks {
if v.Status == 1 {
if mintime == 0 || mintime > v.Duration {
mintime = v.Duration
}
}
if v.Status == 2 {
ok = true
}
}
items[comm.Reddot18105] = &pb.ReddotItem{
Rid: int32(comm.Reddot18105),
Activated: ok,
Nextchanagetime: mintime,
}
break
case comm.Reddot18112:
//派发奖励
wr := this.ModuleTools.GetGlobalConf().DispatchWeektaskreward
for i, v := range wr {
Idx := int32(i + 1)
ok = false
for _, v := range info.Nb.WeekReceived {
if v == Idx {
ok = true
break
}
}
if ok {
continue
}
if info.Nb.WeekCount >= v.N {
items[comm.Reddot18112] = &pb.ReddotItem{
Rid: int32(comm.Reddot18112),
Activated: true,
}
break
}
}
break
}
}
}
return
}