go_dreamfactory/modules/mainline/module.go
2023-12-18 14:51:49 +08:00

195 lines
5.0 KiB
Go

package mainline
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 Mainline struct {
modules.ModuleBase
modelMline *ModelMline
service core.IService
api *apiComp
configure *configureComp
battle comm.IBattle
modelShop *ModelShop
modelTask *Modeltask
}
func NewModule() core.IModule {
return &Mainline{}
}
func (this *Mainline) GetType() core.M_Modules {
return comm.ModuleMainline
}
func (this *Mainline) 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 *Mainline) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelMline = this.RegisterComp(new(ModelMline)).(*ModelMline)
this.modelShop = this.RegisterComp(new(ModelShop)).(*ModelShop)
this.modelTask = this.RegisterComp(new(Modeltask)).(*Modeltask)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
func (this *Mainline) 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 *Mainline) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range rid {
if v == comm.Reddot24101 {
reddot[comm.Reddot24101] = &pb.ReddotItem{
Rid: int32(comm.Reddot24101),
Activated: this.CheckPoint(session.GetUserId()),
}
break
}
}
return
}
// 红点检测
func (this *Mainline) CheckPoint(uid string) bool {
// info, err := this.modelMline.getMainlineData(uid)
// if err != nil {
// return false
// }
// for _, v := range list {
// mLineConf := this.configure.GetMainChapterConf(v.ChapterId)
// if mLineConf == nil {
// return false
// }
// var maxstar int32
// for _, v1 := range v.Star {
// maxstar += v1
// }
// awardConf := this.configure.GetMainStarRewardConf(mLineConf.Starreward)
// for _, v1 := range awardConf {
// if v1.Starnum > maxstar {
// break
// }
// if _, ok := v.Award[v1.Starnum]; !ok { // 找到没有领奖的数据
// return true
// }
// }
// }
return false
}
// 跳转主线管卡
func (this *Mainline) BingoJumpLevel(session comm.IUserSession, level int32) (errdata *pb.ErrorData) {
var (
info *pb.DBMainline
confs []*cfg.GameMainStageData
err error
)
if confs, err = this.configure.GetMainStageConfs(); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
info, err = this.modelMline.getMainlineData(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
info.Level = make(map[int32]int32)
info.Lastlevel = make(map[int32]*pb.DBMainlineLastLevel)
info.Chapteraward = make(map[int32]*pb.DBMainlineAward)
info.Exploreaward = make(map[int32]*pb.DBMainlineAward)
info.Groupaward = make(map[int32]*pb.DBMainlineAward)
for _, v := range confs {
if v.Id <= level {
info.Level[v.Id] = 7
}
}
this.modelMline.updateprogress(info)
if err = this.modelMline.updateMainlineData(session.GetUserId(), info); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
return
}
// 查询用户主线通关 db.changeUserPassword("root", "palsweasd*1!")
func (this *Mainline) InquireMainLinePassLevel(uid string) (levels map[int32]int32) {
var (
info *pb.DBMainline
err error
)
levels = make(map[int32]int32)
info, err = this.modelMline.getMainlineData(uid)
if err != nil {
this.Errorln(err)
return
}
levels = info.Level
return
}
// 埋点完成通知
func (this *Mainline) BuriedsNotify(session comm.IUserSession, conds []*pb.ConIProgress) {
this.Debug("主线任务通知", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "conds", Value: conds})
var (
szChange []int32
)
info, err := this.modelShop.getMainlineShopData(session.GetUserId())
if err == nil {
shopinfo := this.configure.GetAllShopConf()
info.Unlock = make(map[int32]int32)
for _, v1 := range shopinfo {
if _, ok := info.Unlock[v1.Key]; !ok {
for _, v := range conds {
if int32(v.State) == 1 && v.Conid == v1.Unlock { // 记录解锁的数据
info.Unlock[v1.Key] = 1
szChange = append(szChange, v1.Key)
}
}
}
}
if len(szChange) > 0 {
this.modelShop.updateMainlineShopData(session.GetUserId(), info)
session.SendMsg(string(this.GetType()), "shopchange", &pb.MainlineShopChangePush{
Cid: szChange,
})
}
}
}