Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving building system #1705

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modified ladder spawn processor 2nd part detection
  • Loading branch information
tornac1234 committed Jan 29, 2022
commit 261ce28cb724aa1af05ce9ce082abb194159bd86
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