91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package plunder
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) PvpChallengeCheck(session comm.IUserSession, req *pb.PlunderPvpChallengeReq) (errdata *pb.ErrorData) {
|
|
if req.Oid == "" || req.Battle.Format == nil || len(req.Battle.Format) != 5 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
|
|
for _, v := range req.Battle.Format {
|
|
if v != "" {
|
|
return
|
|
}
|
|
}
|
|
errdata = &pb.ErrorData{ //没有英雄
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "no hero",
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战
|
|
func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpChallengeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
record *pb.DBBattleRecord
|
|
err error
|
|
land *pb.DBPlunderLand // 岛屿数据
|
|
list *pb.DBPlunder
|
|
)
|
|
if errdata = this.PvpChallengeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if land, err = this.module.modelLand.getPlunderLandData(list.Landid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 校验oid
|
|
if _, ok := land.Ship[req.Oid]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlunderNotFoundShip,
|
|
Title: pb.ErrorCode_PlunderNotFoundShip.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata, record = this.module.battle.CreatePlunderPvpBattle(session, &pb.BattlePVEPlunderReq{
|
|
Ptype: pb.PlayType_plunderpvp,
|
|
Title: "",
|
|
Rulesid: 105,
|
|
Format: req.Battle,
|
|
}); errdata != nil {
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "challenge", &pb.ArenaChallengeResp{Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: 105,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: land.Ship[req.Oid].Uid,
|
|
Buleflist: land.Ship[req.Oid].Defend,
|
|
Tasks: record.Tasks,
|
|
}})
|
|
|
|
return
|
|
}
|