Example #1
0
        public void ConstructionComplete(GameObject ghost)
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxEntity.GetId(ghost);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                baseId = NitroxEntity.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>() != null)
            {
                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();

                UnityEngine.Object.Destroy(ghost);
                NitroxEntity.SetNewId(finishedPiece, id);

                if (baseId == null)
                {
                    baseId = NitroxEntity.GetId(finishedPiece.GetComponentInParent <Base>().gameObject);
                }
            }

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }
Example #2
0
        public void ConstructionComplete(GameObject ghost)
        {
            Optional <string> newlyConstructedBaseGuid = Optional <string> .Empty();

            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            string guid = GuidHelper.GetGuid(ghost);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                newlyConstructedBaseGuid = Optional <string> .Of(GuidHelper.GetGuid(constructedBase));
            }

            // For base pieces, we must switch the guid from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>() != null)
            {
                Optional <object> opBasePiece   = TransientLocalObjectManager.Get(TransientObjectType.LATEST_CONSTRUCTED_BASE_PIECE);
                GameObject        finishedPiece = (GameObject)opBasePiece.Get();

                UnityEngine.Object.Destroy(ghost);
                GuidHelper.SetNewGuid(finishedPiece, guid);
            }

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(guid, newlyConstructedBaseGuid);

            packetSender.Send(constructionCompleted);
        }
Example #3
0
        public sealed override void Update(float dt)
        {
            base.Update(dt);
            if (!ResourcesRequested)
            {
                ResourcesRequested = true;
                ResourceDirector.RequestIngredients(BuildingDescription.ConstructionInformation.ResourceTypes.ToArray());
            }
            if (!IsConstructing)
            {
                return;
            }
            PassedConstructionTime += dt;
            Progress = PassedConstructionTime / BuildingDescription.ConstructionInformation.ConstructionTime;
            if (PassedConstructionTime >= BuildingDescription.ConstructionInformation.ConstructionTime)
            {
                PassedConstructionTime = 0;
                IsConstructing         = false;

                Building building = new Building(Position, World, BuildingDescription);
                World.StructureManager.RemoveStructure(this);
                World.StructureManager.CreateStrucuture(building);
                ConstructionCompleted?.Invoke(this);
            }
            OnRequiresRedraw();
        }
Example #4
0
        public void ConstructionComplete(GameObject gameObject)
        {
            Optional <string> newlyConstructedBaseGuid = Optional <string> .Empty();

            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                newlyConstructedBaseGuid = Optional <string> .Of(GuidHelper.GetGuid(constructedBase));
            }

            string guid = GuidHelper.GetGuid(gameObject);

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(guid, newlyConstructedBaseGuid);

            packetSender.Send(constructionCompleted);
        }
Example #5
0
        public void ConstructionComplete(GameObject gameObject)
        {
            Optional <String> newlyConstructedBaseGuid = Optional <String> .Empty();

            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                newlyConstructedBaseGuid = Optional <String> .Of(GuidHelper.GetGuid(constructedBase));
            }

            Vector3 itemPosition = gameObject.transform.position;
            String  guid         = GuidHelper.GetGuid(gameObject);

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(PlayerId, ApiHelper.Vector3(itemPosition), guid, newlyConstructedBaseGuid);

            Send(constructionCompleted);
        }
Example #6
0
        public void ConstructionComplete(GameObject ghost, Optional <Base> lastTargetBase, Int3 lastTargetBaseOffset)
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxEntity.GetId(ghost);

            Log.Info($"Construction complete on {id} {ghost.name}");

            if (opConstructedBase.HasValue)
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Value;
                baseId = NitroxEntity.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>())
            {
                Int3 latestCell = lastTargetBaseOffset;
                Base latestBase = lastTargetBase.HasValue ? lastTargetBase.Value : ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                baseId = NitroxEntity.GetId(latestBase.gameObject);

                Transform cellTransform = latestBase.GetCellObject(latestCell);

                // This check ensures that the latestCell actually leads us to the correct entity.  The lastTargetBaseOffset is unreliable as the base shape
                // can change which makes the target offset change. It may be possible to fully deprecate lastTargetBaseOffset and only rely on GetClosestCell;
                // however, there may still be pieces were the ghost base's target offset is authoratitive due to incorrect game object positioning.
                if (latestCell == default(Int3) || cellTransform == null)
                {
                    latestBase.GetClosestCell(ghost.transform.position, out latestCell, out Vector3 _, out float _);
                    cellTransform = latestBase.GetCellObject(latestCell);
                    Validate.NotNull(cellTransform, "Unable to find cell transform at " + 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}");

                Log.Info($"Setting id to finished piece: {finishedPiece.name} {id}");

                Object.Destroy(ghost);
                NitroxEntity.SetNewId(finishedPiece, id);

                BasePieceSpawnProcessor.RunSpawnProcessor(finishedPiece.GetComponent <BaseDeconstructable>(), latestBase, latestCell, finishedPiece);
            }
            else if (ghost.TryGetComponent(out Constructable constructable))
            {
                FurnitureSpawnProcessor.RunSpawnProcessor(constructable);
            }
            else
            {
                Log.Error($"Found ghost which is neither base piece nor a constructable: {ghost.name}");
            }

            Log.Info($"Construction Completed {id} in base {baseId}");

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }
Example #7
0
        public void ConstructionComplete(GameObject ghost)
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxEntity.GetId(ghost);

            if (opConstructedBase.IsPresent())
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Get();
                baseId = NitroxEntity.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>() != null)
            {
                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
                {
                    latestBase = ((GameObject)opConstructedBase.Get()).GetComponent <Base>();
                    Vector3 worldPosition;
                    float   distance;

                    latestBase.GetClosestCell(ghost.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("Setting id to finished piece: " + finishedPiece.name + " " + id);

                UnityEngine.Object.Destroy(ghost);
                NitroxEntity.SetNewId(finishedPiece, id);

                BasePieceSpawnProcessor customSpawnProcessor = BasePieceSpawnProcessor.From(finishedPiece.GetComponent <BaseDeconstructable>());
                customSpawnProcessor.SpawnPostProcess(latestBase, latestCell, finishedPiece);
            }

            Log.Info("Construction Completed " + id);

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }
Example #8
0
        public void ConstructionComplete(GameObject ghost, Optional <Base> lastTargetBase, Int3 lastTargetBaseOffset, Base.Face lastTargetFace = default(Base.Face))
        {
            NitroxId          baseId            = null;
            Optional <object> opConstructedBase = TransientLocalObjectManager.Get(TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            NitroxId id = NitroxEntity.GetId(ghost);

            if (opConstructedBase.HasValue)
            {
                GameObject constructedBase = (GameObject)opConstructedBase.Value;
                baseId = NitroxEntity.GetId(constructedBase);
            }

            // For base pieces, we must switch the id from the ghost to the newly constructed piece.
            // Furniture just uses the same game object as the ghost for the final product.
            if (ghost.GetComponent <ConstructableBase>())
            {
                Int3 latestCell = lastTargetBaseOffset;
                Base latestBase = lastTargetBase.HasValue ? lastTargetBase.Value : ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                baseId = NitroxEntity.GetId(latestBase.gameObject);

                Transform  cellTransform;
                GameObject placedPiece = null;

                if (!latestBase)
                {
                    if (opConstructedBase.HasValue)
                    {
                        latestBase = ((GameObject)opConstructedBase.Value).GetComponent <Base>();
                    }

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

                if (latestCell != default(Int3))
                {
                    cellTransform = latestBase.GetCellObject(latestCell);
                    if (cellTransform != null)
                    {
                        placedPiece = FindFinishedPiece(cellTransform);
                    }
                }

                // This check ensures that the latestCell actually leads us to the correct entity.  The lastTargetBaseOffset is unreliable as the base shape
                // can change which makes the target offset change. It may be possible to fully deprecate lastTargetBaseOffset and only rely on GetClosestCell;
                // however, there may still be pieces were the ghost base's target offset is authoritative due to incorrect game object positioning.
                if (placedPiece == null)
                {
                    Int3 position = latestBase.WorldToGrid(ghost.gameObject.transform.position);
                    cellTransform = latestBase.GetCellObject(position);

                    Validate.NotNull(cellTransform, "Unable to find cell transform at " + latestCell);
                    placedPiece = FindFinishedPiece(cellTransform);
                }

                Validate.NotNull(placedPiece, $"Could not find finished piece in cell {latestCell}");

                Object.Destroy(ghost);
                NitroxEntity.SetNewId(placedPiece, id);

                BasePieceSpawnProcessor.RunSpawnProcessor(placedPiece.GetComponent <BaseDeconstructable>(), latestBase, latestCell, placedPiece);
            }
            else if (ghost.TryGetComponent(out Constructable constructable))
            {
                FurnitureSpawnProcessor.RunSpawnProcessor(constructable);
            }
            else
            {
                Log.Error($"Found ghost which is neither base piece nor a constructable: {ghost.name}");
            }

            ConstructionCompleted constructionCompleted = new ConstructionCompleted(id, baseId);

            packetSender.Send(constructionCompleted);
        }