Skip to content

Commit c0cb780

Browse files
committed
* Fixed a bug with some base piece types not having their guid copied when base geometry is being recalculated.
* When completing a base piece's construction try to create the base (using the parent id) if it does not exist.
1 parent 696cea4 commit c0cb780

File tree

13 files changed

+44
-56
lines changed

13 files changed

+44
-56
lines changed

NitroxClient/Communication/Packets/Processors/ConstructionCompletedProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public ConstructionCompletedProcessor(BuildThrottlingQueue buildEventQueue)
1616

1717
public override void Process(ConstructionCompleted completedPacket)
1818
{
19-
Log.Debug("Processing ConstructionCompleted " + completedPacket.Guid + " " + completedPacket.NewBaseCreatedGuid);
20-
buildEventQueue.EnqueueConstructionCompleted(completedPacket.Guid, completedPacket.NewBaseCreatedGuid);
19+
Log.Debug("Processing ConstructionCompleted " + completedPacket.Guid + " " + completedPacket.BaseGuid);
20+
buildEventQueue.EnqueueConstructionCompleted(completedPacket.Guid, completedPacket.BaseGuid);
2121
}
2222
}
2323
}

NitroxClient/Communication/Packets/Processors/InitialPlayerSyncProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ private void SpawnBasePieces(List<BasePiece> basePieces)
216216
buildEventQueue.EnqueueBasePiecePlaced(basePiece);
217217

218218
if (basePiece.ConstructionCompleted)
219-
{
220-
buildEventQueue.EnqueueConstructionCompleted(basePiece.Guid, basePiece.NewBaseGuid);
219+
{
220+
buildEventQueue.EnqueueConstructionCompleted(basePiece.Guid, basePiece.BaseGuid);
221221
}
222222
else
223223
{

NitroxClient/GameLogic/Bases/BuildThrottlingQueue.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public void EnqueueBasePiecePlaced(BasePiece basePiece)
3232
Enqueue(new BasePiecePlacedEvent(basePiece));
3333
}
3434

35-
public void EnqueueConstructionCompleted(string guid, Optional<string> newBaseCreatedGuid)
35+
public void EnqueueConstructionCompleted(string guid, string baseGuid)
3636
{
3737
Log.Info("Enqueuing item to have construction completed " + guid);
38-
Enqueue(new ConstructionCompletedEvent(guid, newBaseCreatedGuid));
38+
Enqueue(new ConstructionCompletedEvent(guid, baseGuid));
3939
}
4040

4141
public void EnqueueAmountChanged(string guid, float amount)
@@ -97,12 +97,12 @@ public bool RequiresFreshFrame()
9797
public class ConstructionCompletedEvent : BuildEvent
9898
{
9999
public string Guid { get; }
100-
public Optional<string> NewBaseCreatedGuid { get; }
100+
public string BaseGuid { get; }
101101

102-
public ConstructionCompletedEvent(string guid, Optional<string> newBaseCreatedGuid)
102+
public ConstructionCompletedEvent(string guid, string baseGuid)
103103
{
104104
Guid = guid;
105-
NewBaseCreatedGuid = newBaseCreatedGuid;
105+
BaseGuid = baseGuid;
106106
}
107107

108108
public bool RequiresFreshFrame()

NitroxClient/GameLogic/Building.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NitroxClient.Communication.Abstract;
22
using NitroxClient.GameLogic.Helper;
3+
using NitroxClient.GameLogic.Spawning;
34
using NitroxClient.Unity.Helper;
45
using NitroxModel.DataStructures.GameLogic;
56
using NitroxModel.DataStructures.GameLogic.Buildings.Rotation;
@@ -87,17 +88,17 @@ public void ChangeConstructionAmount(GameObject gameObject, float amount)
8788

8889
public void ConstructionComplete(GameObject ghost)
8990
{
90-
Optional<string> newlyConstructedBaseGuid = Optional<string>.Empty();
91+
string baseGuid = null;
9192
Optional<object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
9293

9394
string guid = GuidHelper.GetGuid(ghost);
9495

9596
if (opConstructedBase.IsPresent())
9697
{
9798
GameObject constructedBase = (GameObject)opConstructedBase.Get();
98-
newlyConstructedBaseGuid = Optional<string>.Of(GuidHelper.GetGuid(constructedBase));
99+
baseGuid = GuidHelper.GetGuid(constructedBase);
99100
}
100-
101+
101102
// For base pieces, we must switch the guid from the ghost to the newly constructed piece.
102103
// Furniture just uses the same game object as the ghost for the final product.
103104
if(ghost.GetComponent<ConstructableBase>() != null)
@@ -107,9 +108,14 @@ public void ConstructionComplete(GameObject ghost)
107108

108109
UnityEngine.Object.Destroy(ghost);
109110
GuidHelper.SetNewGuid(finishedPiece, guid);
111+
112+
if(baseGuid == null)
113+
{
114+
baseGuid = GuidHelper.GetGuid(finishedPiece.GetComponentInParent<Base>().gameObject);
115+
}
110116
}
111-
112-
ConstructionCompleted constructionCompleted = new ConstructionCompleted(guid, newlyConstructedBaseGuid);
117+
118+
ConstructionCompleted constructionCompleted = new ConstructionCompleted(guid, baseGuid);
113119
packetSender.Send(constructionCompleted);
114120
}
115121

NitroxClient/MonoBehaviours/ThrottledBuilder.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private void ActionBuildEvent(BuildEvent buildEvent)
108108

109109
private void BuildBasePiece(BasePiecePlacedEvent basePiecePlacedBuildEvent)
110110
{
111+
Log.Info("BuildBasePiece " + basePiecePlacedBuildEvent.BasePiece.Guid + " " + basePiecePlacedBuildEvent.BasePiece.TechType);
111112
BasePiece basePiece = basePiecePlacedBuildEvent.BasePiece;
112113
GameObject buildPrefab = CraftData.GetBuildPrefab(basePiece.TechType);
113114
MultiplayerBuilder.overridePosition = basePiece.ItemPosition;
@@ -124,7 +125,7 @@ private void BuildBasePiece(BasePiecePlacedEvent basePiecePlacedBuildEvent)
124125

125126
if(basePiece.ParentGuid.IsPresent())
126127
{
127-
parentBase = GuidHelper.RequireObjectFrom(basePiece.ParentGuid.Get());
128+
parentBase = GuidHelper.GetObjectFrom(basePiece.ParentGuid.Get()).OrElse(null);
128129
}
129130

130131
Constructable constructable;
@@ -155,6 +156,7 @@ private void BuildBasePiece(BasePiecePlacedEvent basePiecePlacedBuildEvent)
155156

156157
private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
157158
{
159+
Log.Info("Constructed completed " + constructionCompleted.Guid);
158160
GameObject constructing = GuidHelper.RequireObjectFrom(constructionCompleted.Guid);
159161

160162
ConstructableBase constructableBase = constructing.GetComponent<ConstructableBase>();
@@ -176,12 +178,12 @@ private void ConstructionCompleted(ConstructionCompletedEvent constructionComple
176178
Constructable constructable = constructing.GetComponent<Constructable>();
177179
constructable.constructedAmount = 1f;
178180
constructable.SetState(true, true);
179-
}
181+
}
180182

181-
if (constructionCompleted.NewBaseCreatedGuid.IsPresent())
183+
if (constructionCompleted.BaseGuid != null && GuidHelper.GetObjectFrom(constructionCompleted.BaseGuid).IsEmpty())
182184
{
183-
string newBaseGuid = constructionCompleted.NewBaseCreatedGuid.Get();
184-
ConfigureNewlyConstructedBase(newBaseGuid);
185+
Log.Info("Creating base: " + constructionCompleted.BaseGuid);
186+
ConfigureNewlyConstructedBase(constructionCompleted.BaseGuid);
185187
}
186188
}
187189

NitroxModel/DataStructures/GameLogic/BasePiece.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ public string SerializableParentBaseGuid {
4848
public bool IsFurniture { get; set; }
4949

5050
[ProtoMember(11)]
51-
public string SerializableNewBaseGuid
52-
{
53-
get { return (NewBaseGuid.IsPresent()) ? NewBaseGuid.Get() : null; }
54-
set { NewBaseGuid = Optional<string>.OfNullable(value); }
55-
}
56-
57-
[ProtoIgnore]
58-
public Optional<string> NewBaseGuid { get; set; }
51+
public string BaseGuid { get; set; }
5952

6053
[ProtoMember(12, DynamicType = true)]
6154
public RotationMetadata SerializableRotationMetadata
@@ -79,7 +72,6 @@ public BasePieceMetadata SerializableMetadata
7972

8073
public BasePiece()
8174
{
82-
NewBaseGuid = Optional<string>.Empty();
8375
ParentGuid = Optional<string>.Empty();
8476
RotationMetadata = Optional<RotationMetadata>.Empty();
8577
Metadata = Optional<BasePieceMetadata>.Empty();
@@ -97,14 +89,13 @@ public BasePiece(string guid, Vector3 itemPosition, Quaternion rotation, Vector3
9789
IsFurniture = isFurniture;
9890
ConstructionAmount = 0.0f;
9991
ConstructionCompleted = false;
100-
NewBaseGuid = Optional<string>.Empty();
10192
RotationMetadata = rotationMetadata;
10293
Metadata = Optional<BasePieceMetadata>.Empty();
10394
}
10495

10596
public override string ToString()
10697
{
107-
return "[BasePiece - ItemPosition: " + ItemPosition + " Guid: " + Guid + " Rotation: " + Rotation + " CameraPosition: " + CameraPosition + "CameraRotation: " + CameraRotation + " TechType: " + TechType + " ParentGuid: " + ParentGuid + " ConstructionAmount: " + ConstructionAmount + " IsFurniture: " + IsFurniture + " NewBaseGuid: " + NewBaseGuid + " RotationMetadata: " + RotationMetadata + "]";
98+
return "[BasePiece - ItemPosition: " + ItemPosition + " Guid: " + Guid + " Rotation: " + Rotation + " CameraPosition: " + CameraPosition + "CameraRotation: " + CameraRotation + " TechType: " + TechType + " ParentGuid: " + ParentGuid + " ConstructionAmount: " + ConstructionAmount + " IsFurniture: " + IsFurniture + " BaseGuid: " + BaseGuid + " RotationMetadata: " + RotationMetadata + "]";
10899
}
109100
}
110101
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
using System;
2-
using NitroxModel.DataStructures.Util;
3-
using UnityEngine;
42

53
namespace NitroxModel.Packets
64
{
75
[Serializable]
86
public class ConstructionCompleted : Packet
97
{
108
public string Guid { get; }
11-
public Optional<string> NewBaseCreatedGuid { get; }
9+
public string BaseGuid { get; }
1210

13-
public ConstructionCompleted(string guid, Optional<string> newBaseCreatedGuid)
11+
public ConstructionCompleted(string guid, string baseGuid)
1412
{
1513
Guid = guid;
16-
NewBaseCreatedGuid = newBaseCreatedGuid;
14+
BaseGuid = baseGuid;
1715
}
1816

1917
public override string ToString()
2018
{
21-
return "[ConstructionCompleted Guid: " + Guid + " NewBaseCreatedGuid: " + NewBaseCreatedGuid + "]";
19+
return "[ConstructionCompleted Guid: " + Guid + " BaseGuid: " + BaseGuid + "]";
2220
}
2321
}
2422
}

NitroxPatcher/Patches/BaseDeconstructable_Deconstruct_Patch.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Harmony;
66
using NitroxClient.GameLogic.Helper;
77
using NitroxModel.Helper;
8-
using NitroxModel.Logger;
98
using UnityEngine;
109
using static NitroxClient.GameLogic.Helper.TransientLocalObjectManager;
1110

NitroxPatcher/Patches/Base_ClearGeometry_Patch.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Base_ClearGeometry_Patch : NitroxPatch
1919
* them so that we can update the newly placed pieces with the proper id. The new
2020
* pieces are added by Base.SpawnPiece (see that patch)
2121
*/
22-
public static Dictionary<Int3, string> LastClearedCellsByGuid = new Dictionary<Int3, string>();
22+
public static Dictionary<Vector3, string> LastClearedCellsByPosition = new Dictionary<Vector3, string>();
2323

2424
public static void Prefix(Base __instance)
2525
{
@@ -43,14 +43,12 @@ public static void Prefix(Base __instance)
4343
{
4444
Transform child = cellObject.GetChild(i);
4545

46-
if(child != null && child.gameObject != null)
46+
if (child != null && child.gameObject != null)
4747
{
48-
Int3 cell = __instance.WorldToGrid(child.position);
49-
50-
if(cell != Int3.zero && child.gameObject.GetComponent<UniqueIdentifier>() != null)
48+
if(child.gameObject.GetComponent<UniqueIdentifier>() != null)
5149
{
5250
string guid = child.gameObject.GetComponent<UniqueIdentifier>().Id;
53-
LastClearedCellsByGuid[cell] = guid;
51+
LastClearedCellsByPosition[child.position] = guid;
5452
}
5553
}
5654
}

NitroxPatcher/Patches/Base_SpawnPiece_Patch.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ public static void Postfix(Base __instance, Transform __result)
2424
return;
2525
}
2626

27-
Int3 cell = __instance.WorldToGrid(__result.position);
28-
2927
string guid;
3028

31-
if (Base_ClearGeometry_Patch.LastClearedCellsByGuid.TryGetValue(cell, out guid))
29+
if (Base_ClearGeometry_Patch.LastClearedCellsByPosition.TryGetValue(__result.position, out guid))
3230
{
3331
GuidHelper.SetNewGuid(__result.gameObject, guid);
3432
}

NitroxServer/Communication/Packets/Processors/ConstructionCompletedPacketProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ConstructionCompletedPacketProcessor(BaseData baseData, PlayerManager pla
1818

1919
public override void Process(ConstructionCompleted packet, Player player)
2020
{
21-
baseData.BasePieceConstructionCompleted(packet.Guid, packet.NewBaseCreatedGuid);
21+
baseData.BasePieceConstructionCompleted(packet.Guid, packet.BaseGuid);
2222
playerManager.SendPacketToOtherPlayers(packet, player);
2323
}
2424
}

NitroxServer/GameLogic/Bases/BaseData.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void BasePieceConstructionAmountChanged(string guid, float constructionAm
6767
}
6868
}
6969

70-
public void BasePieceConstructionCompleted(string guid, Optional<string> newlyCreatedParentGuid)
70+
public void BasePieceConstructionCompleted(string guid, string baseGuid)
7171
{
7272
BasePiece basePiece;
7373

@@ -77,14 +77,10 @@ public void BasePieceConstructionCompleted(string guid, Optional<string> newlyCr
7777
{
7878
basePiece.ConstructionAmount = 1.0f;
7979
basePiece.ConstructionCompleted = true;
80-
basePiece.NewBaseGuid = newlyCreatedParentGuid;
80+
basePiece.BaseGuid = baseGuid;
81+
basePiece.ParentGuid = Optional<string>.OfNullable(baseGuid);
8182

82-
if (newlyCreatedParentGuid.IsPresent())
83-
{
84-
basePiece.ParentGuid = Optional<string>.Empty();
85-
}
86-
87-
lock(completedBasePieceHistory)
83+
lock (completedBasePieceHistory)
8884
{
8985
completedBasePieceHistory.Add(basePiece);
9086
}

NitroxServer/Serialization/World/PersistedWorldData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace NitroxServer.Serialization.World
1414
[ProtoContract]
1515
public class PersistedWorldData
1616
{
17-
private const long CURRENT_VERSION = 5;
17+
private const long CURRENT_VERSION = 6;
1818

1919
[ProtoMember(1)]
2020
public long version { get; set; } = CURRENT_VERSION;

0 commit comments

Comments
 (0)