package mline import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson/primitive" ) type Mline struct { modules.ModuleBase modelMline *ModelMline service core.IService api *apiComp configure *configureComp battle comm.IBattle } func NewModule() core.IModule { return &Mline{} } func (this *Mline) GetType() core.M_Modules { return comm.ModuleMline } func (this *Mline) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service return } func (this *Mline) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelMline = this.RegisterComp(new(ModelMline)).(*ModelMline) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } func (this *Mline) Start() (err error) { err = this.ModuleBase.Start() var module core.IModule if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { return } this.battle = module.(comm.IBattle) return } //红点查询 func (this *Mline) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) { reddot = make(map[comm.ReddotType]bool) for _, v := range rid { if v == comm.Reddot5 { reddot[comm.Reddot5] = this.CheckPoint(session.GetUserId()) break } } return } // 红点检测 func (this *Mline) CheckPoint(uid string) bool { list, err := this.modelMline.getMainlineList(uid) if err != nil { return false } for _, v := range list { b := false for _, v1 := range this.configure.GetAllChapterID() { if v.ChapterId == v1 { b = true continue } } if !b { return false } // 查看所有小关是否通关 szStage := this.configure.GetAllStageByChapterID(v.ChapterId) if len(szStage) != len(v.Star) { return false } } return false } // 参数 难度 + 章节id func (this *Mline) ModifyMlineDataByNanduID(session comm.IUserSession, id int32) (code pb.ErrorCode) { var del []string connf := this.configure.GetMainStageConf(id) if connf == nil { return } list, err := this.modelMline.getMainlineList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } for _, v := range list { del = append(del, v.Id) } // 清除 this.modelMline.cleanChapterDataById(session.GetUserId(), del...) _data := this.configure.GetAllChapterID() for _, v := range _data { if v <= connf.Chapterid { newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CType: connf.Episodetype, ChapterId: v, StageId: id, Star: map[int32]int32{}, Award: map[int32]bool{}, Ps: map[int32]int32{}, } stageConf := this.configure.GetAllStageByChapterID(v) for _, v := range stageConf { newData.Star[v] = 3 } this.modelMline.addNewChapter(session.GetUserId(), newData) } } // 修改扩展数据 if rst, err := this.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度 _mp := rst.Mline var cType int32 conf := this.configure.GetMainChapterConf(connf.Chapterid) if conf != nil { cType = conf.ChapterType } if _mp == nil { _mp = make(map[int32]int32, 1) _mp[cType] = id } else { if v, ok := _mp[cType]; ok { if v <= id { _mp[cType] = id } } else { _mp[cType] = id } } this.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ "mline": _mp, }) } return } func (this *Mline) GetUserMlineData(uid string, chapterType int32) (chapterId int32) { if rst, err := this.ModuleUser.GetUserExpand(uid); err == nil { // 统计主线进度 _mp := rst.Mline if v, ok := _mp[chapterType]; ok { chapterId = v return } } return } func (this *Mline) CheckCommpleteStage(uid string, stageId int32) (b bool) { conf := this.configure.GetMainStageConf(stageId) if conf == nil { return false } _szData, err := this.modelMline.getMainlineList(uid) if err == nil { for _, v := range _szData { if _, ok := v.Star[conf.Id]; ok { return true } } } return true }