-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and fix EscapePodMetadata handling
- Loading branch information
Showing
13 changed files
with
249 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
NitroxClient/GameLogic/Spawning/Metadata/Processor/EscapePodMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using NitroxClient.Communication; | ||
using NitroxClient.GameLogic.FMOD; | ||
using NitroxClient.GameLogic.Spawning.Metadata.Processor.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.Packets; | ||
using UnityEngine; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Processor; | ||
|
||
public class EscapePodMetadataProcessor : EntityMetadataProcessor<EscapePodMetadata> | ||
{ | ||
public override void ProcessMetadata(GameObject gameObject, EscapePodMetadata metadata) | ||
{ | ||
if (!gameObject.TryGetComponent(out EscapePod pod)) | ||
{ | ||
Log.Error($"[{nameof(EscapePodMetadataProcessor)}] Could not get the EscapePod component from the provided gameobject."); | ||
return; | ||
} | ||
|
||
if (!pod.radioSpawner.spawnedObj.TryGetComponent(out Radio radio)) | ||
{ | ||
Log.Error($"[{nameof(EscapePodMetadataProcessor)}] Could not get Radio from EscapePod."); | ||
return; | ||
} | ||
|
||
if (!pod.liveMixin.IsFullHealth() && metadata.PodRepaired) | ||
{ | ||
pod.OnRepair(); | ||
} | ||
|
||
if (!radio.liveMixin.IsFullHealth() && metadata.RadioRepaired) | ||
{ | ||
radio.OnRepair(); | ||
} | ||
|
||
ProcessInitialSyncMetadata(pod, radio, metadata); | ||
} | ||
|
||
public static void ProcessInitialSyncMetadata(EscapePod pod, Radio radio, EscapePodMetadata metadata) | ||
{ | ||
using FMODSoundSuppressor soundSuppressor = FMODSystem.SuppressSubnauticaSounds(); | ||
using PacketSuppressor<EntityMetadataUpdate> packetSuppressor = PacketSuppressor<EntityMetadataUpdate>.Suppress(); | ||
|
||
if (metadata.PodRepaired) | ||
{ | ||
pod.liveMixin.health = pod.liveMixin.maxHealth; | ||
pod.healthScalar = 1; | ||
pod.damageEffectsShowing = true; | ||
|
||
using (FMODSystem.SuppressSubnauticaSounds()) | ||
{ | ||
pod.UpdateDamagedEffects(); | ||
} | ||
pod.lightingController.SnapToState(0); | ||
} | ||
else | ||
{ | ||
IntroLifepodDirector introLifepodDirector = pod.GetComponent<IntroLifepodDirector>(); | ||
introLifepodDirector.OnProtoDeserializeObjectTree(null); | ||
introLifepodDirector.ToggleActiveObjects(false); | ||
pod.lightingController.SnapToState(2); | ||
} | ||
|
||
if (metadata.RadioRepaired) | ||
{ | ||
radio.liveMixin.health = radio.liveMixin.maxHealth; | ||
Object.Destroy(radio.liveMixin.loopingDamageEffectObj); | ||
} | ||
else | ||
{ | ||
pod.DamageRadio(); | ||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
NitroxClient/GameLogic/Spawning/Metadata/Processor/RepairedComponentMetadataProcessor.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
NitroxModel/DataStructures/GameLogic/Entities/Metadata/EscapePodMetadata.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
using BinaryPack.Attributes; | ||
|
||
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
|
||
[Serializable] | ||
[DataContract] | ||
public class EscapePodMetadata : EntityMetadata | ||
{ | ||
[DataMember(Order = 1)] | ||
public bool PodRepaired { get; } | ||
|
||
[DataMember(Order = 2)] | ||
public bool RadioRepaired { get; } | ||
|
||
[IgnoreConstructor] | ||
protected EscapePodMetadata() | ||
{ | ||
//Constructor for serialization. Has to be "protected" for json serialization. | ||
} | ||
|
||
public EscapePodMetadata(bool podRepaired, bool radioRepaired) | ||
{ | ||
PodRepaired = podRepaired; | ||
RadioRepaired = radioRepaired; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"[{nameof(EscapePodMetadata)} - PodRepaired: {PodRepaired}, RadioRepaired: {RadioRepaired}]"; | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
NitroxModel/DataStructures/GameLogic/Entities/Metadata/RepairedComponentMetadata.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.