예제 #1
0
        private void OnDestroy()
        {
            double resourceAmount    = 0f;
            double resourceMaxAmount = 0f;
            int    resourceId        = PartResourceLibrary.Instance.GetDefinition("EngineIgnitors").id;

            if (part != null)
            {
                part.GetConnectedResourceTotals(resourceId, out resourceAmount, out resourceMaxAmount);
            }

            if (File.Exists <EngineIgnitorEVA>(_kerbal.name + ".sav"))
            {
                File.Delete <EngineIgnitorEVA>(_kerbal.name + ".sav");
            }
            if (resourceAmount > 0)
            {
                using (var file = File.Create <EngineIgnitorEVA>(_kerbal.name + ".sav"))
                {
                    var aaa1 = vessel;
                    var aaa2 = vessel.id;
                    var aaa3 = vessel.name;

                    var bbb1 = FlightGlobals.ActiveVessel;
                    var bbb2 = FlightGlobals.ActiveVessel.id.GetHashCode();
                    var bbb3 = FlightGlobals.ActiveVessel.name;

                    var info = new KerbalInfo
                    {
                        VesselId      = FlightGlobals.ActiveVessel.id.GetHashCode(),
                        KerbalName    = _kerbal.name,
                        Time          = Planetarium.GetUniversalTime().GetHashCode(),
                        FoundIgnitors = resourceAmount
                    };

                    var result = IOUtils.SerializeToBinary(info);

                    file.Write(result, 0, result.Length);
                }
            }
        }
예제 #2
0
        public override void OnStart(StartState state)
        {
            _kerbal = vessel.GetVesselCrew().First();
            var evaKerbalExp  = _kerbal.experienceTrait.Title;
            var evaKerbalMale = _kerbal.gender == ProtoCrewMember.Gender.Male;

            if (!evaKerbalExp.Equals("Engineer") || !evaKerbalMale)
            {
                part.RemoveResource("EngineIgnitors");
            }
            else
            {
                if (File.Exists <EngineIgnitorEVA>(_kerbal.name + ".sav"))
                {
                    using (var file = File.Open <EngineIgnitorEVA>(_kerbal.name + ".sav", FileMode.Open))
                    {
                        var buffer = new byte[file.Length];

                        file.Read(buffer, 0, buffer.Length);

                        var result = IOUtils.DeserializeFromBinary(buffer) as KerbalInfo;

                        if (result != null)
                        {
                            _info = result;
                            var currentTime   = Planetarium.GetUniversalTime().GetHashCode();
                            var currentVessel = FlightGlobals.ActiveVessel.id.GetHashCode();

                            if (currentTime > _info.Time && currentVessel == _info.VesselId)
                            {
                                int resourceId = PartResourceLibrary.Instance.GetDefinition("EngineIgnitors").id;
                                part.RequestResource(resourceId, -_info.FoundIgnitors);
                            }
                        }
                    }
                }
            }
        }