コード例 #1
0
ファイル: FailureModule.cs プロジェクト: zhichaoxi2006/DangIt
        public void Maintenance()
        {
            this.Log("Initiating EVA maitenance");

            // 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.MaintenanceCost)
            {
                this.Log("Spare parts check: OK! Maintenance allowed allowed");
                DiscountAge(this.MaintenanceBonus);
                DangIt.Broadcast("This should last a little longer now");
            }
            else
            {
                this.Log("Spare parts check: failed! Maintenance NOT allowed");
                DangIt.Broadcast("You need " + this.MaintenanceCost + " spares to maintain this.");
            }
        }
コード例 #2
0
        protected void EmptyEvaSuit(Part evaPart, Part container)
        {
            this.Log("Emptying the EVA suit from " + evaPart.name + " to " + container.name);

            // Compute how much can be left in the container
            double capacity = container.Resources[Spares.Name].maxAmount - container.Resources[Spares.Name].amount;
            double deposit  = Math.Min(evaPart.Resources[Spares.Name].amount, capacity);

            // Add it to the spares container and drain it from the EVA part
            container.RequestResource(Spares.Name, -deposit);
            // Once again, MC2 breaks the RequestResource on evaPart, but with the above checks, decrementing should work just fine instead, I think! -TrypChangeling
            //evaPart.RequestResource(Spares.Name, deposit);
            evaPart.Resources[Spares.Name].amount -= deposit;

            // GUI acknowledge
            try
            {
                DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " has left " + deposit + " spares", false, 1f);
            }
            catch (Exception) // The kerbal reenters before this method is called: in that case, trying to get his name will throw an exception
            {
                DangIt.Broadcast("You left " + deposit + " spares", false, 1f);
            }

            ResourceDisplay.Instance.Refresh();
        }
コード例 #3
0
        protected void FillEvaSuit(Part evaPart, Part container)
        {
            // Check if the EVA part contains the spare parts resource: if not, add a new config node
            if (!evaPart.Resources.Contains(Spares.Name))
            {
                this.Log("The eva part doesn't contain spares, adding the config node");

                ConfigNode node = new ConfigNode("RESOURCE");
                node.AddValue("name", Spares.Name);
                node.AddValue("maxAmount", Spares.MaxEvaAmount);
                node.AddValue("amount", 0);
                evaPart.Resources.Add(node);
            }


            // Compute how much the kerbal can take
            double desired     = Math.Min(Spares.MaxEvaAmount - evaPart.Resources[Spares.Name].amount, Spares.Increment);
            double amountTaken = Math.Min(desired, container.Resources[Spares.Name].amount);

            // Take it from the container and add it to the EVA
            container.RequestResource(Spares.Name, amountTaken);
            evaPart.RequestResource(Spares.Name, -amountTaken);

            // GUI stuff
            DangIt.Broadcast(evaPart.vessel.GetVesselCrew().First().name + " has taken " + amountTaken + " spares", false, 1f);
            ResourceDisplay.Instance.Refresh();
        }
コード例 #4
0
ファイル: FailureModule.cs プロジェクト: zhichaoxi2006/DangIt
        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);
            }
        }
コード例 #5
0
ファイル: FailureModule.cs プロジェクト: deimos790/DangIt
        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);
            }
        }
コード例 #6
0
ファイル: FailureModule.cs プロジェクト: deimos790/DangIt
        public void Fail()
        {
            try
            {
                this.Log("Initiating Fail()");

                // First, run the custom failure logic
                // The child class can refuse to fail in FailBegin()
                if (!this.DI_FailBegin())
                {
                    this.Log(this.DebugName + " has not agreed to fail, failure aborted!");
                    return;
                }
                else
                {
                    this.Log(this.DebugName + " has agreed to fail, failure allowed.");
                }

                // If control reaches this point, the child class has agreed to fail
                // Disable the part and handle the internal state and notifications

                this.DI_Disable();

                TimeWarp.SetRate(0, true);      // stop instantly
                this.SetFailureState(true);     // Sets the failure state, handles the events, handles the glow

                if (!this.Silent)
                {
                    DangIt.Broadcast(this.FailureMessage);
                    DangIt.PostMessage("Failure!",
                                       this.FailureMessage,
                                       MessageSystemButton.MessageButtonColor.RED,
                                       MessageSystemButton.ButtonIcons.ALERT);

                    if (FindObjectOfType <AlarmManager>() != null)
                    {
                        FindObjectOfType <AlarmManager>().AddAlarm(this, DangIt.Instance.CurrentSettings.GetSoundLoopsForPriority(Priority));
                        if (FindObjectOfType <AlarmManager>().HasAlarmsForModule(this))
                        {
                            Events ["MuteAlarms"].active    = true;
                            Events ["MuteAlarms"].guiActive = true;
                        }
                    }
                }

                DangIt.FlightLog(this.FailureMessage);
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
コード例 #7
0
ファイル: FailureModule.cs プロジェクト: deimos790/DangIt
        public void Maintenance()
        {
            this.Log("Initiating EVA maitenance");

            Part evaPart = DangIt.FindEVAPart();

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

            if (!CheckOutExperience(evaPart.protoModuleCrew[0]))
            {
                DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " isn't really qualified for this...", true);
                return;
            }

            if (this.part.temperature > DangIt.Instance.CurrentSettings.GetMaxServicingTemp())
            {
                DangIt.Broadcast("This is too hot to service right now", true);
                return;
            }


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

                // Consume the spare parts
                // MC2 Breaks RequestResource, since amount is checked, simply decrement! Just like in SparesContainer! Whee! -TrypChangeling
                // evaPart.RequestResource(Spares.Name, this.MaintenanceCost);
                evaPart.Resources[Spares.Name].amount -= this.MaintenanceCost;

                // Distance between the kerbal's perks and the required perks, used to scale the maintenance bonus according to the kerbal's skills
                int expDistance = evaPart.protoModuleCrew[0].experienceLevel - this.PerksRequirementValue;

                //// The higher the skill gap, the higher the maintenance bonus
                //// The + 1 is there to makes it so that a maintenance bonus is always gained even when the perks match exactly
                this.DiscountAge(this.MaintenanceBonus * ((expDistance + 1) / 3));

                DangIt.Broadcast("This should last a little longer now");
            }
            else
            {
                this.Log("Spare parts check: failed! Maintenance NOT allowed");
                DangIt.Broadcast("You need " + this.MaintenanceCost + " spares to maintain this.");
            }
        }
コード例 #8
0
ファイル: FailureModule.cs プロジェクト: deimos790/DangIt
        /// <summary>
        /// Check if a kerbal is able to repair a part,
        /// factoring spares, perks, and additional conditions
        /// </summary>
        private bool CheckRepairConditions(Part evaPart)
        {
            bool   allow  = true;
            string reason = string.Empty;


            #region Amount of spare parts
            if (!evaPart.Resources.Contains(Spares.Name) || evaPart.Resources[Spares.Name].amount < this.RepairCost)
            {
                allow  = false;
                reason = "not carrying enough spares";
                DangIt.Broadcast("You need " + this.RepairCost + " spares to repair this.", true);
            }
            #endregion

            #region Part temperature
            if (this.part.temperature > DangIt.Instance.CurrentSettings.GetMaxServicingTemp())
            {
                allow  = false;
                reason = "part is too hot (" + part.temperature.ToString() + " degrees)";
                DangIt.Broadcast("This is too hot to service right now", true);
            }
            #endregion


            if (!CheckOutExperience(evaPart.protoModuleCrew[0]))
            {
                allow  = false;
                reason = "perks don't match requirements";
                DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " has no idea how to fix this...", true);
            }


            if (allow)
            {
                this.Log("Repair allowed!");
            }
            else
            {
                this.Log("Repair NOT allowed. Reason: " + reason);
            }

            return(allow);
        }
コード例 #9
0
ファイル: FailureModule.cs プロジェクト: zhichaoxi2006/DangIt
        public void Fail()
        {
            try
            {
                this.Log("Initiating Fail()");

                // First, run the custom failure logic
                // The child class can refuse to fail in FailBegin()
                if (!this.DI_FailBegin())
                {
                    this.Log(this.DebugName + " has not agreed to fail, failure aborted!");
                    return;
                }
                else
                {
                    this.Log(this.DebugName + " has agreed to fail, failure allowed.");
                }

                // If control reaches this point, the child class has agreed to fail
                // Disable the part and handle the internal state and notifications

                this.DI_Disable();

                TimeWarp.SetRate(0, true);      // stop instantly
                this.SetFailureState(true);     // Sets the failure state, handles the events, handles the glow

                if (!this.Silent)
                {
                    DangIt.Broadcast(this.FailureMessage);
                    DangIt.PostMessage("Failure!",
                                       this.FailureMessage,
                                       MessageSystemButton.MessageButtonColor.RED,
                                       MessageSystemButton.ButtonIcons.ALERT);

                }

                DangIt.FlightLog(this.FailureMessage);

            }
            catch (Exception e)
            {
                OnError(e);
            }
        }
コード例 #10
0
        protected void FillEvaSuit(Part evaPart, Part container)
        {
            // Check if the EVA part contains the spare parts resource: if not, add a new config node
            if (!evaPart.Resources.Contains(Spares.Name))
            {
                this.Log("The eva part doesn't contain spares, adding the config node");

                ConfigNode node = new ConfigNode("RESOURCE");
                node.AddValue("name", Spares.Name);
                node.AddValue("maxAmount", Spares.MaxEvaAmount);
                node.AddValue("amount", 0);
                evaPart.Resources.Add(node);
            }

            // Override maxAmount set by other mods (such as MC2) causing taking of parts to fail -TrypChangeling
            if (evaPart.Resources[Spares.Name].maxAmount < Spares.MaxEvaAmount)
            {
                evaPart.Resources[Spares.Name].maxAmount = Spares.MaxEvaAmount;
            }


            // Compute how much the kerbal can take
            double desired = Spares.MaxEvaAmount - evaPart.Resources[Spares.Name].amount;

            desired = Math.Min(desired, Spares.MinIncrement);
            double amountTaken = Math.Min(desired, container.Resources[Spares.Name].amount);

            // Take it from the container and add it to the EVA
            container.RequestResource(Spares.Name, amountTaken);
            // RequestResource is being overridden by MC2 for some reason - however, with above checks, simply incrementing the value should work... I think! - TrypChangeling
            // evaPart.RequestResource(Spares.Name, -amountTaken);
            evaPart.Resources[Spares.Name].amount += amountTaken;

            // GUI stuff
            DangIt.Broadcast(evaPart.vessel.GetVesselCrew().First().name + " has taken " + amountTaken + " spares", false, 1f);
            ResourceDisplay.Instance.Refresh();
        }
コード例 #11
0
        /*
         * [KSPEvent(guiActiveUnfocused = false, unfocusedRange = DangIt.EvaRepairDistance, guiName = "Show perks", active = false)]
         * public void ShowPerks()
         * {
         *  try
         *  {
         *      ICrewFilesServer server = CrewFilesManager.Server;
         *
         *      if (server == null) throw new Exception("server is null!");
         *
         *      ProtoCrewMember kerbal = DangIt.FindEVAPart().vessel.GetVesselCrew().First();
         *      ConfigNode kerbalFile = server.GetKerbalFile(kerbal);
         *
         *      if (kerbalFile == null) throw new Exception("kerbalFile is null!");
         *
         *      ConfigNode perksNode = kerbalFile.GetNode(PerkGenerator.NodeName);
         *
         *      if (perksNode == null) throw new Exception("perksNode is null!");
         *
         *      this.Log(kerbal.name + " has " + perksNode.CountNodes + " perks");
         *  }
         *  catch (Exception e)
         *  {
         *      this.Log(e.Message);
         *      return;
         *  }
         *
         * }
         */


        protected void EmptyEvaSuit(Part evaPart, Part container)
        {
            this.Log("Emptying the EVA suit from " + evaPart.name + " to " + container.name);

            // Compute how much can be left in the container
            double capacity = container.Resources[Spares.Name].maxAmount - container.Resources[Spares.Name].amount;
            double deposit  = Math.Min(evaPart.Resources[Spares.Name].amount, capacity);

            // Add it to the spares container and drain it from the EVA part
            container.RequestResource(Spares.Name, -deposit);
            evaPart.RequestResource(Spares.Name, deposit);

            // GUI acknowledge
            try
            {
                DangIt.Broadcast(evaPart.protoModuleCrew[0].name + " has left " + deposit + " spares", false, 1f);
            }
            catch (Exception)
            {
                DangIt.Broadcast("You left " + deposit + " spares", false, 1f);
            }

            ResourceDisplay.Instance.Refresh();
        }