airobot/busi/arena.go
2022-12-13 10:38:33 +08:00

81 lines
1.7 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{}
herolistrsp *pb.HeroListResp
)
if herolist := ai.Get("hero.list"); herolist == nil {
ai.Stop()
return
} else {
herolistrsp = herolist.(*pb.HeroListResp)
if herolistrsp.List == nil || len(herolistrsp.List) == 0 {
ai.Stop()
return
}
}
if code = ai.SendMsg("arena", "matche", &pb.ArenaMatcheReq{}, matche); code != pb.ErrorCode_Success {
ai.Stop()
return
}
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{herolistrsp.List[0].Id},
},
}, challenge); code != pb.ErrorCode_Success {
ai.Stop()
return
}
time.Sleep(time.Second * 5)
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,
Process: []byte{123},
Completetask: []int32{},
},
}, challenge); code != pb.ErrorCode_Success {
ai.Stop()
return
}
time.Sleep(time.Second * 2)
}
return
}