Beispiel #1
0
 //=====================================================================
 // Construct
 //
 // Figure out whether we're starting, ending, or continuing
 // construction and plays the appropriate sounds
 //=====================================================================
 private bool Construct(Constructable c, bool state)
 {
     if (c != null && !c.constructed)
     {
         bool constructed = c.constructed;
         bool flag        = (!state) ? c.Deconstruct() : c.Construct();
         if (flag)
         {
             this.constructable = c;
         }
         else if (state && !constructed)
         {
             global::Utils.PlayFMODAsset(this.completeSound, c.transform, 20f);
         }
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        public override GameObject GetGameObject()
        {
            var        prefab       = GameObject.Instantiate(_ionCubeGenPrefab);
            GameObject consoleModel = prefab.FindChild("model");

            // Update sky applier
            SkyApplier skyApplier = prefab.AddComponent <SkyApplier>();

            skyApplier.renderers = consoleModel.GetComponentsInChildren <MeshRenderer>();
            skyApplier.anchorSky = Skies.Auto;

            //Add the constructible component to the prefab
            Constructable constructible = prefab.AddComponent <Constructable>();

            CreateDisplayedIonCube(prefab);

            constructible.allowedInBase           = true;  // Only allowed in Base
            constructible.allowedInSub            = false; // Not allowed in Cyclops
            constructible.allowedOutside          = false;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = true; // Only on ground
            constructible.allowedOnWall           = false;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.rotationEnabled         = true;
            constructible.techType = this.TechType;
            constructible.model    = consoleModel;

            //Add the prefabIdentifier
            PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>();

            prefabID.ClassId = this.ClassID;

            // Add the custom component
            CubeGeneratorMono cubeGenerator = prefab.AddComponent <CubeGeneratorMono>(); // Moved to the bottom to allow constructible to be added

            CubeGeneratorAnimator cubeGeneratorAnimator = prefab.AddComponent <CubeGeneratorAnimator>();

            IonGeneratorDisplay cubeGeneratorDisplay = prefab.AddComponent <IonGeneratorDisplay>();

            FMOD_CustomLoopingEmitter FMOD_CustomLoopingEmitter = prefab.AddComponent <FMOD_CustomLoopingEmitter>();

            return(prefab);
        }
Beispiel #3
0
        static bool Prefix(BuilderTool __instance, Constructable constructable)
        {
            if (!constructable.gameObject.GetComponent <DebrisDeconstructable>())
            {
                return(true);
            }

            HandReticle hand = HandReticle.main;

            hand.SetInteractText(L10n.str("ids_salvageableDebris"), __instance.deconstructText, false, false, HandReticle.Hand.None);

            if (!constructable.constructed)
            {
                hand.SetProgress(constructable.amount);
                hand.SetIcon(HandReticle.IconType.Progress, 1.5f);
            }

            return(false);
        }
Beispiel #4
0
        private static void CreateGhost()
        {
            Constructable component = prefab.GetComponent <Constructable>();

            constructableTechType = component.techType;
            allowedOutside        = component.allowedOutside;
            ConstructableBase component2 = prefab.GetComponent <ConstructableBase>();

            if (component2 != null)
            {
                GameObject gameObject = Object.Instantiate <GameObject>(prefab);
                component2 = gameObject.GetComponent <ConstructableBase>();
                ghostModel = component2.model;
                BaseGhost component3 = ghostModel.GetComponent <BaseGhost>();
                component3.SetupGhost();
                ghostModelPosition = Vector3.zero;
                ghostModelRotation = Quaternion.identity;
                ghostModelScale    = Vector3.one;
                renderers          = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial);
                InitBounds(ghostModel);
            }
            else
            {
                ghostModel = Object.Instantiate <GameObject>(component.model);
                ghostModel.SetActive(true);
                Transform  component4 = component.GetComponent <Transform>();
                Transform  component5 = component.model.GetComponent <Transform>();
                Quaternion quaternion = Quaternion.Inverse(component4.rotation);
                ghostModelPosition = quaternion * (component5.position - component4.position);
                ghostModelRotation = quaternion * component5.rotation;
                ghostModelScale    = component5.lossyScale;
                Collider[] componentsInChildren = ghostModel.GetComponentsInChildren <Collider>();
                foreach (Collider collider in componentsInChildren)
                {
                    Object.Destroy(collider);
                }

                renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial);
                SetupRenderers(ghostModel, Player.main.IsInSub());
                CreatePowerPreview();
                InitBounds(prefab);
            }
        }
Beispiel #5
0
            public void reset(Constructable constructable)
            {
                if (constructable == null)
                {
#if DBG_CPOINTS
                    debugSphere.SetActive(false);
#endif
                    constructionTime = 0f;
                    return;
                }

                constructionInterval = UnityEngine.Random.Range(pointSwitchTimeMin, pointSwitchTimeMax);
                constructionPoint    = constructable.GetRandomConstructionPoint();
                constructionTime    %= constructionInterval;
#if DBG_CPOINTS
                debugSphere.SetActive(true);
                debugSphere.transform.position = constructionPoint;
#endif
            }
        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);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets a list of <see cref="Comment"/> objects which are associated with the
        /// specified <see cref="Constructable"/> object.
        /// </summary>
        /// <returns></returns>
        protected IEnumerable <Comment> GetComment(Constructable constructable)
        {
            Comment comment;

            // Get all the comments.
            Dictionary <Constructable, string> comments = new Dictionary <Constructable, string>();

            if (insertComments)
            {
                foreach (Constructable c in section)
                {
                    comment = c as Comment;
                    if (comment != null && comment.AssociatedConstructable != null)
                    {
                        if (comments.ContainsKey(comment.AssociatedConstructable))
                        {
                            // Multiple comments about the same Constructable are put together.
                            comments[comment.AssociatedConstructable] += "\n" + comment.Text;
                        }
                        else
                        {
                            // A comment about an uncommented Constructable.
                            comments.Add(comment.AssociatedConstructable, comment.Text);
                        }
                    }
                }
            }

            foreach (Constructable c in section)
            {
                comment = c as Comment;
                // Only use those comments which are not associated with a Constructable.
                if (comment != null)
                {
                    if (!insertComments || comment.AssociatedConstructable != null)
                    {
                        continue;
                    }
                }
                WriteConstructable(objectfile, section, c, comments);
            }
        }
Beispiel #8
0
        // Token: 0x06002BA8 RID: 11176 RVA: 0x00104A5C File Offset: 0x00102C5C
        public static bool CanDestroyObject(GameObject go)
        {
            Player componentInParent = go.GetComponentInParent <Player>();

            if (componentInParent != null)
            {
                return(false);
            }
            LargeWorldEntity component = go.GetComponent <LargeWorldEntity>();

            if (component != null && component.cellLevel >= LargeWorldEntity.CellLevel.Global)
            {
                return(false);
            }
            SubRoot componentInParent2 = go.GetComponentInParent <SubRoot>();

            if (componentInParent2 != null)
            {
                return(false);
            }
            Constructable componentInParent3 = go.GetComponentInParent <Constructable>();

            if (componentInParent3 != null)
            {
                return(false);
            }
            IObstacle component2 = go.GetComponent <IObstacle>();

            if (component2 != null)
            {
                return(false);
            }
            Pickupable component3 = go.GetComponent <Pickupable>();

            if (component3 != null && component3.attached)
            {
                return(false);
            }
            PlaceTool component4 = go.GetComponent <PlaceTool>();

            return(!(component4 != null));
        }
Beispiel #9
0
        public override void Awake()
        {
            base.Awake();

            if (Buildable == null)
            {
                Buildable = GetComponentInChildren <Constructable>();
            }

            if (SaveData == null)
            {
                string id = GetComponentInParent <PrefabIdentifier>().Id;
                SaveData = new AuxUpgradeConsoleSaveData(id);
            }

            if (this.Modules == null)
            {
                InitializeModules();
            }
        }
Beispiel #10
0
        public override void Process(ConstructionCompleted completedPacket)
        {
            Console.WriteLine("Processing ConstructionAmountChanged " + completedPacket.Guid + " " + completedPacket.PlayerId + " " + completedPacket.NewBaseCreatedGuid);

            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(completedPacket.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    constructing  = opGameObject.Get();
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.Construct();

                if (completedPacket.NewBaseCreatedGuid.IsPresent())
                {
                    String newBaseGuid = completedPacket.NewBaseCreatedGuid.Get();
                    configureNewlyConstructedBase(newBaseGuid);
                }
            }
        }
Beispiel #11
0
 private bool Construct(Constructable c, bool state)
 {
     if (c != null && !c.constructed && this.energyMixin.charge > 0f)
     {
         float amount = ((!state) ? this.powerConsumptionDeconstruct : this.powerConsumptionConstruct) * Time.deltaTime;
         this.energyMixin.ConsumeEnergy(amount);
         bool constructed = c.constructed;
         bool flag        = (!state) ? c.Deconstruct() : c.Construct();
         if (flag)
         {
             this.constructable = c;
         }
         else if (state && !constructed)
         {
             global::Utils.PlayFMODAsset(this.completeSound, c.transform, 20f);
         }
         return(true);
     }
     return(false);
 }
        private void OnHover(Constructable constructable)
        {
            if (isActive)
            {
                HandReticle main = HandReticle.main;
                if (constructable.constructed)
                {
#if SN1
                    main.SetInteractText(Language.main.Get(constructable.techType), deconstructText, false, false, HandReticle.Hand.Left);
#elif BZ
                    main.SetText(HandReticle.TextType.Hand, this.deconstructText, false);
#endif
                }
                else
                {
                    var stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(constructText);
                    foreach (KeyValuePair <TechType, int> keyValuePair in constructable.GetRemainingResources())
                    {
                        TechType key   = keyValuePair.Key;
                        string   text  = Language.main.Get(key);
                        int      value = keyValuePair.Value;
                        if (value > 1)
                        {
                            stringBuilder.AppendLine(Language.main.GetFormat <string, int>("RequireMultipleFormat", text, value));
                        }
                        else
                        {
                            stringBuilder.AppendLine(text);
                        }
                    }
#if SN1
                    main.SetInteractText(Language.main.Get(constructable.techType), stringBuilder.ToString(), false, false, HandReticle.Hand.Left);
#elif BZ
                    main.SetText(HandReticle.TextType.Hand, stringBuilder.ToString(), false);
#endif
                    main.SetProgress(constructable.amount);
                    main.SetIcon(HandReticle.IconType.Progress, 1.5f);
                }
            }
        }
Beispiel #13
0
        public override GameObject GetGameObject()
        {
            // Instantiates a copy of the prefab that is loaded from the AssetBundle loaded above.
            GameObject _prefab = GameObject.Instantiate(Utils.Helper.Bundle.LoadAsset <GameObject>("LightSource_2.prefab"));

            _prefab.name = _ClassID;
            //Need a tech tag for most prefabs
            var techTag = _prefab.AddComponent <TechTag>();

            techTag.type = TechType;

            _prefab.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global;
            _prefab.EnsureComponent <PrefabIdentifier>().ClassId   = ClassID;

            // Update all shaders
            ApplySubnauticaShaders(_prefab);

            // Add constructable - This prefab normally isn't constructed.
            Constructable constructible = _prefab.AddComponent <Constructable>();

            constructible.constructedAmount       = 1;
            constructible.allowedInBase           = true;
            constructible.allowedInSub            = true;
            constructible.allowedOutside          = true;
            constructible.allowedOnCeiling        = true;
            constructible.allowedOnGround         = true;
            constructible.allowedOnWall           = true;
            constructible.allowedOnConstructables = false;
            constructible.techType             = this.TechType;
            constructible.rotationEnabled      = true;
            constructible.placeDefaultDistance = 1f;
            constructible.placeMinDistance     = 0.1f;
            constructible.placeMaxDistance     = 5f;
            constructible.surfaceType          = VFXSurfaceTypes.metal;
            constructible.model        = _prefab.FindChild("Model").gameObject;//.transform.GetChild(0).gameObject;
            constructible.forceUpright = true;

            _prefab.AddComponent <InGame.LightSource>();

            return(_prefab);
        }
Beispiel #14
0
        private static void AlertedNewBuilderBuild(BuilderTool arg1, Constructable arg2)
        {
            if (arg2 != null)
            {
                Log.Info($"Name: {arg2.gameObject.name}");

                var powerFX = arg2.GetComponent(typeof(PowerFX));

                if (powerFX != null)
                {
                    var fx = powerFX as PowerFX;
                    Log.Info($"PowerFX: {fx.vfxPrefab.name}");
                }

                //var list = arg2.GetComponentsInChildren(typeof(Component));
                //for (int i = 0; i < list.Length; i++)
                //{
                //    Log.Info($"Component Name: {list[i].name}");
                //}
            }
        }
Beispiel #15
0
            public static Constructable initConstructable(GameObject prefab, GameObject model)
            {
                Constructable c = prefab.ensureComponent <Constructable>();

                c.allowedInBase           = false;
                c.allowedInSub            = false;
                c.allowedOutside          = false;
                c.allowedOnWall           = false;
                c.allowedOnGround         = false;
                c.allowedOnCeiling        = false;
                c.allowedOnConstructables = false;

                c.enabled               = true;
                c.rotationEnabled       = true;
                c.controlModelState     = true;
                c.deconstructionAllowed = true;

                c.model = model;

                return(c);
            }
Beispiel #16
0
        public override void Awake()
        {
            base.Awake();

            if (WorldInstance == null)
            {
                WorldInstance = GetComponentInChildren <Constructable>();
            }

            if (SaveData == null)
            {
                string id = GetComponentInParent <PrefabIdentifier>().Id;
                SaveData = new DataSaver(id);
                ID       = id;
            }

            if (Armour == null)
            {
                Init();
            }
        }
Beispiel #17
0
            public static void Postfix(ref Constructable __instance, ref Building ___building)
            {
                // Check if the building is not a background object
                if (___building.Def.ObjectLayer != ObjectLayer.Building)
                {
                    return;
                }
                PrioritySetting masterPriority = __instance.GetComponent <Prioritizable> ().GetMasterPriority();

                ___building.RunOnArea(delegate(int offset_cell) {
                    GameObject gameObject = Grid.Objects [offset_cell, (int)ObjectLayer.Plants];
                    if (gameObject != null)
                    {
                        // This component should always exist but lets check it just in case
                        if (gameObject.GetComponent <Uprootable> () != null)
                        {
                            gameObject.GetComponent <Uprootable> ().MarkForUproot(true);
                            gameObject.GetComponent <Prioritizable> ().SetMasterPriority(masterPriority);
                        }
                    }
                });
            }
Beispiel #18
0
        public override GameObject GetGameObject()
        {
            var BaseDrillModule = new GameObject
            {
                name = NameID
            };

            // Add prefab ID
            PrefabIdentifier prefabId = BaseDrillModule.AddComponent <PrefabIdentifier>();

            prefabId.ClassId = NameID;
            prefabId.name    = FriendlyName;

            // Add tech tag
            TechTag techTag = BaseDrillModule.AddComponent <TechTag>();

            techTag.type = this.TechType;


            // Add constructable - This prefab normally isn't constructed.
            Constructable constructible = BaseDrillModule.AddComponent <Constructable>();

            constructible.allowedInBase           = true;
            constructible.allowedInSub            = false;
            constructible.allowedOutside          = false;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = true;
            constructible.allowedOnWall           = false;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.rotationEnabled         = false;
            constructible.techType = this.TechType; // This was necessary to correctly associate the recipe at building time
            GameObject BasedrillMesh = GameObject.CreatePrimitive(PrimitiveType.Cube);

            constructible.model = BasedrillMesh;
            BasedrillMesh.AddComponent <BaseDrillMesh>();
            BasedrillMesh.transform.SetParent(BaseDrillModule.transform);
            return(BaseDrillModule);
        }
Beispiel #19
0
        public override void Process(DeconstructionBegin packet)
        {
            Log.Info("Received deconstruction packet for id: " + packet.Id);

            GameObject deconstructing = NitroxEntity.RequireObjectFrom(packet.Id);

            Constructable       constructable       = deconstructing.GetComponent <Constructable>();
            BaseDeconstructable baseDeconstructable = deconstructing.GetComponent <BaseDeconstructable>();

            using (packetSender.Suppress <DeconstructionBegin>())
            {
                if (baseDeconstructable != null)
                {
                    TransientLocalObjectManager.Add(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GUID, packet.Id);
                    baseDeconstructable.Deconstruct();
                }
                else if (constructable != null)
                {
                    constructable.SetState(false, false);
                }
            }
        }
Beispiel #20
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();
                }
            }
        }
        public override void Process(DeconstructionBegin packet)
        {
            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(packet.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    deconstructing = opGameObject.Get();
                Constructable constructable  = deconstructing.GetComponent <Constructable>();

                if (constructable != null)
                {
                    constructable.SetState(false, false);
                }
                else
                {
                    Console.WriteLine("Gameobject did not have a valid constructable component!");
                }
            }
            else
            {
                Console.WriteLine("Could not find game object to deconstruct: " + packet.Guid);
            }
        }
Beispiel #22
0
        public void ConstructItem(String guid, String subGuid, Vector3 position, Quaternion rotation, Transform cameraTransform, TechType techType)
        {
            GameObject buildPrefab = CraftData.GetBuildPrefab(techType);

            MultiplayerBuilder.overridePosition   = position;
            MultiplayerBuilder.overrideQuaternion = rotation;
            MultiplayerBuilder.overrideTransform  = cameraTransform;
            MultiplayerBuilder.placePosition      = position;
            MultiplayerBuilder.placeRotation      = rotation;
            MultiplayerBuilder.Begin(buildPrefab);

            Optional <GameObject> opSub = GuidHelper.GetObjectFrom(subGuid);

            if (opSub.IsEmpty())
            {
                Console.WriteLine("Could not locate sub with guid" + subGuid);
                return;
            }

            SubRoot subRoot = opSub.Get().GetComponent <SubRoot>();

            GameObject gameObject = MultiplayerBuilder.TryPlaceFurniture(subRoot);

            GuidHelper.SetNewGuid(gameObject, guid);

            Constructable constructable = gameObject.GetComponentInParent <Constructable>();

            Validate.NotNull(constructable);

            /**
             * Manually call start to initialize the object as we may need to interact with it within the same frame.
             */
            MethodInfo startCrafting = typeof(Constructable).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance);

            Validate.NotNull(startCrafting);
            startCrafting.Invoke(constructable, new object[] { });
        }
Beispiel #23
0
    public GameObject CreateBuildingUnderConstruction(BuildingDef def)
    {
        GameObject gameObject = CreateBuilding(def, constructionTemplate, null);

        Object.DontDestroyOnLoad(gameObject);
        KSelectable component = gameObject.GetComponent <KSelectable>();

        component.SetName(def.Name);
        for (int i = 0; i < def.Mass.Length; i++)
        {
            gameObject.GetComponent <PrimaryElement>().MassPerUnit += def.Mass[i];
        }
        KPrefabID kPrefabID = AddID(gameObject, def.PrefabID + "UnderConstruction");

        UpdateComponentRequirement <BuildingCellVisualizer>(gameObject, def.CheckRequiresBuildingCellVisualizer());
        Constructable component2 = gameObject.GetComponent <Constructable>();

        component2.SetWorkTime(def.ConstructionTime);
        Rotatable rotatable = UpdateComponentRequirement <Rotatable>(gameObject, def.PermittedRotations != PermittedRotations.Unrotatable);

        if ((bool)rotatable)
        {
            rotatable.permittedRotations = def.PermittedRotations;
        }
        Add2DComponents(def, gameObject, "place", false, kPrefabID.defaultLayer = LayerMask.NameToLayer("Construction"));
        UpdateComponentRequirement <Vent>(gameObject, false);
        bool required = (Object)def.BuildingComplete.GetComponent <AnimTileable>() != (Object)null;

        UpdateComponentRequirement <AnimTileable>(gameObject, required);
        if (def.RequiresPowerInput)
        {
            GeneratedBuildings.RegisterLogicPorts(gameObject, LogicOperationalController.INPUT_PORTS_0_0);
        }
        Assets.AddPrefab(kPrefabID);
        gameObject.PreInit();
        return(gameObject);
    }
Beispiel #24
0
        public static bool Prefix(Constructable __instance)
        {
            if (__instance.constructed)
            {
                return(true);
            }

            // If we are constructing a base piece then we'll want to store all of the BaseGhost information
            // as it will not be available when the construction hits 100%
            if (__instance is ConstructableBase constructableBase)
            {
                BaseGhost baseGhost = constructableBase.gameObject.GetComponentInChildren <BaseGhost>();
                if (baseGhost != null)
                {
                    lastTargetBase       = baseGhost.TargetBase;
                    lastTargetBaseOffset = baseGhost.TargetOffset;
                }

                lastFace = baseGhost switch
                {
                    BaseAddFaceGhost {
                        anchoredFace : { }
                    } baseAddFaceGhost => baseAddFaceGhost.anchoredFace.Value,
                    BaseAddModuleGhost {
                        anchoredFace : { }
                    } baseAddModuleGhost => baseAddModuleGhost.anchoredFace.Value,
                    _ => lastFace
                };
            }
            else
            {
                lastTargetBase       = null;
                lastTargetBaseOffset = default(Int3);
            }

            return(true);
        }
        public static void Postfix(Constructable __instance, bool __result)
        {
            if (!__result)
            {
                return;
            }
            if (__instance.constructedAmount <= 0f)
            {
                if (!__instance.TryGetComponent(out NitroxEntity nitroxEntity))
                {
                    return;
                }

                Resolve <Building>().DeconstructionComplete(__instance.gameObject);
                Log.Debug("Finished deconstructing, now removing ghost NitroxEntity");

                Resolve <GeometryRespawnManager>().NitroxIdsToIgnore.Add(nitroxEntity.Id);
                Log.Debug($"Added ghost to ignore list: {nitroxEntity.Id}");
            }
            else
            {
                Resolve <Building>().ChangeConstructionAmount(__instance.gameObject, __instance.constructedAmount);
            }
        }
        // Static reproduction of Constructable.Construct to replace the body of the existing method
        public static bool Construct(Constructable constructable)
        {
            if (constructable._constructed)
            {
                return(false);
            }

            var resourceMap = ConstructableResourceMap.GetValue(constructable) as List <TechType>;

            var count = resourceMap.Count;

            var resourceID = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            constructable.constructedAmount += Time.deltaTime / ((float)count * (float)ConstructableGetConstructInterval.Invoke(constructable, new object[] { }));
            constructable.constructedAmount  = Mathf.Clamp01(constructable.constructedAmount);

            var resourceID2 = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            if (resourceID != resourceID2)
            {
                var techType = resourceMap[resourceID2 - 1];
                if (!CrafterLogicHelper.DestroyItemInLocalContainers(techType) && GameModeUtils.RequiresIngredients())
                {
                    constructable.constructedAmount = (float)resourceID / (float)count;
                    return(false);
                }
            }

            ConstructableUpdateMaterial.Invoke(constructable, new object[] { });
            if (constructable.constructedAmount >= 1f)
            {
                constructable.SetState(true, true);
            }

            return(true);
        }
Beispiel #27
0
    public override void UseButtonDown()
    {
        base.UseButtonDown();
        NVRPlayer player = AttachedHand.GetComponentInParent <NVRPlayer> ();

        if (!player.LeftHand || !player.RightHand)
        {
            return;
        }
        NVRInteractable left  = player.LeftHand.CurrentlyInteracting;
        NVRInteractable right = player.RightHand.CurrentlyInteracting;

        if (!left || !right)
        {
            return;
        }
        GameObject leftGame  = left.gameObject;
        GameObject rightGame = right.gameObject;

        if (!leftGame || !rightGame)
        {
            return;
        }

        Constructable leftCons  = leftGame.GetComponent <Constructable> ();
        Constructable rightCons = rightGame.GetComponent <Constructable> ();

        if (leftCons && rightCons &&
            player.LeftHand.UseButtonPressed && player.RightHand.UseButtonPressed)
        {
            Debug.Log("MAKING CONNECTION");
            FixedJoint f = left.gameObject.AddComponent <FixedJoint> ();
            f.breakForce    = breakForce;
            f.connectedBody = right.gameObject.GetComponent <Rigidbody> ();
        }
    }
        public static bool Prefix(Constructable __instance)
        {
            if (!__instance._constructed && __instance.constructedAmount < 1.0f)
            {
                NitroxServiceLocator.LocateService <Building>().ChangeConstructionAmount(__instance.gameObject, __instance.constructedAmount);
            }

            // If we are constructing a base piece then we'll want to store all of the BaseGhost information
            // as it will not be available when the construction hits 100%
            BaseGhost baseGhost = __instance.gameObject.GetComponentInChildren <BaseGhost>();

            if (baseGhost != null && baseGhost.TargetBase)
            {
                lastTargetBase       = baseGhost.TargetBase.GetComponent <Base>();
                lastTargetBaseOffset = baseGhost.TargetOffset;
            }
            else
            {
                lastTargetBase       = null;
                lastTargetBaseOffset = default(Int3);
            }

            return(true);
        }
        public static bool CanDeconstruct_Prefix(Constructable __instance, ref bool __result, out string reason)
        {
            string techTypeStr = __instance.techType.AsString();

            if (techTypeStr.StartsWith("DecorativeLocker") ||
                techTypeStr.StartsWith("DecorativeLockerClosed") ||
                techTypeStr.StartsWith("DecorativeLockerDoor") ||
                techTypeStr.StartsWith("CargoBox01_damaged") ||
                techTypeStr.StartsWith("CargoBox01a") ||
                techTypeStr.StartsWith("CargoBox01b"))
            {
                foreach (Transform tr in __instance.gameObject.transform)
                {
                    if (tr.name.StartsWith("Locker(Clone)"))
                    {
                        StorageContainer sc = tr.GetComponent <StorageContainer>();
                        if (sc != null && sc.container != null && sc.container.count > 0)
                        {
                            if (Language.main != null)
                            {
                                string notEmptyError = Language.main.Get("DeconstructNonEmptyStorageContainerError");
                                reason = (!string.IsNullOrEmpty(notEmptyError) ? notEmptyError : "Not empty!");
                            }
                            else
                            {
                                reason = "Not empty!";
                            }
                            __result = false;
                            return(false);
                        }
                    }
                }
            }
            reason = null;
            return(true);
        }
        public override GameObject GetGameObject()
        {
            SubRoot currentSub = Player.main.currentSub;

            if (currentSub != null)
            {
                QuickLogger.Debug($"Current Sub = {currentSub.GetInstanceID()}", true);

                var manager = ShippingTargetManager.FindManager(currentSub);

                QuickLogger.Debug($"Manager {manager}", true);

                if (manager != null && manager.ShippingTargets.Count >= ShippingTargetManager.MaxShippingContainers)
                {
                    ErrorMessage.AddMessage(Language.main.Get(OverLimitKey));
                    return(null);
                }
            }
            else
            {
                QuickLogger.Debug($"Current Sub is null");
            }
            var        prefab       = GameObject.Instantiate(_Prefab);
            GameObject consoleModel = prefab.FindChild("model");

            // Update sky applier
            SkyApplier skyApplier = prefab.AddComponent <SkyApplier>();

            skyApplier.renderers = consoleModel.GetComponentsInChildren <MeshRenderer>();
            skyApplier.anchorSky = Skies.Auto;

            //Add the constructable component to the prefab
            Constructable constructable = prefab.AddComponent <Constructable>();

            constructable.allowedInBase           = true; // Only allowed in Base
            constructable.allowedInSub            = true; // Not allowed in Cyclops
            constructable.allowedOutside          = false;
            constructable.allowedOnCeiling        = false;
            constructable.allowedOnGround         = true; // Only on ground
            constructable.allowedOnWall           = false;
            constructable.allowedOnConstructables = false;
            constructable.controlModelState       = true;
            constructable.rotationEnabled         = true;
            constructable.techType = this.TechType;
            constructable.model    = consoleModel;

            var center = new Vector3(0f, 1.022878f, 0.3840232f);       // Y reduced to allow tube fitting
            var size   = new Vector3(1.63731f, 1.920672f, 0.8025026f); // Y reduced to allow tube fitting

            GameObjectHelpers.AddConstructableBounds(prefab, size, center);

            prefab.EnsureComponent <AlterraShippingTransferHandler>();

            prefab.EnsureComponent <AlterraShippingDisplay>();

            prefab.EnsureComponent <AlterraShippingAnimator>();

            prefab.EnsureComponent <AlterraShippingTarget>();

            //Add the prefabIdentifier
            PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>();

            prefabID.ClassId = this.ClassID;

            return(prefab);
        }
 /// <inheritdoc />
 public override void VisitConstructable(Constructable constructable)
 {
     throw new LanguageException("The constructable is not known or supported.");
 }
        /// <summary>
        /// Writes the comment associated with the specified constructable.
        /// </summary>
        /// <param name="constructable">The <see cref="Constructable"/> to write the comment of.</param>
        /// <param name="linelength">The number of written characters on this line.</param>
        private void WriteCommentOf(Constructable constructable, int linelength)
        {
            // We don't write comments associated with comments.
            if (constructable is Comment)
                return;

            if (constructable.Comment != null)
                WriteCommentString(constructable.Comment.Text, linelength, 0, -1);
            else
                Writer.WriteLine();
        }