Example #1
0
        /// <summary>
        /// Module re-start logic. OnStart will be called usually once for each scene,
        /// editor included.
        /// Put your custom start logic in DI_Start(): if you need to act on other part's
        /// variable, this is the place to do it, not DI_Reset()
        /// </summary>
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                if (HighLogic.LoadedSceneIsFlight) // nothing to do in editor
                {
                    this.Log("Starting in flight: last reset " + TimeOfLastReset + ", now " + DangIt.Now());

                    // Reset the internal state at the beginning of the flight
                    // this condition also catches a revert to launch (+1 second for safety)
                    if (DangIt.Now() < (this.TimeOfLastReset + 1))
                        this.Reset();

                    // If the part was saved when it was failed,
                    // re-run the failure logic to disable it
                    // ONLY THE DISABLING PART IS RUN!
                    if (this.HasFailed)
                        this.DI_Disable();

                    DangIt.ResetShipGlow(this.part.vessel);
                }

                this.DI_Start(state);
                this.StartCoroutine("RuntimeFetch");
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
Example #2
0
        public void EvaRepair()
        {
            try
            {
                this.Log("Initiating EVA repair");

                // Get the EVA part (parts can hold resources)
                Part evaPart = DangIt.FindEVAPart();

                if (evaPart == null)
                {
                    DangIt.Broadcast("DangIt ERROR: couldn't find an active EVA!");
                    this.Log("ERROR: couldn't find an active EVA!");
                    return;
                }

                // Check if he is carrying enough spares
                if (evaPart.Resources.Contains(Spares.Name) && evaPart.Resources[Spares.Name].amount >= this.RepairCost)
                {
                    this.Log("Spare parts check: OK! Repair allowed");

                    this.DI_EvaRepair();
                    this.SetFailureState(false);

                    DangIt.FlightLog(this.RepairMessage);

                    float intelligence = 1 - evaPart.vessel.GetVesselCrew().First().stupidity;
                    float discountedCost = (float)Math.Round( RepairCost * (1 - UnityEngine.Random.Range(0f, intelligence)) );
                    float discount = RepairCost - discountedCost;

                    this.Log("Kerbal's intelligence: " + intelligence + ", discount: " + discount);

                    evaPart.RequestResource(Spares.Name, discountedCost);
                    ResourceDisplay.Instance.Refresh();

                    DangIt.Broadcast(this.RepairMessage, true);

                    DiscountAge(this.RepairBonus);

                    if (discount > 0)
                    {
                        DangIt.Broadcast(evaPart.vessel.GetVesselCrew().First().name + " was able to save " + discount + " spare parts");
                    }

                }
                else
                {
                    this.Log("Spare parts check: failed! Repair NOT allowed");
                    DangIt.Broadcast("You need " + this.RepairCost + " spares to repair this.", true);
                }

                DangIt.ResetShipGlow(this.part.vessel);

            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
Example #3
0
        public void EvaRepair()
        {
            try
            {
                this.Log("Initiating EVA repair");

                // Get the EVA part (parts can hold resources)
                Part evaPart = DangIt.FindEVAPart();

                if (evaPart == null)
                {
                    throw new Exception("ERROR: couldn't find an active EVA!");
                }

                // Check if the kerbal is able to perform the repair
                if (CheckRepairConditions(evaPart))
                {
                    this.DI_EvaRepair();
                    this.SetFailureState(false);

                    DangIt.FlightLog(this.RepairMessage);

                    //TODO: experience repair boni
                    float intelligence   = 1 - evaPart.protoModuleCrew[0].stupidity;
                    float discountedCost = (float)Math.Round(RepairCost * (1 - UnityEngine.Random.Range(0f, intelligence)));
                    float discount       = RepairCost - discountedCost;

                    this.Log("Kerbal's intelligence: " + intelligence + ", discount: " + discount);

                    // One more MC2 hack - TrypChangeling
                    // evaPart.RequestResource(Spares.Name, discountedCost);
                    evaPart.Resources[Spares.Name].amount -= discountedCost;
                    ResourceDisplay.Instance.Refresh();

                    DangIt.Broadcast(this.RepairMessage, true);
                    this.DiscountAge(this.RepairBonus);

                    if (discount > 0)
                    {
                        DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " was able to save " + discount + " spare parts");
                    }

                    FindObjectOfType <AlarmManager>().RemoveAllAlarmsForModule(this);                    //Remove alarms from this module
                }

                DangIt.ResetShipGlow(this.part.vessel);
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
Example #4
0
        /// <summary>
        /// Sets / resets the failure of the part.
        /// Also resets the ship's glow and sets the event's visibility
        /// </summary>
        protected void SetFailureState(bool state)
        {
            try
            {
                this.HasFailed = state;
                DangIt.ResetShipGlow(this.part.vessel);

                Events["Fail"].active        = !state;
                Events["EvaRepair"].active   = state;
                Events["Maintenance"].active = !state;
            }
            catch (Exception e)
            {
                this.OnError(e);
            }
        }