Skip to content

Commit

Permalink
Modified ladder spawn processor 2nd part detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tornac1234 committed Jan 28, 2022
1 parent b376908 commit dbd39b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using NitroxClient.MonoBehaviours;
using NitroxModel.Core;
using NitroxModel.DataStructures;
using NitroxModel.DataStructures.Util;
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxClient.GameLogic.Bases.Spawning.BasePiece
Expand All @@ -16,22 +18,21 @@ protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameO
{
bool builtLadderOnFloor = finishedPiece.name.Contains("Bottom");
int searchDirection = builtLadderOnFloor ? -1 : 1;
bool shouldSearch = true;

Int3 cellToSearch;
Optional<GameObject> otherLadderPiece;

Int3 cellToSearch = Int3.zero;
Optional<GameObject> otherLadderPiece = Optional.Empty;
int searchOffset = searchDirection;
do
int maxY = NitroxServiceLocator.LocateService<IMap>().DimensionsInBatches.Y;
for (int i = 0; i < maxY; i++)
{
cellToSearch = new Int3(latestCell.x, latestCell.y + searchOffset, latestCell.z);

otherLadderPiece = FindSecondLadderPiece(latestBase, cellToSearch, out bool shouldKeepSearching);
if (otherLadderPiece.HasValue || !shouldKeepSearching)
if (!FindSecondLadderPiece(latestBase, cellToSearch, out otherLadderPiece) || otherLadderPiece.HasValue)
{
shouldSearch = false;
break;
}
searchOffset += searchDirection;
} while (shouldSearch);
}

if (otherLadderPiece.HasValue)
{
Expand All @@ -47,35 +48,35 @@ protected override void SpawnPostProcess(Base latestBase, Int3 latestCell, GameO
}
}

private Optional<GameObject> FindSecondLadderPiece(Base latestBase, Int3 cellToSearch, out bool shouldKeepSearching)
private bool FindSecondLadderPiece(Base latestBase, Int3 cellToSearch, out Optional<GameObject> piece)
{
Transform cellTransform = latestBase.GetCellObject(cellToSearch);
shouldKeepSearching = false;
piece = Optional.Empty;
if (!cellTransform)
{
return Optional.Empty;
return false;
}
foreach (Transform child in cellTransform)
{
NitroxEntity id = child.GetComponent<NitroxEntity>();
BaseDeconstructable baseDeconstructable = child.GetComponent<BaseDeconstructable>();
bool isNewBasePiece = id == null && baseDeconstructable != null;

if (isNewBasePiece)
{
TechType techType = baseDeconstructable.recipe;
if (techType == TechType.BaseLadder)
{
return Optional.Of(child.gameObject);
piece = Optional.Of(child.gameObject);
return true;
}
}
if (child.name.Contains("ConnectorLadder"))
{
shouldKeepSearching = true;
return true;
}
}

return Optional.Empty;
return false;
}
}
}
3 changes: 1 addition & 2 deletions NitroxClient/MonoBehaviours/ThrottledBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using NitroxClient.Communication.Abstract;
using NitroxClient.GameLogic.Bases;
using NitroxClient.GameLogic.Bases.Spawning.BasePiece;
Expand Down Expand Up @@ -189,7 +188,7 @@ private void ConstructionCompleted(ConstructionCompletedEvent constructionComple

constructableBase.constructedAmount = 1f;
constructableBase.SetState(true, true);

if (!latestBase)
{
Optional<object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
Expand Down

0 comments on commit dbd39b1

Please sign in to comment.