diff --git a/modules/friend/api_cross_agree.go b/modules/friend/api_cross_agree.go index c22c3924b..ffea4e561 100644 --- a/modules/friend/api_cross_agree.go +++ b/modules/friend/api_cross_agree.go @@ -168,7 +168,6 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (e // event.TriggerEvent(comm.EventFriendChange, uid, int32(len(self.FriendIds))) } - go this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeFriend, int32(len(self.FriendIds))) // 拥有xx个好友 // this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype10, int32(len(agreeIds))) var tasks []*pb.BuriedParam @@ -180,11 +179,13 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (e Num: optNum, } session.SendMsg(string(this.module.GetType()), FriendSubTypeAgree, resp) - if len(tasks) > 0 { - go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeFriend, int32(len(self.FriendIds))) + if len(tasks) > 0 { this.module.ModuleBuried.TriggerBuried(session, tasks...) - }) - } + } + }) return } diff --git a/modules/friend/api_cross_del.go b/modules/friend/api_cross_del.go index ac36a2734..6d012ee50 100644 --- a/modules/friend/api_cross_del.go +++ b/modules/friend/api_cross_del.go @@ -78,8 +78,9 @@ func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (errda ) return } - go this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeFriend, int32(len(self.FriendIds))) session.SendMsg(string(this.module.GetType()), FriendSubTypeDel, &pb.FriendDelResp{FriendId: req.FriendId, UserId: self.Uid}) - + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeFriend, int32(len(self.FriendIds))) + }) return } diff --git a/modules/mline/api.go b/modules/mline/api.go deleted file mode 100644 index 6d1c0f420..000000000 --- a/modules/mline/api.go +++ /dev/null @@ -1,34 +0,0 @@ -package mline - -import ( - "go_dreamfactory/lego/core" - "go_dreamfactory/modules" -) - -const ( - MlineGetListResp = "getlist" - MlineChallengeResp = "challenge" - MlineCleanStageResp = "cleanstage" - MlineChallengeOverResp = "challengeover" - MlineGetRewardResp = "getreward" -) - -type apiComp struct { - modules.MCompGate - service core.IService - module *Mline -} - -//组件初始化接口 -func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - err = this.MCompGate.Init(service, module, comp, options) - this.module = module.(*Mline) - this.service = service - return -} - -func (this *apiComp) Start() (err error) { - err = this.MCompGate.Start() - - return -} diff --git a/modules/mline/api_challenge.go b/modules/mline/api_challenge.go deleted file mode 100644 index 911d6da9c..000000000 --- a/modules/mline/api_challenge.go +++ /dev/null @@ -1,146 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - cfg "go_dreamfactory/sys/configure/structs" - - "go.mongodb.org/mongo-driver/bson/primitive" -) - -// 参数校验 -func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (errdata *pb.ErrorData) { - if req.StageId == 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - } - } - return -} - -// /挑战主线关卡 -func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (errdata *pb.ErrorData) { - var ( - curChapter *pb.DBMline // 当前章节信息 - ps int32 // 消耗的体力 - psAnt *cfg.Gameatn - stageConf *cfg.GameMainStageData // 当前章节数据 - preStageConf *cfg.GameMainStageData // 上一章节数据 - err error - bNew bool // 是否是新章节 - ) - - if errdata = this.ChallengeCheck(session, req); errdata != nil { - return // 参数校验失败直接返回 - } - if stageConf, err = this.module.configure.GetMainStageConf(req.StageId); err != nil { // 配置文件校验 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - Message: err.Error(), - } - return - } - - list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) - for _, v := range list { - if stageConf.Chapterid == v.ChapterId { - curChapter = v - break - } - } - - if stageConf.Previoustage != 0 { // 前置关卡是0 不需要做校验 直接通过 - preStageConf, err = this.module.configure.GetMainStageConf(stageConf.Previoustage) - if err != nil { // 配置文件校验 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - Message: err.Error(), - } - return - } - - for _, v := range list { - if preStageConf.Chapterid == v.ChapterId { // 有上一章节数据 - if _, ok := v.Star[preStageConf.Id]; !ok { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlinePreNotFound, - Title: pb.ErrorCode_MainlinePreNotFound.ToString(), - } - return - } - break - } - } - - } - if curChapter == nil { - curChapter = &pb.DBMline{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - CType: stageConf.Episodetype, - ChapterId: stageConf.Chapterid, - StageId: stageConf.Id, - Star: map[int32]int32{}, - Award: map[int32]bool{}, - Ps: map[int32]int32{}, - } - bNew = true - } - if v1, ok := curChapter.Ps[req.StageId]; !ok || v1 == 0 { - - for _, v := range stageConf.PsConsume { - if v.A == "attr" && v.T == "ps" { - ps += v.N - } - } - for _, v := range stageConf.PsMg { - if v.A == "attr" && v.T == "ps" { - ps += v.N - } - } - psAnt = &cfg.Gameatn{ // 构建一个atn 对象 - A: "attr", - T: "ps", - N: ps, - } - if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); errdata != nil { - return - } - - curChapter.Ps[req.StageId] = ps - if bNew { - this.module.modelMline.addNewChapter(session.GetUserId(), curChapter) // 首次打新的章节 - } else { - this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{"ps": curChapter.Ps}) - } - } - errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ - Rulesid: stageConf.BattleReadyID, - Ptype: pb.PlayType_mainline, - Title: "", - Format: req.Battle, - Mformat: stageConf.FormatList, - }) - if errdata != nil { - return - } - session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MlineChallengeResp{ - Info: &pb.BattleInfo{ - Id: record.Id, - Title: record.Title, - Rulesid: stageConf.BattleReadyID, - Btype: record.Btype, - Ptype: record.Ptype, - RedCompId: record.RedCompId, - Redflist: record.Redflist, - BlueCompId: record.BlueCompId, - Buleflist: record.Buleflist, - Tasks: record.Tasks, - }, - StageId: req.StageId, - }) - return -} diff --git a/modules/mline/api_challengeover.go b/modules/mline/api_challengeover.go deleted file mode 100644 index 941b3e970..000000000 --- a/modules/mline/api_challengeover.go +++ /dev/null @@ -1,265 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - cfg "go_dreamfactory/sys/configure/structs" -) - -// 参数校验 -func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) { - if req.StageId == 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - } - return - } - return -} - -// /挑战主线关卡 -func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) { - var ( - curChapter *pb.DBMline // 当前章节信息 - stageConf *cfg.GameMainStageData - - isWin bool - first bool // 判断是否是首通 - update map[string]interface{} - rsp *pb.MlineChallengeOverResp - star int32 // 评星 - tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0) - err error - consumPs int32 - ) - rsp = &pb.MlineChallengeOverResp{} - update = make(map[string]interface{}) - if errdata = this.ChallengeOverCheck(session, req); errdata != nil { - return // 参数校验失败直接返回 - } - if stageConf, err = this.module.configure.GetMainStageConf(req.StageId); err != nil { // 配置文件校验 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - Message: err.Error(), - } - return - } - - list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) - for _, v := range list { - if stageConf.Chapterid == v.ChapterId { - curChapter = v - break - } - } - if curChapter == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - } - return - } - // 校验通过 - errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report) - if errdata != nil { - return - } - // if v, ok := curChapter.Ps[req.StageId]; !ok || v == 0 { - // errdata = &pb.ErrorData{ - // Code: pb.ErrorCode_HuntingLvErr, - // Title: pb.ErrorCode_HuntingLvErr.ToString(), - // Message: fmt.Sprintf("关卡体力参数异常,uid:%s,预扣体力:%d", session.GetUserId(), v), - // } - // return - // } - consumPs = curChapter.Ps[req.StageId] - curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 - update["ps"] = curChapter.Ps - if !isWin { // 战斗失败返还扣除的体力 - if errdata = this.module.DispenseRes(session, stageConf.PsConsume, true); errdata != nil { // 返还预扣体力 - return - } - this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) - - rsp.Data = curChapter - session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 - return - } - // 评星规则 - if len(stageConf.Star) != len(stageConf.StarType) || len(stageConf.Star) != len(stageConf.StarValue) || len(stageConf.StarValue) != len(stageConf.StarType) { - this.module.Errorf("配置错误, 参数数量不一致,StageId: %d", req.StageId) - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ConfigNoFound, - Title: pb.ErrorCode_ConfigNoFound.ToString(), - } - return - } - - var szStar []int32 - szStar = append(szStar, 1<<0) - szStar = append(szStar, 1<<1) - szStar = append(szStar, 1<<2) - for i, v := range stageConf.StarType { - if v == comm.MainStarType1 { - star ^= szStar[i] - } else if v == comm.MainStarType2 { - if req.Report.Death <= stageConf.StarValue[i] { - star ^= szStar[i] - } - } else if v == comm.MainStarType3 { - if req.Report.Round <= stageConf.StarValue[i] { - star ^= szStar[i] - } - } - } - - // 判断是不是首通 - if _, ok := curChapter.Star[req.StageId]; !ok { - first = true - curChapter.Star[req.StageId] = star // 星级赋值 - update["star"] = curChapter.Star - } - - // 判断星数 - var ( - totalStar int32 - preStar int32 - ) - if curChapter.Star[req.StageId] != star { - for _, v := range szStar { - if star&v == v { - totalStar++ - } - - if curChapter.Star[req.StageId]&v == v { - preStar++ - } - } - if totalStar >= preStar { // 给最高星 - curChapter.Star[req.StageId] = star - update["star"] = curChapter.Star - } - } - - curChapter.StageId = req.StageId - update["stageId"] = curChapter.StageId - - if first { // 发奖 - if rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度 - _mp := rst.Mline - if v, ok := _mp[curChapter.CType]; ok { - if v <= req.StageId { - _mp[curChapter.CType] = req.StageId - } - } else { - _mp[curChapter.CType] = req.StageId - } - this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ - "mline": _mp, - }) - } - - if errdata = this.module.DispenseRes(session, stageConf.Firstaward, true); errdata != nil { - this.module.Debugf("Mline first DispenseRes err:+%v", stageConf.Firstaward) - } - for _, v := range stageConf.Firstaward { - rsp.Reward = append(rsp.Reward, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } else { - if errdata = this.module.DispenseRes(session, stageConf.Commonaward, true); errdata != nil { - this.module.Debugf("Mline Commonaward DispenseRes err:+%v", stageConf.Commonaward) - } - for _, v := range stageConf.Commonaward { - rsp.Reward = append(rsp.Reward, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } - user, err := this.module.ModuleUser.GetUser(session.GetUserId()) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), - } - return - } - if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(stageConf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 { - if errdata = this.module.DispenseRes(session, lotteryward, true); errdata != nil { - this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward) - } - for _, v := range lotteryward { - rsp.Reward = append(rsp.Reward, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } - // 加英雄经验 - if stageConf.HeroExp > 0 { - var heroObjs []string - if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { - for _, v := range req.Report.Info.Redflist[0].Team { - if !v.Ishelp { // 助战英雄不加经验 - heroObjs = append(heroObjs, v.Oid) - } - } - } - this.module.ModuleHero.AddHerosExp(session, heroObjs, stageConf.HeroExp) - } - - rsp.HeroExp = stageConf.HeroExp - rsp.UserExp, _ = this.module.ModuleUser.ConsumePsAddExp(session, consumPs) - this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) - rsp.Data = curChapter - session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 - // 校验功能开启 - module, err2 := this.module.service.GetModule(comm.ModuleSys) - if err2 == nil { - if isys, ok := module.(comm.ISys); ok { - isys.CheckOpenCond(session, comm.OpencondTypeMaxmapid, req.StageId) // 校验新功能是否开启 - } - } - // 主线任务统计 Rtype60 - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype60, 1)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype61, 1, int32(req.StageId))) - var ( - ChapterStar int32 - allStar int32 - ) - for _, v1 := range curChapter.Star { - star := 0 - for _, v := range szStar { - if v1&v == v { - ChapterStar++ - star++ - } - } - } - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype158, ChapterStar, curChapter.ChapterId, curChapter.CType)) - for _, v2 := range list { - for _, v1 := range v2.Star { - for _, v := range szStar { - if v1&v == v { - allStar++ - } - } - } - } - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype160, allStar, stageConf.Chapterid)) - - go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { - this.module.ModuleBuried.TriggerBuried(session, tasks...) - }) - return -} diff --git a/modules/mline/api_cleanstage.go b/modules/mline/api_cleanstage.go deleted file mode 100644 index dfc4294e6..000000000 --- a/modules/mline/api_cleanstage.go +++ /dev/null @@ -1,77 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - cfg "go_dreamfactory/sys/configure/structs" -) - -//参数校验 -func (this *apiComp) CleanStageCheck(session comm.IUserSession, req *pb.MlineCleanStageReq) (errdata *pb.ErrorData) { - if req.StageId == 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - } - } - return -} - -///挑战主线关卡 -func (this *apiComp) CleanStage(session comm.IUserSession, req *pb.MlineCleanStageReq) (errdata *pb.ErrorData) { - var ( - curChapter *pb.DBMline // 当前章节信息 - stageConf *cfg.GameMainStageData - rsp *pb.MlineCleanStageResp - err error - ) - rsp = &pb.MlineCleanStageResp{} - if errdata = this.CleanStageCheck(session, req); errdata != nil { - return // 参数校验失败直接返回 - } - if stageConf, err = this.module.configure.GetMainStageConf(req.StageId); err != nil { // 配置文件校验 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - Message: err.Error(), - } - return - } - - list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) - for _, v := range list { - if stageConf.Chapterid == v.ChapterId { - curChapter = v - break - } - } - if curChapter == nil { // 校验是不是新的数据 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - } - return - } - if v, ok := curChapter.Star[req.StageId]; !ok || v < 3 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNoEnoughStar, - Title: pb.ErrorCode_MainlineNoEnoughStar.ToString(), - } - return - } - if errdata = this.module.DispenseRes(session, stageConf.Commonaward, true); errdata != nil { - this.module.Debugf("Mline Clean DispenseRes err:+%v", stageConf.Commonaward) - return - } - rsp.StageId = req.StageId - for _, v := range stageConf.Commonaward { - rsp.Reward = append(rsp.Reward, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - - session.SendMsg(string(this.module.GetType()), MlineChallengeResp, rsp) - return -} diff --git a/modules/mline/api_getReward.go b/modules/mline/api_getReward.go deleted file mode 100644 index d2fb56f54..000000000 --- a/modules/mline/api_getReward.go +++ /dev/null @@ -1,83 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" -) - -//参数校验 -func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.MlineGetRewardReq) (errdata *pb.ErrorData) { - if req.CId == 0 || req.Star == 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - } - } - return -} - -// 领取奖励 -func (this *apiComp) GetReward(session comm.IUserSession, req *pb.MlineGetRewardReq) (errdata *pb.ErrorData) { - var ( - curChapter *pb.DBMline // 当前章节信息 - update map[string]interface{} - rsp *pb.MlineGetRewardResp - ) - rsp = &pb.MlineGetRewardResp{} - update = make(map[string]interface{}) - if errdata = this.GetRewardCheck(session, req); errdata != nil { - return - } - - mLineConf := this.module.configure.GetMainChapterConf(req.CId) - if mLineConf == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ConfigNoFound, - Title: pb.ErrorCode_ConfigNoFound.ToString(), - } - return - } - list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) - for _, v := range list { - if req.CId == v.ChapterId { - curChapter = v - break - } - } - if curChapter == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineNotFindChapter, - Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), - } - return - } - if b, ok := curChapter.Award[req.Star]; ok && b { // 重复领奖 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_MainlineRepeatReward, - Title: pb.ErrorCode_MainlineRepeatReward.ToString(), - } - return - } - - curChapter.Award[req.Star] = true - update["award"] = curChapter.Award - awardConf := this.module.configure.GetMainStarRewardConf(mLineConf.Starreward) - for _, v := range awardConf { - if v.Starnum == req.Star { - if errdata = this.module.DispenseRes(session, v.Reward, true); errdata != nil { - return - } - for _, v := range v.Reward { - rsp.Reward = append(rsp.Reward, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } - } - rsp.Data = curChapter - this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) - session.SendMsg(string(this.module.GetType()), MlineGetRewardResp, rsp) // 数据推送 - return -} diff --git a/modules/mline/api_getlist.go b/modules/mline/api_getlist.go deleted file mode 100644 index 488f67f8a..000000000 --- a/modules/mline/api_getlist.go +++ /dev/null @@ -1,72 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "go.mongodb.org/mongo-driver/bson/primitive" -) - -//参数校验 -func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) { - if req.CType == 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ReqParameterError, - Title: pb.ErrorCode_ReqParameterError.ToString(), - } - } - return -} - -///获取主线关卡信息 -func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq) (errdata *pb.ErrorData) { - rsp := &pb.MlineGetListResp{} - - errdata = this.GetListCheck(session, req) - if errdata != nil { - return // 参数校验失败直接返回 - } - - list, err := this.module.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 { - if v.CType == req.CType { - rsp.Data = append(rsp.Data, v) - } - } - if len(rsp.Data) == 0 { // 什么数据都没有 创建一条 - if chapterConf, err := this.module.configure.GetFirstChapterIDByType(req.CType); err == nil { // 配置文件校验 - if stageConf := this.module.configure.GetFirstStageIDByChapter(chapterConf.Id); stageConf != nil { - newData := &pb.DBMline{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - CType: stageConf.Episodetype, - ChapterId: stageConf.Chapterid, - StageId: stageConf.Id, - Star: map[int32]int32{}, - Award: map[int32]bool{}, - Ps: map[int32]int32{}, - } - rsp.Data = append(rsp.Data, newData) - this.module.modelMline.addNewChapter(session.GetUserId(), newData) - } - } else { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ConfigNoFound, - Title: pb.ErrorCode_ConfigNoFound.ToString(), - Message: err.Error(), - } - return - } - } - - session.SendMsg(string(this.module.GetType()), MlineGetListResp, rsp) - return -} diff --git a/modules/mline/comp_configure.go b/modules/mline/comp_configure.go deleted file mode 100644 index 2faa4de69..000000000 --- a/modules/mline/comp_configure.go +++ /dev/null @@ -1,183 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/lego/core" - "go_dreamfactory/modules" - "go_dreamfactory/sys/configure" - cfg "go_dreamfactory/sys/configure/structs" - "sync" -) - -const moduleName = "mline" -const ( - game_mainchapter = "game_mainchapter.json" - game_mainstage = "game_mainstage.json" - game_mainstarreward = "game_mainstarreward.json" -) - -///配置管理基础组件 -type configureComp struct { - modules.MCompConfigure - module *Mline - hlock sync.RWMutex - - _mapMilne map[int32][]int32 // key 章节id value cid -} - -//组件初始化接口 -func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - err = this.MCompConfigure.Init(service, module, comp, options) - this.module = module.(*Mline) - err = this.LoadMultiConfigure(map[string]interface{}{ - game_mainchapter: cfg.NewGameMainChapter, - game_mainstage: cfg.NewGameMainStage, - game_mainstarreward: cfg.NewGameMainStarreward, - }) - - configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.LoadMlineStage) - - return -} - -//读取配置数据 -func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { - return configure.GetConfigure(name) - -} - -func (this *configureComp) GetMainChapterConf(id int32) (data *cfg.GameMainChapterData) { - if v, err := this.GetConfigure(game_mainchapter); err == nil { - if configure, ok := v.(*cfg.GameMainChapter); ok { - return configure.Get(id) - } - } - this.module.Errorf("GameMainChapterData conf not found key :%d", id) - return -} - -func (this *configureComp) GetMainStarRewardConf(boxId int32) (data []*cfg.GameMainStarrewardData) { - if v, err := this.GetConfigure(game_mainstarreward); err == nil { - if configure, ok := v.(*cfg.GameMainStarreward); ok { - for _, v1 := range configure.GetDataList() { - if v1.Boxid == boxId { - data = append(data, v1) - } - } - } - } - return -} - -func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageData, err error) { - var ( - v interface{} - ) - if v, err = this.GetConfigure(game_mainstage); err == nil { - if configure, ok := v.(*cfg.GameMainStage); ok { - data = configure.Get(id) - if data != nil { - return - } - } - } - err = comm.NewNotFoundConfErr(moduleName, game_mainstage, id) - return -} - -// 获取上一关卡信息 -func (this *configureComp) GetPreMainChapter(stageId int32) (preStageID int32) { - if v, err := this.GetConfigure(game_mainstage); err == nil { - if configure, ok := v.(*cfg.GameMainStage); ok { - for _, v1 := range configure.GetDataList() { - if v1.Previoustage == stageId { - preStageID = v1.Id - break - } - } - } - } - return -} - -func (this *configureComp) GetFirstChapterIDByType(iType int32) (conf *cfg.GameMainChapterData, err error) { - var ( - v interface{} - ) - if v, err = this.GetConfigure(game_mainchapter); err == nil { - if configure, ok := v.(*cfg.GameMainChapter); ok { - for _, conf = range configure.GetDataList() { - if conf.ChapterType == iType { - return - } - } - } - } - err = comm.NewNotFoundConfErr(moduleName, game_mainchapter, iType) - return -} - -func (this *configureComp) GetFirstStageIDByChapter(chapterID int32) *cfg.GameMainStageData { - if v, err := this.GetConfigure(game_mainstage); err == nil { - if configure, ok := v.(*cfg.GameMainStage); ok { - for _, v := range configure.GetDataList() { - if v.Chapterid == chapterID { - return v - } - } - } - } - return nil -} - -// 红点用 获取所有章节数据 -func (this *configureComp) GetAllChapterID() (chapter []int32) { - if v, err := this.GetConfigure(game_mainchapter); err == nil { - if configure, ok := v.(*cfg.GameMainChapter); ok { - for _, v1 := range configure.GetDataList() { - chapter = append(chapter, v1.Id) - } - } - } - return -} - -func (this *configureComp) GetAllStageByChapterID(chapterID int32) (stage []int32) { - return this._mapMilne[chapterID] -} - -func (this *configureComp) LoadMlineStage() { - if v, err := this.GetConfigure(game_mainstage); err == nil { - if configure, ok := v.(*cfg.GameMainStage); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - this._mapMilne = make(map[int32][]int32) - for _, v1 := range configure.GetDataList() { - this._mapMilne[v1.Chapterid] = append(this._mapMilne[v1.Chapterid], v1.Id) - } - } - } - return -} - -// GM 专用 获取这个章节之前的所有章节信息 -func (this *configureComp) GMGetPreStage(chapterID int32) (chapter []int32) { - curChapter := this.GetMainChapterConf(chapterID) - if curChapter == nil { - return - } - - if v, err := this.GetConfigure(game_mainchapter); err == nil { - if configure, ok := v.(*cfg.GameMainChapter); ok { - for _, conf := range configure.GetDataList() { - //if conf.ChapterType == curChapter.ChapterType { - if chapterID == conf.Id { - break - } - chapter = append(chapter, conf.Id) - //} - } - } - } - return -} diff --git a/modules/mline/model_mainline.go b/modules/mline/model_mainline.go deleted file mode 100644 index 02f7a0215..000000000 --- a/modules/mline/model_mainline.go +++ /dev/null @@ -1,78 +0,0 @@ -package mline - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/lego/core" - "go_dreamfactory/modules" - "go_dreamfactory/pb" - - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/x/bsonx" -) - -type ModelMline struct { - modules.MCompModel - module *Mline -} - -func (this *ModelMline) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.TableName = comm.TableMline - err = this.MCompModel.Init(service, module, comp, options) - this.module = module.(*Mline) - //创建uid索引 - this.DB.CreateIndex(core.SqlTable(comm.TableMline), mongo.IndexModel{ - Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, - }) - return -} - -// 获取章节信息 -func (this *ModelMline) getMainlineList(uid string) (mLine []*pb.DBMline, err error) { - mLine = make([]*pb.DBMline, 0) - this.GetList(uid, &mLine) - return -} - -func (this *ModelMline) getMainlineListByObj(uid string, obj string) (mLine *pb.DBMline, err error) { - mLine = &pb.DBMline{} - err = this.GetListObj(uid, obj, mLine) - return -} - -// 修改章节信息 -func (this *ModelMline) modifyMlineData(uid string, objId string, data map[string]interface{}) error { - return this.module.modelMline.ChangeList(uid, objId, data) -} - -// 增加新的章节数据 -func (this *ModelMline) addNewChapter(uId string, data *pb.DBMline) (err error) { - update := make(map[string]*pb.DBMline) - update[data.Id] = data - if err = this.AddLists(uId, update); err != nil { - this.module.Errorln(err) - } - - return err -} - -// 增加新的章节数据 -func (this *ModelMline) cleanChapter(uId string) (err error) { - - if err = this.DelByUId(uId); err != nil { - this.module.Errorf("err:%v", err) - return - } - return nil -} - -// 清除数据 -func (this *ModelMline) cleanChapterDataById(uId string, ids ...string) (err error) { - if len(ids) > 0 { - this.module.Debugf("cleanChapterDataById:%s,%v", uId, ids) - if err = this.DelListlds(uId, ids); err != nil { - this.module.Errorf("err:%v", err) - return - } - } - return nil -} diff --git a/modules/mline/module.go b/modules/mline/module.go deleted file mode 100644 index a8e79467d..000000000 --- a/modules/mline/module.go +++ /dev/null @@ -1,221 +0,0 @@ -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 -} diff --git a/modules/sociaty/api_cross_sign.go b/modules/sociaty/api_cross_sign.go index c5d039775..3bdf65bcd 100644 --- a/modules/sociaty/api_cross_sign.go +++ b/modules/sociaty/api_cross_sign.go @@ -84,7 +84,9 @@ func (this *apiComp) Sign(session comm.IUserSession, req *pb.SociatySignReq) (er this.module.modelSociaty.EventApp.Dispatch(comm.EventSociatyRankChanged, &SociatyListen{ sociaty: sociaty, }) - go this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeWorldtaskid, sociaty.Lv) + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeWorldtaskid, sociaty.Lv) + }) } if err := this.module.modelSociaty.updateSociaty(sociaty.Id, update); err != nil { errdata = &pb.ErrorData{ diff --git a/modules/sys/module.go b/modules/sys/module.go index 0080dd59d..fdf8f95cf 100644 --- a/modules/sys/module.go +++ b/modules/sys/module.go @@ -82,7 +82,7 @@ func (this *ModuleSys) CheckOpenCond(session comm.IUserSession, itype comm.Openc if list, err = this.modelSys.GetOpenCondList(session.GetUserId()); err != nil { return } - defer session.Push() + update = make(map[string]interface{}) switch itype { case comm.OpencondTypePlatlv: diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 154bf35a7..e463d7f08 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -275,8 +275,11 @@ func (this *ModelUser) changelv(session comm.IUserSession, lv int32, exp int64, ) } this.module.chat.SendSysChatToUser(session, comm.ChatSystem12, lv, 0, name) - go this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypePlatlv, lv) + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypePlatlv, lv) + }) session.Push() + } func (this *ModelUser) CleanUserMerchantmoney(session comm.IUserSession) (err error) { diff --git a/modules/wtask/api_finish.go b/modules/wtask/api_finish.go index b2af04dc7..00d5e0adb 100644 --- a/modules/wtask/api_finish.go +++ b/modules/wtask/api_finish.go @@ -150,6 +150,8 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WTaskFinishReq) ( if conf.Des == 5 { this.module.caravan.TaskComplete(session, req.Tid) } - go this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeWorldtaskid, req.Tid) + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeWorldtaskid, req.Tid) + }) return }