mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
多载具提前兼容
This commit is contained in:
@@ -119,9 +119,6 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
|||||||
player.Rot.X = float64(motionInfo.Rot.X)
|
player.Rot.X = float64(motionInfo.Rot.X)
|
||||||
player.Rot.Y = float64(motionInfo.Rot.Y)
|
player.Rot.Y = float64(motionInfo.Rot.Y)
|
||||||
player.Rot.Z = float64(motionInfo.Rot.Z)
|
player.Rot.Z = float64(motionInfo.Rot.Z)
|
||||||
|
|
||||||
// 处理耐力消耗
|
|
||||||
g.ImmediateStamina(player, motionInfo.State)
|
|
||||||
} else {
|
} else {
|
||||||
// 非玩家实体在移动 更新场景实体的位置信息
|
// 非玩家实体在移动 更新场景实体的位置信息
|
||||||
sceneEntity.pos = &model.Vector{
|
sceneEntity.pos = &model.Vector{
|
||||||
@@ -139,6 +136,12 @@ func (g *GameManager) CombatInvocationsNotify(player *model.Player, payloadMsg p
|
|||||||
sceneEntity.lastMoveSceneTimeMs = entityMoveInfo.SceneTime
|
sceneEntity.lastMoveSceneTimeMs = entityMoveInfo.SceneTime
|
||||||
sceneEntity.lastMoveReliableSeq = entityMoveInfo.ReliableSeq
|
sceneEntity.lastMoveReliableSeq = entityMoveInfo.ReliableSeq
|
||||||
|
|
||||||
|
// 角色和载具的耐力消耗
|
||||||
|
if sceneEntity.avatarEntity != nil || (sceneEntity.gadgetEntity != nil && sceneEntity.gadgetEntity.gadgetVehicleEntity != nil) {
|
||||||
|
// 处理耐力消耗
|
||||||
|
g.ImmediateStamina(player, motionInfo.State)
|
||||||
|
}
|
||||||
|
|
||||||
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
|
player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry)
|
||||||
case proto.CombatTypeArgument_COMBAT_TYPE_ARGUMENT_ANIMATOR_STATE_CHANGED:
|
case proto.CombatTypeArgument_COMBAT_TYPE_ARGUMENT_ANIMATOR_STATE_CHANGED:
|
||||||
evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo)
|
evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo)
|
||||||
|
|||||||
@@ -278,10 +278,14 @@ func (g *GameManager) VehicleRestoreStaminaHandler(player *model.Player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取玩家创建的载具实体
|
// 获取玩家创建的载具实体
|
||||||
entity := g.GetSceneVehicleEntity(scene, player.VehicleInfo.LastCreateEntityId)
|
entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId)
|
||||||
if entity == nil {
|
if entity == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 确保实体类型是否为载具
|
||||||
|
if entity.gadgetEntity == nil || entity.gadgetEntity.gadgetVehicleEntity == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
// 判断玩家处于载具中
|
// 判断玩家处于载具中
|
||||||
if g.IsPlayerInVehicle(player, entity.gadgetEntity.gadgetVehicleEntity) {
|
if g.IsPlayerInVehicle(player, entity.gadgetEntity.gadgetVehicleEntity) {
|
||||||
// 角色回复耐力
|
// 角色回复耐力
|
||||||
@@ -303,9 +307,16 @@ func (g *GameManager) SustainStaminaHandler(player *model.Player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取玩家处于的载具实体
|
// 获取玩家处于的载具实体
|
||||||
entity := g.GetSceneVehicleEntity(scene, player.VehicleInfo.InVehicleEntityId)
|
entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId)
|
||||||
|
if entity == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 确保实体类型是否为载具
|
||||||
|
if entity.gadgetEntity == nil || entity.gadgetEntity.gadgetVehicleEntity == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
// 根据玩家是否处于载具中更新耐力
|
// 根据玩家是否处于载具中更新耐力
|
||||||
if entity != nil && g.IsPlayerInVehicle(player, entity.gadgetEntity.gadgetVehicleEntity) {
|
if g.IsPlayerInVehicle(player, entity.gadgetEntity.gadgetVehicleEntity) {
|
||||||
// 更新载具耐力
|
// 更新载具耐力
|
||||||
g.UpdateVehicleStamina(player, entity, player.StaminaInfo.CostStamina)
|
g.UpdateVehicleStamina(player, entity, player.StaminaInfo.CostStamina)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ func (g *GameManager) CreateVehicleReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
// TODO 验证将要创建的载具位置是否有效 Retcode_RET_CREATE_VEHICLE_POS_INVALID
|
// TODO 验证将要创建的载具位置是否有效 Retcode_RET_CREATE_VEHICLE_POS_INVALID
|
||||||
|
|
||||||
// 清除已创建的载具
|
// 清除已创建的载具
|
||||||
if player.VehicleInfo.LastCreateEntityId != 0 {
|
lastEntityId, ok := player.VehicleInfo.LastCreateEntityIdMap[req.VehicleId]
|
||||||
g.DestroyVehicleEntity(player, scene, req.VehicleId, player.VehicleInfo.LastCreateEntityId)
|
if ok {
|
||||||
|
g.DestroyVehicleEntity(player, scene, req.VehicleId, lastEntityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建载具实体
|
// 创建载具实体
|
||||||
@@ -46,7 +47,7 @@ func (g *GameManager) CreateVehicleReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
GAME_MANAGER.AddSceneEntityNotify(player, proto.VisionType_VISION_TYPE_BORN, []uint32{entityId}, true, false)
|
GAME_MANAGER.AddSceneEntityNotify(player, proto.VisionType_VISION_TYPE_BORN, []uint32{entityId}, true, false)
|
||||||
|
|
||||||
// 记录创建的载具信息
|
// 记录创建的载具信息
|
||||||
player.VehicleInfo.LastCreateEntityId = entityId
|
player.VehicleInfo.LastCreateEntityIdMap[req.VehicleId] = entityId
|
||||||
player.VehicleInfo.LastCreateTime = time.Now().UnixMilli()
|
player.VehicleInfo.LastCreateTime = time.Now().UnixMilli()
|
||||||
|
|
||||||
// PacketCreateVehicleRsp
|
// PacketCreateVehicleRsp
|
||||||
@@ -57,19 +58,6 @@ func (g *GameManager) CreateVehicleReq(player *model.Player, payloadMsg pb.Messa
|
|||||||
g.SendMsg(cmd.CreateVehicleRsp, player.PlayerID, player.ClientSeq, createVehicleRsp)
|
g.SendMsg(cmd.CreateVehicleRsp, player.PlayerID, player.ClientSeq, createVehicleRsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSceneVehicleEntity 获取场景内的载具实体
|
|
||||||
func (g *GameManager) GetSceneVehicleEntity(scene *Scene, entityId uint32) *Entity {
|
|
||||||
entity := scene.GetEntity(entityId)
|
|
||||||
if entity == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// 确保实体类型是否为载具
|
|
||||||
if entity.entityType == uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET) && entity.gadgetEntity.gadgetType == GADGET_TYPE_VEHICLE {
|
|
||||||
return entity
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsPlayerInVehicle 判断玩家是否在载具中
|
// IsPlayerInVehicle 判断玩家是否在载具中
|
||||||
func (g *GameManager) IsPlayerInVehicle(player *model.Player, gadgetVehicleEntity *GadgetVehicleEntity) bool {
|
func (g *GameManager) IsPlayerInVehicle(player *model.Player, gadgetVehicleEntity *GadgetVehicleEntity) bool {
|
||||||
if gadgetVehicleEntity == nil {
|
if gadgetVehicleEntity == nil {
|
||||||
@@ -85,15 +73,19 @@ func (g *GameManager) IsPlayerInVehicle(player *model.Player, gadgetVehicleEntit
|
|||||||
|
|
||||||
// DestroyVehicleEntity 删除载具实体
|
// DestroyVehicleEntity 删除载具实体
|
||||||
func (g *GameManager) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleId uint32, entityId uint32) {
|
func (g *GameManager) DestroyVehicleEntity(player *model.Player, scene *Scene, vehicleId uint32, entityId uint32) {
|
||||||
entity := g.GetSceneVehicleEntity(scene, entityId)
|
entity := scene.GetEntity(entityId)
|
||||||
if entity == nil {
|
if entity == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 目前原神仅有一种载具 多载具时可能跟载具耐力回复冲突 到时候再改
|
// 确保实体类型是否为载具
|
||||||
|
if entity.gadgetEntity == nil || entity.gadgetEntity.gadgetVehicleEntity == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 目前原神仅有一种载具 多载具目前理论上是兼容了 到时候有问题再改
|
||||||
// 确保载具Id为将要创建的 (每种载具允许存在1个)
|
// 确保载具Id为将要创建的 (每种载具允许存在1个)
|
||||||
// if entity.gadgetEntity.gadgetVehicleEntity.vehicleId != vehicleId {
|
if entity.gadgetEntity.gadgetVehicleEntity.vehicleId != vehicleId {
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// 该载具是否为此玩家的
|
// 该载具是否为此玩家的
|
||||||
if entity.gadgetEntity.gadgetVehicleEntity.owner != player {
|
if entity.gadgetEntity.gadgetVehicleEntity.owner != player {
|
||||||
return
|
return
|
||||||
@@ -185,14 +177,14 @@ func (g *GameManager) VehicleInteractReq(player *model.Player, payloadMsg pb.Mes
|
|||||||
scene := world.GetSceneById(player.SceneId)
|
scene := world.GetSceneById(player.SceneId)
|
||||||
|
|
||||||
// 获取载具实体
|
// 获取载具实体
|
||||||
entity := g.GetSceneVehicleEntity(scene, req.EntityId)
|
entity := scene.GetEntity(req.EntityId)
|
||||||
if entity == nil {
|
if entity == nil {
|
||||||
logger.Error("vehicle entity is nil, entityId: %v", req.EntityId)
|
logger.Error("vehicle entity is nil, entityId: %v", req.EntityId)
|
||||||
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_ENTITY_NOT_EXIST)
|
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_ENTITY_NOT_EXIST)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 判断实体类型是否为载具
|
// 判断实体类型是否为载具
|
||||||
if entity.entityType != uint32(proto.ProtEntityType_PROT_ENTITY_TYPE_GADGET) || entity.gadgetEntity.gadgetType != GADGET_TYPE_VEHICLE {
|
if entity.gadgetEntity == nil || entity.gadgetEntity.gadgetVehicleEntity == nil {
|
||||||
logger.Error("vehicle entity error, entityType: %v", entity.entityType)
|
logger.Error("vehicle entity error, entityType: %v", entity.entityType)
|
||||||
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_GADGET_NOT_VEHICLE)
|
g.CommonRetError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{}, proto.Retcode_RET_GADGET_NOT_VEHICLE)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ func (p *Player) InitAll() {
|
|||||||
p.CoopApplyMap = make(map[uint32]int64)
|
p.CoopApplyMap = make(map[uint32]int64)
|
||||||
p.StaminaInfo = new(StaminaInfo)
|
p.StaminaInfo = new(StaminaInfo)
|
||||||
p.VehicleInfo = new(VehicleInfo)
|
p.VehicleInfo = new(VehicleInfo)
|
||||||
|
p.VehicleInfo.LastCreateEntityIdMap = make(map[uint32]uint32)
|
||||||
p.InitAllAvatar()
|
p.InitAllAvatar()
|
||||||
p.InitAllWeapon()
|
p.InitAllWeapon()
|
||||||
p.InitAllItem()
|
p.InitAllItem()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type VehicleInfo struct {
|
type VehicleInfo struct {
|
||||||
InVehicleEntityId uint32 // 玩家所在载具的实体Id
|
InVehicleEntityId uint32 // 玩家所在载具的实体Id
|
||||||
LastCreateTime int64 // 最后一次创建载具的时间
|
LastCreateTime int64 // 最后一次创建载具的时间
|
||||||
LastCreateEntityId uint32 // 最后一次创建载具的实体Id
|
LastCreateEntityIdMap map[uint32]uint32 // 最后一次创建载具的实体Id map[vehicleId]EntityId
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user