Fix event crashing when ghosts are present.

This commit is contained in:
Víctor Aguilera Puerto
2020-10-09 12:04:18 +02:00
parent ea30709cde
commit 4e085d8847

View File

@@ -1,3 +1,4 @@
#nullable enable
using JetBrains.Annotations; using JetBrains.Annotations;
using Content.Server.GameObjects.Components.Doors; using Content.Server.GameObjects.Components.Doors;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
@@ -22,7 +23,7 @@ namespace Content.Server.StationEvents
public override StationEventWeight Weight => StationEventWeight.Low; public override StationEventWeight Weight => StationEventWeight.Low;
public override int? MaxOccurrences => 1; public override int? MaxOccurrences => 1;
private float _elapsedTime; private float _elapsedTime;
private int _eventDuration; private int _eventDuration;
protected override string StartAnnouncement => Loc.GetString( protected override string StartAnnouncement => Loc.GetString(
"The clover hat hackers turned the bolts of all the airlocks in the station down. We have dispatched high quality hacking equipment at every crewmember location so that this productive shift can continue"); "The clover hat hackers turned the bolts of all the airlocks in the station down. We have dispatched high quality hacking equipment at every crewmember location so that this productive shift can continue");
protected override string EndAnnouncement => Loc.GetString( protected override string EndAnnouncement => Loc.GetString(
@@ -39,11 +40,10 @@ namespace Content.Server.StationEvents
var playerManager = IoCManager.Resolve<IPlayerManager>(); var playerManager = IoCManager.Resolve<IPlayerManager>();
foreach (var player in playerManager.GetAllPlayers()) foreach (var player in playerManager.GetAllPlayers())
{ {
var inventory = player.AttachedEntity.GetComponent<InventoryComponent>(); if (player.AttachedEntity == null || !player.AttachedEntity.TryGetComponent(out InventoryComponent? inventory)) return;
if (player.AttachedEntity == null) return; if (inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.BELT, out ItemComponent? item)
if (inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.BELT, out ItemComponent item) && item?.Owner.Prototype?.ID == "UtilityBeltClothingFilledEvent") return;
&& item.Owner.Prototype.ID == "UtilityBeltClothingFilledEvent") return; if (player.AttachedEntity.TryGetComponent<IDamageableComponent>(out var damageable)
if (player.AttachedEntity.TryGetComponent<IDamageableComponent>(out var damageable)
&& damageable.CurrentDamageState == DamageState.Dead) return; && damageable.CurrentDamageState == DamageState.Dead) return;
var entityManager = IoCManager.Resolve<IEntityManager>(); var entityManager = IoCManager.Resolve<IEntityManager>();
@@ -65,7 +65,7 @@ namespace Content.Server.StationEvents
{ {
return; return;
} }
_elapsedTime += frameTime; _elapsedTime += frameTime;
if (_elapsedTime < _eventDuration) if (_elapsedTime < _eventDuration)
@@ -76,4 +76,4 @@ namespace Content.Server.StationEvents
Running = false; Running = false;
} }
} }
} }