go_dreamfactory/modules/buried/module.go
2023-05-25 13:42:09 +08:00

160 lines
4.1 KiB
Go

package buried
import (
"fmt"
"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"
"time"
)
/*
模块名:用户埋点完成条件触发系统
模块描述:用户埋点数据中心管理模块
开发人员:李伟
*/
type Buried struct {
modules.ModuleBase
service base.IRPCXService
configure *configureComp
modelBuried *modelBuried
}
func NewModule() core.IModule {
return &Buried{}
}
func (this *Buried) GetType() core.M_Modules {
return comm.ModuleBuried
}
func (this *Buried) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
func (this *Buried) Start() (err error) {
err = this.ModuleBase.Start()
return
}
//装备组件
func (this *Buried) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelBuried = this.RegisterComp(new(modelBuried)).(*modelBuried)
}
//激活数据采集点
func (this *Buried) ActivationBuried(uid string, conids ...int32) (err error) {
return
}
//触发埋点
func (this *Buried) TriggerBuried(uid string, burieds ...*comm.BuriedParam) {
var (
pass map[*comm.BuriedParam][]*cfg.GameBuriedCondiData = make(map[*comm.BuriedParam][]*cfg.GameBuriedCondiData)
model *buriedModel
bdatas map[int32]*pb.DBBuried
bdata *pb.DBBuried
ok bool
complete bool
completeConIds []int32 //完成id列表
err error
)
if model, err = this.modelBuried.getburiedModel(uid); err != nil {
this.Error("获取用户埋点数据模型对象失败!", log.Field{Key: "err", Value: err.Error()})
return
}
for _, buried := range burieds {
conds := this.configure.getCondiDatas(buried.Btype)
for _, cond := range conds {
if checkburied(buried, cond) { //判断此埋点数据是否有效
if _, ok := pass[buried]; !ok {
pass[buried] = make([]*cfg.GameBuriedCondiData, 0)
}
pass[buried] = append(pass[buried], cond)
}
}
}
if len(pass) > 0 {
if bdatas, err = model.getUserBurieds(uid); err != nil {
return
}
}
completeConIds = make([]int32, 0)
//处理校验通过埋点数据
for buried, conds := range pass {
if bdata, ok = bdatas[bdata.Btype]; !ok {
bdatas[bdata.Btype] = &pb.DBBuried{
Uid: uid,
Btype: bdata.Btype,
Items: make(map[int32]*pb.DBBuriedItem),
}
}
for _, cond := range conds {
if cond.Rtype == rtype1 { //创号后入录
if complete, err = this.updateAndCheckBuried(bdata, buried, cond, true); complete {
completeConIds = append(completeConIds, cond.Id)
}
} else if cond.Rtype == rtype2 { //任务接取后才会录入 判断用户埋点数据是否存在 不存在等待任务系统调用接口 ActivationBuried 激活
if complete, err = this.updateAndCheckBuried(bdata, buried, cond, false); complete {
completeConIds = append(completeConIds, cond.Id)
}
}
}
}
//通知事件
if len(completeConIds) > 0 {
}
}
//更新并校验完成
func (this *Buried) updateAndCheckBuried(bdata *pb.DBBuried, burie *comm.BuriedParam, cond *cfg.GameBuriedCondiData, autoActivated bool) (complete bool, err error) {
var (
ok bool
bitem *pb.DBBuriedItem
)
if bitem, ok = bdata.Items[int32(cond.Id)]; !ok {
if autoActivated { //自动激活
bitem = &pb.DBBuriedItem{
Conid: cond.Id,
State: pb.BuriedItemState_Activated,
Value: 0,
Timestamp: time.Now().Unix(),
}
} else {
return
}
}
if bitem.State == pb.BuriedItemState_Inactivated || bitem.State == pb.BuriedItemState_Freeze { //未激活和冻结 不在处理
return
}
switch cond.Vtype { //数据接入方式
case overlay: //累加数据
bitem.Value += burie.Value
case cover:
bitem.Value = burie.Value
default:
err = fmt.Errorf("未知的埋点数据处理类型:%d", cond.Vtype)
return
}
if bitem.Value >= cond.Value { //完成进度
complete = true
}
return
}