private void StartRemovalTimer(LegacyShelter shelter, float lifetimeSeconds, ShelterData shelterData)
{
var shelterId = shelter.net.ID.Value;
if (lifetimeSeconds <= 0)
{
CleanupShelter(shelterData, shelter, shelterId);
return;
}
shelterData.RemovalTimer = Time.realtimeSinceStartup + lifetimeSeconds;
DataFileUtil.Save(DataFileUtil.GetFilePath(), _storedData);
timer.Once(lifetimeSeconds, () => CleanupShelter(shelterData, shelter, shelterId));
}
private void CleanupShelter(ShelterData shelterData, LegacyShelter? shelter, ulong shelterId)
{
foreach (ulong entityId in shelterData.InteriorEntities)
{
var entity = FindEntityById(entityId);
entity?.Kill();
}
shelter?.Kill();
if (_storedData.Shelters.Remove(shelterId))
{
DataFileUtil.Save(DataFileUtil.GetFilePath(), _storedData);
}
}