Esempio n. 1
0
 private void Update()
 {
     if (health == null)
     {
         health = GetComponent <TurbineHealth>();
     }
     if (constructable == null)
     {
         constructable = gameObject.GetComponent <Constructable>();
     }
     if (constructable.constructed && Time.time > timeEastereggEnd && !NeedsMaintenance)
     {
         if (!loopSource.isPlaying)
         {
             loopSource.Play();
         }
         float amount = this.GetRechargeScalar() * DayNightCycle.main.deltaTime * 40f * WindyMultiplier(new Vector2(transform.position.x, transform.position.z));
         this.relay.ModifyPower(amount / 4f, out float num);
         if (QPatch.config.TurbineTakesDamage && health.health - num > 0f)
         {
             health.TakeDamage(num / 15f);
         }
         this.spin.spinSpeed    = amount * 10f;
         this.loopSource.volume = Mathf.Clamp(amount, 0.6f, 1f);
     }
     if (NeedsMaintenance)
     {
         this.spin.spinSpeed = 0f;
         loopSource.Stop();
     }
 }
Esempio n. 2
0
 void Start()
 {
     health = gameObject.AddComponent <TurbineHealth>();
     health.SetData();
     health.health = 200f;
     PDAEncyclopedia.Add("WindTurbine", true);
 }
Esempio n. 3
0
        void Start()
        {
            health = gameObject.EnsureComponent <TurbineHealth>(); //gameObject.AddComponent<TurbineHealth>();
            health.SetData();
            health.health = 200f;
#if SUBNAUTICA
            PDAEncyclopedia.Add("WindTurbine", true);
#elif BELOWZERO
            PDAEncyclopedia.Add("WindTurbine", true, false);
#endif
        }
Esempio n. 4
0
        private void Update()
        {
            if (health == null)
            {
                health = GetComponent <TurbineHealth>();
            }
            if (constructable == null)
            {
                constructable = gameObject.GetComponent <Constructable>();
            }

            if (NeedsMaintenance)
            {
                this.spin.spinSpeed = 0f;
                if (loopSource != null)
                {
                    loopSource.Stop();
                }
            }
            else if (constructable.constructed && Time.time > timeEastereggEnd)
            {
                float deltaTime = Time.deltaTime;
                if (!loopSource.isPlaying)
                {
                    loopSource.Play();
                }
                float amount   = this.GetRechargeScalar() * DayNightCycle.main.deltaTime * 40f * WindyMultiplier(new Vector2(transform.position.x, transform.position.z));
                float powerGen = QPatch.config.PowerProductionScale * amount / 4f;
                this.profileEnergy += powerGen;
                this.profileTime   += deltaTime;
                if (profileTime >= 1)
                {
                    this.generationRate = this.profileEnergy / this.profileTime;
                    this.profileEnergy  = 0f;
                    this.profileTime    = 0;
                }
                this.relay.ModifyPower(powerGen, out float num);
                float damage = 200f / QPatch.config.SecondsUntilNeedMaintenance * deltaTime;
                if (QPatch.config.TurbineTakesDamage && health.health - damage > 0f)
                {
                    health.TakeDamage(num / 15f);
                }
                this.spin.spinSpeed    = amount * 10f;
                this.loopSource.volume = Mathf.Clamp(amount, 0.6f, 1f);
            }
        }
Esempio n. 5
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                AssetBundleRequest request = QPatch.bundle.LoadAssetAsync <GameObject>("turbineprefab.prefab");
                yield return(request);

                prefab = request.asset as GameObject;
                prefab.SetActive(false); // Keep the prefab inactive until we're done adding components

                //Need a tech tag for most prefabs
                var techTag = prefab.EnsureComponent <TechTag>();
                techTag.type = TechType;

                // Set prefab identifier, not sure what this does
                var prefabId = prefab.EnsureComponent <PrefabIdentifier>();
                prefabId.ClassId = ClassID;

                //A collider for the turbine pole and builder tool
                var collider = prefab.EnsureComponent <BoxCollider>();
                collider.size   = new Vector3(2f, 17f, 2f);
                collider.center = new Vector3(0f, 9f, 0f);

                //Update all shaders
                var renderers = prefab.GetComponentsInChildren <Renderer>();
                var shader    = Shader.Find("MarmosetUBER");

                foreach (var renderer in renderers)
                {
                    foreach (Material mat in renderer.materials)
                    {
                        mat.shader = shader;
                        mat.SetTexture("_Specular", mat.mainTexture);
                        if (mat.name.StartsWith("Mat5"))
                        {
                            mat.EnableKeyword("MARMO_EMISSION");
                            mat.SetVector("_EmissionColor", new Color(1f, 0.3f, 0f) * 1f);
                            mat.SetVector("_Illum_ST", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
                        }
                    }
                }

                var skyApplier = prefab.AddComponent <SkyApplier>();
                skyApplier.renderers = renderers;
                skyApplier.anchorSky = Skies.Auto;

                // Add constructable - This prefab normally isn't constructed.
                Constructable constructible = prefab.EnsureComponent <Constructable>();
                constructible.allowedInBase           = false;
                constructible.allowedInSub            = false;
                constructible.allowedOutside          = true;
                constructible.allowedOnCeiling        = false;
                constructible.allowedOnGround         = true;
                constructible.allowedOnWall           = false;
                constructible.allowedOnConstructables = true;
                constructible.techType             = this.TechType;
                constructible.rotationEnabled      = true;
                constructible.placeDefaultDistance = 6f;
                constructible.placeMinDistance     = 0.5f;
                constructible.placeMaxDistance     = 15f;
                constructible.surfaceType          = VFXSurfaceTypes.metal;
                constructible.model        = prefab.FindChild("Pole");
                constructible.forceUpright = true;

                prefab.FindChild("Blade Parent").EnsureComponent <Light>();

                var         bounds  = prefab.EnsureComponent <ConstructableBounds>();
                WindTurbine turbine = prefab.EnsureComponent <WindTurbine>();

                GameObject lightEmitter = new GameObject("Light Emitter");
                lightEmitter.transform.parent        = prefab.transform;
                lightEmitter.transform.localPosition = new Vector3(0f, 2f, 0f);
                var light = lightEmitter.EnsureComponent <Light>();
                light.intensity             = 1f;
                light.range                 = 20f;
                light.lightShadowCasterMode = LightShadowCasterMode.Everything;

                AssetBundleRequest request2 = QPatch.bundle.LoadAssetAsync <AudioClip>("turbineloop");
                yield return(request2);

                turbine.soundLoop = request2.asset as AudioClip;
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SolarPanel);
                yield return(task);

                PowerRelay     powerRelay = GameObject.Instantiate(task.GetResult()).GetComponent <PowerRelay>();
                IPrefabRequest req3       = PrefabDatabase.GetPrefabForFilenameAsync("Base/Ghosts/PowerSystemPreview.prefab");
                yield return(req3);

                if (req3.TryGetPrefab(out powerRelay.powerSystemPreviewPrefab))
                {
                    turbine.relayPrefab = powerRelay;
                }
                TurbineHealth turbineHealth = prefab.EnsureComponent <TurbineHealth>();
                PowerSource   powerSource   = prefab.EnsureComponent <PowerSource>();
                powerSource.maxPower           = QPatch.config.MaxPower;
                powerRelay.internalPowerSource = powerSource;
                powerRelay.dontConnectToRelays = false;
                powerRelay.maxOutboundDistance = 50;
                //powerRelay.powerSystemPreviewPrefab = Resources.Load<GameObject>("Base/Ghosts/PowerSystemPreview.prefab");
                turbine.Activate();
            }
            prefab.SetActive(true);
            gameObject.Set(prefab);
        }