Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into liwei
This commit is contained in:
commit
840bc4c986
12
cmd/robot/assistant.go
Normal file
12
cmd/robot/assistant.go
Normal file
@ -0,0 +1,12 @@
|
||||
package robot
|
||||
|
||||
// 场景:在测试的接口中,输入参数为了能达到自动化,都是从业务中已有的协议中返回获取,作为下一个协议的输入参数。
|
||||
// 但是会存在,协议中的输入参数无法从上一个协议中获取,比如:添加好友协议,输入参数是“目标玩家ID”,为了能够动态
|
||||
// 测试添加好友协议,如果专门为这个协议添加返回目标玩家的接口,显然有点不合适。一个方案是,设计一个助手,专门处
|
||||
// 理这类问题,这个助手可以返回合适的数据,作为输入参数。
|
||||
|
||||
type assistant struct {
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
@ -95,13 +95,6 @@ var (
|
||||
}
|
||||
|
||||
},
|
||||
}, {
|
||||
desc: "删除黑名单",
|
||||
mainType: string(comm.ModuleFriend),
|
||||
subType: friend.FriendSubTypeDelBlack,
|
||||
req: &pb.FriendDelBlackReq{},
|
||||
rsp: &pb.FriendDelBlackResp{},
|
||||
// enabled: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -23,17 +23,18 @@ var (
|
||||
// fmt.Printf("%d- %v\n", (i + 1), v)
|
||||
// }
|
||||
// },
|
||||
enabled: true,
|
||||
// enabled: true,
|
||||
next: func(robot *Robot, rsp proto.Message) {
|
||||
tcs := []*TestCase{}
|
||||
if r, ok := rsp.(*pb.HeroListResp); ok {
|
||||
for _, v := range r.List {
|
||||
heroId := v.Id
|
||||
tc := &TestCase{
|
||||
desc: "英雄详情",
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.HeroSubTypeInfo,
|
||||
req: &pb.HeroInfoReq{
|
||||
HeroId: v.Id,
|
||||
HeroId: heroId,
|
||||
},
|
||||
rsp: &pb.HeroInfoResp{},
|
||||
enabled: true,
|
||||
@ -48,10 +49,10 @@ var (
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.Awaken,
|
||||
req: &pb.HeroAwakenReq{
|
||||
HeroObjID: v.Id,
|
||||
HeroObjID: heroId,
|
||||
},
|
||||
rsp: &pb.HeroAwakenResp{},
|
||||
enabled: true,
|
||||
//enabled: true,
|
||||
},
|
||||
}
|
||||
robot.addBuilders(tcs)
|
||||
@ -59,19 +60,9 @@ var (
|
||||
}
|
||||
tcs = append(tcs, tc)
|
||||
}
|
||||
robot.addBuilders(tcs) //这里一定要调用此方法才会发送请求
|
||||
}
|
||||
|
||||
robot.addBuilders(tcs)
|
||||
},
|
||||
}, {
|
||||
desc: "英雄详情",
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.HeroSubTypeInfo,
|
||||
req: &pb.HeroInfoReq{
|
||||
HeroId: "62c676d57deea8b9af8884a5",
|
||||
},
|
||||
rsp: &pb.HeroInfoResp{},
|
||||
// enabled: true,
|
||||
}, {
|
||||
desc: "抽卡",
|
||||
mainType: string(comm.ModuleHero),
|
||||
@ -82,17 +73,45 @@ var (
|
||||
rsp: &pb.HeroChoukaResp{},
|
||||
// enabled: true,
|
||||
}, {
|
||||
desc: "英雄列表",
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.HeroSubTypeList,
|
||||
req: &pb.HeroListReq{},
|
||||
rsp: &pb.HeroListResp{},
|
||||
enabled: true,
|
||||
next: func(robot *Robot, rsp proto.Message) {
|
||||
if r, ok := rsp.(*pb.HeroListResp); ok {
|
||||
tcs := []*TestCase{}
|
||||
selHero := r.List[0] //选中的英雄
|
||||
for _, v := range r.List {
|
||||
heroId := v.Id
|
||||
tc := &TestCase{
|
||||
desc: "英雄升星",
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.StrengthenUpStar,
|
||||
req: &pb.HeroStrengthenUpStarReq{
|
||||
HeroObjID: "62bd0489ff6632434a7d0d1f",
|
||||
HeroObjID: selHero.Id,
|
||||
HeroRace: []*pb.CostCardData{
|
||||
{
|
||||
CostCardObj: heroId,
|
||||
},
|
||||
},
|
||||
Hero: []*pb.CostCardData{
|
||||
{
|
||||
CostCardObj: "",
|
||||
CostCardObj: heroId,
|
||||
},
|
||||
},
|
||||
},
|
||||
rsp: &pb.HeroStrengthenUpStarResp{},
|
||||
enabled: true,
|
||||
}
|
||||
tcs = append(tcs, tc)
|
||||
}
|
||||
robot.addBuilders(tcs)
|
||||
}
|
||||
},
|
||||
}, {
|
||||
|
||||
// enabled: true,
|
||||
}, {
|
||||
mainType: string(comm.ModuleHero),
|
||||
|
@ -129,7 +129,7 @@ type TestCase struct {
|
||||
enabled bool //是否启用
|
||||
start time.Time //启用时间
|
||||
hs time.Duration //耗时
|
||||
requested bool //是否是请求的case
|
||||
// requested bool //是否是请求的case
|
||||
print func(rsp proto.Message) //定义打印
|
||||
next func(robot *Robot, rsp proto.Message) //处理下一层用例请求
|
||||
}
|
||||
@ -160,7 +160,7 @@ func (r *Robot) handleReq() {
|
||||
// go func() {
|
||||
for len(r.builderMap) > 0 {
|
||||
for _, b := range r.builderMap {
|
||||
if b.enabled && b.req != nil && !b.requested {
|
||||
if b.enabled && b.req != nil {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
// r.reqCh <- b.id
|
||||
b.start = time.Now()
|
||||
@ -173,7 +173,6 @@ func (r *Robot) handleReq() {
|
||||
zlog.Errorf("send to client err:%v", err)
|
||||
}
|
||||
|
||||
|
||||
r.handleRsp(b.id)
|
||||
}
|
||||
}
|
||||
@ -201,6 +200,7 @@ func (r *Robot) handleNotify(uuid string, msg *pb.UserMessage) {
|
||||
desc: "错误通知",
|
||||
mainType: comm.MainTypeNotify,
|
||||
subType: comm.SubTypeErrorNotify,
|
||||
req: rsp.Arg,
|
||||
rsp: rsp,
|
||||
}
|
||||
|
||||
@ -232,7 +232,6 @@ func (r *Robot) handleRsp(id string) {
|
||||
// uuid := <-r.reqCh
|
||||
r.handleNotify(uuid, msg)
|
||||
if v, ok := r.builderMap[uuid]; ok {
|
||||
|
||||
if v.enabled &&
|
||||
(msg.MainType == v.mainType &&
|
||||
msg.SubType == v.subType) {
|
||||
@ -423,7 +422,7 @@ func (r *Robot) printReply(msg *pb.UserMessage, tc *TestCase) {
|
||||
|
||||
//
|
||||
zlog.Debug("-------------------------------------")
|
||||
zlog.Debugf("uuid:%s", tc.id)
|
||||
// zlog.Debugf("uuid:%s", tc.id)
|
||||
zlog.Debugf("描述:%s", tc.desc)
|
||||
zlog.Debugf("协议:%s.%s", mainType, subType)
|
||||
zlog.Debugf("耗时:%v", tc.hs)
|
||||
|
@ -24,13 +24,27 @@ var user_builders = []*TestCase{
|
||||
subType: "addres",
|
||||
req: &pb.UserAddResReq{
|
||||
Res: &pb.UserAssets{
|
||||
A: "attr",
|
||||
T: "10001",
|
||||
N: 12,
|
||||
A: "item",
|
||||
T: "10011",
|
||||
N: 13,
|
||||
},
|
||||
},
|
||||
rsp: &pb.UserAddResResp{},
|
||||
enabled: true,
|
||||
//enabled: true,
|
||||
},
|
||||
{
|
||||
desc: "添加资源",
|
||||
mainType: string(comm.ModuleUser),
|
||||
subType: "addres",
|
||||
req: &pb.UserAddResReq{
|
||||
Res: &pb.UserAssets{
|
||||
A: "item",
|
||||
T: "10001",
|
||||
N: 1,
|
||||
},
|
||||
},
|
||||
rsp: &pb.UserAddResResp{},
|
||||
//enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ const ( //消息回复的头名称
|
||||
Resonance = "resonance" // 英雄共鸣属性
|
||||
ResonanceReset = "resonancereset" // 共鸣重置
|
||||
StrengthenUpSkill = "strengthenupskill" // 技能强化
|
||||
StrengthenUpStar = "strengthensupstar" // 英雄升星
|
||||
StrengthenUpStar = "strengthenupstar" // 英雄升星
|
||||
Awaken = "awaken" // 英雄觉醒
|
||||
HeroLock = "lock" // 英雄锁定
|
||||
)
|
||||
|
@ -86,6 +86,17 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
|
||||
property[awakenData.Phasebonus[0]] += int32(value)
|
||||
}
|
||||
this.module.modelHero.mergeMainProperty(session.GetUserId(), _hero.Id, property)
|
||||
|
||||
_heroMap := map[string]interface{}{
|
||||
"juexingLv": _hero.JuexingLv + 1,
|
||||
}
|
||||
// 保存数据
|
||||
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), _hero.Id, _heroMap)
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
|
@ -14,6 +14,19 @@ func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.He
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
||||
for _, v := range req.Hero {
|
||||
if v.CostCardObj == req.HeroObjID { // 不允许消耗自己
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range req.HeroRace {
|
||||
if v.CostCardObj == req.HeroObjID {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -21,11 +34,24 @@ func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.He
|
||||
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
target *cfg.Game_heroStarupData // 配置表目标升星英雄信息
|
||||
costRaceCount int32
|
||||
costNeedHeroCount int32 // 消耗指定英雄的数量
|
||||
costRaceHeroCount int32 // 消耗种族英雄的数量
|
||||
_hero *pb.DBHero // 目标英雄
|
||||
raceHero *pb.DBHero // 消耗阵容的英雄
|
||||
tagHero *pb.DBHero // 消耗指定英雄
|
||||
mapCostHero map[string]int32 // 所有消耗英雄分类
|
||||
bCheckNeedhero bool // 指定英雄校验
|
||||
bCheckRacehero bool // 种族英雄校验
|
||||
)
|
||||
mapCostHero = make(map[string]int32, 0)
|
||||
for _, v := range req.Hero {
|
||||
mapCostHero[v.CostCardObj] += v.Amount
|
||||
costNeedHeroCount += v.Amount
|
||||
}
|
||||
for _, v := range req.HeroRace {
|
||||
mapCostHero[v.CostCardObj] += v.Amount
|
||||
costRaceHeroCount += v.Amount
|
||||
}
|
||||
|
||||
code = this.StrengthenUpStarCheck(session, req) // check
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
@ -43,68 +69,53 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
||||
}
|
||||
|
||||
for _, value := range tagHeroConfig.GetDataList() {
|
||||
if _hero.HeroID == value.Id && _hero.Star == value.Star && _hero.Lv == value.Maxlevel { // 找到了 满足升星条件
|
||||
if _hero.HeroID == value.Id && _hero.Star == value.Star && _hero.Lv >= value.Maxlevel { // 找到了 满足升星条件
|
||||
target = value
|
||||
break
|
||||
}
|
||||
}
|
||||
if target == nil {
|
||||
code = pb.ErrorCode_HeroNoExist
|
||||
return
|
||||
}
|
||||
// 优先校验数量对不对
|
||||
if target.Needheronum != costNeedHeroCount || target.Needracenum != costRaceHeroCount {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
// 指定英雄消耗校验
|
||||
for _, v := range req.Hero {
|
||||
if tagHero, code = this.module.GetHero(session.GetUserId(), v.CostCardObj); code != pb.ErrorCode_Success {
|
||||
// 遍历所有消耗英雄
|
||||
for k, v := range mapCostHero {
|
||||
if tagHero, code = this.module.GetHero(session.GetUserId(), k); code != pb.ErrorCode_Success { // 没有这个英雄
|
||||
return
|
||||
} else {
|
||||
if tagHero.Block { // 锁定的卡不允许被消耗
|
||||
code = pb.ErrorCode_HeroIsLock
|
||||
return
|
||||
}
|
||||
if tagHero.SameCount < v.Amount { // 校验数量
|
||||
if tagHero.SameCount < v { // 校验数量
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
// 校验ID
|
||||
if tagHero.HeroID != target.Needhero && tagHero.Star != target.Needherostar && tagHero.SameCount < target.Needheronum {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
|
||||
if tagHero.HeroID == target.Needhero && tagHero.Star == target.Needherostar && tagHero.SameCount >= target.Needheronum {
|
||||
bCheckNeedhero = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验阵容英雄消耗
|
||||
for _, v := range req.HeroRace {
|
||||
if raceHero, code = this.module.GetHero(session.GetUserId(), v.CostCardObj); code != pb.ErrorCode_Success {
|
||||
return
|
||||
} else {
|
||||
if raceHero.Block { // 锁定的卡不允许被消耗
|
||||
code = pb.ErrorCode_HeroIsLock
|
||||
return
|
||||
}
|
||||
// 校验阵容信息
|
||||
if raceHero.Star != target.Needracestar {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
bFind := false
|
||||
|
||||
for _, value := range target.Needrace { // 阵营校验
|
||||
if raceHero.Formation == value {
|
||||
bFind = true
|
||||
if tagHero.Formation == value {
|
||||
bCheckRacehero = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !bFind {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
|
||||
this.module.Debugf("指定英雄校验结果:%b,种族英雄校验结果:%b", bCheckNeedhero, bCheckRacehero)
|
||||
}
|
||||
}
|
||||
if !bCheckRacehero || !bCheckNeedhero {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return // 校验失败
|
||||
}
|
||||
|
||||
costRaceCount += v.Amount
|
||||
}
|
||||
if costRaceCount != target.Needracenum { // 数量不匹配
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
// 金币消耗判断
|
||||
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "gold")
|
||||
if curGold < target.Gold { // 金币不足
|
||||
@ -119,24 +130,15 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
||||
code = pb.ErrorCode_GoldNoEnough
|
||||
return
|
||||
}
|
||||
// 消耗指定英雄
|
||||
for _, v := range req.Hero {
|
||||
code = this.module.DelCard(session.GetUserId(), v.CostCardObj, v.Amount)
|
||||
for k, v := range mapCostHero {
|
||||
code = this.module.DelCard(session.GetUserId(), k, v)
|
||||
if code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_DBError
|
||||
this.module.Errorf("del hero err card:%s,count = %d", v.CostCardObj, v.Amount)
|
||||
this.module.Errorf("del hero err card:%s,count = %d", k, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//消耗种族英雄
|
||||
for _, v := range req.HeroRace {
|
||||
code = this.module.DelCard(session.GetUserId(), v.CostCardObj, v.Amount)
|
||||
if code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
}
|
||||
code = this.module.modelHero.HeroStarUp(session, _hero) // 执行升星操作
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
|
@ -20,15 +20,6 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c
|
||||
return
|
||||
}
|
||||
|
||||
rsp := &pb.UserAddResResp{}
|
||||
|
||||
defer func() {
|
||||
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeAddRes, rsp); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
user := this.module.modelUser.GetUser(session.GetUserId())
|
||||
if user == nil {
|
||||
code = pb.ErrorCode_UserSessionNobeing
|
||||
@ -42,6 +33,12 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c
|
||||
}
|
||||
res = append(res, atn)
|
||||
code = this.module.DispenseRes(session.GetUserId(), res, true)
|
||||
rsp.Res = req.Res
|
||||
if code == pb.ErrorCode_Success {
|
||||
rsp := &pb.UserAddResResp{
|
||||
Res: req.Res,
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), UserSubTypeAddRes, rsp)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -122,6 +122,8 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32, bPush bo
|
||||
}
|
||||
_change.Diamond += add
|
||||
update[comm.ResDiamond] = user.Diamond + add
|
||||
default:
|
||||
code = pb.ErrorCode_Unknown
|
||||
}
|
||||
|
||||
if len(update) == 0 {
|
||||
|
@ -67,6 +67,7 @@ enum ErrorCode {
|
||||
HeroMaxAwaken = 1312; // 达到最大觉醒等级
|
||||
HeroIsLock = 1313; // 英雄被锁定不能被消耗
|
||||
HeroMaxCount = 1314; // 英雄达到最大数量
|
||||
HeroCostTypeErr = 1315; // 消耗英雄参数不匹配
|
||||
|
||||
// equipment
|
||||
EquipmentOnFoundEquipment = 1400; // 未找到武器
|
||||
|
Loading…
Reference in New Issue
Block a user