Exemplo n.º 1
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            Log.Info("Constructed completed " + constructionCompleted.Guid);
            GameObject constructing = GuidHelper.RequireObjectFrom(constructionCompleted.Guid);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                constructableBase.constructedAmount = 1f;
                constructableBase.SetState(true, true);

                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();
                UnityEngine.Object.Destroy(constructableBase.gameObject);
                GuidHelper.SetNewGuid(finishedPiece, constructionCompleted.Guid);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);
            }

            if (constructionCompleted.BaseGuid != null && GuidHelper.GetObjectFrom(constructionCompleted.BaseGuid).IsEmpty())
            {
                Log.Info("Creating base: " + constructionCompleted.BaseGuid);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseGuid);
            }
        }
Exemplo n.º 2
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject    constructing  = GuidHelper.RequireObjectFrom(constructionCompleted.Guid);
            Constructable constructable = constructing.GetComponent <Constructable>();

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

            if (constructionCompleted.NewBaseCreatedGuid.IsPresent())
            {
                string newBaseGuid = constructionCompleted.NewBaseCreatedGuid.Get();
                ConfigureNewlyConstructedBase(newBaseGuid);
            }
        }
Exemplo n.º 3
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructing.TryGetComponent(out ConstructableBase constructableBase))
            {
                Int3 latestCell = default(Int3);
                Base latestBase = null;

                // must fetch BEFORE setState or else the BaseGhost gets destroyed
                BaseGhost baseGhost = constructing.GetComponentInChildren <BaseGhost>();

                if (baseGhost)
                {
                    latestCell = baseGhost.TargetOffset;
                    latestBase = baseGhost.TargetBase;
                }

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

                if (!latestBase)
                {
                    Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                    Validate.NotNull(latestBase, "latestBase can not be null");
                }

                Transform cellTransform = latestBase.GetCellObject(latestCell);

                if (latestCell == default(Int3) || !cellTransform)
                {
                    latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out _, out _);
                    cellTransform = latestBase.GetCellObject(latestCell);

                    Validate.NotNull(cellTransform, $"Must have a cell transform, one not found near {constructing.gameObject.transform.position} for latestCell {latestCell}");
                }

                GameObject finishedPiece = null;

                // There can be multiple objects in a cell (such as a corridor with hatches built into it)
                // we look for a object that is able to be deconstructed that hasn't been tagged yet.
                foreach (Transform child in cellTransform)
                {
                    bool isNewBasePiece = !child.GetComponent <NitroxEntity>() && child.GetComponent <BaseDeconstructable>();

                    if (isNewBasePiece)
                    {
                        finishedPiece = child.gameObject;
                        break;
                    }
                }

                Validate.NotNull(finishedPiece, $"Could not find finished piece in cell {latestCell} when constructing {constructionCompleted.PieceId}");

                Log.Debug($"Construction completed on a base piece: {constructionCompleted.PieceId} {finishedPiece.name}");

                Destroy(constructableBase.gameObject);
                NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId);

                BasePieceSpawnProcessor.RunSpawnProcessor(finishedPiece.GetComponent <BaseDeconstructable>(), latestBase, latestCell, finishedPiece);
            }
            else if (constructing.TryGetComponent(out Constructable constructable))
            {
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                FurnitureSpawnProcessor.RunSpawnProcessor(constructable);

                Log.Debug($"Construction completed on a piece of furniture: {constructionCompleted.PieceId} {constructable.gameObject.name}");
            }
            else
            {
                Log.Error($"Found ghost which is neither base piece nor a constructable: {constructing.name}");
            }

            if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue)
            {
                Log.Debug($"Creating base: {constructionCompleted.BaseId}");
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }
Exemplo n.º 4
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                Int3 latestCell = default(Int3);
                Base latestBase = null;

                // must fetch BEFORE setState or else the BaseGhost gets destroyed
                BaseGhost baseGhost = constructing.GetComponentInChildren <BaseGhost>();

                if (baseGhost)
                {
                    latestCell = baseGhost.TargetOffset;
                    latestBase = baseGhost.TargetBase;
                }

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

                if (latestBase == null)
                {
                    Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                    Validate.NotNull(latestBase, "latestBase can not be null");
                }

                Transform cellTransform = latestBase.GetCellObject(latestCell);

                if (latestCell == default(Int3) || cellTransform == null)
                {
                    Vector3 worldPosition;
                    float   distance;

                    latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out worldPosition, out distance);
                    cellTransform = latestBase.GetCellObject(latestCell);

                    Validate.NotNull(cellTransform, "Must have a cell transform, one not found near " + constructing.gameObject.transform.position + " for latestcell " + latestCell);
                }

                GameObject finishedPiece = null;

                // There can be multiple objects in a cell (such as a corridor with hatces built into it)
                // we look for a object that is able to be deconstucted that hasn't been tagged yet.
                foreach (Transform child in cellTransform)
                {
                    bool isNewBasePiece = (child.GetComponent <NitroxEntity>() == null &&
                                           child.GetComponent <BaseDeconstructable>() != null);

                    if (isNewBasePiece)
                    {
                        finishedPiece = child.gameObject;
                        break;
                    }
                }

                Validate.NotNull(finishedPiece, "Could not find finished piece in cell " + latestCell + " when constructing " + constructionCompleted.PieceId + " " + finishedPiece.name);

                Log.Info("Construction completed on a base piece: " + constructionCompleted.PieceId + " " + finishedPiece.name);

                UnityEngine.Object.Destroy(constructableBase.gameObject);
                NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId);

                BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>());
                customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                Log.Info("Construction completed on a piece of furniture: " + constructionCompleted.PieceId + " " + constructable.gameObject.name);
            }

            if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue)
            {
                Log.Info("Creating base: " + constructionCompleted.BaseId);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }
Exemplo n.º 5
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            ConstructableBase constructableBase = constructing.GetComponent <ConstructableBase>();

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructableBase)
            {
                constructableBase.constructedAmount = 1f;
                constructableBase.SetState(true, true);

                Optional <object> latestBaseOp = TransientLocalObjectManager.Get(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION);

                Int3 latestCell;
                Base latestBase;

                if (latestBaseOp.IsPresent())
                {
                    latestCell = TransientLocalObjectManager.Require <Int3>(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION);
                    latestBase = (Base)latestBaseOp.Get();
                }
                else
                {
                    Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    latestBase = ((GameObject)opConstructedBase.Get()).GetComponent <Base>();
                    Validate.NotNull(latestBase, "latestBase can not be null");

                    Vector3 worldPosition;
                    float   distance;

                    latestBase.GetClosestCell(constructing.gameObject.transform.position, out latestCell, out worldPosition, out distance);
                }

                Transform  cellTransform = latestBase.GetCellObject(latestCell);
                GameObject finishedPiece = null;

                // There can be multiple objects in a cell (such as a corridor with hatces built into it)
                // we look for a object that is able to be deconstucted that hasn't been tagged yet.
                foreach (Transform child in cellTransform)
                {
                    bool isNewBasePiece = (child.GetComponent <NitroxEntity>() == null &&
                                           child.GetComponent <BaseDeconstructable>() != null);

                    if (isNewBasePiece)
                    {
                        finishedPiece = child.gameObject;
                        break;
                    }
                }

                Validate.NotNull(finishedPiece, "Could not find finished piece in cell " + latestCell);

                Log.Info("Construction completed on a base piece: " + constructionCompleted.PieceId + " " + finishedPiece.name);

                UnityEngine.Object.Destroy(constructableBase.gameObject);
                NitroxEntity.SetNewId(finishedPiece, constructionCompleted.PieceId);

                BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>());
                customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece);
            }
            else
            {
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.SetState(true, true);

                Log.Info("Construction completed on a piece of furniture: " + constructionCompleted.PieceId + " " + constructable.gameObject.name);
            }

            if (constructionCompleted.BaseId != null && NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).IsEmpty())
            {
                Log.Info("Creating base: " + constructionCompleted.BaseId);
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }
Exemplo n.º 6
0
        private void ConstructionCompleted(ConstructionCompletedEvent constructionCompleted)
        {
            GameObject constructing = NitroxEntity.RequireObjectFrom(constructionCompleted.PieceId);

            // For bases, we need to transfer the GUID off of the ghost and onto the finished piece.
            // Furniture just re-uses the same piece.
            if (constructing.TryGetComponent(out ConstructableBase constructableBase))
            {
                Int3 latestCell = default;
                Base latestBase = null;

                // must fetch BEFORE setState as the BaseGhost gets destroyed
                BaseGhost baseGhost = constructableBase.model.AliveOrNull()?.GetComponent <BaseGhost>();
                if (baseGhost && baseGhost.TargetBase)
                {
                    latestBase = baseGhost.TargetBase;
                    latestCell = latestBase.WorldToGrid(baseGhost.transform.position);
                }

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


                Transform  cellTransform;
                GameObject placedPiece = null;


                if (!latestBase)
                {
                    Optional <object> opConstructedBase = Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);
                    if (opConstructedBase.HasValue)
                    {
                        latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                    }

                    Validate.NotNull(latestBase, "latestBase can not be null");
                    latestCell = latestBase !.WorldToGrid(constructing.transform.position);
                }

                if (latestCell != default(Int3))
                {
                    cellTransform = latestBase.GetCellObject(latestCell);

                    if (cellTransform)
                    {
                        placedPiece = FindFinishedPiece(cellTransform);
                    }
                }

                if (!placedPiece)
                {
                    Int3 position = latestBase.WorldToGrid(constructableBase.transform.position);
                    cellTransform = latestBase.GetCellObject(position);
                    Validate.NotNull(cellTransform, "Unable to find cell transform at " + position);

                    placedPiece = FindFinishedPiece(cellTransform);
                }

                Validate.NotNull(placedPiece, $"Could not find placed Piece in cell {latestCell} when constructing {constructionCompleted.PieceId}");

                // This destroy instruction must be executed now, else it won't be able to happen in the case the action will have a later completion
                Destroy(constructableBase.gameObject);
                if (BuildingInitialSyncProcessor.LaterConstructionTechTypes.Contains(constructableBase.techType))
                {
                    // We need to transfer these 3 objects to the later completed event
                    Add(TransientObjectType.LATER_CONSTRUCTED_BASE, placedPiece);
                    Add(TransientObjectType.LATER_OBJECT_LATEST_BASE, latestBase);
                    Add(TransientObjectType.LATER_OBJECT_LATEST_CELL, latestCell);
                    return;
                }

                FinishConstructionCompleted(placedPiece, latestBase, latestCell, constructionCompleted.PieceId);
            }
            else if (constructing.TryGetComponent(out Constructable constructable))
            {
                constructable.constructedAmount = 1f;
                constructable.SetState(true);

                FurnitureSpawnProcessor.RunSpawnProcessor(constructable);
            }
            else
            {
                Log.Error($"Found ghost which is neither base piece nor a constructable: {constructing.name}");
            }

            if (constructionCompleted.BaseId != null && !NitroxEntity.GetObjectFrom(constructionCompleted.BaseId).HasValue)
            {
                ConfigureNewlyConstructedBase(constructionCompleted.BaseId);
            }
        }