载具存档、载具理论支持多人游戏、修复停泊时回复载具耐力功能
This commit is contained in:
1 parent
4c40989edc
commit
bd504e5fe5
9 files changed
+126
-37
No files matched your search
@@ -250,7 +250,7 @@ func (s *Scene) CreateEntityGadgetClient(pos, rot *model.Vector, entityId, confi
|
||||
s.CreateEntity(entity)
|
||||
}
|
||||
|
||||
func (s *Scene) CreateEntityGadgetVehicle(player *model.Player, pos, rot *model.Vector, vehicleId uint32) uint32 {
|
||||
func (s *Scene) CreateEntityGadgetVehicle(ownerUid uint32, pos, rot *model.Vector, vehicleId uint32) uint32 {
|
||||
entityId := s.world.GetNextWorldEntityId(constant.ENTITY_TYPE_GADGET)
|
||||
entity := &Entity{
|
||||
id: entityId,
|
||||
@@ -272,7 +272,8 @@ func (s *Scene) CreateEntityGadgetVehicle(player *model.Player, pos, rot *model.
|
||||
gadgetType: GADGET_TYPE_VEHICLE,
|
||||
gadgetVehicleEntity: &GadgetVehicleEntity{
|
||||
vehicleId: vehicleId,
|
||||
owner: player,
|
||||
worldId: s.world.id,
|
||||
ownerUid: ownerUid,
|
||||
maxStamina: 240, // TODO 应该也能在配置表找到
|
||||
curStamina: 240, // TODO 与maxStamina一致
|
||||
memberMap: make(map[uint32]*model.Player),
|
||||
@@ -636,7 +637,8 @@ func (g *GadgetClientEntity) GetPropOwnerEntityId() uint32 {
|
||||
|
||||
type GadgetVehicleEntity struct {
|
||||
vehicleId uint32
|
||||
owner *model.Player
|
||||
worldId uint32
|
||||
ownerUid uint32
|
||||
maxStamina float32
|
||||
curStamina float32
|
||||
memberMap map[uint32]*model.Player // uint32 = pos
|
||||
@@ -646,8 +648,8 @@ func (g *GadgetVehicleEntity) GetVehicleId() uint32 {
|
||||
return g.vehicleId
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetOwner() *model.Player {
|
||||
return g.owner
|
||||
func (g *GadgetVehicleEntity) GetOwnerUid() uint32 {
|
||||
return g.ownerUid
|
||||
}
|
||||
|
||||
func (g *GadgetVehicleEntity) GetMaxStamina() float32 {
|
||||
|
||||
@@ -190,7 +190,7 @@ func (g *Game) ScenePlayerLocationNotify(world *World) {
|
||||
}
|
||||
scenePlayerLocationNotify.PlayerLocList = append(scenePlayerLocationNotify.PlayerLocList, playerLocationInfo)
|
||||
// 载具位置
|
||||
for _, entityId := range scenePlayer.VehicleInfo.LastCreateEntityIdMap {
|
||||
for _, entityId := range scenePlayer.VehicleInfo.CreateEntityIdMap {
|
||||
entity := scene.GetEntity(entityId)
|
||||
// 确保实体类型是否为载具
|
||||
if entity != nil && entity.GetEntityType() == constant.ENTITY_TYPE_GADGET && entity.gadgetEntity.gadgetVehicleEntity != nil {
|
||||
@@ -202,7 +202,7 @@ func (g *Game) ScenePlayerLocationNotify(world *World) {
|
||||
},
|
||||
EntityId: entity.id,
|
||||
CurHp: entity.fightProp[constant.FIGHT_PROP_CUR_HP],
|
||||
OwnerUid: entity.gadgetEntity.gadgetVehicleEntity.owner.PlayerID,
|
||||
OwnerUid: entity.gadgetEntity.gadgetVehicleEntity.ownerUid,
|
||||
Pos: &proto.Vector{
|
||||
X: float32(entity.pos.X),
|
||||
Y: float32(entity.pos.Y),
|
||||
|
||||
@@ -404,6 +404,13 @@ func (g *Game) UserWorldRemovePlayer(world *World, player *model.Player) {
|
||||
delTeamEntityNotify := g.PacketDelTeamEntityNotify(scene, player)
|
||||
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify)
|
||||
|
||||
// 清除其他玩家的载具
|
||||
if world.owner != player {
|
||||
for vehicleId, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
g.DestroyVehicleEntity(player, scene, vehicleId, entityId)
|
||||
}
|
||||
}
|
||||
|
||||
if world.GetMultiplayer() {
|
||||
playerQuitFromMpNotify := &proto.PlayerQuitFromMpNotify{
|
||||
Reason: proto.PlayerQuitFromMpNotify_BACK_TO_MY_WORLD,
|
||||
|
||||
+36
-2
@@ -317,6 +317,11 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
entityIdList = append(entityIdList, entityId)
|
||||
}
|
||||
g.AddSceneEntityNotify(player, visionType, entityIdList, false, false)
|
||||
// 加载该场景的载具
|
||||
if world.owner == player {
|
||||
vehicleEntityIdList := g.CreateSceneVehicle(scene)
|
||||
g.AddSceneEntityNotify(player, visionType, vehicleEntityIdList, false, false)
|
||||
}
|
||||
if WORLD_MANAGER.IsBigWorld(world) {
|
||||
bigWorldAoi := world.GetBigWorldAoi()
|
||||
otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
|
||||
@@ -699,6 +704,27 @@ func (g *Game) GetVisionEntity(scene *Scene, pos *model.Vector) map[uint32]*Enti
|
||||
return visionEntity
|
||||
}
|
||||
|
||||
// CreateSceneVehicle 创建场景内的载具
|
||||
func (g *Game) CreateSceneVehicle(scene *Scene) []uint32 {
|
||||
world := scene.GetWorld()
|
||||
owner := world.GetOwner()
|
||||
dbWorld := owner.GetDbWorld()
|
||||
dbScene := dbWorld.GetSceneById(scene.GetId())
|
||||
entityIdList := make([]uint32, 0, len(dbScene.GetVehicleMap()))
|
||||
for _, vehicle := range dbScene.GetVehicleMap() {
|
||||
// 创建载具
|
||||
entityId := scene.CreateEntityGadgetVehicle(vehicle.OwnerUid, vehicle.Pos, vehicle.Rot, vehicle.VehicleId)
|
||||
if entityId == 0 {
|
||||
logger.Error("create vehicle error, sceneId: %v", dbScene.SceneId)
|
||||
return entityIdList
|
||||
}
|
||||
entityIdList = append(entityIdList, entityId)
|
||||
// 记录数据
|
||||
owner.VehicleInfo.CreateEntityIdMap[vehicle.VehicleId] = entityId
|
||||
}
|
||||
return entityIdList
|
||||
}
|
||||
|
||||
// GetNeighborGroup 获取某位置附近的场景组
|
||||
func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*gdconf.Group {
|
||||
aoiManager, exist := WORLD_MANAGER.GetSceneBlockAoiMap()[sceneId]
|
||||
@@ -734,6 +760,9 @@ func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*g
|
||||
|
||||
// AddSceneGroup 加载场景组
|
||||
func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
|
||||
if groupConfig == nil {
|
||||
return
|
||||
}
|
||||
group := scene.GetGroupById(uint32(groupConfig.Id))
|
||||
if group != nil {
|
||||
return
|
||||
@@ -1616,14 +1645,19 @@ func (g *Game) PacketSceneGadgetInfoClient(gadgetClientEntity *GadgetClientEntit
|
||||
}
|
||||
|
||||
func (g *Game) PacketSceneGadgetInfoVehicle(gadgetVehicleEntity *GadgetVehicleEntity) *proto.SceneGadgetInfo {
|
||||
player := USER_MANAGER.GetOnlineUser(gadgetVehicleEntity.ownerUid)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, userId: %v", gadgetVehicleEntity.ownerUid)
|
||||
return new(proto.SceneGadgetInfo)
|
||||
}
|
||||
sceneGadgetInfo := &proto.SceneGadgetInfo{
|
||||
GadgetId: gadgetVehicleEntity.GetVehicleId(),
|
||||
AuthorityPeerId: WORLD_MANAGER.GetWorldByID(gadgetVehicleEntity.GetOwner().WorldId).GetPlayerPeerId(gadgetVehicleEntity.GetOwner()),
|
||||
AuthorityPeerId: WORLD_MANAGER.GetWorldByID(gadgetVehicleEntity.worldId).GetPlayerPeerId(player),
|
||||
IsEnableInteract: true,
|
||||
Content: &proto.SceneGadgetInfo_VehicleInfo{
|
||||
VehicleInfo: &proto.VehicleInfo{
|
||||
MemberList: make([]*proto.VehicleMember, 0, len(gadgetVehicleEntity.GetMemberMap())),
|
||||
OwnerUid: gadgetVehicleEntity.GetOwner().PlayerID,
|
||||
OwnerUid: gadgetVehicleEntity.GetOwnerUid(),
|
||||
CurStamina: gadgetVehicleEntity.GetCurStamina(),
|
||||
},
|
||||
},
|
||||
|
||||
+20
-17
@@ -168,23 +168,26 @@ func (g *Game) VehicleRestoreStaminaHandler(player *model.Player) {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
// 获取玩家创建的载具实体
|
||||
entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId)
|
||||
if entity == nil {
|
||||
return
|
||||
}
|
||||
// 确保实体类型是否为载具
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil {
|
||||
return
|
||||
}
|
||||
// 判断玩家处于载具中
|
||||
if g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
|
||||
// 角色回复耐力
|
||||
g.UpdatePlayerStamina(player, constant.STAMINA_COST_IN_SKIFF)
|
||||
} else {
|
||||
// 载具回复耐力
|
||||
g.UpdateVehicleStamina(player, entity, constant.STAMINA_COST_SKIFF_NOBODY)
|
||||
// 遍历玩家创建的载具实体
|
||||
for _, entityId := range player.VehicleInfo.CreateEntityIdMap {
|
||||
// 获取载具实体
|
||||
entity := scene.GetEntity(entityId)
|
||||
if entity == nil {
|
||||
continue
|
||||
}
|
||||
// 确保实体类型是否为载具
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
if gadgetEntity == nil || gadgetEntity.GetGadgetVehicleEntity() == nil {
|
||||
continue
|
||||
}
|
||||
// 判断玩家处于载具中
|
||||
if g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
|
||||
// 角色回复耐力
|
||||
g.UpdatePlayerStamina(player, constant.STAMINA_COST_IN_SKIFF)
|
||||
} else {
|
||||
// 载具回复耐力
|
||||
g.UpdateVehicleStamina(player, entity, constant.STAMINA_COST_SKIFF_NOBODY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
|
||||
// TODO 验证将要创建的载具位置是否有效 Retcode_RET_CREATE_VEHICLE_POS_INVALID
|
||||
|
||||
// 清除已创建的载具
|
||||
lastEntityId, ok := player.VehicleInfo.LastCreateEntityIdMap[req.VehicleId]
|
||||
lastEntityId, ok := player.VehicleInfo.CreateEntityIdMap[req.VehicleId]
|
||||
if ok {
|
||||
g.DestroyVehicleEntity(player, scene, req.VehicleId, lastEntityId)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
|
||||
// 创建载具实体
|
||||
pos := &model.Vector{X: float64(req.Pos.X), Y: float64(req.Pos.Y), Z: float64(req.Pos.Z)}
|
||||
rot := &model.Vector{X: float64(req.Rot.X), Y: float64(req.Rot.Y), Z: float64(req.Rot.Z)}
|
||||
entityId := scene.CreateEntityGadgetVehicle(player, pos, rot, req.VehicleId)
|
||||
entityId := scene.CreateEntityGadgetVehicle(player.PlayerID, pos, rot, req.VehicleId)
|
||||
if entityId == 0 {
|
||||
logger.Error("vehicle entityId is 0, uid: %v", player.PlayerID)
|
||||
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
|
||||
@@ -67,8 +67,15 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
GAME.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false)
|
||||
// 记录创建的载具信息
|
||||
player.VehicleInfo.LastCreateEntityIdMap[req.VehicleId] = entityId
|
||||
player.VehicleInfo.CreateEntityIdMap[req.VehicleId] = entityId
|
||||
player.VehicleInfo.LastCreateTime = time.Now().UnixMilli()
|
||||
// 记录房主的载具位置
|
||||
owner := world.GetOwner()
|
||||
if owner == player {
|
||||
dbWorld := owner.GetDbWorld()
|
||||
dbScene := dbWorld.GetSceneById(scene.GetId())
|
||||
dbScene.GetVehicleMap()[req.VehicleId] = model.NewDbVehicle(req.VehicleId, player.PlayerID, pos, rot)
|
||||
}
|
||||
|
||||
// PacketCreateVehicleRsp
|
||||
createVehicleRsp := &proto.CreateVehicleRsp{
|
||||
@@ -108,7 +115,7 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
return
|
||||
}
|
||||
// 该载具是否为此玩家的
|
||||
if gadgetEntity.GetGadgetVehicleEntity().GetOwner() != player {
|
||||
if gadgetEntity.GetGadgetVehicleEntity().GetOwnerUid() != player.PlayerID {
|
||||
return
|
||||
}
|
||||
// 如果玩家正在载具中
|
||||
@@ -121,6 +128,17 @@ func (g *Game) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleI
|
||||
// 删除已创建的载具
|
||||
scene.DestroyEntity(entity.GetId())
|
||||
g.RemoveSceneEntityNotifyBroadcast(scene, proto.VisionType_VISION_MISS, []uint32{entity.GetId()}, false, 0)
|
||||
// 删除玩家载具在线数据
|
||||
delete(player.VehicleInfo.CreateEntityIdMap, vehicleId)
|
||||
// 删除房主的载具存档
|
||||
world := scene.world
|
||||
owner := world.GetOwner()
|
||||
if owner == player {
|
||||
dbWorld := owner.GetDbWorld()
|
||||
dbScene := dbWorld.GetSceneById(scene.GetId())
|
||||
delete(dbScene.GetVehicleMap(), vehicleId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// EnterVehicle 进入载具
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
type DbVehicle struct {
|
||||
VehicleId uint32 // 载具Id
|
||||
OwnerUid uint32 // 所有者Id
|
||||
Pos *Vector // 位置
|
||||
Rot *Vector // 旋转
|
||||
}
|
||||
|
||||
func NewDbVehicle(vehicleId uint32, ownerId uint32, pos *Vector, rot *Vector) *DbVehicle {
|
||||
return &DbVehicle{
|
||||
VehicleId: vehicleId,
|
||||
OwnerUid: ownerId,
|
||||
Pos: pos,
|
||||
Rot: rot,
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type DbScene struct {
|
||||
SceneId uint32
|
||||
UnlockPointMap map[uint32]bool
|
||||
SceneGroupMap map[uint32]*DbSceneGroup
|
||||
VehicleMap map[uint32]*DbVehicle
|
||||
}
|
||||
|
||||
type DbWorld struct {
|
||||
@@ -40,6 +41,7 @@ func NewScene(sceneId uint32) *DbScene {
|
||||
SceneId: sceneId,
|
||||
UnlockPointMap: make(map[uint32]bool),
|
||||
SceneGroupMap: make(map[uint32]*DbSceneGroup),
|
||||
VehicleMap: make(map[uint32]*DbVehicle),
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -93,6 +95,13 @@ func (s *DbScene) GetSceneGroupById(groupId uint32) *DbSceneGroup {
|
||||
return dbSceneGroup
|
||||
}
|
||||
|
||||
func (s *DbScene) GetVehicleMap() map[uint32]*DbVehicle {
|
||||
if s.VehicleMap == nil {
|
||||
s.VehicleMap = make(map[uint32]*DbVehicle)
|
||||
}
|
||||
return s.VehicleMap
|
||||
}
|
||||
|
||||
func (g *DbSceneGroup) GetVariableByName(name string) int32 {
|
||||
return g.VariableMap[name]
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,16 +1,15 @@
|
||||
package model
|
||||
|
||||
type VehicleInfo struct {
|
||||
InVehicleEntityId uint32 // 玩家所在载具的实体Id
|
||||
LastCreateTime int64 // 最后一次创建载具的时间
|
||||
// TODO 玩家可以在其他世界创建载具 需要额外处理
|
||||
LastCreateEntityIdMap map[uint32]uint32 // 最后一次创建载具的实体Id map[vehicleId]EntityId
|
||||
InVehicleEntityId uint32 // 玩家所在载具的实体Id
|
||||
LastCreateTime int64 // 最后一次创建载具的时间
|
||||
CreateEntityIdMap map[uint32]uint32 // 创建载具的实体Id map[vehicleId]EntityId
|
||||
}
|
||||
|
||||
func NewVehicleInfo() *VehicleInfo {
|
||||
return &VehicleInfo{
|
||||
InVehicleEntityId: 0,
|
||||
LastCreateTime: 0,
|
||||
LastCreateEntityIdMap: make(map[uint32]uint32),
|
||||
InVehicleEntityId: 0,
|
||||
LastCreateTime: 0,
|
||||
CreateEntityIdMap: make(map[uint32]uint32),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user