From f1e7ea36ef5b45ae53356ef1992440914ec37309 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 3 Apr 2023 18:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E4=BA=AC=E9=87=8D=E5=A4=8D=E6=8C=91?= =?UTF-8?q?=E6=88=98=E8=A7=A3=E9=94=81=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hunting/api_challenge.go | 2 +- modules/hunting/api_challengeover.go | 27 +++++++++++++++-------- modules/hunting/api_getlist.go | 21 +----------------- modules/hunting/comp_configure.go | 13 ++++++++++- modules/hunting/model_hunting.go | 13 +++++++++++ modules/sys/model_sys.go | 32 ++++++++++++++-------------- modules/viking/api_challenge.go | 2 +- modules/viking/api_challengeover.go | 10 +++++---- modules/viking/api_getlist.go | 13 +---------- modules/viking/model_viking.go | 20 ++++++++++------- 10 files changed, 81 insertions(+), 72 deletions(-) diff --git a/modules/hunting/api_challenge.go b/modules/hunting/api_challenge.go index 17038fcaf..b5dd31681 100644 --- a/modules/hunting/api_challenge.go +++ b/modules/hunting/api_challenge.go @@ -44,7 +44,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallen if !ok { // 类型校验 hunting.Boss[req.BossType] = 1 } - if value < req.Difficulty { + if value < req.Difficulty-1 { code = pb.ErrorCode_HuntingLvErr return } diff --git a/modules/hunting/api_challengeover.go b/modules/hunting/api_challengeover.go index 362696479..0f30905f1 100644 --- a/modules/hunting/api_challengeover.go +++ b/modules/hunting/api_challengeover.go @@ -45,18 +45,28 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingCha return } - value, ok := hunting.Boss[req.BossType] - if !ok { // 类型校验 + if req.Difficulty == 1 && hunting.Boss[req.BossType] == 0 { hunting.Boss[req.BossType] = 1 } - if value == req.Difficulty { - newChallenge = true - } else if value < req.Difficulty { + if value, ok := hunting.Boss[req.BossType]; ok { // 类型校验 + if value < req.Difficulty-1 { + code = pb.ErrorCode_HuntingLvErr + return + } + } else { code = pb.ErrorCode_HuntingLvErr return } - + if hunting.Boss[req.BossType] < req.Difficulty { + hunting.Boss[req.BossType] = req.Difficulty + } + // 校验是不是达到最大难度 + maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossType) + if hunting.Boss[req.BossType] > maxDifficulity { + hunting.Boss[req.BossType] = maxDifficulity + } + mapData["boss"] = hunting.Boss code, bWin = this.module.battle.CheckBattleReport(session, req.Report) if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success { return @@ -73,16 +83,15 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingCha } key := strconv.Itoa(int(req.BossType)) + "_" + strconv.Itoa(int(req.Difficulty)) if hunting.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 - hunting.Boss[req.BossType]++ mapData["boss"] = hunting.Boss if code = this.module.DispenseRes(session, cfgHunting.Firstprize, true); code != pb.ErrorCode_Success { return } } - + hunting.BossTime[key] = req.Report.Costtime // 耗时校验 当前战斗胜利时间消耗小于之前刷新数据 if hunting.BossTime[key] > req.Report.Costtime || hunting.BossTime[key] == 0 && req.Difficulty >= hunting.Boss[req.BossType] { - hunting.BossTime[key] = req.Report.Costtime + mapData["bossTime"] = hunting.BossTime // 更新时间 userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) this.module.CheckRank(session.GetUserId(), req.BossType, req.Difficulty, req.Report, userinfo) diff --git a/modules/hunting/api_getlist.go b/modules/hunting/api_getlist.go index a8fde745f..a86d43ecf 100644 --- a/modules/hunting/api_getlist.go +++ b/modules/hunting/api_getlist.go @@ -2,11 +2,8 @@ package hunting import ( "go_dreamfactory/comm" - "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" - "strconv" - "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) @@ -26,24 +23,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success { return } - list, err := this.module.modelHunting.getHuntingList(session.GetUserId()) - if mgo.MongodbNil == err { - list = &pb.DBHunting{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - Boss: make(map[int32]int32), - BossTime: make(map[string]int32), - } - _cfg := this.module.configure.GetHuntingBossTypeConfigData() - for k := range _cfg { - list.Boss[k] = 1 - str := strconv.Itoa(int(k)) + "_1" - list.BossTime[str] = 0 - } + list, _ := this.module.modelHunting.getHuntingList(session.GetUserId()) - this.module.modelHunting.Add(session.GetUserId(), list) - - } if session.GetUserId() != "" { // 恢复时间 if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { list.RecoveryTime = userexpand.Recovertimeunifiedticket diff --git a/modules/hunting/comp_configure.go b/modules/hunting/comp_configure.go index b389266d8..79856c7ab 100644 --- a/modules/hunting/comp_configure.go +++ b/modules/hunting/comp_configure.go @@ -19,12 +19,13 @@ type configureComp struct { hlock sync.RWMutex modules.MCompConfigure _huntingMap map[int64]*cfg.GameHuntingBossData + boos map[int32]int32 // key bossid value difficulty } //组件初始化接口 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.boos = make(map[int32]int32, 0) this._huntingMap = make(map[int64]*cfg.GameHuntingBossData, 0) configure.RegisterConfigure(game_huntingboss, cfg.NewGameHuntingBoss, func() { if v, err := this.GetConfigure(game_huntingboss); err == nil { @@ -33,6 +34,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp defer this.hlock.Unlock() for _, value := range configure.GetDataList() { this._huntingMap[int64(value.Type<<16)+int64(value.Difficulty)] = value + this.boos[value.Type]++ } return } @@ -42,6 +44,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp return }) err = this.LoadConfigure(game_challenge, cfg.NewGameHuntingChallenge) + return } @@ -111,6 +114,14 @@ func (this *configureComp) GetMaxBuyChallengeCount() int32 { return 0 } +// 获取boss 最大难点 +func (this *configureComp) GetMaxDifficultyByBossID(bossId int32) int32 { + if v, ok := this.boos[bossId]; ok { + return v + } + return 0 +} + // 获取最后一条数据 func (this *configureComp) GetLastBuyChallenge() (data *cfg.GameHuntingChallengeData) { if v, err := this.GetConfigure(game_challenge); err == nil { diff --git a/modules/hunting/model_hunting.go b/modules/hunting/model_hunting.go index 3927e51b7..04672c07f 100644 --- a/modules/hunting/model_hunting.go +++ b/modules/hunting/model_hunting.go @@ -3,9 +3,11 @@ package hunting import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -34,6 +36,17 @@ func (this *modelHunting) modifyHuntingDataByObjId(uid string, data map[string]i func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err error) { result = &pb.DBHunting{} if err = this.Get(uid, result); err != nil { + if mgo.MongodbNil == err { + result = &pb.DBHunting{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Boss: make(map[int32]int32), + BossTime: make(map[string]int32), + } + + this.Add(uid, result) + err = nil + } return } diff --git a/modules/sys/model_sys.go b/modules/sys/model_sys.go index 7a5b95c91..faddee198 100644 --- a/modules/sys/model_sys.go +++ b/modules/sys/model_sys.go @@ -27,23 +27,23 @@ func (this *ModelSys) Init(service core.IService, module core.IModule, comp core // 是否允许访问功能,条件:玩家等级 func (this *ModelSys) IsAccess(funName string, uid string) (code pb.ErrorCode) { - user := this.moduleSys.ModuleUser.GetUser(uid) - if user != nil { - if conf := this.moduleSys.configure.getFuncCfg(funName); conf != nil { - if conf.ActivateType == 1 { // 已经手动激活过 - list, _ := this.GetOpenCondList(uid) - if v, ok := list.Cond[funName]; ok && v == 1 { - return - } - } else { - if id := this.validCond(uid, conf); id != "" { // 条件满足已经激活 - return - } - } + // user := this.moduleSys.ModuleUser.GetUser(uid) + // if user != nil { + // if conf := this.moduleSys.configure.getFuncCfg(funName); conf != nil { + // if conf.ActivateType == 1 { // 已经手动激活过 + // list, _ := this.GetOpenCondList(uid) + // if v, ok := list.Cond[funName]; ok && v == 1 { + // return + // } + // } else { + // if id := this.validCond(uid, conf); id != "" { // 条件满足已经激活 + // return + // } + // } - } - } - code = pb.ErrorCode_OpenCondErr + // } + // } + //code = pb.ErrorCode_OpenCondErr return } diff --git a/modules/viking/api_challenge.go b/modules/viking/api_challenge.go index b6ddae10d..08dc8c518 100644 --- a/modules/viking/api_challenge.go +++ b/modules/viking/api_challenge.go @@ -55,7 +55,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.VikingChalleng viking.Boss[req.BossId] = 1 } if value, ok := viking.Boss[req.BossId]; ok { // 类型校验 - if value < req.Difficulty { + if value < req.Difficulty-1 { code = pb.ErrorCode_HuntingLvErr return } diff --git a/modules/viking/api_challengeover.go b/modules/viking/api_challengeover.go index 737bf3dcb..8615f3482 100644 --- a/modules/viking/api_challengeover.go +++ b/modules/viking/api_challengeover.go @@ -53,7 +53,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal } if value, ok := viking.Boss[req.BossId]; ok { // 类型校验 - if value < req.Difficulty { + if value < req.Difficulty-1 { code = pb.ErrorCode_HuntingLvErr return } @@ -61,6 +61,9 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal code = pb.ErrorCode_HuntingLvErr return } + if viking.Boss[req.BossId] < req.Difficulty { + viking.Boss[req.BossId] = req.Difficulty + } // 校验是不是达到最大难度 maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossId) if viking.Boss[req.BossId] > maxDifficulity { @@ -84,16 +87,15 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal if code = this.module.ConsumeRes(session, vikingCfg.PsConsume, true); code != pb.ErrorCode_Success { return } - key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 - viking.Boss[req.BossId]++ + mapData["boss"] = viking.Boss if code = this.module.DispenseRes(session, vikingCfg.Firstprize, true); code != pb.ErrorCode_Success { return } } - viking.BossTime[key] = req.Report.Costtime + if viking.BossTime[key] > req.Report.Costtime || (viking.BossTime[key] == 0 && req.Difficulty >= viking.Boss[req.BossId]) { viking.BossTime[key] = req.Report.Costtime userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) diff --git a/modules/viking/api_getlist.go b/modules/viking/api_getlist.go index 25d1f0bb8..132e0f1dc 100644 --- a/modules/viking/api_getlist.go +++ b/modules/viking/api_getlist.go @@ -2,10 +2,8 @@ package viking import ( "go_dreamfactory/comm" - "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" - "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) @@ -24,17 +22,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success { return } - list, err := this.module.modelViking.getVikingList(session.GetUserId()) - if mgo.MongodbNil == err { - list = &pb.DBViking{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - Boss: make(map[int32]int32), - BossTime: make(map[string]int32), - } + list, _ := this.module.modelViking.getVikingList(session.GetUserId()) - this.module.modelViking.Add(session.GetUserId(), list) - } if session.GetUserId() != "" { // 恢复时间 if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { list.RecoveryTime = userexpand.Recovertimeunifiedticket diff --git a/modules/viking/model_viking.go b/modules/viking/model_viking.go index a1ddc52d9..792e46520 100644 --- a/modules/viking/model_viking.go +++ b/modules/viking/model_viking.go @@ -3,6 +3,7 @@ package viking import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -28,17 +29,20 @@ func (this *modelViking) Init(service core.IService, module core.IModule, comp c } func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err error) { - result = &pb.DBViking{ - Id: primitive.NewObjectID().Hex(), - Uid: uid, - Boss: make(map[int32]int32), - BossTime: make(map[string]int32), - } + result = &pb.DBViking{} if err = this.Get(uid, result); err != nil { - + if mgo.MongodbNil == err { + result = &pb.DBViking{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Boss: make(map[int32]int32), + BossTime: make(map[string]int32), + } + err = nil + this.module.modelViking.Add(uid, result) + } return } - err = nil return result, err }