Restore Continue session facts from typed state
This commit is contained in:
parent
8b8a86f6ae
commit
2a047cba28
6 changed files with 86 additions and 12 deletions
|
|
@ -2543,9 +2543,36 @@ public class ActionGameManager : MonoBehaviour
|
|||
entity.Zone = Zone;
|
||||
Zone.Entities.Add(entity);
|
||||
entity.Activate();
|
||||
entity.HeatsinksEnabled = entitySnapshot.HeatsinksEnabled;
|
||||
entity.RestoreThermalExposure((float)entitySnapshot.Heatstroke, (float)entitySnapshot.Hypothermia);
|
||||
RestoreActiveConsumablesFromTypedEntitySnapshot(entity, entitySnapshot);
|
||||
BindToEntity(entity);
|
||||
}
|
||||
|
||||
private void RestoreActiveConsumablesFromTypedEntitySnapshot(Entity entity, AetheriaRuntimeEntitySnapshot snapshot)
|
||||
{
|
||||
foreach (var activeConsumable in snapshot.ActiveConsumables)
|
||||
{
|
||||
var item = CreateLoadoutItem(new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
activeConsumable.ItemKey,
|
||||
activeConsumable.Quality,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
false)) as ConsumableItem;
|
||||
if (item == null)
|
||||
{
|
||||
Debug.LogWarning($"Typed active consumable {activeConsumable.ItemKey} could not be lowered for restored entity {snapshot.RecordKey}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.RestoreActiveConsumable(
|
||||
item,
|
||||
(float)activeConsumable.RemainingDuration,
|
||||
(float)activeConsumable.Duration);
|
||||
}
|
||||
}
|
||||
|
||||
private static GalaxyZone ResolveStartZone(AetheriaRuntimeRunStateSnapshot run)
|
||||
{
|
||||
if (CurrentGalaxy?.Zones == null || CurrentGalaxy.Zones.Length == 0)
|
||||
|
|
|
|||
|
|
@ -315,6 +315,20 @@ public abstract class Entity
|
|||
_activeConsumables.Add(new ConsumableItemEffect(item, this));
|
||||
}
|
||||
|
||||
public void RestoreThermalExposure(float heatstroke, float hypothermia)
|
||||
{
|
||||
Heatstroke = saturate(heatstroke);
|
||||
Hypothermia = saturate(hypothermia);
|
||||
}
|
||||
|
||||
public void RestoreActiveConsumable(ConsumableItem item, float remainingDuration, float duration)
|
||||
{
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
_activeConsumables.Add(new ConsumableItemEffect(item, this, remainingDuration, duration));
|
||||
}
|
||||
|
||||
public ConsumableItemEffect FindActiveConsumable(string itemKey)
|
||||
{
|
||||
return _activeConsumables.FirstOrDefault(ac => ac.Item?.ItemKey == itemKey);
|
||||
|
|
@ -1182,13 +1196,20 @@ public class ConsumableItemEffect
|
|||
private readonly BezierCurve _effectiveness;
|
||||
|
||||
public ConsumableItemEffect(ConsumableItem item, Entity entity)
|
||||
: this(item, entity, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public ConsumableItemEffect(ConsumableItem item, Entity entity, float? remainingDuration, float? duration)
|
||||
{
|
||||
Item = item;
|
||||
Entity = entity;
|
||||
RuntimeItem = entity.ItemManager.GetRuntimeItem(item);
|
||||
_duration = RuntimeItem?.Duration > 0 ? (float)RuntimeItem.Duration : 0;
|
||||
_duration = duration.GetValueOrDefault(RuntimeItem?.Duration > 0 ? (float)RuntimeItem.Duration : 0);
|
||||
_effectiveness = CreateEffectivenessCurve(RuntimeItem);
|
||||
RemainingDuration = _duration;
|
||||
RemainingDuration = remainingDuration.HasValue
|
||||
? clamp(remainingDuration.Value, 0, Duration)
|
||||
: _duration;
|
||||
|
||||
Behaviors = entity.ItemManager.CreateRuntimeBehaviors(this);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue