优化
This commit is contained in:
parent
65560dfa5c
commit
718981064f
@ -114,11 +114,12 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_key := data.D[0].(string)
|
_key := data.D[0].(string)
|
||||||
_objKey := make([]string, 0)
|
|
||||||
|
_obj := bson.M{}
|
||||||
for _, v := range data.D[1].(bson.D) {
|
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 {
|
if err != nil {
|
||||||
log.Errorf("delete %s db err:%v", core.SqlTable(_key), err)
|
log.Errorf("delete %s db err:%v", core.SqlTable(_key), err)
|
||||||
ErrorLogCount[data.ID]++
|
ErrorLogCount[data.ID]++
|
||||||
|
@ -13,23 +13,25 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
curLv int32
|
curLv int32
|
||||||
curExp int32 // 当前英雄的经验
|
curExp int32 // 当前英雄的经验
|
||||||
costGold int32 // 当前需要消耗金币的数量
|
costRes int32 // 当前需要消资源的数量
|
||||||
addExp int32 // 需要增加的经验
|
addExp int32 // 需要增加的经验
|
||||||
curGold int32
|
curGold int32
|
||||||
//atn = map[string]interface{}{}
|
atn = map[string]interface{}{}
|
||||||
)
|
)
|
||||||
|
atn = make(map[string]interface{}, 0)
|
||||||
|
curGold = 0
|
||||||
|
costRes = 0
|
||||||
_hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
_hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
||||||
|
|
||||||
if err != 0 {
|
if err != pb.ErrorCode_Success {
|
||||||
code.Code = pb.ErrorCode_HeroNoExist
|
code.Code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_expHero, err := this.moduleHero.GetHero(session.GetUserId(), req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在
|
_expHero, err := this.moduleHero.GetHero(session.GetUserId(), req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在
|
||||||
|
|
||||||
if err != 0 {
|
if err != pb.ErrorCode_Success {
|
||||||
code.Code = pb.ErrorCode_HeroNoExist
|
code.Code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -39,7 +41,7 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero
|
|||||||
}
|
}
|
||||||
curLv = _hero.Lv
|
curLv = _hero.Lv
|
||||||
curExp = _hero.Exp // 当前英雄的经验
|
curExp = _hero.Exp // 当前英雄的经验
|
||||||
|
addExp = 1000
|
||||||
// 查询 本次消耗会获得多少经验
|
// 查询 本次消耗会获得多少经验
|
||||||
expConf := this.moduleHero.configure.GetHeroExp(_expHero.HeroID)
|
expConf := this.moduleHero.configure.GetHeroExp(_expHero.HeroID)
|
||||||
if expConf != nil {
|
if expConf != nil {
|
||||||
@ -72,6 +74,7 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero
|
|||||||
curExp = _data.Heroexp[0].N
|
curExp = _data.Heroexp[0].N
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if _data.Heroexp[0].N > curExp { // 经验不够升级则不能执行升级操作
|
if _data.Heroexp[0].N > curExp { // 经验不够升级则不能执行升级操作
|
||||||
break
|
break
|
||||||
} else { // 升级操作
|
} else { // 升级操作
|
||||||
@ -82,13 +85,18 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero
|
|||||||
curLv -= 1
|
curLv -= 1
|
||||||
break
|
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")
|
curGold = this.user.QueryAttributeValue(session.GetUserId(), atn["t"].(string))
|
||||||
if curGold < costGold {
|
if curGold < costRes {
|
||||||
// code.Code = pb.ErrorCode_GoldNoEnough
|
code.Code = pb.ErrorCode_GoldNoEnough
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code.Code = pb.ErrorCode_HeroNoExist
|
code.Code = pb.ErrorCode_HeroNoExist
|
||||||
@ -97,12 +105,13 @@ func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.Hero
|
|||||||
|
|
||||||
// 校验金币消耗
|
// 校验金币消耗
|
||||||
result = map[string]interface{}{
|
result = map[string]interface{}{
|
||||||
"costGold": costGold,
|
"costRes": costRes,
|
||||||
"curExp": curExp,
|
"curExp": curExp,
|
||||||
"curLv": curLv,
|
"curLv": curLv,
|
||||||
"addExp": addExp,
|
"addExp": addExp,
|
||||||
"heroObj": _hero,
|
"heroObj": _hero,
|
||||||
//"atn": atn,
|
"curRes": curGold,
|
||||||
|
"atn": atn,
|
||||||
}
|
}
|
||||||
return
|
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) {
|
func (this *apiComp) StrengthenUplv(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroStrengthenUplvReq) (code pb.ErrorCode) {
|
||||||
var (
|
var (
|
||||||
curLv int32
|
curLv int32
|
||||||
curExp int32 // 当前英雄的经验
|
curExp int32 // 当前英雄的经验
|
||||||
costGold int32 // 当前需要消耗金币的数量
|
costRes int32 // 当前需要消耗金币的数量
|
||||||
addExp int32 // 需要增加的经验
|
addExp int32 // 需要增加的经验
|
||||||
//atn = map[string]interface{}{}
|
curRes int32
|
||||||
|
atn = map[string]interface{}{}
|
||||||
)
|
)
|
||||||
|
|
||||||
costGold = agrs["costGold"].(int32)
|
costRes = agrs["costRes"].(int32)
|
||||||
curLv = agrs["curLv"].(int32)
|
curLv = agrs["curLv"].(int32)
|
||||||
curExp = agrs["curExp"].(int32)
|
curExp = agrs["curExp"].(int32)
|
||||||
addExp = agrs["addExp"].(int32)
|
addExp = agrs["addExp"].(int32)
|
||||||
_hero := agrs["heroObj"].(*pb.DBHero)
|
_hero := agrs["heroObj"].(*pb.DBHero)
|
||||||
|
curRes = agrs["curRes"].(int32)
|
||||||
|
atn = agrs["atn"].(map[string]interface{})
|
||||||
if _hero == nil {
|
if _hero == nil {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
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})
|
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) // 加经验
|
code = this.moduleHero.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return
|
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 {
|
if code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user