135 lines
3.1 KiB
Go
135 lines
3.1 KiB
Go
package achieve
|
|
|
|
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 Achieve struct {
|
|
modules.ModuleBase
|
|
service core.IService
|
|
wtask comm.IWtask
|
|
api *apiComp
|
|
model *modelComp
|
|
configure *configureComp
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Achieve{}
|
|
}
|
|
|
|
func (this *Achieve) GetType() core.M_Modules {
|
|
return comm.ModuleAchieve
|
|
}
|
|
|
|
func (this *Achieve) 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 *Achieve) 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 *Achieve) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.model = this.RegisterComp(new(modelComp)).(*modelComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 任务条件达成通知
|
|
func (this *Achieve) 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.Reddot34101),
|
|
Activated: true,
|
|
},
|
|
}})
|
|
}
|
|
}
|
|
|
|
// 红点需求
|
|
func (this *Achieve) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
|
|
var (
|
|
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot34101}
|
|
confs []*cfg.GameAchieveTaskData
|
|
info *pb.DBAchieveData
|
|
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 confs, err = this.configure.getAchieveTaskAll(); err != nil {
|
|
return
|
|
}
|
|
|
|
if info, err = this.model.getmodel(session.GetUserId()); err != nil {
|
|
return
|
|
}
|
|
|
|
for _, v := range selfrid {
|
|
if _, ok = rid[v]; ok {
|
|
switch v {
|
|
case comm.Reddot34101:
|
|
for _, v := range confs {
|
|
comdi = append(comdi, v.Key)
|
|
}
|
|
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.Receive[v.Conid]; !ok || !value {
|
|
items[comm.Reddot34101] = &pb.ReddotItem{
|
|
Rid: int32(comm.Reddot34101),
|
|
Activated: true,
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|