Ejemplo n.º 1
0
        protected void calculateRemodelCostModifier(string skillRequired = "Engineer")
        {
            int highestLevel = 0;

            //Check for a kerbal on EVA
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                if (experience.TypeName == skillRequired)
                {
                    reconfigureCostModifier = baseSkillModifier * experience.CrewMemberExperienceLevel();
                    return;
                }
            }

            //No kerbal on EVA. Check the part for the highest ranking kerbal onboard with the required skill.
            if (this.part.CrewCapacity > 0)
            {
                foreach (ProtoCrewMember protoCrew in this.part.protoModuleCrew)
                {
                    if (protoCrew.experienceTrait.TypeName == skillRequired)
                    {
                        if (protoCrew.experienceLevel > highestLevel)
                        {
                            highestLevel = protoCrew.experienceLevel;
                        }
                    }
                }
            }

            reconfigureCostModifier = baseSkillModifier * highestLevel;
        }
Ejemplo n.º 2
0
        protected void reconfigureDrill()
        {
            //If required, make sure we have the proper skill
            if (PathfinderSettings.requireSkillCheck)
            {
                if (FlightGlobals.ActiveVessel.isEVA)
                {
                    Vessel vessel = FlightGlobals.ActiveVessel;
                    Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                    if (experience.TypeName != requiredSkill)
                    {
                        ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, requiredSkill), 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }

            //If needed, pay the cost to reconfigure
            if (PathfinderSettings.payToRemodel)
            {
                //Make sure we can afford it
                PartResourceDefinition definition = ResourceHelper.DefinitionForResource(requiredResource);

                //Pay for the reconfiguration cost.
                double partsPaid = this.part.RequestResource(definition.id, reconfigureCost, ResourceFlowMode.ALL_VESSEL);

                //Could we afford it?
                if (Math.Abs(partsPaid) / Math.Abs(reconfigureCost) < 0.999f)
                {
                    ScreenMessages.PostScreenMessage(string.Format(insufficientResourcesMsg, reconfigureCost, requiredResource), 6.0f, ScreenMessageStyle.UPPER_CENTER);

                    //Put back what we took
                    this.part.RequestResource(definition.id, -partsPaid, ResourceFlowMode.ALL_VESSEL);
                    return;
                }
            }

            //Now reconfigure the drill.
            ModuleResourceHarvester drill;

            PResource.Resource res;
            for (int drillIndex = 0; drillIndex < groundDrills.Count; drillIndex++)
            {
                drill = groundDrills[drillIndex];
                res   = resourceList[groundDrillResourceIndexes[drillIndex]];
                setupDrillGUI(drill, res);
            }
            ScreenMessages.PostScreenMessage(kDrillReconfigured, 5.0f, ScreenMessageStyle.UPPER_CENTER);
        }
Ejemplo n.º 3
0
        public void ShowDrillSwitchWindow()
        {
            //Make sure we have an experienced engineer.
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                if (experience.TypeName != "Engineer" && PathfinderSettings.requireSkillCheck)
                {
                    ScreenMessages.PostScreenMessage(kEngineerNeeded, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
            }

            drillSwitchWindow.groundDrills = groundDrills;
            drillSwitchWindow.SetVisible(true);
        }
Ejemplo n.º 4
0
        protected float calculateRepairCost()
        {
            float repairUnits = repairAmount;

            if (FlightGlobals.ActiveVessel.isEVA == false)
            {
                return(-1.0f); //Should not get to here as the event is set up for EVA only.
            }

            //Anybody can repair the scope, but the right skill can reduce the cost by as much as 60%
            Experience.ExperienceTrait experience = FlightGlobals.ActiveVessel.GetVesselCrew()[0].experienceTrait;
            if (experience.TypeName == repairSkill)
            {
                repairUnits = repairUnits * (0.9f - (experience.CrewMemberExperienceLevel() * 0.1f));
            }

            //Now make sure the kerbal has enough resources to conduct repairs.
            //Get the resource definition
            PartResourceDefinition definition = ResourceHelper.DefinitionForResource(repairResource);

            if (definition == null)
            {
                return(-1.0f);
            }

            //make sure the ship has enough of the resource
            Vessel.ActiveResource activeResource = FlightGlobals.ActiveVessel.GetActiveResource(definition);
            if (activeResource == null)
            {
                return(-1.0f);
            }

            if (activeResource.amount < repairUnits)
            {
                return(-1.0f);
            }

            return(repairUnits);
        }
Ejemplo n.º 5
0
        protected bool hasSufficientSkill()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!WBIMainSettings.RequiresSkillCheck)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(skillRequired))
            {
                return(true);
            }
            bool hasAtLeastOneCrew = false;

            //Tearing down the current configuration returns 70% of the current configuration's resource, plus 5% per skill point
            //of the highest ranking kerbal in the module with the appropriate skill required to reconfigure, or 5% per skill point
            //of the kerbal on EVA if the kerbal has the required skill.
            //If anybody can reconfigure the module to the desired template, then get the highest ranking Engineer and apply his/her skill bonus.
            if (string.IsNullOrEmpty(skillRequired))
            {
                calculateRemodelCostModifier();
                return(true);
            }

            //Make sure we have an experienced person either out on EVA performing the reconfiguration, or inside the module.
            //Check EVA first
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                if (experience.TypeName != skillRequired)
                {
                    ScreenMessages.PostScreenMessage(kInsufficientSkill + Utils.GetTraitsWithEffect(skillRequired), 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    return(false);
                }

                calculateRemodelCostModifier(skillRequired);
                return(true);
            }

            //Now check the vessel itself
            foreach (ProtoCrewMember protoCrew in this.part.vessel.GetVesselCrew())
            {
                if (protoCrew.experienceTrait.TypeName == skillRequired)
                {
                    hasAtLeastOneCrew = true;
                    break;
                }
            }

            if (!hasAtLeastOneCrew)
            {
                ScreenMessages.PostScreenMessage(kInsufficientSkill + Utils.GetTraitsWithEffect(skillRequired), 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            //Yup, we have sufficient skill.
            calculateRemodelCostModifier(skillRequired);
            return(true);
        }
Ejemplo n.º 6
0
        protected virtual void performAnalysis()
        {
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            float  experienceLevel = 0f;
            float  analysisRoll    = 0f;
            string analysisResultMessage;
            float  efficiencyModifier = 0f;
            float  currentModifier    = 0f;

            //Decrement the attempts remaining count
            int samplesLeft = getSamplesLeft() - 1;

            if (samplesLeft <= 0)
            {
                samplesLeft = 0;
            }
            WBIPathfinderScenario.Instance.SetCoreSamplesRemaining(this.part.vessel.mainBody.flightGlobalsIndex, biome.name, (HarvestTypes)resourceType, samplesLeft);
            coreSampleStatus = samplesLeft.ToString();

            UIPartActionWindow tweakableUI = Utils.FindActionWindow(this.part);

            if (tweakableUI != null)
            {
                tweakableUI.displayDirty = true;
            }

            //If an experienced scientist is taking the core sample, then the scientist's experience will
            //affect the analysis.
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel vessel = FlightGlobals.ActiveVessel;
                Experience.ExperienceTrait experience = vessel.GetVesselCrew()[0].experienceTrait;

                if (experience.TypeName == analysisSkill)
                {
                    experienceLevel = experience.CrewMemberExperienceLevel();
                }
            }

            //Add in the science lab bonus
            experienceLevel += getGeologyLabBonus();

            //Seed the random number generator
            UnityEngine.Random.seed = System.Environment.TickCount;

            //Roll 3d6 to approximate a bell curve, then convert it to a value between 1 and 100.
            analysisRoll  = UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll *= 5.5556f;

            //Now add the experience modifier
            analysisRoll += experienceLevel * kExperiencePercentModifier;

            //TODO: Did we strike gold?

            //Since we're using a bell curve, anything below maxWorsenRoll worsens the biome's extraction rates.
            //Anything above minImprovementRoll improves the biome's extraction rates.
            //A skilled scientist can affect the modifier by as much as 5%.
            if (analysisRoll <= maxWorsenRoll)
            {
                //Calculate the modifier
                efficiencyModifier = -kBaseEfficiencyModifier * (1.0f - (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionWorsened, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);

                //Modify harvesters on the active vessel
                WBIDrillManager.Instance.UpdateHarvesterEfficiencies(this.part.vessel);
            }

            //Good result!
            else if (analysisRoll >= minImprovementRoll)
            {
                //Calculate the modifier
                efficiencyModifier = kBaseEfficiencyModifier * (1.0f + (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionImproved, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);

                //Modify harvisters on the active vessel
                WBIDrillManager.Instance.UpdateHarvesterEfficiencies(this.part.vessel);
            }

            else
            {
                analysisResultMessage = kResourceExtractionUnchanged + biome.name;
            }

            //Inform the player of the result.
            ScreenMessages.PostScreenMessage(analysisResultMessage, 5.0f, ScreenMessageStyle.UPPER_CENTER);
            DeployExperiment();


            //First timers: show the tooltip.
            if (WBIPathfinderScenario.Instance.HasShownToolTip(kToolTip) == false)
            {
                WBIPathfinderScenario.Instance.SetToolTipShown(kToolTip);

                WBIToolTipWindow introWindow = new WBIToolTipWindow(kFirstCoreSampleTitle, kFirstCoreSampleMsg);
                introWindow.SetVisible(true);
            }
        }