202 lines
5.9 KiB
Go
202 lines
5.9 KiB
Go
package plunder
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
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
|
|
}
|
|
|
|
// / 状态 0 运输 1 正在被攻击 2 战败cd中 3 掠夺成功
|
|
// /挑战
|
|
func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpChallengeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
record *pb.DBBattleRecord
|
|
err error
|
|
devconf *cfg.GamePlunderDevelopData
|
|
land *pb.DBPlunderLand // 岛屿数据
|
|
list *pb.DBPlunder
|
|
lock *redis.RedisMutex
|
|
users []string
|
|
changeShip map[string]*pb.ShipData
|
|
attrs map[int32]int32 = make(map[int32]int32)
|
|
heros []*pb.DBHero
|
|
)
|
|
if errdata = this.PvpChallengeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
changeShip = make(map[string]*pb.ShipData)
|
|
if list, err = this.module.modelPlunder.getPlunderData(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
// 次数校验
|
|
if list.Pvpcount > this.module.ModuleTools.GetGlobalConf().PlunderPvpPlunderum {
|
|
errdata = &pb.ErrorData{ // 不能挑战了
|
|
Code: pb.ErrorCode_PlundeMaxPVPTransportNum,
|
|
Title: pb.ErrorCode_PlundeMaxPVPTransportNum.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
lock, err = this.module.modelLand.landMutexLock(list.Landid)
|
|
err = lock.Lock()
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
defer lock.Unlock()
|
|
if land, err = this.module.modelLand.getPlunderLandData(list.Landid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range land.Uinfo {
|
|
users = append(users, v.Uid)
|
|
}
|
|
// 校验oid
|
|
if _, ok := land.Ship[req.Oid]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlunderNotFoundShip,
|
|
Title: pb.ErrorCode_PlunderNotFoundShip.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 品质校验
|
|
if int64(land.Ship[req.Oid].Line.Itype) == 0 { // 普通船不能被掠夺
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlundeNormalShip,
|
|
Title: pb.ErrorCode_PlundeNormalShip.ToString(),
|
|
Message: fmt.Sprintf("ErrorCode_PlundeNormalShip :%d", land.Ship[req.Oid].Line.Itype),
|
|
}
|
|
return
|
|
}
|
|
if land.Ship[req.Oid].Line.Etime < configure.Now().Unix() { // 船到达不能被掠夺
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlundeShipReach,
|
|
Title: pb.ErrorCode_PlundeShipReach.ToString(),
|
|
Message: fmt.Sprintf("PlundeShipReach :%d", land.Ship[req.Oid].Line.Etime),
|
|
}
|
|
return
|
|
}
|
|
if land.Ship[req.Oid].Status == 2 {
|
|
if land.Ship[req.Oid].Cd >= configure.Now().Unix() { // cd
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlundeShipCDIng,
|
|
Title: pb.ErrorCode_PlundeShipCDIng.ToString(),
|
|
Message: fmt.Sprintf("ErrorCode_PlundeShipCDIng :%d", land.Ship[req.Oid].Cd),
|
|
}
|
|
return
|
|
}
|
|
land.Ship[req.Oid].Status = 0
|
|
}
|
|
// 状态校验 状态 0 运输 1 正在被攻击 2 战败cd中 3 掠夺成功
|
|
if land.Ship[req.Oid].Status != 0 { // return
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlunderNotFoundShip,
|
|
Title: pb.ErrorCode_PlunderNotFoundShip.ToString(),
|
|
Message: fmt.Sprintf("Status err,curStutus :%d", land.Ship[req.Oid].Status),
|
|
}
|
|
return
|
|
}
|
|
|
|
if heros, err = this.module.modelPlunder.queryUserHeros(session.GetUserId(), req.Battle.Format); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for k, v := range list.Develop {
|
|
if v == 1 {
|
|
if devconf, err = this.module.configure.getPlunderDevelopById(k); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range devconf.Skilleffect {
|
|
attrs[v.A] += v.N
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, v := range heros {
|
|
if v != nil {
|
|
for attr, value := range attrs {
|
|
v.AddProperty[attr] += value
|
|
}
|
|
}
|
|
}
|
|
|
|
if errdata, record = this.module.battle.CreatePvpBattle(session, &pb.BattlePVPReq{
|
|
Rulesid: this.module.ModuleTools.GetGlobalConf().PlunderPvpBattlereadyid,
|
|
Ptype: pb.PlayType_arena,
|
|
Redformat: &pb.PVPFormation{Uid: session.GetUserId(), Leadpos: req.Battle.Leadpos, Format: heros},
|
|
Buleformat: &pb.PVPFormation{Uid: land.Ship[req.Oid].Uid, Leadpos: land.Ship[req.Oid].Defend.Leadpos, Format: land.Ship[req.Oid].Defend.Formt},
|
|
}); errdata != nil {
|
|
return
|
|
}
|
|
land.Ship[req.Oid].Status = 1 // 修改状态
|
|
changeShip[req.Oid] = land.Ship[req.Oid] // 广播数据
|
|
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
|
|
"ship": land.Ship,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "pvpchallenge", &pb.PlunderPvpChallengeResp{
|
|
Oid: req.Oid,
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: this.module.ModuleTools.GetGlobalConf().PlunderPvpBattlereadyid,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
},
|
|
})
|
|
// 通知大家
|
|
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
|
|
Ship: changeShip,
|
|
}, users...)
|
|
return
|
|
}
|