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
}
for k := range list.Setout {
if req.Index == int32(k) {
for _, v := range list.Setout {
if req.Index == v {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Code: pb.ErrorCode_PlundeRepleteRecive,
Title: pb.ErrorCode_PlundeRepleteRecive.ToString(),
Message: fmt.Sprintf("list.Setout %d,", req.Pos),
}
return

View File

@ -1,8 +1,11 @@
package plunder
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
)
// 参数校验
@ -27,18 +30,22 @@ func (this *apiComp) PvpChallengeCheck(session comm.IUserSession, req *pb.Plunde
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
land *pb.DBPlunderLand // 岛屿数据
list *pb.DBPlunder
record *pb.DBBattleRecord
err error
land *pb.DBPlunderLand // 岛屿数据
list *pb.DBPlunder
lock *redis.RedisMutex
users []string
changeShip map[string]*pb.ShipData
)
if errdata = this.PvpChallengeCheck(session, req); errdata != nil {
return
}
changeShip = make(map[string]*pb.ShipData)
if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
@ -46,7 +53,15 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
}
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 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
@ -54,7 +69,9 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
}
return
}
for _, v := range land.Uinfo {
users = append(users, v.Uid)
}
// 校验oid
if _, ok := land.Ship[req.Oid]; !ok {
errdata = &pb.ErrorData{
@ -63,7 +80,32 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
}
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{
Ptype: pb.PlayType_plunderpvp,
Title: "",
@ -72,23 +114,29 @@ func (this *apiComp) PvpChallenge(session comm.IUserSession, req *pb.PlunderPvpC
}); errdata != nil {
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{}{
"ship": land.Ship,
})
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,
}})
session.SendMsg(string(this.module.GetType()), "pvpchallenge", &pb.PlunderPvpChallengeResp{
Oid: req.Oid,
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,
},
})
// 通知大家
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
Ship: changeShip,
}, users...)
return
}

View File

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

View File

@ -2,9 +2,11 @@ package plunder
import (
"context"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
@ -109,3 +111,8 @@ func (this *modelLand) createPlunderLandData(uid string) (land *pb.DBPlunderLand
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
ErrorCode_PlunderNotFoundShip ErrorCode = 5401 // pvp 没找到数据
ErrorCode_PlunderLineUnlock ErrorCode = 5402 // 队列没解锁
ErrorCode_PlundeRepleteRecive ErrorCode = 5403 // 重复接取
ErrorCode_PlundeShipReach ErrorCode = 5404 //船已经达到不能被掠夺
ErrorCode_PlundeNormalShip ErrorCode = 5405 //普通船不能被掠夺
)
// Enum value maps for ErrorCode.
@ -883,6 +886,9 @@ var (
5301: "TntegralDayMaxChallenge",
5401: "PlunderNotFoundShip",
5402: "PlunderLineUnlock",
5403: "PlundeRepleteRecive",
5404: "PlundeShipReach",
5405: "PlundeNormalShip",
}
ErrorCode_value = map[string]int32{
"Success": 0,
@ -1289,6 +1295,9 @@ var (
"TntegralDayMaxChallenge": 5301,
"PlunderNotFoundShip": 5401,
"PlunderLineUnlock": 5402,
"PlundeRepleteRecive": 5403,
"PlundeShipReach": 5404,
"PlundeNormalShip": 5405,
}
)
@ -1323,7 +1332,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{
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,
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,
@ -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,
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,
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 (