public override void Process(ConstructorBeginCrafting packet)
        {
            GameObject gameObject = GuidHelper.RequireObjectFrom(packet.ConstructorGuid);
            Crafter    crafter    = gameObject.RequireComponentInChildren <Crafter>(true);

            vehicles.AddVehicle(VehicleModelFactory.BuildFrom(packet));
            MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance);

            Validate.NotNull(onCraftingBegin);
            onCraftingBegin.Invoke(crafter, new object[] { packet.TechType.Enum(), packet.Duration }); //TODO: take into account latency for duration

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();
                constructedObject.AddComponent <NitroxEntity>();
                GuidHelper.SetNewGuid(constructedObject, packet.ConstructedItemGuid);
                VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(constructedObject, packet.InteractiveChildIdentifiers);
            }
            else
            {
                Log.Error("Could not find constructed object!");
            }
        }
Example #2
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);
        }
        public static void Prefix(BaseDeconstructable __instance)
        {
            string guid = GuidHelper.GetGuid(__instance.gameObject);

            Log.Info("Deconstructing " + guid);
            TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, guid);
        }
Example #4
0
        public static bool Prefix(Constructable __instance, bool value)
        {
            // check to see if they are trying to update constructed value from true to false.  This means that they
            // are trying to deconstruct an object.
            if (__instance.constructed && value == false)
            {
                Optional <object> opId = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

                NitroxId id;

                // Check to see if they are trying to deconstruct a base piece.  If so, we will need to use the
                // id in LATEST_DECONSTRUCTED_BASE_PIECE_GUID because base pieces get destroyed and recreated with
                // a ghost (furniture just uses the same game object).
                if (opId.IsPresent())
                {
                    // base piece, get id before ghost appeared
                    id = (NitroxId)opId.Get();
                    Log.Info("Deconstructing base piece with id: " + id);
                }
                else
                {
                    // furniture, just use the same object to get the id
                    id = NitroxEntity.GetId(__instance.gameObject);
                    Log.Info("Deconstructing furniture with id: " + id);
                }

                NitroxServiceLocator.LocateService <Building>().DeconstructionBegin(id);
            }

            return(true);
        }
Example #5
0
        public static void Postfix(Constructable __instance)
        {
            if (!__instance._constructed && __instance.constructedAmount == 1f)
            {
                Optional <object> opId = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

                NitroxId id;

                // Check to see if they are trying to deconstruct a base piece.  If so, we will need to use the
                // id in LATEST_DECONSTRUCTED_BASE_PIECE_GUID because base pieces get destroyed and recreated with
                // a ghost (furniture just uses the same game object).
                if (opId.HasValue)
                {
                    // base piece, get id before ghost appeared
                    id = (NitroxId)opId.Value;
                    Log.Info("Deconstructing base piece with id: " + id);
                }
                else
                {
                    // furniture, just use the same object to get the id
                    id = NitroxEntity.GetId(__instance.gameObject);
                    Log.Info("Deconstructing furniture with id: " + id);
                }

                NitroxServiceLocator.LocateService <Building>().DeconstructionBegin(id);
            }
        }
Example #6
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            NitroxId constructorId = NitroxEntity.GetId(constructor);

            Log.Debug("Building item from constructor with id: " + constructorId);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.HasValue)
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Value;
                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject);

                VehicleModel vehicleModel = vehicles.BuildVehicleModelFrom(constructedObject, techType);
                vehicles.AddVehicle(vehicleModel);

                packetSender.Send(new ConstructorBeginCrafting(vehicleModel, constructorId, duration));

                vehicles.SpawnDefaultBatteries(constructedObject, childIdentifiers);

                MonoBehaviour monoBehaviour = constructor.GetComponent <MonoBehaviour>();
                //We want to store the fallen position of the object to avoid flying object on reload
                if (monoBehaviour)
                {
                    monoBehaviour.StartCoroutine(vehicles.UpdateVehiclePositionAfterSpawn(vehicleModel, constructedObject, duration + 10.0f));
                }
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #7
0
        private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged)
        {
            Log.Debug($"Processing ConstructionAmountChanged {amountChanged.Id} {amountChanged.Amount}");

            GameObject          constructing        = NitroxEntity.RequireObjectFrom(amountChanged.Id);
            BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>();

            // Bases don't  send a deconstruct being packet.  Instead, we just make sure
            // that if we are changing the amount that we set it into deconstruction mode
            // if it still has a BaseDeconstructable object on it.
            if (baseDeconstructable != null)
            {
                baseDeconstructable.Deconstruct();

                // After we have begun the deconstructing for a base piece, we need to transfer the id
                Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GHOST);

                if (opGhost.HasValue)
                {
                    GameObject ghost = (GameObject)opGhost.Value;
                    Destroy(constructing);
                    NitroxEntity.SetNewId(ghost, amountChanged.Id);
                }
                else
                {
                    Log.Error($"Could not find newly created ghost to set deconstructed id {amountChanged.Id}");
                }
            }
            else
            {
                Constructable constructable = constructing.GetComponentInChildren <Constructable>();
                constructable.constructedAmount = amountChanged.Amount;
                constructable.Construct();
            }
        }
Example #8
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            NitroxId constructorId = NitroxEntity.GetId(constructor);

            Log.Debug("Building item from constructor with id: " + constructorId);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.HasValue)
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Value;
                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject);

                VehicleModel vehicleModel = vehicles.BuildVehicleModelFrom(constructedObject, techType);
                vehicles.AddVehicle(vehicleModel);

                ConstructorBeginCrafting beginCrafting = VehicleConstructionFactory.BuildFrom(vehicleModel, constructorId, duration);
                packetSender.Send(beginCrafting);

                vehicles.SpawnDefaultBatteries(constructedObject, childIdentifiers);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #9
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);
        }
        public override void Process(ConstructorBeginCrafting packet)
        {
            GameObject gameObject = GuidHelper.RequireObjectFrom(packet.ConstructorGuid);
            Crafter    crafter    = gameObject.RequireComponentInChildren <Crafter>(true);

            MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance);

            Validate.NotNull(onCraftingBegin);
            onCraftingBegin.Invoke(crafter, new object[] { packet.TechType, packet.Duration }); //TODO: take into account latency for duration

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();
                GuidHelper.SetNewGuid(constructedObject, packet.ConstructedItemGuid);

                SetInteractiveChildrenGuids(constructedObject, packet.InteractiveChildIdentifiers);

                if (packet.TechType == TechType.Cyclops)
                {
                    SubRoot subRoot = constructedObject.GetComponent <SubRoot>();
                    if (subRoot != null)
                    {
                        GuidHelper.SetNewGuid(subRoot.upgradeConsole.modules.owner, packet.ConstructedModulesEquipmentGuid.Get());
                        Log.Info("New Modules Guid: " + GuidHelper.GetGuid(subRoot.upgradeConsole.modules.owner));
                    }
                }
            }
            else
            {
                Log.Error("Could not find constructed object!");
            }
        }
Example #11
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            string constructorGuid = GuidHelper.GetGuid(constructor);

            Log.Debug("Building item from constructor with uuid: " + constructorGuid);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();

                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject);
                Vehicle vehicle = constructedObject.GetComponent <Vehicle>();
                string  constructedObjectGuid = GuidHelper.GetGuid(constructedObject);

                //Initialize some default values to serialize.
                Vector3[] HSB       = new Vector3[5];
                Vector3[] Colours   = new Vector3[5];
                Vector4   tmpColour = Color.white;
                string    name      = "Cyclops"; // Cant find a way to actually get the Cyclops name.

                getObjectAttributes(vehicle, name, HSB, Colours, tmpColour, constructedObjectGuid);
                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType, duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation, name, HSB, Colours);
                packetSender.Send(beginCrafting);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #12
0
        public static void Prefix(BaseDeconstructable __instance)
        {
            NitroxId id = NitroxIdentifier.GetId(__instance.gameObject);

            Log.Info("Deconstructing " + id);
            TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id);
        }
Example #13
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);
            }
        }
Example #14
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            string constructorGuid = GuidHelper.GetGuid(constructor);

            Log.Debug("Building item from constructor with uuid: " + constructorGuid);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();

                List <InteractiveChildObjectIdentifier> childIdentifiers = ExtractGuidsOfInteractiveChildren(constructedObject);
                string constructedObjectGuid = GuidHelper.GetGuid(constructedObject);

                Optional <string> ModuleGuid = Optional <string> .Empty();

                if (techType == TechType.Cyclops)
                {
                    SubRoot subRoot = constructedObject.GetComponent <SubRoot>();
                    if (subRoot != null)
                    {
                        Log.Info("New Cyclop Modules Guid: " + GuidHelper.GetGuid(subRoot.upgradeConsole.modules.owner));
                        ModuleGuid = Optional <string> .Of(GuidHelper.GetGuid(subRoot.upgradeConsole.modules.owner));
                    }
                }

                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, ModuleGuid, techType, duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation);
                packetSender.Send(beginCrafting);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
        public static void Prefix(BaseDeconstructable __instance)
        {
            NitroxId id = NitroxEntity.GetId(__instance.gameObject);

            Log.Info("Deconstructing " + id);
            NitroxServiceLocator.LocateService <Building>().DeconstructionBegin(id);

            TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, id);
        }
        /**
         * On base pieces we need to have special logic during deconstruction to transfer the id from the main
         * object to the ghost.  This method will see if we have a stored LATEST_DECONSTRUCTED_BASE_PIECE_GUID
         * (set from deconstructor patch).  If we do, then we'll copy the id to the new ghost.  This is in
         * amount changed as we don't currently have a good hook for 'startDeconstruction'; this method will
         * run its logic on the first amount changed instead - effectively the same thing.
         */
        public static void CheckToCopyIdToGhost(Constructable __instance)
        {
            Optional <object> opId = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

            if (opId.IsPresent())
            {
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, null);

                NitroxId id = (NitroxId)opId.Get();
                Log.Info("Setting ghost id " + id);
                NitroxEntity.SetNewId(__instance.gameObject, id);
            }
        }
        /**
         * On base pieces we need to have special logic during deconstruction to transfer the guid from the main
         * object to the ghost.  This method will see if we have a stored LATEST_DECONSTRUCTED_BASE_PIECE_GUID
         * (set from deconstructor patch).  If we do, then we'll copy the guid to the new ghost.  This is in
         * amount changed as we don't currently have a good hook for 'startDeconstruction'; this method will
         * run its logic on the first amount changed instead - effectively the same thing.
         */
        public static void CheckToCopyGuidToGhost(Constructable __instance)
        {
            Optional <object> opGuid = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

            if (opGuid.IsPresent())
            {
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, null);

                string guid = (string)opGuid.Get();
                Log.Info("Setting ghost guid " + guid);
                GuidHelper.SetNewGuid(__instance.gameObject, guid);
            }
        }
Example #18
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            NitroxId constructorId = NitroxEntity.GetId(constructor);

            Log.Debug("Building item from constructor with id: " + constructorId);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.HasValue)
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Value;

                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject);
                Vehicle   vehicle             = constructedObject.GetComponent <Vehicle>();
                NitroxId  constructedObjectId = NitroxEntity.GetId(constructedObject);
                Vector3[] HSB       = new Vector3[5];
                Vector3[] Colours   = new Vector3[5];
                Vector4   tmpColour = Color.white;
                string    name      = "";
                float     health    = 1;

                if (!vehicle)
                { // Cyclops
                    GameObject   target        = NitroxEntity.RequireObjectFrom(constructedObjectId);
                    SubNameInput subNameInput  = target.RequireComponentInChildren <SubNameInput>();
                    SubName      subNameTarget = (SubName)subNameInput.ReflectionGet("target");

                    Colours = subNameTarget.GetColors();
                    HSB     = subNameTarget.GetColors();
                    name    = subNameTarget.GetName();
                    health  = target.GetComponent <LiveMixin>().health;
                }
                else if (vehicle)
                { // Seamoth & Prawn Suit
                    health  = vehicle.GetComponent <LiveMixin>().health;
                    name    = (string)vehicle.ReflectionCall("GetName", true);
                    HSB     = vehicle.subName.GetColors();
                    Colours = vehicle.subName.GetColors();
                }
                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorId, constructedObjectId, techType.Model(), duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation,
                                                                                      name, HSB, Colours, health);
                vehicles.AddVehicle(VehicleModelFactory.BuildFrom(beginCrafting));
                packetSender.Send(beginCrafting);

                SpawnDefaultBatteries(constructedObject, childIdentifiers);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #19
0
        private void ConfigureNewlyConstructedBase(string newBaseGuid)
        {
            Optional <object> opNewlyCreatedBase = TransientLocalObjectManager.Get(TransientLocalObjectManager.TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            if (opNewlyCreatedBase.IsPresent())
            {
                GameObject newlyCreatedBase = (GameObject)opNewlyCreatedBase.Get();
                GuidHelper.SetNewGuid(newlyCreatedBase, newBaseGuid);
            }
            else
            {
                Log.Error("Could not assign new base guid as no newly constructed base was found");
            }
        }
Example #20
0
        public override void Process(DeconstructionBegin packet)
        {
            Log.Info("Received deconstruction packet for basePieceId: " + packet.Id);

            GameObject          deconstructing      = NitroxEntity.RequireObjectFrom(packet.Id);
            BaseDeconstructable baseDeconstructable = deconstructing.RequireComponent <BaseDeconstructable>();

            TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, packet.Id);

            using (packetSender.Suppress <DeconstructionBegin>())
            {
                baseDeconstructable.Deconstruct();
            }
        }
Example #21
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            string constructorGuid = GuidHelper.GetGuid(constructor);

            Log.Debug("Building item from constructor with uuid: " + constructorGuid);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();

                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject);
                Vehicle   vehicle = constructedObject.GetComponent <Vehicle>();
                string    constructedObjectGuid = GuidHelper.GetGuid(constructedObject);
                Vector3[] HSB       = new Vector3[5];
                Vector3[] Colours   = new Vector3[5];
                Vector4   tmpColour = Color.white;
                string    name      = "";

                if (!vehicle)
                { // Cylcops
                    GameObject   target        = GuidHelper.RequireObjectFrom(constructedObjectGuid);
                    SubNameInput subNameInput  = target.RequireComponentInChildren <SubNameInput>();
                    SubName      subNameTarget = (SubName)subNameInput.ReflectionGet("target");

                    Colours = subNameTarget.GetColors();
                    HSB     = subNameTarget.GetColors();
                    name    = subNameTarget.GetName();
                }
                else if (vehicle)
                { // Seamoth & Prawn Suit
                    name    = (string)vehicle.ReflectionCall("GetName", true);
                    HSB     = vehicle.subName.GetColors();
                    Colours = vehicle.subName.GetColors();
                }
                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType.Model(), duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation,
                                                                                      name, HSB, Colours);
                vehicles.AddVehicle(VehicleModelFactory.BuildFrom(beginCrafting));
                packetSender.Send(beginCrafting);

                // Mark vehicle as controlled by nitrox (used for sending add/remove batteries aka storage slots)
                constructedObject.AddComponent <NitroxEntity>();
                SpawnDefaultBatteries(constructedObject, childIdentifiers);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #22
0
        private void ConfigureNewlyConstructedBase(NitroxId newBaseId)
        {
            Optional <object> opNewlyCreatedBase = TransientLocalObjectManager.Get(TransientLocalObjectManager.TransientObjectType.BASE_GHOST_NEWLY_CONSTRUCTED_BASE_GAMEOBJECT);

            if (opNewlyCreatedBase.HasValue)
            {
                GameObject newlyCreatedBase = (GameObject)opNewlyCreatedBase.Value;
                NitroxEntity.SetNewId(newlyCreatedBase, newBaseId);
            }
            else
            {
                Log.Error("Could not assign new base id as no newly constructed base was found");
            }
        }
        public override void Process(ConstructorBeginCrafting packet)
        {
            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(packet.ConstructorGuid);

            if (opGameObject.IsEmpty())
            {
                Console.WriteLine("Trying to build " + packet.TechType + " with unmanaged constructor - ignoring.");
                return;
            }

            GameObject gameObject = opGameObject.Get();
            Crafter    crafter    = gameObject.GetComponentInChildren <Crafter>(true);

            if (crafter == null)
            {
                Console.WriteLine("Trying to build " + packet.TechType + " but we did not have a corresponding constructorInput - how did that happen?");
                return;
            }

            Optional <TechType> opTechType = ApiHelper.TechType(packet.TechType);

            if (opTechType.IsEmpty())
            {
                Console.WriteLine("Trying to build unknown tech type: " + packet.TechType + " - ignoring.");
                return;
            }

            MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance);

            Validate.NotNull(onCraftingBegin);
            onCraftingBegin.Invoke(crafter, new object[] { opTechType.Get(), packet.Duration }); //TODO: take into account latency for duration

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();
                GuidHelper.SetNewGuid(constructedObject, packet.ConstructedItemGuid);

                SetInteractiveChildrenGuids(constructedObject, packet.InteractiveChildIdentifiers);
            }
            else
            {
                Console.WriteLine("Could not find constructed object!");
            }
        }
Example #24
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 #25
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);
        }
        public static void Postfix(Constructable __instance)
        {
            /**
             * On base pieces we need to have special logic during deconstruction to transfer the id from the main
             * object to the ghost.  This method will see if we have a stored LATEST_DECONSTRUCTED_BASE_PIECE_GUID
             * (set from deconstructor patch or incoming deconstruction packet).  If we do, then we'll copy the id
             * to the new ghost.
             */
            Optional <object> opId = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID);

            if (opId.IsPresent())
            {
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, null);

                NitroxId id = (NitroxId)opId.Get();
                Log.Info("Setting ghost id via Constructable_SetState_Patch " + id);
                NitroxEntity.SetNewId(__instance.gameObject, id);
            }
        }
Example #27
0
        public void ConstructorBeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            String constructorGuid = GuidHelper.GetGuid(constructor);

            Console.WriteLine("Building item from constructor with uuid: " + constructorGuid);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject           = (GameObject)opConstructedObject.Get();
                String     constructedObjectGuid       = GuidHelper.GetGuid(constructedObject);
                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(PlayerId, constructorGuid, constructedObjectGuid, ApiHelper.TechType(techType), duration);
                Send(beginCrafting);
            }
            else
            {
                Console.WriteLine("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #28
0
        public static void Prefix(BaseGhost __instance)
        {
            // Null out fields that will be used for storing state
            TransientLocalObjectManager.Remove(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION);
            TransientLocalObjectManager.Remove(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION);

            // In this case, our piece is part of an existing, larger base.  We'll record the base and offset.
            // We don't directly record the piece as it will be re-built when the base rebuilds geometry (this
            // happens each time a piece is built, subnautica destroys all others and replaces them).
            if (__instance.TargetBase != null)
            {
                Log.Debug("Placed BaseGhost is a new piece of an existing base");
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_BASE_WITH_NEW_CONSTRUCTION, __instance.TargetBase);
                TransientLocalObjectManager.Add(TransientObjectType.LATEST_BASE_CELL_WITH_NEW_CONSTRUCTION, __instance.TargetOffset);
            }
            else
            {
                Log.Debug("Placed BaseGhost is the first piece of a new base.");
            }
        }
Example #29
0
        public void BeginCrafting(GameObject constructor, TechType techType, float duration)
        {
            string constructorGuid = GuidHelper.GetGuid(constructor);

            Log.Debug("Building item from constructor with uuid: " + constructorGuid);

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();

                List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject);
                string constructedObjectGuid           = GuidHelper.GetGuid(constructedObject);
                ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType, duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation);
                packetSender.Send(beginCrafting);
            }
            else
            {
                Log.Error("Could not send packet because there wasn't a corresponding constructed object!");
            }
        }
Example #30
0
        private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged)
        {
            Log.Info("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.Amount);

            GameObject          constructing        = GuidHelper.RequireObjectFrom(amountChanged.Guid);
            BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>();

            // Bases don't  send a deconstruct being packet.  Instead, we just make sure
            // that if we are changing the amount that we set it into deconstruction mode
            // if it still has a BaseDeconstructable object on it.
            if (baseDeconstructable != null)
            {
                baseDeconstructable.Deconstruct();

                // After we have begun the deconstructing for a base piece, we need to transfer the guid
                Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE);

                if (opGhost.IsPresent())
                {
                    GameObject ghost = (GameObject)opGhost.Get();
                    UnityEngine.Object.Destroy(constructing);
                    GuidHelper.SetNewGuid(ghost, amountChanged.Guid);
                }
                else
                {
                    Log.Info("Could not find newly created ghost to set deconstructed guid ");
                }
            }
            else
            {
                Constructable constructable = constructing.GetComponentInChildren <Constructable>();
                constructable.constructedAmount = amountChanged.Amount;

                using (packetSender.Suppress <ConstructionAmountChanged>())
                {
                    constructable.Construct();
                }
            }
        }