From 718981064f32cf65a69b1258bb467a383d0f5553 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 30 Jun 2022 16:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/dbservice/db_comp.go | 7 ++-- modules/hero/api_strengthen.go | 68 ++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/modules/dbservice/db_comp.go b/modules/dbservice/db_comp.go index 2b8dfca63..2fd0bed63 100644 --- a/modules/dbservice/db_comp.go +++ b/modules/dbservice/db_comp.go @@ -114,11 +114,12 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { continue } _key := data.D[0].(string) - _objKey := make([]string, 0) + + _obj := bson.M{} for _, v := range data.D[1].(bson.D) { - _objKey = append(_objKey, v.Value.(string)) + _obj[v.Key] = v.Value } - _, err = this.DB.DeleteMany(core.SqlTable(_key), bson.M{"_id": bson.M{"$in": _objKey}}, options.Delete()) + _, err = this.DB.DeleteMany(core.SqlTable(_key), _obj, options.Delete()) if err != nil { log.Errorf("delete %s db err:%v", core.SqlTable(_key), err) ErrorLogCount[data.ID]++ diff --git a/modules/hero/api_strengthen.go b/modules/hero/api_strengthen.go index 1c7e08c3c..75a0bc158 100644 --- a/modules/hero/api_strengthen.go +++ b/modules/hero/api_strengthen.go @@ -13,23 +13,25 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero return } var ( - curLv int32 - curExp int32 // 当前英雄的经验 - costGold int32 // 当前需要消耗金币的数量 - addExp int32 // 需要增加的经验 - curGold int32 - //atn = map[string]interface{}{} + curLv int32 + curExp int32 // 当前英雄的经验 + costRes int32 // 当前需要消资源的数量 + addExp int32 // 需要增加的经验 + curGold int32 + atn = map[string]interface{}{} ) - + atn = make(map[string]interface{}, 0) + curGold = 0 + costRes = 0 _hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在 - if err != 0 { + if err != pb.ErrorCode_Success { code.Code = pb.ErrorCode_HeroNoExist return } _expHero, err := this.moduleHero.GetHero(session.GetUserId(), req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在 - if err != 0 { + if err != pb.ErrorCode_Success { code.Code = pb.ErrorCode_HeroNoExist return } @@ -39,7 +41,7 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero } curLv = _hero.Lv curExp = _hero.Exp // 当前英雄的经验 - + addExp = 1000 // 查询 本次消耗会获得多少经验 expConf := this.moduleHero.configure.GetHeroExp(_expHero.HeroID) if expConf != nil { @@ -72,6 +74,7 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero curExp = _data.Heroexp[0].N break } + if _data.Heroexp[0].N > curExp { // 经验不够升级则不能执行升级操作 break } else { // 升级操作 @@ -82,13 +85,18 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero curLv -= 1 break } - costGold += _data.Gold[0].N // 统计 升级需要消耗金币的数量 + costRes += _data.Gold[0].N } } + for _, v := range _data.Gold { + atn["a"] = v.A + atn["t"] = v.T + atn["n"] = v.N + } // 金币消耗判断 - curGold = this.user.QueryAttributeValue(session.GetUserId(), "gold") - if curGold < costGold { - // code.Code = pb.ErrorCode_GoldNoEnough + curGold = this.user.QueryAttributeValue(session.GetUserId(), atn["t"].(string)) + if curGold < costRes { + code.Code = pb.ErrorCode_GoldNoEnough } } else { code.Code = pb.ErrorCode_HeroNoExist @@ -97,12 +105,13 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero // 校验金币消耗 result = map[string]interface{}{ - "costGold": costGold, - "curExp": curExp, - "curLv": curLv, - "addExp": addExp, - "heroObj": _hero, - //"atn": atn, + "costRes": costRes, + "curExp": curExp, + "curLv": curLv, + "addExp": addExp, + "heroObj": _hero, + "curRes": curGold, + "atn": atn, } return } @@ -110,18 +119,21 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero /// 英雄升级 func (this *apiComp) StrengthenUplv(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroStrengthenUplvReq) (code pb.ErrorCode) { var ( - curLv int32 - curExp int32 // 当前英雄的经验 - costGold int32 // 当前需要消耗金币的数量 - addExp int32 // 需要增加的经验 - //atn = map[string]interface{}{} + curLv int32 + curExp int32 // 当前英雄的经验 + costRes int32 // 当前需要消耗金币的数量 + addExp int32 // 需要增加的经验 + curRes int32 + atn = map[string]interface{}{} ) - costGold = agrs["costGold"].(int32) + costRes = agrs["costRes"].(int32) curLv = agrs["curLv"].(int32) curExp = agrs["curExp"].(int32) addExp = agrs["addExp"].(int32) _hero := agrs["heroObj"].(*pb.DBHero) + curRes = agrs["curRes"].(int32) + atn = agrs["atn"].(map[string]interface{}) if _hero == nil { code = pb.ErrorCode_HeroNoExist return @@ -131,14 +143,14 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, agrs map[string]i session.SendMsg(string(this.moduleHero.GetType()), StrengthenUplv, &pb.HeroStrengthenUplvResp{Hero: _hero}) } }() - log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costGold, addExp) + log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costRes, addExp) // 执行升级逻辑 code = this.moduleHero.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验 if code != pb.ErrorCode_Success { return } // 消耗道具 - code = this.user.AddAttributeValue(session.GetUserId(), "gold", -costGold) // 减少金币 + code = this.user.AddAttributeValue(session.GetUserId(), atn["t"].(string), int32(curRes-costRes)) // 减少金币 if code != pb.ErrorCode_Success { return }