资源校验整合
This commit is contained in:
parent
d01d24912a
commit
59f978937a
@ -25,9 +25,17 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
addExp int32 // 需要增加的经验
|
addExp int32 // 需要增加的经验
|
||||||
costGold int32 // 需要消耗的资源
|
costGold int32 // 需要消耗的资源
|
||||||
_hero *pb.DBHero // 目标英雄
|
_hero *pb.DBHero // 目标英雄
|
||||||
|
|
||||||
cost []*cfg.Gameatn // 消耗的道具
|
cost []*cfg.Gameatn // 消耗的道具
|
||||||
)
|
)
|
||||||
|
code = this.StrengthenUplvCheck(session, req) // check
|
||||||
|
if code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID)
|
||||||
|
if code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
for k, v := range req.Item {
|
for k, v := range req.Item {
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
continue
|
continue
|
||||||
@ -48,15 +56,6 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
T: "gold",
|
T: "gold",
|
||||||
N: costGold,
|
N: costGold,
|
||||||
})
|
})
|
||||||
code = this.StrengthenUplvCheck(session, req) // check
|
|
||||||
if code != pb.ErrorCode_Success {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID)
|
|
||||||
if code != pb.ErrorCode_Success {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 金币消耗判断
|
// 金币消耗判断
|
||||||
if code = this.module.CheckRes(session, cost); code != pb.ErrorCode_Success {
|
if code = this.module.CheckRes(session, cost); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
|
@ -238,26 +238,36 @@ func (this *ModuleBase) SendMsgToCUsers(mainType, subType string, msg proto.Mess
|
|||||||
|
|
||||||
// 只校验资源 参数 atn格式
|
// 只校验资源 参数 atn格式
|
||||||
func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) (code pb.ErrorCode) {
|
func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) (code pb.ErrorCode) {
|
||||||
//校验消费资源是否充足
|
var (
|
||||||
|
items map[string]int32 // 道具背包 批量处理
|
||||||
|
attrs map[string]int32 // 属性
|
||||||
|
)
|
||||||
for _, v := range res {
|
for _, v := range res {
|
||||||
if v.A == comm.AttrType { //用户属性资源
|
switch v.A {
|
||||||
if amount := this.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T); amount < int64(v.N) {
|
case comm.AttrType:
|
||||||
code = pb.ErrorCode_ResNoEnough
|
attrs[v.T] = v.N
|
||||||
this.Warnf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
case comm.ItemType:
|
||||||
return
|
items[v.T] = v.N
|
||||||
|
default:
|
||||||
|
this.Errorf("not found res type") // 找不到资源类型
|
||||||
}
|
}
|
||||||
} else if v.A == comm.ItemType { //道具资源
|
}
|
||||||
// if resID, err = strconv.Atoi(v.T); err != nil {
|
// 校验数量
|
||||||
// code = pb.ErrorCode_ConfigurationException
|
for k, v := range attrs {
|
||||||
// return
|
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < int64(v) { // -v 负负得正
|
||||||
// }
|
|
||||||
if amount := this.ModuleItems.QueryItemAmount(session.GetUserId(), v.T); amount < uint32(v.N) {
|
|
||||||
code = pb.ErrorCode_ResNoEnough
|
code = pb.ErrorCode_ResNoEnough
|
||||||
this.Warnf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
this.Warnf("资源不足", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "T", Value: k}, log.Field{Key: "N", Value: v})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for k, v := range items { //校验消费资源是否充足
|
||||||
|
if int32(this.ModuleItems.QueryItemAmount(session.GetUserId(), k)) < v {
|
||||||
|
code = pb.ErrorCode_ResNoEnough
|
||||||
|
this.Warnf("道具不足", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "T", Value: k}, log.Field{Key: "N", Value: v})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +284,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn
|
|||||||
switch v.A {
|
switch v.A {
|
||||||
case comm.AttrType:
|
case comm.AttrType:
|
||||||
attrs[v.T] -= v.N
|
attrs[v.T] -= v.N
|
||||||
|
|
||||||
case comm.ItemType:
|
case comm.ItemType:
|
||||||
items[v.T] -= v.N
|
items[v.T] -= v.N
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user