diff --git a/busi/arena.go b/busi/arena.go index fb3dd75..e0d04e5 100644 --- a/busi/arena.go +++ b/busi/arena.go @@ -39,12 +39,16 @@ func (f *ArenaScene) Run(ai lib.IRobot) (err error) { return } } - + if code = ai.SendMsg("arena", "info", &pb.ArenaInfoReq{}, &pb.ArenaInfoResp{}); code != pb.ErrorCode_Success { + ai.Stop() + return + } + Sleep(time.Second*0, time.Second*1) if code = ai.SendMsg("arena", "matche", &pb.ArenaMatcheReq{}, matche); code != pb.ErrorCode_Success { ai.Stop() return } - + Sleep(time.Second*0, time.Second*1) for _, v := range matche.Players { if code = ai.SendMsg("arena", "challenge", &pb.ArenaChallengeReq{ Playerid: v.Uid, diff --git a/busi/chat.go b/busi/chat.go index fec5d69..31ea5bb 100644 --- a/busi/chat.go +++ b/busi/chat.go @@ -36,12 +36,12 @@ func (f *ChatScene) Run(ai lib.IRobot) (err error) { ai.Stop() return } - time.Sleep(time.Second * 1) + Sleep(time.Second*0, time.Second*3) //工会聊天 if resp := ai.Get("user.login"); resp != nil { userlogin = resp.(*pb.UserLoginResp) - if userlogin.Ex.SociatyId != "" { + if userlogin.Ex != nil && userlogin.Ex.SociatyId != "" { if code = ai.SendMsg("chat", "send", &pb.ChatSendReq{ Channel: pb.ChatChannel_Union, TargetId: userlogin.Ex.SociatyId, diff --git a/busi/hero.go b/busi/hero.go index 2fe5111..66dfb36 100644 --- a/busi/hero.go +++ b/busi/hero.go @@ -26,44 +26,56 @@ func (f *HeroScene) Info() lib.SceneInfo { func (f *HeroScene) Run(robot lib.IRobot) error { f.AddHero(robot, "25001") // 加阿宝 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "44911") // 升级精灵 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "45921") // 技能精灵 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "45921") // 技能精灵 + Sleep(time.Second*0, time.Second*1) // f.AddAttrGold(robot) // 加金币 // f.AddAttrDiamond(robot) // 加钻石 - time.Sleep(10 * time.Millisecond) // 等待10ms - f.HeroLvUp(robot) // 英雄升级 - time.Sleep(10 * time.Millisecond) // 等待10ms - f.HeroSkillLvUp(robot) // 技能升级 + f.HeroLvUp(robot) // 英雄升级 + Sleep(time.Second*0, time.Second*1) + f.HeroSkillLvUp(robot) // 技能升级 // 升星 - time.Sleep(10 * time.Millisecond) // 等待10ms + Sleep(time.Second*0, time.Second*1) f.HeroStarUp(robot) - + Sleep(time.Second*0, time.Second*1) // time.Sleep(50 * time.Millisecond) // f.HeroResonance(robot) // 共鸣 f.AddItem(robot, "50001") // 觉醒材料 + Sleep(time.Second*0, time.Second*1) f.HeroAwaken(robot) - + Sleep(time.Second*0, time.Second*1) f.AddItem(robot, "30001") // 抽卡材料 - f.HeroDraw(robot) // 普通十连 - + Sleep(time.Second*0, time.Second*1) + f.HeroDraw(robot) // 普通十连 + Sleep(time.Second*0, time.Second*1) // 购买抽卡道具 f.HeroDraw(robot) - + Sleep(time.Second*0, time.Second*1) // 卡牌融合 f.AddHero(robot, "25004") // 加英雄 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "25004") // 加英雄 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "25004") // 加英雄 + Sleep(time.Second*0, time.Second*1) f.AddHero(robot, "25004") // 加英雄 + Sleep(time.Second*0, time.Second*1) f.HeroFusion(robot) - - f.AddItem(robot, "525001") + Sleep(time.Second*0, time.Second*1) + f.AddItem(robot, "25001") + Sleep(time.Second*0, time.Second*1) f.HeroTalent(robot) + Sleep(time.Second*0, time.Second*1) f.HeroTalentV2(robot) // 学习其他天赋 + Sleep(time.Second*0, time.Second*1) return nil } @@ -156,19 +168,21 @@ func (f *HeroScene) HeroLvUp(robot lib.IRobot) error { break } } - // 升级 - lvReq := &pb.HeroStrengthenUplvReq{ - HeroObjID: lvcard.Id, - ExpCards: []*pb.MapStringInt32{}, - } - lvReq.ExpCards = append(lvReq.ExpCards, &pb.MapStringInt32{ - Key: expCard.Id, - Value: 1, - }) - lvRsp := &pb.HeroStrengthenUplvResp{} - code = robot.SendMsg("hero", "strengthenuplv", lvReq, lvRsp) - if code != pb.ErrorCode_Success { - return nil + if lvcard != nil { + // 升级 + lvReq := &pb.HeroStrengthenUplvReq{ + HeroObjID: lvcard.Id, + ExpCards: []*pb.MapStringInt32{}, + } + lvReq.ExpCards = append(lvReq.ExpCards, &pb.MapStringInt32{ + Key: expCard.Id, + Value: 1, + }) + lvRsp := &pb.HeroStrengthenUplvResp{} + code = robot.SendMsg("hero", "strengthenuplv", lvReq, lvRsp) + if code != pb.ErrorCode_Success { + return nil + } } return nil diff --git a/busi/login.go b/busi/login.go index ad8d513..d1a4808 100644 --- a/busi/login.go +++ b/busi/login.go @@ -1,6 +1,8 @@ package busi import ( + "time" + "github.com/Pallinder/go-randomdata" "legu.airobot/lib" "legu.airobot/pb" @@ -33,5 +35,6 @@ func (l *LoginScene) Run(robot lib.IRobot) error { if code := robot.SendMsg("user", "login", req, rsp); code == pb.ErrorCode_Success { robot.Store("user.login", rsp) } + Sleep(time.Second*0, time.Second*1) return nil } diff --git a/busi/mfantasy.go b/busi/mfantasy.go index 6cd36fc..93bd990 100644 --- a/busi/mfantasy.go +++ b/busi/mfantasy.go @@ -40,17 +40,17 @@ func (f *MfantasyScene) Run(ai lib.IRobot) (err error) { return } } - + Sleep(time.Second*0, time.Second*1) if code = ai.SendMsg("gm", "cmd", &pb.GMCmdReq{ Cmod: "bingo:moon,1", }, &pb.GMCmdResp{}); code != pb.ErrorCode_Success { ai.Stop() } - + Sleep(time.Second*0, time.Second*1) if code = ai.SendMsg("moonfantasy", "getlist", &pb.MoonfantasyGetListReq{}, mflist); code != pb.ErrorCode_Success { ai.Stop() } - + Sleep(time.Second*0, time.Second*1) for _, v := range mflist.Dfantasys { if code = ai.SendMsg("moonfantasy", "battle", &pb.MoonfantasyBattleReq{ Mid: v.Monster, diff --git a/busi/pay.go b/busi/pay.go index 62820cc..2ddc97d 100644 --- a/busi/pay.go +++ b/busi/pay.go @@ -31,21 +31,21 @@ func (f *PayScene) Run(ai lib.IRobot) (err error) { }, &pb.PayDailyBuyResp{}); code != pb.ErrorCode_Success { return } - time.Sleep(time.Second) + Sleep(time.Second*0, time.Second*1) if code = ai.SendMsg("pay", "dailybuy", &pb.PayDailyBuyReq{ Id: 2, }, &pb.PayDailyBuyResp{}); code != pb.ErrorCode_Success { ai.Stop() return } - time.Sleep(time.Second) + Sleep(time.Second*0, time.Second*1) - if code = ai.SendMsg("privilege", "buyyueka", &pb.PrivilegeBuyYuekaReq{ - CID: "yueka_lv1", - }, &pb.PrivilegeBuyYuekaResp{}); code != pb.ErrorCode_Success { - ai.Stop() - return - } - time.Sleep(time.Second) + // if code = ai.SendMsg("privilege", "buyyueka", &pb.PrivilegeBuyYuekaReq{ + // CID: "yueka_lv1", + // }, &pb.PrivilegeBuyYuekaResp{}); code != pb.ErrorCode_Success { + // ai.Stop() + // return + // } + // time.Sleep(time.Second) return } diff --git a/busi/resmgr.go b/busi/resmgr.go index 75e285d..759ab37 100644 --- a/busi/resmgr.go +++ b/busi/resmgr.go @@ -1,6 +1,8 @@ package busi import ( + "time" + "legu.airobot/lib" "legu.airobot/pb" ) @@ -29,6 +31,7 @@ func (f *ResMgrScene) Run(ai lib.IRobot) (err error) { }, &pb.GMCmdResp{}); code != pb.ErrorCode_Success { ai.Stop() } + Sleep(time.Second*0, time.Second*1) herolistreq := &pb.HeroListReq{} herolistresp := &pb.HeroListResp{} if code = ai.SendMsg("hero", "list", herolistreq, herolistresp); code != pb.ErrorCode_Success { @@ -36,13 +39,14 @@ func (f *ResMgrScene) Run(ai lib.IRobot) (err error) { return } ai.Store("hero.list", herolistresp) - + Sleep(time.Second*0, time.Second*1) itemlistreq := &pb.ItemsGetlistReq{} itemlistresp := &pb.ItemsGetlistResp{} - if code = ai.SendMsg("item", "list", itemlistreq, itemlistresp); code != pb.ErrorCode_Success { + if code = ai.SendMsg("items", "list", itemlistreq, itemlistresp); code != pb.ErrorCode_Success { ai.Stop() return } - ai.Store("item.list", itemlistresp) + ai.Store("items.list", itemlistresp) + Sleep(time.Second*0, time.Second*1) return nil } diff --git a/busi/shop.go b/busi/shop.go index 3b9f67e..8099131 100644 --- a/busi/shop.go +++ b/busi/shop.go @@ -25,7 +25,7 @@ func (f *ShopScene) Info() lib.SceneInfo { func (f *ShopScene) Run(ai lib.IRobot) (err error) { var ( code pb.ErrorCode - shops *pb.ShopGetListResp + shops *pb.ShopGetListResp = &pb.ShopGetListResp{} ) if code = ai.SendMsg("gm", "cmd", &pb.GMCmdReq{ Cmod: "bingo:attr,gold,100000", @@ -42,11 +42,12 @@ func (f *ShopScene) Run(ai lib.IRobot) (err error) { } for _, v := range shops.Goods { if v.LeftBuyNum > 0 { - ai.SendMsg("shop", "buy", &pb.ChatSendReq{ - Channel: pb.ChatChannel_World, - Content: "hello! are you good?", - }, shops) - time.Sleep(time.Second * 1) + ai.SendMsg("shop", "buy", &pb.ShopBuyReq{ + ShopType: pb.ShopType_GoldShop, + GoodsId: v.GoodsId, + BuyNum: 1, + }, &pb.ShopBuyResp{}) + Sleep(time.Second*0, time.Second*1) } } return nil diff --git a/lib/robot.go b/lib/robot.go index 07ed154..8e5446b 100644 --- a/lib/robot.go +++ b/lib/robot.go @@ -202,7 +202,8 @@ func (m *Robot) Start() bool { //设置状态为已启动 atomic.StoreUint32(&m.status, STATUS_STARTED) - + //显示场景结果 + go m.processResult() m.syncCall() return true @@ -245,8 +246,6 @@ func (m *Robot) syncCall() { m.elipseTotal += elapsedTime logrus.WithField("t", elapsedTime.String()).Debug("场景【" + info.Name + "】执行完毕耗时统计") - //显示场景结果 - m.processResult() } } @@ -312,9 +311,22 @@ func (m *Robot) processResult() { statis.AvgElapse = avg routes[head] = statis } - m.ReportMap[r.Num] = routes + + if r.Elapse < min { + min = r.Elapse + } + statis := &Statistics{ + Route: head, + SceneName: r.SceneName, + ElapseTotal: route.ElapseTotal + r.Elapse, + MaxElapse: max, + MinElapse: min, + CallCount: route.CallCount + 1, + } + avg := (statis.MaxElapse + statis.MinElapse) / 2 + statis.AvgElapse = avg + routes[head] = statis } else { - route := make(map[string]*Statistics) statis := &Statistics{ Route: head, SceneName: r.SceneName, @@ -325,9 +337,23 @@ func (m *Robot) processResult() { } avg := (statis.MaxElapse + statis.MinElapse) / 2 statis.AvgElapse = avg - route[head] = statis - m.ReportMap[r.Num] = route + routes[head] = statis } + m.ReportMap[r.Num] = routes + } else { + route := make(map[string]*Statistics) + statis := &Statistics{ + Route: head, + SceneName: r.SceneName, + ElapseTotal: r.Elapse, + MaxElapse: r.Elapse, + MinElapse: r.Elapse, + CallCount: 1, + } + avg := (statis.MaxElapse + statis.MinElapse) / 2 + statis.AvgElapse = avg + route[head] = statis + m.ReportMap[r.Num] = route } }() diff --git a/main.go b/main.go index 6412ab3..0a781bc 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func init() { &busi.ArenaScene{}, &busi.ReddotScene{}, &busi.PayScene{}, + &busi.MfantasyScene{}, ) }