public void OnProtoSerialize(ProtobufSerializer serializer)
        {
            QuickLogger.Info($"Saving {_prefabID.Id} Data");

            if (!Directory.Exists(SaveDirectory))
            {
                Directory.CreateDirectory(SaveDirectory);
            }

            var saveData = new SaveData
            {
                HasBreakerTripped = PowerManager.GetHasBreakerTripped(),
                TurbineRot        = new TargetRotation(_targetRotation),
                Health            = HealthManager.GetHealth(),
                Charge            = PowerManager.GetCharge(),
                DegPerSec         = BiomeManager.GetBiomeData(_currentBiome).Speed,
                Biome             = _currentBiome,
                CurrentSpeed      = _currentSpeed,
                PassedTime        = HealthManager.GetPassedTime(),
                StoredPower       = PowerManager.GetStoredPower()
            };

            var output = JsonConvert.SerializeObject(saveData, Formatting.Indented);

            File.WriteAllText(SaveFile, output);

            QuickLogger.Info($"Saved {_prefabID.Id} Data");


            //TODO Replace this
            //LoadItems.CleanOldSaveData();
        }
        private void SystemHandler()
        {
            if (MaxSpeed <= 0)
            {
                MaxSpeed = BiomeManager.GetBiomeData(_currentBiome).Speed;
            }


            /*
             * Handles starting and stopping the turbine and its rotor based off conditions
             */
            if (IsConstructed)
            {
                if (PowerManager.GetHasBreakerTripped() || !IsUnderWater() || HealthManager.GetHealth() <= 0)
                {
                    if (!string.IsNullOrEmpty(_currentBiome))
                    {
                        ChangeMotorSpeed(MaxSpeed);
                    }
                    StopMotor();
                }
                else
                {
                    if (!string.IsNullOrEmpty(_currentBiome))
                    {
                        ChangeMotorSpeed(MaxSpeed);
                    }
                    StartMotor();
                    RotateRotor();
                }
            }
        }
        private void Initialize()
        {
            _buildable = GetComponent <Constructable>() ?? GetComponentInParent <Constructable>();

            if (FindComponents())
            {
                QuickLogger.Debug($"Turbine Components Found", true);

                _prefabID = GetComponentInParent <PrefabIdentifier>();

                var currentBiome = BiomeManager.GetBiome();

                if (!string.IsNullOrEmpty(currentBiome))
                {
                    var data = BiomeManager.GetBiomeData(currentBiome);
                }

                AISolutionsData.Instance.OnRotationChanged += AiSolutionsDataOnOnRotationChanged;

                if (HealthManager == null)
                {
                    HealthManager = gameObject.GetComponent <AIJetStreamT242HealthManager>() ?? GetComponentInParent <AIJetStreamT242HealthManager>();
                }


                HealthManager.Initialize(this);
                HealthManager.SetHealth(100);
                HealthManager.SetDamageModel(_damage);

                if (PowerManager == null)
                {
                    PowerManager          = GetComponentInParent <AIJetStreamT242PowerManager>() ?? GetComponent <AIJetStreamT242PowerManager>();
                    PowerManager.maxPower = 300;
                }



                if (PowerRelay == null)
                {
                    PowerRelay = gameObject.AddComponent <PowerRelay>();

                    PowerRelay.internalPowerSource = PowerManager;
                    PowerRelay.maxOutboundDistance = 15;
                    PowerRelay.dontConnectToRelays = false;


                    PowerFX    yourPowerFX = gameObject.AddComponent <PowerFX>();
                    PowerRelay powerRelay  = CraftData.GetPrefabForTechType(TechType.SolarPanel).GetComponent <PowerRelay>();

                    yourPowerFX.vfxPrefab   = powerRelay.powerFX.vfxPrefab;
                    yourPowerFX.attachPoint = gameObject.transform;
                    PowerRelay.powerFX      = yourPowerFX;

                    Resources.UnloadAsset(powerRelay);
                }

                PowerManager.Initialize(this);

                AnimationManager = gameObject.GetComponentInParent <AIJetStreamT242AnimationManager>();

                BeaconManager = gameObject.GetComponentInParent <BeaconController>();

                if (_display == null)
                {
                    _display = GetComponent <AIJetStreamT242Display>() ?? GetComponentInParent <AIJetStreamT242Display>();
                }

                IsInitialized = true;
                //_currentBiome = BiomeManager.GetBiome();
            }
            else
            {
                IsInitialized = false;
                throw new MissingComponentException("Failed to find all components");
            }

            if (!IsInitialized)
            {
                return;
            }

            PowerManager.OnKillBattery += Unsubscribe;
        }
Esempio n. 4
0
        private void Initialize()
        {
            _buildable = GetComponent <Constructable>() ?? GetComponentInParent <Constructable>();

            if (FindComponents())
            {
                QuickLogger.Debug($"Turbine Components Found", true);

                _prefabID = GetComponentInParent <PrefabIdentifier>();

                var currentBiome = BiomeManager.GetBiome();

                if (!string.IsNullOrEmpty(currentBiome))
                {
                    var data = BiomeManager.GetBiomeData(currentBiome);
                }

                AISolutionsData.Instance.OnRotationChanged += AiSolutionsDataOnOnRotationChanged;

                if (HealthManager == null)
                {
                    HealthManager = gameObject.GetComponent <AIJetStreamT242HealthManager>() ?? GetComponentInParent <AIJetStreamT242HealthManager>();
                }


                HealthManager.Initialize(this);
                HealthManager.SetHealth(100);
                HealthManager.SetDamageModel(_damage);

                if (PowerManager == null)
                {
                    PowerManager = GetComponentInParent <AIJetStreamT242PowerManager>() ?? GetComponent <AIJetStreamT242PowerManager>();
                }

                PowerManager.Initialize(this);

                AnimationManager = gameObject.GetComponentInParent <AIJetStreamT242AnimationManager>();

                BeaconManager = gameObject.GetComponentInParent <BeaconController>();

                if (_display == null)
                {
                    _display = GetComponent <AIJetStreamT242Display>() ?? GetComponentInParent <AIJetStreamT242Display>();
                }

                IsInitialized = true;
                //_currentBiome = BiomeManager.GetBiome();
            }
            else
            {
                IsInitialized = false;
                throw new MissingComponentException("Failed to find all components");
            }

            if (!IsInitialized)
            {
                return;
            }

            PowerManager.OnKillBattery += Unsubscribe;
        }