diff --git a/modules/hero/api_awaken.go b/modules/hero/api_awaken.go index 614bf4582..189e35edd 100644 --- a/modules/hero/api_awaken.go +++ b/modules/hero/api_awaken.go @@ -24,11 +24,7 @@ func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenRe func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (code pb.ErrorCode, data proto.Message) { var ( awakenData *cfg.Game_heroAwakenData - bCheckOk bool - costRes map[string]int32 ) - costRes = make(map[string]int32, 0) - bCheckOk = true _hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) if err != pb.ErrorCode_Success { @@ -59,58 +55,20 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c code = pb.ErrorCode_ConfigNoFound return } - // 参数校验 - for _, v := range awakenData.Phaseneed { - if v.A == "attr" { // 消耗玩家身上资源 - curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T) - if curGold < v.N { - bCheckOk = false - break - } - costRes[v.T] = v.N - } else if v.A == "item" { //消耗道具 - itemid, err := strconv.Atoi(v.T) - if err != nil { - curCount := this.module.items.QueryItemAmount(nil, session.GetUserId(), int32(itemid)) - if curCount < uint32(v.N) { - bCheckOk = false - break - } - } - } - } - if !bCheckOk { - code = pb.ErrorCode_GoldNoEnough - return - } + if _hero == nil || awakenData == nil { code = pb.ErrorCode_HeroNoExist return } - - for _, v := range awakenData.Phaseneed { - if v.A == "attr" { // 消耗玩家身上资源 - if _data, ok := costRes[v.T]; ok { - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), v.T, _data) - if code != pb.ErrorCode_Success { - return - } - } - - } else if v.A == "item" { //消耗道具 - itemid, err := strconv.Atoi(v.T) - if err != nil { - code = this.module.items.AddItem(nil, session.GetUserId(), int32(itemid), -v.N) - if code != pb.ErrorCode_Success { - return - } - } - } - } if len(awakenData.Phasebonus) < 2 { code = pb.ErrorCode_ConfigNoFound return } + // 消耗校验 + code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed) + if code != pb.ErrorCode_Success { + return + } // 加属性 awakenData _value, ok := strconv.Atoi(awakenData.Phasebonus[0]) if ok == nil { // 升级技能 diff --git a/modules/hero/api_resonance.go b/modules/hero/api_resonance.go index c1ee3c6e9..8c60c10f0 100644 --- a/modules/hero/api_resonance.go +++ b/modules/hero/api_resonance.go @@ -62,16 +62,6 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR } } } - // 金币校验 - for _, v := range resonConfig.Need { - if v.A == "attr" { // 查询玩家身上资源是否满足 - value := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T) - if value < v.N { - code = pb.ErrorCode_ResNoEnough - return - } - } - } code = this.module.DelCard(req.CostObjID, req.Amount) // 删除材料卡 if code != pb.ErrorCode_Success { @@ -84,18 +74,12 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR code = pb.ErrorCode_ConfigNoFound return } - for _, v := range resonConfig.Need { - if v.A == "attr" { // 查询玩家身上资源是否满足 - value := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T) - if value >= v.N { // 直接删除财富 - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), v.T, value-v.N) // 扣除资源 - break - } else { - code = pb.ErrorCode_ResNoEnough - return - } - } + // 消耗校验 + code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need) + if code != pb.ErrorCode_Success { + return } + _heroMap := map[string]interface{}{ "resonateNum": _hero.ResonateNum + resonConfig.Energy, } diff --git a/modules/hero/api_resonanceReset.go b/modules/hero/api_resonanceReset.go index e75e97f04..783d62116 100644 --- a/modules/hero/api_resonanceReset.go +++ b/modules/hero/api_resonanceReset.go @@ -54,20 +54,10 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson code = pb.ErrorCode_ConfigNoFound // 没找到配置消耗 return } - for _, v := range _costConfig.Var { - if v.A == "attr" { - value := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T) - if value < v.N { - code = pb.ErrorCode_ResNoEnough // 资源不足 - return - } - } - } - - for _, v := range _costConfig.Var { - if v.A == "attr" { - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), v.T, -v.N) // 扣资源 - } + // 消耗校验 + code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var) + if code != pb.ErrorCode_Success { + return } property := make(map[string]int32, 0) property[comm.HpPro] -= _hero.AddProperty[comm.HpPro] diff --git a/modules/hero/api_strengthen.go b/modules/hero/api_strengthen.go index 24526612a..2612ccbf7 100644 --- a/modules/hero/api_strengthen.go +++ b/modules/hero/api_strengthen.go @@ -129,12 +129,12 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren } // 消耗道具 for k, v := range costRes { - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), k, int32(curRes[k]-v)) // 减少金币 if code != pb.ErrorCode_Success { return } } + // 删除经验卡 err1 := this.module.modelHero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount) if err1 != nil {