package mainline import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "sort" ) type Mainline struct { modules.ModuleBase modelMainline *ModelMainline api *apiComp configure *configureComp } 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) { err = this.ModuleBase.Init(service, module, options) return } func (this *Mainline) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelMainline = this.RegisterComp(new(ModelMainline)).(*ModelMainline) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } // 接口信息 给其他模块调用 用来修改主线关卡信息 func (this *Mainline) ModifyMainlineData(uid string, objId string, data map[string]interface{}) (code pb.ErrorCode) { err := this.modelMainline.modifyMainlineData(uid, objId, data) if err != nil { code = pb.ErrorCode_DBError } return } // 校验是否能挑战该关卡 func (this *Mainline) CheckChallengeChapter(stroyId int32, uid string, zhangjieID int32) (code pb.ErrorCode) { var ( curChapter *pb.DBMainline ) _szData, err := this.modelMainline.getMainlineList(uid) if err != nil { code = pb.ErrorCode_DBError return } sort.SliceStable(_szData, func(i, j int) bool { // 排序 return _szData[i].ChapterId > _szData[j].ChapterId }) // 取出最后一条数据 curChapter = _szData[len(_szData)-1] if curChapter == nil { code = pb.ErrorCode_MainlineNotFindChapter // 没有找到主线关卡信息 return } // 获取关卡难度用来取配置文件 switch curChapter.Intensity { case 1: configData := this.configure.GetMainlineEasyChapter(curChapter.MainlineId) if configData != nil { // 校验章节 if configData.Chapter != zhangjieID { code = pb.ErrorCode_ConfigNoFound return } // 如果这一关是路线二的话 if configData.Route == 2 && curChapter.ChapterId > stroyId { // 当前的关卡ID 大于路线2的ID 即可 return } // 判断下一关是不是当前传入的值 if configData.Previoustage != stroyId { code = pb.ErrorCode_MainlineIDFailed return } } break case 2: configData := this.configure.GetMainlineHardChapter(curChapter.MainlineId) if configData != nil { // 校验章节 if configData.Chapter != zhangjieID { code = pb.ErrorCode_ConfigNoFound return } // 判断下一关是不是当前传入的值 if configData.Previoustage != stroyId { code = pb.ErrorCode_MainlineIDFailed return } } break } return }