This commit is contained in:
liwei1dao 2024-01-19 15:22:36 +08:00
commit a01deafe9d
5 changed files with 121 additions and 39 deletions

View File

@ -48,11 +48,11 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.PlunderChallen
return return
} }
for k := range list.Setout { for _, v := range list.Setout {
if req.Index == int32(k) { if req.Index == v {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError, Code: pb.ErrorCode_PlundeRepleteRecive,
Title: pb.ErrorCode_ReqParameterError.ToString(), Title: pb.ErrorCode_PlundeRepleteRecive.ToString(),
Message: fmt.Sprintf("list.Setout %d,", req.Pos), Message: fmt.Sprintf("list.Setout %d,", req.Pos),
} }
return return

View File

@ -1,8 +1,11 @@
package plunder package plunder
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
) )
// 参数校验 // 参数校验
@ -27,6 +30,7 @@ func (this *apiComp) PvpChallengeCheck(session comm.IUserSession, req *pb.Plunde
return return
} }
// / 状态 0 运输 1 正在被攻击 2 战败cd中 3 掠夺成功
// /挑战 // /挑战
func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpChallengeReq) (errdata *pb.ErrorData) { func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpChallengeReq) (errdata *pb.ErrorData) {
var ( var (
@ -34,11 +38,14 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
err error err error
land *pb.DBPlunderLand // 岛屿数据 land *pb.DBPlunderLand // 岛屿数据
list *pb.DBPlunder list *pb.DBPlunder
lock *redis.RedisMutex
users []string
changeShip map[string]*pb.ShipData
) )
if errdata = this.PvpChallengeCheck(session, req); errdata != nil { if errdata = this.PvpChallengeCheck(session, req); errdata != nil {
return return
} }
changeShip = make(map[string]*pb.ShipData)
if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil { if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
@ -46,7 +53,15 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
} }
return return
} }
if lock, err = this.module.modelLand.landMutexLock(list.Landid); 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 { if land, err = this.module.modelLand.getPlunderLandData(list.Landid); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
@ -54,7 +69,9 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
} }
return return
} }
for _, v := range land.Uinfo {
users = append(users, v.Uid)
}
// 校验oid // 校验oid
if _, ok := land.Ship[req.Oid]; !ok { if _, ok := land.Ship[req.Oid]; !ok {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
@ -63,7 +80,32 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
} }
return 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 != 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 errdata, record = this.module.battle.CreatePlunderPvpBattle(session, &pb.BattlePVEPlunderReq{ if errdata, record = this.module.battle.CreatePlunderPvpBattle(session, &pb.BattlePVEPlunderReq{
Ptype: pb.PlayType_plunderpvp, Ptype: pb.PlayType_plunderpvp,
Title: "", Title: "",
@ -72,12 +114,14 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
}); errdata != nil { }); errdata != nil {
return return
} }
land.Ship[req.Oid].Status = 1 land.Ship[req.Oid].Status = 1 // 修改状态
// 修改状态 changeShip[req.Oid] = land.Ship[req.Oid] // 广播数据
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{ this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
"ship": land.Ship, "ship": land.Ship,
}) })
session.SendMsg(string(this.module.GetType()), "challenge", &pb.ArenaChallengeResp{Info: &pb.BattleInfo{ session.SendMsg(string(this.module.GetType()), "pvpchallenge", &pb.PlunderPvpChallengeResp{
Oid: req.Oid,
Info: &pb.BattleInfo{
Id: record.Id, Id: record.Id,
Title: record.Title, Title: record.Title,
Rulesid: 105, Rulesid: 105,
@ -88,7 +132,11 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
BlueCompId: land.Ship[req.Oid].Uid, BlueCompId: land.Ship[req.Oid].Uid,
Buleflist: land.Ship[req.Oid].Defend, Buleflist: land.Ship[req.Oid].Defend,
Tasks: record.Tasks, Tasks: record.Tasks,
}}) },
})
// 通知大家
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
Ship: changeShip,
}, users...)
return return
} }

View File

@ -2,6 +2,7 @@ package plunder
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
@ -27,11 +28,13 @@ func (this *apiComp) PvpChallengeOver(session comm.IUserSession, req *pb.Plunder
iswin bool iswin bool
conf *cfg.GamePlunderData conf *cfg.GamePlunderData
users []string users []string
lock *redis.RedisMutex
changeShip map[string]*pb.ShipData // 数据变化通知
) )
if errdata = this.PvpChallengeOverCheck(session, req); errdata != nil { if errdata = this.PvpChallengeOverCheck(session, req); errdata != nil {
return return
} }
changeShip = make(map[string]*pb.ShipData)
if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil { if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
@ -39,7 +42,15 @@ func (this *apiComp) PvpChallengeOver(session comm.IUserSession, req *pb.Plunder
} }
return return
} }
if lock, err = this.module.modelLand.landMutexLock(list.Landid); 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 { if land, err = this.module.modelLand.getPlunderLandData(list.Landid); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
@ -74,23 +85,25 @@ func (this *apiComp) PvpChallengeOver(session comm.IUserSession, req *pb.Plunder
if !iswin { if !iswin {
land.Ship[req.Oid].Cd = configure.Now().Unix() + int64(conf.Protecttime) land.Ship[req.Oid].Cd = configure.Now().Unix() + int64(conf.Protecttime)
land.Ship[req.Oid].Status = 2 land.Ship[req.Oid].Status = 2
changeShip[req.Oid] = land.Ship[req.Oid]
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{ this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
"ship": land.Ship, "ship": land.Ship,
}) })
// 通知大家 // 通知大家
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{ this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
Ship: land.Ship, Ship: changeShip,
}, users...) }, users...)
return return
} }
land.Ship[req.Oid].Status = 3 land.Ship[req.Oid].Status = 3
// 修改状态 // 修改状态
changeShip[req.Oid] = land.Ship[req.Oid]
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{ this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
"ship": land.Ship, "ship": land.Ship,
}) })
// 通知大家 // 通知大家
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{ this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
Ship: land.Ship, Ship: changeShip,
}, users...) }, users...)
session.SendMsg(string(this.module.GetType()), "pvpchallengeover", &pb.PlunderPvpChallengeOverResp{ session.SendMsg(string(this.module.GetType()), "pvpchallengeover", &pb.PlunderPvpChallengeOverResp{
Atno: []*pb.UserAtno{}, Atno: []*pb.UserAtno{},

View File

@ -2,9 +2,11 @@ package plunder
import ( import (
"context" "context"
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
@ -109,3 +111,8 @@ func (this *modelLand) createPlunderLandData(uid string) (land *pb.DBPlunderLand
return return
} }
// 创建分布式锁
func (this *modelLand) landMutexLock(oid string) (result *redis.RedisMutex, err error) {
return this.module.modelLand.NewRedisMutex(fmt.Sprintf("%s-%s_lock", this.TableName, oid), 5)
}

View File

@ -474,6 +474,9 @@ const (
//plunder //plunder
ErrorCode_PlunderNotFoundShip ErrorCode = 5401 // pvp 没找到数据 ErrorCode_PlunderNotFoundShip ErrorCode = 5401 // pvp 没找到数据
ErrorCode_PlunderLineUnlock ErrorCode = 5402 // 队列没解锁 ErrorCode_PlunderLineUnlock ErrorCode = 5402 // 队列没解锁
ErrorCode_PlundeRepleteRecive ErrorCode = 5403 // 重复接取
ErrorCode_PlundeShipReach ErrorCode = 5404 //船已经达到不能被掠夺
ErrorCode_PlundeNormalShip ErrorCode = 5405 //普通船不能被掠夺
) )
// Enum value maps for ErrorCode. // Enum value maps for ErrorCode.
@ -883,6 +886,9 @@ var (
5301: "TntegralDayMaxChallenge", 5301: "TntegralDayMaxChallenge",
5401: "PlunderNotFoundShip", 5401: "PlunderNotFoundShip",
5402: "PlunderLineUnlock", 5402: "PlunderLineUnlock",
5403: "PlundeRepleteRecive",
5404: "PlundeShipReach",
5405: "PlundeNormalShip",
} }
ErrorCode_value = map[string]int32{ ErrorCode_value = map[string]int32{
"Success": 0, "Success": 0,
@ -1289,6 +1295,9 @@ var (
"TntegralDayMaxChallenge": 5301, "TntegralDayMaxChallenge": 5301,
"PlunderNotFoundShip": 5401, "PlunderNotFoundShip": 5401,
"PlunderLineUnlock": 5402, "PlunderLineUnlock": 5402,
"PlundeRepleteRecive": 5403,
"PlundeShipReach": 5404,
"PlundeNormalShip": 5405,
} }
) )
@ -1323,7 +1332,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{ var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0xac, 0x4b, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x6f, 0x2a, 0xf3, 0x4b, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10,
0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76,
@ -1926,7 +1935,12 @@ var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x13, 0x50, 0x6c, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e, 0x0a, 0x13, 0x50, 0x6c, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e,
0x64, 0x53, 0x68, 0x69, 0x70, 0x10, 0x99, 0x2a, 0x12, 0x16, 0x0a, 0x11, 0x50, 0x6c, 0x75, 0x6e, 0x64, 0x53, 0x68, 0x69, 0x70, 0x10, 0x99, 0x2a, 0x12, 0x16, 0x0a, 0x11, 0x50, 0x6c, 0x75, 0x6e,
0x64, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x10, 0x9a, 0x2a, 0x64, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x65, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x10, 0x9a, 0x2a,
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x12, 0x18, 0x0a, 0x13, 0x50, 0x6c, 0x75, 0x6e, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x65, 0x74,
0x65, 0x52, 0x65, 0x63, 0x69, 0x76, 0x65, 0x10, 0x9b, 0x2a, 0x12, 0x14, 0x0a, 0x0f, 0x50, 0x6c,
0x75, 0x6e, 0x64, 0x65, 0x53, 0x68, 0x69, 0x70, 0x52, 0x65, 0x61, 0x63, 0x68, 0x10, 0x9c, 0x2a,
0x12, 0x15, 0x0a, 0x10, 0x50, 0x6c, 0x75, 0x6e, 0x64, 0x65, 0x4e, 0x6f, 0x72, 0x6d, 0x61, 0x6c,
0x53, 0x68, 0x69, 0x70, 0x10, 0x9d, 0x2a, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (