Пример #1
0
 static void Postfix(ToggleLights __instance)
 {
     if (Main.config.dbgCfg.showToggleLightStats)
     {
         $"{__instance.energyMixin?.charge} {__instance.energyPerSecond}".onScreen("energy " + __instance.name);
     }
 }
        public static void Postfix(ToggleLights __instance, bool __state)
        {
            if (__state != __instance.lightsActive)
            {
                // Find the right gameobject in the hierarchy to sync on:
                GameObject gameObject = null;
                foreach (Type t in syncedParents)
                {
                    if (__instance.GetComponent(t))
                    {
                        gameObject = __instance.gameObject;
                        break;
                    }
                    else if (__instance.GetComponentInParent(t))
                    {
                        gameObject = __instance.transform.parent.gameObject;
                        break;
                    }
                }

                if (!gameObject)
                {
                    Log.Info("ToggleLights does not have a gameObject to sync on. Is this a new item?");
                    DebugUtils.PrintHierarchy(__instance.gameObject);
                }

                string guid = GuidHelper.GetGuid(gameObject);

                NitroxServiceLocator.LocateService <IPacketSender>().Send(new NitroxModel.Packets.ToggleLights(guid, __instance.lightsActive));
            }
        }
Пример #3
0
        public static void Postfix(ToggleLights __instance, bool __state)
        {
            if (__state != __instance.lightsActive)
            {
                // Find the right gameobject in the hierarchy to sync on:
                GameObject gameObject = null;
                foreach (var t in syncedParents)
                {
                    if (__instance.GetComponent(t))
                    {
                        gameObject = __instance.gameObject;
                        break;
                    }
                    else if (__instance.GetComponentInParent(t))
                    {
                        gameObject = __instance.transform.parent.gameObject;
                        break;
                    }
                }
                if (!gameObject)
                {
                    Log.Info("ToggleLights does not have a gameObject to sync on. Is this a new item?");
                    DebugUtils.DumpComponent(__instance);
                }

                var guid = GuidHelper.GetGuid(gameObject);

                Multiplayer.PacketSender.Send(new NitroxModel.Packets.ToggleLights(Multiplayer.PacketSender.PlayerId, guid, __instance.lightsActive));
            }
        }
Пример #4
0
 static void ToggleLights_UpdateLightEnergy_Postfix(ToggleLights __instance)
 {
     if (Main.config.dbgCfg.showToggleLightStats)
     {
         $"{__instance.energyMixin?.charge} {__instance.energyPerSecond}".onScreen($"energy {__instance.name}");
     }
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        ToggleLights obj = (ToggleLights)target;

        if (GUILayout.Button("Set State Lights"))
        {
            obj.SetStateLightsOfType();
        }
    }
Пример #6
0
 [HarmonyPrefix]      // Harmony postfix
 public static bool Prefix(ToggleLights __instance)
 {
     if (SeamothInfo.preventLightToggle)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #7
0
        private static bool Prefix(ToggleLights __instance)
        {
            float timeLastPlayerModeChange = (float)ToggleLights_timeLastPlayerModeChange.GetValue(__instance);
            float timeLastLightToggle      = (float)ToggleLights_timeLastLightToggle.GetValue(__instance);

            if (Player.main.GetRightHandDown() && !Player.main.GetPDA().isInUse&& Time.time > timeLastPlayerModeChange + 1f && timeLastLightToggle + 0.25f < Time.time)
            {
                __instance.SetLightsActive(!__instance.lightsActive);
                ToggleLights_timeLastLightToggle.SetValue(__instance, Time.time);
            }
            return(true);
        }
Пример #8
0
        public static bool Prefix(SeaMoth __instance)
        {
            // Suppress powered on if a seamoth´s default is set to false
            GameObject   gameObject = __instance.gameObject;
            NitroxId     id         = NitroxIdentifier.GetId(gameObject);
            SeamothModel model      = NitroxServiceLocator.LocateService <Vehicles>().GetVehicles <SeamothModel>(id);

            // Set lights of seamoth
            ToggleLights toggleLights = gameObject.RequireComponentInChildren <ToggleLights>();

            toggleLights.lightsActive = model.LightOn;
            return(model.LightOn);
        }
Пример #9
0
        public static bool Prefix(ToggleLights __instance, bool powered)
        {
            // Find the right gameobject in the hierarchy to sync on:
            // Suppress powered on if a seamoth´s default is set to false
            if (__instance.GetComponentInParent <SeaMoth>() != null && powered)
            {
                GameObject   gameObject = __instance.transform.parent.gameObject;
                NitroxId     id         = NitroxEntity.GetId(gameObject);
                SeamothModel model      = NitroxServiceLocator.LocateService <Vehicles>().GetVehicles <SeamothModel>(id);
                return(model.LightOn == __instance.lightsActive);
            }

            return(true);
        }
Пример #10
0
        static bool Prefix(ToggleLights __instance)
        {
            if (!Player.main.inSeamoth)
            {
                return(true);
            }

            SeaMoth seaMoth = __instance.GetComponentInParent <SeaMoth>();

            if (seaMoth is null || seaMoth != (Player.main.currentMountedVehicle as SeaMoth) || !seaMoth.TryGetComponent(out BuilderModuleMono moduleMono) || !moduleMono.isActive)
            {
                return(true);
            }

            return(false);
        }
Пример #11
0
        public override void Process(NitroxModel.Packets.ToggleLights packet)
        {
            GameObject   gameObject   = NitroxIdentifier.RequireObjectFrom(packet.Id);
            ToggleLights toggleLights = gameObject.GetComponent <ToggleLights>();

            if (toggleLights == null)
            {
                toggleLights = gameObject.RequireComponentInChildren <ToggleLights>();
            }

            if (packet.IsOn != toggleLights.GetLightsActive())
            {
                using (packetSender.Suppress <NitroxModel.Packets.ToggleLights>())
                {
                    toggleLights.SetLightsActive(packet.IsOn);
                }
            }
        }
        public static void MonitorLightBeamKeyDown(SeaMoth thisSeaMoth)
        {
            // Detect key press and set variable to toggle lights Lo / Hi beam
            if (KeyCodeUtils.GetKeyDown(Config.LightsLoHiKeybindValue))
            {
                ToggleLights thisToggleLights = thisSeaMoth.GetComponentInChildren <ToggleLights>();

                if (Vehicle_Update_Patch.HighBeamOn)
                {
                    Utils.PlayEnvSound(thisToggleLights.lightsOffSound, thisToggleLights.lightsOffSound.gameObject.transform.position, 20f);
                    Vehicle_Update_Patch.HighBeamOn = false;
                }
                else
                {
                    Utils.PlayEnvSound(thisToggleLights.lightsOnSound, thisToggleLights.lightsOnSound.gameObject.transform.position, 20f);
                    Vehicle_Update_Patch.HighBeamOn = true;
                }
            }
        }
        public static bool Prefix(SeaMoth __instance)
        {
            // Suppress powered on if a seamoth´s default is set to false
            GameObject gameObject         = __instance.gameObject;
            NitroxId   id                 = NitroxEntity.GetId(gameObject);
            Optional <SeamothModel> model = NitroxServiceLocator.LocateService <Vehicles>().TryGetVehicle <SeamothModel>(id);

            if (!model.HasValue)
            {
                Log.Error($"{nameof(Seamoth_SubConstructionComplete_Patch)}: Could not find {nameof(CyclopsModel)} by Nitrox id {id}.\nGO containing wrong id: {__instance.GetHierarchyPath()}");
                return(false);
            }

            // Set lights of seamoth
            ToggleLights toggleLights = gameObject.RequireComponentInChildren <ToggleLights>();

            toggleLights.lightsActive = model.Value.LightOn;
            return(model.Value.LightOn);
        }
Пример #14
0
        public override void Process(NitroxModel.Packets.ToggleLights packet)
        {
            GameObject   gameObject   = NitroxEntity.RequireObjectFrom(packet.Id);
            ToggleLights toggleLights = gameObject.GetComponent <ToggleLights>();

            if (!toggleLights)
            {
                toggleLights = gameObject.RequireComponentInChildren <ToggleLights>();
            }

            if (packet.IsOn != toggleLights.GetLightsActive())
            {
                using (packetSender.Suppress <NitroxModel.Packets.ToggleLights>())
                    using (FMODSystem.SuppressSounds())
                    {
                        toggleLights.SetLightsActive(packet.IsOn);
                    }
            }
        }
Пример #15
0
        public static void SeaglideMapControlLightFix(SeaMoth thisSeaMoth)
        {
            // Seaglide Map Controls light toggle fix
            if (Player.main.GetRightHandDown() && SeamothInfo.preventLightToggle && OtherModsInfo.SeaglideMapControls)
            {
                ToggleLights thisToggleLights = thisSeaMoth.GetComponentInChildren <ToggleLights>();
                float        thisTLPMCh       = Traverse.Create(thisSeaMoth).Field("timeLastPlayerModeChange").GetValue <float>();

                if (!Player.main.GetPDA().isInUse&& Time.time > thisTLPMCh + 1f && SeamothInfo.timeLastLightToggle + 0.25f < Time.time)
                {
                    thisToggleLights.SetLightsActive(!thisToggleLights.lightsActive);
                    SeamothInfo.timeLastLightToggle = Time.time;
                    thisToggleLights.lightState++;
                    if (thisToggleLights.lightState == thisToggleLights.maxLightStates)
                    {
                        thisToggleLights.lightState = 0;
                    }
                }
            }
        }
Пример #16
0
        public static void Postfix(ToggleLights __instance, bool __state)
        {
            if (__state != __instance.lightsActive)
            {
                // Find the right gameobject in the hierarchy to sync on:
                GameObject gameObject = null;
                Type       type       = null;
                foreach (Type t in syncedParents)
                {
                    if (__instance.GetComponent(t))
                    {
                        type       = t;
                        gameObject = __instance.gameObject;
                        break;
                    }
                    else if (__instance.GetComponentInParent(t))
                    {
                        type       = t;
                        gameObject = __instance.transform.parent.gameObject;
                        break;
                    }
                }

                if (!gameObject)
                {
                    DebugUtils.PrintHierarchy(__instance.gameObject);
                }

                NitroxId id = NitroxEntity.GetId(gameObject);
                // If the floodlight belongs to a seamoth, then set the lights for the model
                if (type == typeof(SeaMoth))
                {
                    NitroxServiceLocator.LocateService <Vehicles>().GetVehicles <SeamothModel>(id).LightOn = __instance.lightsActive;
                }
                NitroxServiceLocator.LocateService <IPacketSender>().Send(new NitroxModel.Packets.ToggleLights(id, __instance.lightsActive));
            }
        }
Пример #17
0
 public static bool Prefix(ToggleLights __instance, out bool __state)
 {
     __state = __instance.lightsActive;
     return(true);
 }
        [HarmonyPostfix]      // Harmony postfix
        public static void Postfix(Vehicle __instance)
        {
            // Implement energy consumption changes
            Player       main             = Player.main; // player
            Vehicle      thisSeamoth      = (__instance as SeaMoth);
            ToggleLights thisToggleLights = __instance.GetComponentInChildren <ToggleLights>();

            if (main != null && thisSeamoth != null)
            {
                // SeamothInfo.CheckModuleStatus(thisSeamoth); -> is checked in Player_Update_Patch

                // Line of code below is reserved for future releases to implement further energy savings with VehiclePowerUpgradeModule
                // bool efficiencyLoaded = thisSeamoth.modules.GetCount(TechType.VehiclePowerUpgradeModule) > 0;

                bool playerPiloting = Player.main.GetMode() == Player.Mode.LockedPiloting;

                if (playerPiloting && Player.main.GetVehicle() == thisSeamoth)
                {
                    // set correct speed factor for Green and Turbo modes and energy usage which is lower in Green mode
                    // SeamothInfo.ModeChanged is flagged in MonitorModeKey class
                    if (SeamothInfo.ModeChanged && SeamothInfo.electronicModuleIn)
                    {
                        if (SeamothInfo.ModeGreenOn)
                        {
                            turboPlus          = 0f;
                            highBeamEnergyCost = 0.025f;
                        }
                        else
                        {
                            turboPlus          = 2f;
                            highBeamEnergyCost = 0.05f;
                        }
                    }

                    // Implement higher energy usage for high beam
                    if (thisToggleLights != null)
                    {
                        LightsAreOn = thisToggleLights.GetLightsActive();
                    }

                    if (HighBeamOn && LightsAreOn) // && SeamothInfo.electricalModuleIn)
                    {
                        ConsumeHighBeamEnergy(__instance, highBeamEnergyCost);
                    }

                    // If Electronic module is NOT in we turn Green mode OFF and turn Cruise Control OFF
                    if (!SeamothInfo.electronicModuleIn)
                    {
                        // if (!SeamothInfo.ModeChanged) ; // && !SeamothInfo.ModeChanged)
                        if (SeamothInfo.ModeGreenOn)
                        {
                            SeamothInfo.ModeGreenOn = false;
                            SeamothInfo.ModeChanged = true;
                        }

                        if (SeamothInfo.CruiseControlOn)
                        {
                            SeamothInfo.CruiseControlOn = false;
                        }
                    }

                    // Set Seamoth gear to 4 if no mechanical module in (speed closest to vanilla)
                    if (!SeamothInfo.mechanicalModuleIn)
                    {
                        if (Config.SeamothGearValue != 4f)
                        {
                            Config.SeamothGearValue = 4f;
                            PlayerPrefs.SetFloat("SeamothGearValueSlider", Config.SeamothGearValue);
                        }
                    }

                    // Set speeds to match gear setting
                    if (SeamothInfo.mechanicalModuleIn || SeamothInfo.electronicModuleIn)
                    {
                        if (Config.SeamothGearValue == 1f && (SeamothInfo.lastSeamothGearValue != 1f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce - (largeFactor * 3f);
                            thisSeamoth.backwardForce        = backwardForce - (smallFactor * 3f);
                            thisSeamoth.sidewardForce        = sidewardForce - (largeFactor * 3f);
                            thisSeamoth.verticalForce        = verticalForce - (largeFactor * 2.5f);
                            SeamothInfo.lastSeamothGearValue = 1f;
                        }
                        else if (Config.SeamothGearValue == 2f && (SeamothInfo.lastSeamothGearValue != 2f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce - (largeFactor * 2f) + turboPlus;
                            thisSeamoth.backwardForce        = backwardForce - (smallFactor * 2f) + turboPlus;
                            thisSeamoth.sidewardForce        = sidewardForce - (largeFactor * 2f) + turboPlus;
                            thisSeamoth.verticalForce        = verticalForce - (largeFactor * 2f) + turboPlus;
                            SeamothInfo.lastSeamothGearValue = 2f;
                        }
                        else if (Config.SeamothGearValue == 3f && (SeamothInfo.lastSeamothGearValue != 3f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce - largeFactor + turboPlus;
                            thisSeamoth.backwardForce        = backwardForce - smallFactor + turboPlus;
                            thisSeamoth.sidewardForce        = sidewardForce - largeFactor + turboPlus;
                            thisSeamoth.verticalForce        = verticalForce - largeFactor + turboPlus;
                            SeamothInfo.lastSeamothGearValue = 3f;
                        }
                        else if (Config.SeamothGearValue == 4f && (SeamothInfo.lastSeamothGearValue != 4f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce + turboPlus;
                            thisSeamoth.backwardForce        = backwardForce + turboPlus;
                            thisSeamoth.sidewardForce        = sidewardForce + turboPlus;
                            thisSeamoth.verticalForce        = verticalForce + turboPlus;
                            SeamothInfo.lastSeamothGearValue = 4f;
                        }
                        else if (Config.SeamothGearValue == 5f && (SeamothInfo.lastSeamothGearValue != 5f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce + largeFactor + (turboPlus * 2f);
                            thisSeamoth.backwardForce        = backwardForce + smallFactor + (turboPlus * 2f);
                            thisSeamoth.sidewardForce        = sidewardForce + largeFactor + (turboPlus * 2f);
                            thisSeamoth.verticalForce        = verticalForce + largeFactor + (turboPlus * 2f);
                            SeamothInfo.lastSeamothGearValue = 5f;
                        }
                        else if (Config.SeamothGearValue == 6f && (SeamothInfo.lastSeamothGearValue != 6f || SeamothInfo.ModeChanged))
                        {
                            thisSeamoth.forwardForce         = forwardForce + (largeFactor * 2f) + (turboPlus * 2f);
                            thisSeamoth.backwardForce        = backwardForce + (smallFactor * 2f) + (turboPlus * 2f);
                            thisSeamoth.sidewardForce        = sidewardForce + (largeFactor * 2f) + (turboPlus * 2f);
                            thisSeamoth.verticalForce        = verticalForce + (largeFactor * 2f) + (turboPlus * 2f);
                            SeamothInfo.lastSeamothGearValue = 6f;
                        }
                        SeamothInfo.ModeChanged = false;
                    }
                    else // If no Electronic (Green/Turbo) or Mechanical (Gears) modules in, set speeds to vanilla
                    {
                        if (SeamothInfo.lastSeamothGearValue != 0f)
                        {
                            thisSeamoth.forwardForce         = forwardForce;
                            thisSeamoth.backwardForce        = backwardForce;
                            thisSeamoth.sidewardForce        = sidewardForce;
                            thisSeamoth.verticalForce        = verticalForce;
                            SeamothInfo.lastSeamothGearValue = 0f;
                        }
                    }
                } // end if (playerPiloting)
            }     //end if (main != null)
        }         // end public static void Postfix(Vehicle __instance)
Пример #19
0
 static bool Prefix(ToggleLights __instance, bool powered)
 {
     return(false);
 }
Пример #20
0
        private static bool Prefix(ToggleLights __instance)
        {
            var moduleMono = __instance.GetComponentInParent <BuilderModuleMono>();

            return(moduleMono is null || !moduleMono.isToggle);
        }
Пример #21
0
        public override GameObject GetGameObject()
        {
            if (sharkPrefabCache)
            {
                return(sharkPrefabCache);
            }

            Console.WriteLine("Beginning shark load");

            Exosuit    exo        = CraftData.GetPrefabForTechType(TechType.Exosuit).GetComponent <Exosuit>();
            SeaMoth    sea        = CraftData.GetPrefabForTechType(TechType.Seamoth).GetComponent <SeaMoth>();
            GameObject ionCrystal = CraftData.GetPrefabForTechType(TechType.PrecursorIonCrystal);

            GameObject shark = MainPatch.bundle.LoadAsset <GameObject>("SharkPrefab.prefab");

            List <string> exclusions = new List <string>
            {
                "Window",
                "Sonar",
                "EnergyBlade",
                "VolumeLight",
                "Shield"
            };

            Material newMat  = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            Vector4  fakesss = newMat.GetVector("_FakeSSSparams");

            fakesss.y = 0f;
            newMat.SetVector("_FakeSSSparams", fakesss);

            foreach (Renderer rend in shark.GetComponentsInChildren <MeshRenderer>())
            {
                if (exclusions.IndexOf(rend.name) == -1)
                {
                    rend.material.shader = Shader.Find("MarmosetUBER");
                }

                if (rend.name == "EnergyBlade")
                {
                    rend.material          = newMat;
                    rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                }
            }

            Console.WriteLine("Setting up component");

            Shark sharkComp = shark.EnsureComponent <Shark>();

            sharkComp.playerSits     = true;
            sharkComp.playerPosition = shark.transform.Find("Scaler/SeatPosition").gameObject;
            sharkComp.handLabel      = "Pilot 5H-4RK";
            sharkComp.controlSheme   = Vehicle.ControlSheme.Submersible;
            sharkComp.mainAnimator   = shark.EnsureComponent <Animator>();
            sharkComp.mainAnimator.runtimeAnimatorController = sea.mainAnimator.runtimeAnimatorController;
            sharkComp.oxygenEnergyCost = 0f;

            sharkComp.bladeControl = shark.EnsureComponent <SharkBladeControl>();

            while (shark.GetComponent <FMOD_CustomLoopingEmitter>())
            {
                GameObject.Destroy(shark.GetComponent <FMOD_CustomLoopingEmitter>());
            }

            sharkComp.chargeUp = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.chargeUp.followParent = true;
            sharkComp.chargeUp.asset        = sea.pulseChargeSound.asset;
            sharkComp.boost = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.boost.followParent      = true;
            sharkComp.boost.asset             = exo.loopingJetSound.asset;
            sharkComp.boost.assetStop         = exo.loopingJetSound.assetStop;
            sharkComp.normalMove              = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.normalMove.followParent = true;
            sharkComp.normalMove.asset        = sea.engineSound.engineRpmSFX.asset;
            sharkComp.chargeFinished          = sea.seamothElectricalDefensePrefab.GetComponent <ElectricalDefense>().defenseSound;
            sharkComp.splash = sea.splashSound;

            sharkComp.welcomeNotification             = shark.EnsureComponent <VoiceNotification>();
            sharkComp.welcomeNotification.text        = "5H-4RK: Welcome aboard, Captain";
            sharkComp.welcomeNotification.minInterval = exo.welcomeNotification.minInterval;
            sharkComp.welcomeNotification.sound       = exo.welcomeNotification.sound;

            sharkComp.rightHandPlug = sharkComp.transform.Find("Scaler/HandTargets/Right");
            sharkComp.leftHandPlug  = sharkComp.transform.Find("Scaler/HandTargets/Left");
            sharkComp.window        = shark.transform.Find("Scaler/SharkMesh/Sonar").gameObject;

            Console.WriteLine("Adding control");

            SharkControl control = shark.EnsureComponent <SharkControl>();

            control.shark       = sharkComp;
            control.sound       = shark.EnsureComponent <SharkSound>();
            control.sound.shark = sharkComp;

            Console.WriteLine("Adding health");

            LiveMixin     mixin = shark.EnsureComponent <LiveMixin>();
            LiveMixinData data  = ScriptableObject.CreateInstance <LiveMixinData>();

            mixin.health              = 100f;
            data.maxHealth            = 100f;
            data.destroyOnDeath       = false;
            data.weldable             = true;
            data.canResurrect         = false;
            data.invincibleInCreative = true;
            mixin.data          = data;
            sharkComp.liveMixin = mixin;

            Console.WriteLine("Adding forces");

            WorldForces worldForces = shark.EnsureComponent <WorldForces>();

            worldForces.aboveWaterGravity = 9.8f;
            worldForces.underwaterDrag    = 1f;
            worldForces.underwaterGravity = 0f;
            worldForces.aboveWaterDrag    = 0.5f;
            worldForces.useRigidbody      = shark.GetComponent <Rigidbody>();

            sharkComp.worldForces = worldForces;

            Console.WriteLine("Setting up other components");

            shark.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global;
            shark.EnsureComponent <SkyApplier>().renderers       = shark.GetComponentsInChildren <Renderer>();
            shark.EnsureComponent <TechTag>().type             = TechType;
            shark.EnsureComponent <PrefabIdentifier>().ClassId = ClassID;
            var vfx        = shark.EnsureComponent <VFXConstructing>();
            var seamothvfx = sea.GetComponentInChildren <VFXConstructing>();

            vfx.blurOffset         = seamothvfx.blurOffset;
            vfx.lineWidth          = seamothvfx.lineWidth;
            vfx.alphaDetailTexture = seamothvfx.alphaDetailTexture;
            vfx.alphaEnd           = seamothvfx.alphaEnd;
            vfx.alphaScale         = seamothvfx.alphaScale;
            vfx.alphaTexture       = seamothvfx.alphaTexture;
            vfx.constructSound     = seamothvfx.constructSound;
            vfx.surfaceSplashSound = seamothvfx.surfaceSplashSound;
            vfx.delay                 = seamothvfx.delay;
            vfx.surfaceSplashFX       = seamothvfx.surfaceSplashFX;
            vfx.surfaceSplashVelocity = seamothvfx.surfaceSplashVelocity;

            var fx = sharkComp.fxControl = shark.EnsureComponent <SharkFXControl>();

            fx.shark   = sharkComp;
            fx.zoomFX  = shark.transform.Find("Scaler/FX/Boost").GetComponent <ParticleSystem>();
            fx.drillFX = shark.transform.Find("Scaler/FX/DrillParticleParent/DrillParticle").GetComponent <ParticleSystem>();
            fx.blinkFX = shark.transform.Find("Scaler/FX/BlinkParticles").GetComponent <ParticleSystem>();

            /*
             * VFXVolumetricLight lightfx = shark.EnsureComponent<VFXVolumetricLight>();
             * lightfx.volumGO = shark.transform.Find("Scaler/SharkMesh/VolumeLight").gameObject;
             * var seamothlight = sea.volumeticLights[0];
             * lightfx.coneMat = new Material(seamothlight.coneMat);
             * lightfx.sphereMat = new Material(seamothlight.sphereMat);
             * lightfx.volumGO.GetComponent<MeshRenderer>().material = lightfx.coneMat;
             * lightfx.intensity = seamothlight.intensity;
             * lightfx.startFallof = seamothlight.startFallof;
             * lightfx.startOffset = seamothlight.startOffset;
             * lightfx.softEdges = seamothlight.softEdges;
             * lightfx.nearClip = seamothlight.nearClip;
             * lightfx.lightSource = shark.transform.Find("Scaler/Headlights/Spot Light").GetComponent<Light>();
             */

            for (int i = 0; i < shark.transform.childCount; i++)
            {
                if (shark.transform.GetChild(i).name.Contains("buildbotpath"))
                {
                    GameObject.Destroy(shark.transform.GetChild(i).gameObject);
                }
            }

            foreach (BuildBotPath path in sea.GetComponentsInChildren <BuildBotPath>())
            {
                Transform newPathParent = new GameObject("buildbotpath").transform;
                newPathParent.parent           = shark.transform;
                newPathParent.localPosition    = Vector3.zero;
                newPathParent.localEulerAngles = Vector3.zero;
                BuildBotPath newPath = newPathParent.gameObject.AddComponent <BuildBotPath>();

                newPath.points = new Transform[path.points.Length];

                int num = 0;
                foreach (Transform trans in path.points)
                {
                    GameObject clone = new GameObject("pathnode" + num);
                    clone.transform.parent        = newPathParent;
                    clone.transform.localPosition = trans.localPosition;
                    clone.transform.localRotation = trans.localRotation;
                    newPath.points[num]           = clone.transform;
                    num++;
                }
            }

            Console.WriteLine("Setting up headlights");

            Transform headLightParent = shark.transform.Find("Scaler/Headlights");

            ToggleLights lights = shark.EnsureComponent <ToggleLights>();

            lights.lightsParent    = headLightParent.gameObject;
            lights.onSound         = sea.toggleLights.lightsOnSound.asset;
            lights.offSound        = sea.toggleLights.lightsOffSound.asset;
            lights.energyPerSecond = 0f;
            sharkComp.lights       = lights;

            Console.WriteLine("Adding smooth cam");

            SharkCameraSmooth camControl = shark.EnsureComponent <SharkCameraSmooth>();

            camControl.shark = sharkComp;
            control.cam      = camControl;

            Console.WriteLine("Adding battery power");

            Transform energyParent = shark.transform.Find("Scaler/BatteryPower").transform;



            sharkComp.energyInterface = shark.EnsureComponent <EnergyInterface>();

            EnergyMixin energy = energyParent.gameObject.EnsureComponent <EnergyMixin>();

            lights.energyMixin             = energy;
            energy.allowBatteryReplacement = true;
            energy.compatibleBatteries     = new List <TechType>
            {
                Shark.internalBattery
            };
            energy.defaultBattery = Shark.internalBattery;

            EnergyMixin.BatteryModels model = new EnergyMixin.BatteryModels();
            model.model = energyParent.Find("PowerCube").gameObject;
            model.model.GetComponent <MeshFilter>().mesh = MainPatch.bundle.LoadAsset <GameObject>("ioncube.obj").GetComponentInChildren <MeshFilter>().mesh;
            MeshRenderer meshRend = model.model.GetComponent <MeshRenderer>();

            meshRend.material = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            model.model.transform.localScale = ionCrystal.GetComponentInChildren <MeshFilter>().transform.lossyScale;
            model.techType       = Shark.internalBattery;
            energy.batteryModels = new EnergyMixin.BatteryModels[]
            {
                model,
            };

            energy.controlledObjects = new GameObject[] { };
            energy.storageRoot       = energyParent.gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.energyInterface.sources = new EnergyMixin[]
            {
                energy
            };

            var energySlot = energyParent.Find("InteractionHandler").gameObject.EnsureComponent <SharkEnergySlot>();

            energySlot.shark = sharkComp;

            Console.WriteLine("Setting up upgrade modules");

            sharkComp.modulesRoot = shark.transform.Find("Scaler/UpgradeModules").gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.weapons = shark.EnsureComponent <SharkGunControl>();
            sharkComp.weapons.weaponFXParent   = shark.transform.Find("Scaler/Weapons").gameObject;
            sharkComp.weapons.weaponModel      = shark.transform.Find("Scaler/SharkMesh/Lasers").gameObject;
            sharkComp.weapons.upgradeInstalled = false;

            sharkComp.blink                 = shark.EnsureComponent <SharkBlinkControl>();
            sharkComp.blink.blinkSound      = CraftData.GetPrefabForTechType(TechType.PropulsionCannon).GetComponent <PropulsionCannon>().shootSound;
            sharkComp.shield                = shark.EnsureComponent <SharkShieldControl>();
            sharkComp.shield.shieldRenderer = shark.transform.Find("Scaler/SharkMesh/Shield").gameObject;

            sharkComp.drill = shark.EnsureComponent <SharkDrillControl>();
            sharkComp.drill.upgradeModels = shark.transform.Find("Scaler/SharkMesh/DrillMeshes").gameObject;

            StorageContainer drillStorage = sharkComp.drill.storageContainer = shark.transform.Find("Scaler/StorageContainerParent").gameObject.EnsureComponent <StorageContainer>();

            drillStorage.storageRoot  = sharkComp.drill.storageContainer.gameObject.EnsureComponent <ChildObjectIdentifier>();
            drillStorage.width        = 4;
            drillStorage.height       = 5;
            drillStorage.storageLabel = "Drill Storage";
            drillStorage.hoverText    = "OpenStorage";
            drillStorage.container    = null;
            drillStorage.CreateContainer();

            var upgradeconsole = sharkComp.modulesRoot.gameObject.EnsureComponent <VehicleUpgradeConsoleInput>();

            sharkComp.upgradesInput = upgradeconsole;
            upgradeconsole.slots    = new VehicleUpgradeConsoleInput.Slot[4];

            Transform modules = sharkComp.modulesRoot.transform;

            upgradeconsole.flap      = modules.Find("Flap");
            upgradeconsole.collider  = modules.GetComponent <Collider>();
            upgradeconsole.timeClose = 0f;
            upgradeconsole.timeOpen  = 0f;

            int j = 0;

            foreach (string slot in sharkComp.slotIDs)
            {
                if (!Equipment.slotMapping.ContainsKey(slot))
                {
                    Equipment.slotMapping.Add(slot, (EquipmentType)MainPatch.sharkTech);
                }

                GameObject nextSlot = shark.transform.Find("Scaler/SharkMesh/Upgrades/Slot" + (j + 1)).gameObject;

                upgradeconsole.slots[j] = new VehicleUpgradeConsoleInput.Slot()
                {
                    id    = slot,
                    model = nextSlot
                };
                j++;
            }

            Console.WriteLine("Adding GUI");

            shark.EnsureComponent <SharkTestGUI>().shark = sharkComp;

            sharkComp.crushDamage                 = shark.EnsureComponent <CrushDamage>();
            sharkComp.crushDamage.crushDepth      = 500f;
            sharkComp.crushDamage.kBaseCrushDepth = 500f;
            sharkComp.crushDamage.liveMixin       = sharkComp.liveMixin;

            shark.EnsureComponent <SharkUIControl>().shark = sharkComp;

            sharkComp.impactdmg = shark.EnsureComponent <DealDamageOnImpact>();
            sharkComp.impactdmg.damageTerrain      = true;
            sharkComp.impactdmg.mirroredSelfDamage = true;

            Console.WriteLine("Beacon");

            PingType pingType = (PingType)MainPatch.sharkTech;

            GameObject   pingObj = Object.Instantiate(Resources.Load <GameObject>("VFX/xSignal"), shark.transform.position, Quaternion.identity);
            PingInstance ping    = pingObj.GetComponent <PingInstance>();

            ping.SetLabel("5H-4RK");
            ping.displayPingInManager = true;
            ping.pingType             = pingType;
            ping._label = "5H-4RK";
            ping.SetVisible(true);
            pingObj.transform.parent           = shark.transform;
            pingObj.transform.localPosition    = Vector3.zero;
            pingObj.transform.localEulerAngles = Vector3.zero;

            Console.WriteLine("Patching into cached pingtypestrings");

            if (!PingManager.sCachedPingTypeStrings.valueToString.ContainsKey(pingType))
            {
                PingManager.sCachedPingTypeStrings.valueToString.Add(pingType, "SharkPing");
            }

            sharkPrefabCache = shark;

            return(shark);
        }
Пример #22
0
        // Manage Lights icons
        internal static void ManageLights()
        {
            if (SeamothInfo.electricalModuleIn && SeamothInfo.seamothLinkModuleIn)
            {
                Vehicle      thisSeamoth      = (Player.main.GetVehicle() as SeaMoth);
                ToggleLights thisToggleLights = thisSeamoth.GetComponentInChildren <ToggleLights>();
                bool         LightsAreOn      = false;
                if (thisToggleLights != null)
                {
                    LightsAreOn = thisToggleLights.GetLightsActive();
                }

                if (!LightsAreOn)                         // lights are off
                {
                    if (!Vehicle_Update_Patch.HighBeamOn) // low beam on
                    {
                        if (ManageAllGUIElements.LightGrayUIGameObject != null)
                        {
                            ManageAllGUIElements.LightGrayUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject.SetActive(false);
                        }

                        if (ManageAllGUIElements.LightLowOffUIGameObject == null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject = PrepareGUIObjects.PrepareGUIObject("LightLowOffUI", GearInfo.light_Position);
                        }
                        if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject = PrepareGUISprite.PrepareGuiElement(ManageAllGUIElements.LightLowOffUIGameObject, "light_low_off_100x100", GearInfo.light_Position, GearInfo.light_Size);
                        }

                        if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject.SetActive(true);
                        }
                    }
                    else // high beam on
                    {
                        if (ManageAllGUIElements.LightGrayUIGameObject != null)
                        {
                            ManageAllGUIElements.LightGrayUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject.SetActive(false);
                        }

                        if (ManageAllGUIElements.LightHighOffUIGameObject == null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject = PrepareGUIObjects.PrepareGUIObject("LightHighOffUI", GearInfo.light_Position);
                        }
                        if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject = PrepareGUISprite.PrepareGuiElement(ManageAllGUIElements.LightHighOffUIGameObject, "light_high_off_100x100", GearInfo.light_Position, GearInfo.light_Size);
                        }

                        if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject.SetActive(true);
                        }
                    }
                }
                else // lights are on
                {
                    if (!Vehicle_Update_Patch.HighBeamOn) // low beam on
                    {
                        if (ManageAllGUIElements.LightGrayUIGameObject != null)
                        {
                            ManageAllGUIElements.LightGrayUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject.SetActive(false);
                        }

                        if (ManageAllGUIElements.LightLowOnUIGameObject == null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject = PrepareGUIObjects.PrepareGUIObject("LightLowOnUI", GearInfo.light_Position);
                        }
                        if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject = PrepareGUISprite.PrepareGuiElement(ManageAllGUIElements.LightLowOnUIGameObject, "light_low_on_100x100", GearInfo.light_Position, GearInfo.light_Size);
                        }

                        if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject.SetActive(true);
                        }
                    }
                    else // high beam on
                    {
                        if (ManageAllGUIElements.LightGrayUIGameObject != null)
                        {
                            ManageAllGUIElements.LightGrayUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOffUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightLowOnUIGameObject.SetActive(false);
                        }
                        if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOffUIGameObject.SetActive(false);
                        }

                        if (ManageAllGUIElements.LightHighOnUIGameObject == null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject = PrepareGUIObjects.PrepareGUIObject("LightHighOnUI", GearInfo.light_Position);
                        }
                        if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject = PrepareGUISprite.PrepareGuiElement(ManageAllGUIElements.LightHighOnUIGameObject, "light_high_on_100x100", GearInfo.light_Position, GearInfo.light_Size);
                        }

                        if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                        {
                            ManageAllGUIElements.LightHighOnUIGameObject.SetActive(true);
                        }
                    }
                }
            }
            else
            {
                if (ManageAllGUIElements.LightLowOnUIGameObject != null)
                {
                    ManageAllGUIElements.LightLowOnUIGameObject.SetActive(false);
                }
                if (ManageAllGUIElements.LightLowOffUIGameObject != null)
                {
                    ManageAllGUIElements.LightLowOffUIGameObject.SetActive(false);
                }
                if (ManageAllGUIElements.LightHighOffUIGameObject != null)
                {
                    ManageAllGUIElements.LightHighOffUIGameObject.SetActive(false);
                }
                if (ManageAllGUIElements.LightHighOnUIGameObject != null)
                {
                    ManageAllGUIElements.LightHighOnUIGameObject.SetActive(false);
                }

                if (ManageAllGUIElements.LightGrayUIGameObject == null)
                {
                    ManageAllGUIElements.LightGrayUIGameObject = PrepareGUIObjects.PrepareGUIObject("LightGrayUI", GearInfo.light_Position);
                }
                if (ManageAllGUIElements.LightGrayUIGameObject != null)
                {
                    ManageAllGUIElements.LightGrayUIGameObject = PrepareGUISprite.PrepareGuiElement(ManageAllGUIElements.LightGrayUIGameObject, "light_gray_100x100", GearInfo.light_Position, GearInfo.light_Size);
                }

                if (ManageAllGUIElements.LightGrayUIGameObject != null)
                {
                    ManageAllGUIElements.LightGrayUIGameObject.SetActive(true);
                }
            }
        }