75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) SetDefFormtCheck(session comm.IUserSession, req *pb.ArenaSetDefFormtReq) (errdata *pb.ErrorData) {
|
|
if len(req.Formt) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: "阵容 不能为空!",
|
|
}
|
|
}
|
|
for _, v := range req.Formt {
|
|
if v != "" {
|
|
return
|
|
}
|
|
}
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: "阵容 不能为空!",
|
|
}
|
|
return
|
|
}
|
|
|
|
// /设置防守阵型
|
|
func (this *apiComp) SetDefFormt(session comm.IUserSession, req *pb.ArenaSetDefFormtReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBArenaUser
|
|
heros []*pb.DBHero
|
|
err error
|
|
)
|
|
if errdata = this.SetDefFormtCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if heros, err = this.module.modelArena.queryUserHeros(session.GetUserId(), req.Formt); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
|
|
return
|
|
}
|
|
info.Defend = &pb.DBPlayerBattleFormt{
|
|
Leadpos: req.Leadpos,
|
|
Formt: heros,
|
|
}
|
|
info.Isdef = true
|
|
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "setdefformt", &pb.ArenaSetDefFormtResp{Issucc: true})
|
|
return
|
|
}
|