fix nil ptr panic

This commit is contained in:
flswld
2023-02-09 01:29:04 +08:00
parent 9d6e95a6b4
commit 867448b80d
3 changed files with 11 additions and 8 deletions

View File

@@ -158,7 +158,7 @@ func (g *GameManager) run() {
} }
func (g *GameManager) gameMainLoopD() { func (g *GameManager) gameMainLoopD() {
for times := 1; times <= 1000; times++ { for times := 1; times <= 100000; times++ {
logger.Warn("start game main loop, times: %v", times) logger.Warn("start game main loop, times: %v", times)
g.gameMainLoop() g.gameMainLoop()
logger.Warn("game main loop stop") logger.Warn("game main loop stop")

View File

@@ -325,17 +325,20 @@ func (g *GameManager) VehicleRestoreStaminaHandler(player *model.Player) {
func (g *GameManager) SustainStaminaHandler(player *model.Player) { func (g *GameManager) SustainStaminaHandler(player *model.Player) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId) world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId) scene := world.GetSceneById(player.SceneId)
// 玩家暂停状态不更新耐力 // 玩家暂停状态不更新耐力
if player.Pause { if player.Pause {
return return
} }
// 获取玩家处于的载具实体 // 获取玩家处于的载具实体
entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId) entity := scene.GetEntity(player.VehicleInfo.InVehicleEntityId)
if entity == nil {
// 更新玩家耐力
g.UpdatePlayerStamina(player, player.StaminaInfo.CostStamina)
return
}
// 确保实体类型是否为载具 且 根据玩家是否处于载具中更新耐力 // 确保实体类型是否为载具 且 根据玩家是否处于载具中更新耐力
gadgetEntity := entity.GetGadgetEntity() gadgetEntity := entity.GetGadgetEntity()
if entity != nil && (gadgetEntity != nil && gadgetEntity.GetGadgetVehicleEntity() != nil) && g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) { if gadgetEntity != nil && gadgetEntity.GetGadgetVehicleEntity() != nil && g.IsPlayerInVehicle(player, gadgetEntity.GetGadgetVehicleEntity()) {
// 更新载具耐力 // 更新载具耐力
g.UpdateVehicleStamina(player, entity, player.StaminaInfo.CostStamina) g.UpdateVehicleStamina(player, entity, player.StaminaInfo.CostStamina)
} else { } else {

View File

@@ -346,10 +346,10 @@ func (t *TickManager) onTickSecond(now int64) {
} }
} }
} }
// GCG游戏Tick // // GCG游戏Tick
for _, game := range GCG_MANAGER.gameMap { // for _, game := range GCG_MANAGER.gameMap {
game.onTick() // game.onTick()
} // }
} }
func (t *TickManager) onTick200MilliSecond(now int64) { func (t *TickManager) onTick200MilliSecond(now int64) {