升级消耗
This commit is contained in:
parent
e4ff953a13
commit
2e7050e6ee
@ -4,6 +4,7 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -22,13 +23,11 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
curLv int32
|
curLv int32
|
||||||
curExp int32 // 当前英雄的经验
|
curExp int32 // 当前英雄的经验
|
||||||
costRes map[string]int32 // 当前需要消资源的数量
|
addExp int32 // 需要增加的经验
|
||||||
addExp int32 // 需要增加的经验
|
costRes map[string][]*cfg.Game_atn // 需要消耗的资源
|
||||||
curRes map[string]int32
|
|
||||||
)
|
)
|
||||||
curRes = make(map[string]int32, 0)
|
costRes = make(map[string][]*cfg.Game_atn, 0)
|
||||||
costRes = make(map[string]int32, 0)
|
|
||||||
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
||||||
defer func() {
|
defer func() {
|
||||||
if code == pb.ErrorCode_Success {
|
if code == pb.ErrorCode_Success {
|
||||||
@ -101,13 +100,16 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, v := range _data.Gold {
|
for _, v := range _data.Gold {
|
||||||
_curRes := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T)
|
if _, ok := costRes[v.T]; !ok {
|
||||||
if _curRes < v.N {
|
costRes[v.T] = append(costRes[v.T], v)
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
} else {
|
||||||
return
|
for _, v1 := range costRes[v.T] {
|
||||||
|
if v1.T == v.T && v1.A == v.A {
|
||||||
|
v1.N += v.N
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curRes[v.T] = _curRes
|
|
||||||
costRes[v.T] += v.N
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,8 +130,8 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗道具
|
// 消耗道具
|
||||||
for k, v := range costRes {
|
for _, v := range costRes {
|
||||||
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), k, int32(curRes[k]-v)) // 减少金币
|
code = this.module.CheckConsumeRes(session.GetUserId(), v)
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user