airobot/busi/arena.go
2022-12-15 18:00:59 +08:00

103 lines
2.3 KiB
Go

package busi
import (
"time"
"legu.airobot/lib"
"legu.airobot/pb"
)
//竞技场场景
var _ lib.IScene = (*ArenaScene)(nil)
type ArenaScene struct {
lib.Action
}
func (f *ArenaScene) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "竞技场",
Desc: "竞技场压测",
}
}
func (f *ArenaScene) Run(ai lib.IRobot) (err error) {
var (
code pb.ErrorCode
matche *pb.ArenaMatcheResp = &pb.ArenaMatcheResp{}
challenge *pb.ArenaChallengeResp = &pb.ArenaChallengeResp{}
)
f.AddHero(ai, "25001") // 加阿宝
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 {
ai.Stop()
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,
Isai: v.Isai,
MformatId: v.Mformatid,
Battle: &pb.BattleFormation{
Leadpos: 0,
Format: []string{herolistresp.List[0].Id},
},
}, challenge); code != pb.ErrorCode_Success {
ai.Stop()
return
}
Sleep(time.Second*3, time.Second*5)
if challenge.Code == pb.ErrorCode_Success {
if code = ai.SendMsg("arena", "challengereward", &pb.ArenaChallengeRewardReq{
Iswin: true,
Isai: v.Isai,
Aiintegral: v.Integral,
Ainame: v.Name,
Report: &pb.BattleReport{
Info: challenge.Info,
Costtime: 1,
Incmd: make([]*pb.BattleCmd, 0),
Outcmd: make([]*pb.BattleCmd, 0),
Completetask: []int32{},
},
}, &pb.ArenaChallengeRewardResp{}); code != pb.ErrorCode_Success {
ai.Stop()
return
}
Sleep(time.Second*1, time.Second*3)
}
break
}
return
}
// 加英雄
func (f *ArenaScene) AddHero(robot lib.IRobot, cid string) error {
var (
code pb.ErrorCode
)
req := &pb.GMCmdReq{
Cmod: "bingo:hero," + cid + ",1",
}
rsp := &pb.GMCmdResp{}
code = robot.SendMsg("gm", "cmd", req, rsp)
if code != pb.ErrorCode_Success {
return nil
}
return nil
}