Exemplo 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;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
            }
        }