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]*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 *Mline) CheckPoint(uid string) bool { list, err := this.modelMline.getMainlineList(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 } // 参数 难度 + 章节id func (this *Mline) ModifyMlineDataByNanduID(session comm.IUserSession, id int32) (errdata *pb.ErrorData) { var del []string var newChapter []int32 var _mp map[int32]int32 _mp = make(map[int32]int32) connf, err := this.configure.GetMainStageConf(id) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: err.Error(), } return } list, err := this.modelMline.getMainlineList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } for _, v := range list { del = append(del, v.Id) } // 清除 this.modelMline.cleanChapterDataById(session.GetUserId(), del...) _data := this.configure.GetAllStageByChapterID(connf.Chapterid) newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CType: connf.Episodetype, ChapterId: connf.Chapterid, StageId: id, Star: map[int32]int32{}, Award: map[int32]bool{}, Ps: map[int32]int32{}, } for _, v := range _data { if v <= id { newData.Star[v] = 7 } } itype := this.configure.GetMainChapterConf(connf.Chapterid).ChapterType if _, ok := _mp[itype]; !ok { _mp[itype] = newData.StageId } for k, v := range _mp { if k == itype && v <= newData.StageId { _mp[itype] = newData.StageId } } newChapter = append(newChapter, connf.Chapterid) // 更新 this.modelMline.addNewChapter(session.GetUserId(), newData) // 获取之前的章节数据 for _, v := range this.configure.GMGetPreStage(connf.Chapterid) { newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CType: connf.Episodetype, ChapterId: v, StageId: 0, Star: map[int32]int32{}, Award: map[int32]bool{}, Ps: map[int32]int32{}, } _data := this.configure.GetAllStageByChapterID(v) for _, v := range _data { if v <= id { newData.Star[v] = 7 newData.StageId = v } } itype := this.configure.GetMainChapterConf(v).ChapterType if _, ok := _mp[itype]; !ok { _mp[itype] = newData.StageId } for k, v := range _mp { if k == itype && v <= newData.StageId { _mp[itype] = newData.StageId } } newChapter = append(newChapter, v) // 更新 this.modelMline.addNewChapter(session.GetUserId(), newData) } // 修改扩展数据 if _, err := this.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度 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, err := this.configure.GetMainStageConf(stageId) if err != 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 }