fix oxygen tank is empty in inventory when reconnecting#2302
fix oxygen tank is empty in inventory when reconnecting#2302Buivol16 wants to merge 1 commit intoSubnauticaNitrox:masterfrom
Conversation
| var iOxygenSource = pickupable.gameObject.GetComponent<IOxygenSource>(); | ||
| var entityMetadataUpdate = GetEntityMetadataUpdateForIOxygenMetadata(iOxygenSource, itemId); | ||
| if (entityMetadataUpdate != null) packetSender.Send(entityMetadataUpdate); |
There was a problem hiding this comment.
This seems like a very specific check when we have methods to extract metadata in a general fashion. Did you test any weird behaviour when sending every extractable metadata?
@tornac1234 what is your opinion on this?
|
|
||
| if (packetSender.Send(new EntityReparented(itemId, ownerId))) | ||
| { | ||
| var iOxygenSource = pickupable.gameObject.GetComponent<IOxygenSource>(); |
There was a problem hiding this comment.
We don't use var at all.
It seems you don't get visual feedback from your IDE for this. We have a .editorconfig file in the project which should setup out code style for you... 🤔
| { | ||
| var iOxygenSource = pickupable.gameObject.GetComponent<IOxygenSource>(); | ||
| var entityMetadataUpdate = GetEntityMetadataUpdateForIOxygenMetadata(iOxygenSource, itemId); | ||
| if (entityMetadataUpdate != null) packetSender.Send(entityMetadataUpdate); |
| [ProtoInclude(79, typeof(SeaTreaderMetadata))] | ||
| [ProtoInclude(80, typeof(StayAtLeashPositionMetadata))] | ||
| [ProtoInclude(81, typeof(EggMetadata))] | ||
| [ProtoInclude(82, typeof(IOxygenSourceMetadata))] |
There was a problem hiding this comment.
Should add tests for it in WorldPersistenceTest
| IOxygenSource iOxygenSource = gameObject.GetComponent<IOxygenSource>(); | ||
|
|
||
| if (iOxygenSource != null) |
There was a problem hiding this comment.
| IOxygenSource iOxygenSource = gameObject.GetComponent<IOxygenSource>(); | |
| if (iOxygenSource != null) | |
| if (gameObject.TryGetComponent(out IOxygenSource iOxygenSource)) |
Makes it a little bit clearer imo. Also you should never compare unity objects against null (see here for explaination), instead threat it like in c++ as a bool
|
|
||
| if (iOxygenSource != null) | ||
| { | ||
| iOxygenSource.AddOxygen(metadata.AvailableOxygen); |
There was a problem hiding this comment.
As this can also possibly be executed on existing tanks I would first calculate the delta of GetOxygenAvailable() and metadata.AvailableOxygen, to then use it for AddOxygen() or RemoveOxygen() depending on plus or minus.
| } | ||
|
|
||
| public void BroadcastItemAdd(Pickupable pickupable, Transform containerTransform) | ||
| public void BroadcastItemAddAndSendMetadata(Pickupable pickupable, Transform containerTransform) |
There was a problem hiding this comment.
Also with this changes the value only gets updated when adding the tank to the inventory and not when we use breath the air in it or rise to the surface. Maybe we need some kind of system to send this data repentantly (like every 1-3 seconds or so).
|
Closing for now, we'll explore another way of doing it |
Fix for issue: #2266