go_dreamfactory/modules/integral/module.go
2024-01-02 15:53:39 +08:00

112 lines
2.7 KiB
Go

package integral
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
type Integral struct {
modules.ModuleBase
modelIntegral *modelIntegral
api *apiComp
configure *configureComp
battle comm.IBattle
service base.IRPCXService
modelRank *modelRank
}
func NewModule() core.IModule {
return &Integral{}
}
func (this *Integral) GetType() core.M_Modules {
return comm.ModuleIntegral
}
func (this *Integral) 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)
return
}
func (this *Integral) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
return
}
this.battle = module.(comm.IBattle)
return
}
func (this *Integral) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelIntegral = this.RegisterComp(new(modelIntegral)).(*modelIntegral)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelRank = this.RegisterComp(new(modelRank)).(*modelRank)
}
// 任务条件达成通知
func (this *Integral) BuriedsNotify(session comm.IUserSession, conds []*pb.ConIProgress) {
var bChange bool
this.Debug("积分boss条件达成通知", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "conds", Value: conds})
dt, err := this.modelIntegral.getIntegralList(session)
if dt.Itype != 2 { // 只有事件模式才有debuff
return
}
confList := this.configure.GetIntegralCondition()
if err != nil {
this.Error(err.Error())
return
}
condMap := make(map[int32]*pb.ConIProgress)
for _, conf := range confList {
for _, cond := range conds {
if cond.Conid == conf.TaskId {
condMap[conf.TaskId] = cond
}
}
}
update := make(map[string]interface{})
if dt.Buff == nil {
dt.Buff = make(map[int32]int32)
for _, v := range condMap {
if v.State == pb.BuriedItemFinishState_buried_finish {
if c, err := this.configure.GetIntegralConditionByTask(v.Conid); err == nil {
dt.Buff[c.Id] = 1
bChange = true
}
}
}
}
for k, v := range condMap {
if dt.Buff[k] != 1 && v.State == pb.BuriedItemFinishState_buried_finish {
dt.Buff[k] = 1
bChange = true
}
}
if bChange {
update["buff"] = dt.Buff
if err := this.modelIntegral.modifyIntegralData(session.GetUserId(), update); err != nil {
this.Error(err.Error())
return
}
}
return
}