protected virtual bool canAffordUpgrade() { if (string.IsNullOrEmpty(upgradeResource)) { return(true); } //If the active vessel is a kerbal, see if the kerbal has the resources double totalResources; if (FlightGlobals.ActiveVessel.isEVA) { Vessel vessel = FlightGlobals.ActiveVessel; totalResources = ResourceHelper.GetTotalResourceAmount(upgradeResource, vessel); if (totalResources >= upgradeCost) { return(true); } } //Check the ship totalResources = ResourceHelper.GetTotalResourceAmount(upgradeResource, this.part.vessel); if (totalResources >= upgradeCost) { return(true); } string errorMessage = string.Format(kInsufficientParts, this.part.partInfo.title, upgradeCost, upgradeResource); ScreenMessages.PostScreenMessage(errorMessage, 5.0f, ScreenMessageStyle.UPPER_CENTER); return(false); }
protected float calculateRepairCost() { if (this.part.vessel == null) { return(-1.0f); } float repairUnits = repairAmount; double totalResources = ResourceHelper.GetTotalResourceAmount(repairResource, this.part.vessel); //Anybody can repair the scope, but the right skill can reduce the cost by as much as 60% ProtoCrewMember astronaut = FlightGlobals.ActiveVessel.GetVesselCrew()[0]; if (astronaut.HasEffect(repairSkill)) { repairUnits = repairUnits * (0.9f - (astronaut.experienceTrait.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 if (totalResources < repairUnits) { return(-1.0f); } return(repairUnits); }
protected virtual double calculateRepairCost() { if (BARISBridge.RepairsRequireResources == false) { return(0f); } if (!Utils.IsExperienceEnabled()) { return(0f); } double repairUnits = repairAmount; double totalAmount; ProtoCrewMember[] crewMembers = FlightGlobals.ActiveVessel.GetVesselCrew().ToArray(); ProtoCrewMember crew; bool repairSkillFound = false; //Make sure we have the right skill to repair the lab. if (string.IsNullOrEmpty(repairSkill) == false) { for (int index = 0; index < crewMembers.Length; index++) { crew = crewMembers[index]; if (crew.HasEffect(repairSkill) || WBIMainSettings.RequiresSkillCheck == false) { repairUnits = repairUnits * (0.9f - (crew.experienceTrait.CrewMemberExperienceLevel() * 0.1f)); repairSkillFound = true; break; } } if (!repairSkillFound) { return(-1.0f); } } //make sure the ship has enough of the resource totalAmount = ResourceHelper.GetTotalResourceAmount(repairResource, this.part.vessel); if (totalAmount < repairUnits) { return(-1.0f); } return(repairUnits); }
protected bool buildExperiment(string requiredResources) { try { string[] resourceList = requiredResources.Split(';'); string[] resourceInfo; Dictionary <string, double> shoppingList = new Dictionary <string, double>(); double amount; string resourceName; //Make sure we have enough of the resource aboard, and add it to our shopping list //if we do. for (int resourceIndex = 0; resourceIndex < resourceList.Length; resourceIndex++) { resourceInfo = resourceList[resourceIndex].Split(','); resourceName = resourceInfo[0]; amount = double.Parse(resourceInfo[1]); if (ResourceHelper.GetTotalResourceAmount(resourceName, this.part.vessel) >= amount) { shoppingList.Add(resourceInfo[0], amount); } } //If our shopping list count doesn't match the resourceList count then we're done. if (shoppingList.Count != resourceList.Length) { return(false); } //Ok, go shopping string[] keyList = shoppingList.Keys.ToArray <string>(); for (int index = 0; index < keyList.Length; index++) { resourceName = keyList[index]; this.part.RequestResource(resourceName, shoppingList[resourceName], ResourceFlowMode.ALL_VESSEL); } } catch { return(false); } return(true); }
protected bool canAffordReconfigure() { if (HighLogic.LoadedSceneIsFlight == false) { return(true); } if (!WBIMainSettings.PayToReconfigure) { return(true); } bool canAffordCost = false; string notEnoughPartsMsg; calculateRemodelCostModifier(); double amount = resourceCost * (1.0 - reconfigureCostModifier); double totalResources = ResourceHelper.GetTotalResourceAmount(resourceRequired, this.part.vessel); //An inflatable part that hasn't been inflated yet is an automatic pass. if (switcher.isInflatable && !switcher.isDeployed) { return(true); } //now check to make sure the vessel has enough parts. if (totalResources >= amount) { canAffordCost = true; } if (!canAffordCost) { notEnoughPartsMsg = string.Format(kInsufficientParts, amount, resourceRequired); ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER); return(false); } return(true); }
protected override bool canAffordReconfigure(string templateName, bool deflatedModulesAutoPass = true) { if (HighLogic.LoadedSceneIsFlight == false) { return(true); } if (!WBIMainSettings.PayToReconfigure) { return(true); } //string value; bool canAffordCost = false; string requiredName = templateManager[templateName].GetValue(kRequiredResourceField); string requiredSkill = kDefaultSkill; float materialModifier = materialCostModifier; if (templateManager[templateName].HasValue(kReconfigureSkillField)) { requiredSkill = templateManager[templateName].GetValue(kReconfigureSkillField); } calculateRemodelCostModifier(requiredSkill); //If we don't have the required resource defined in the template then we can //automatically afford to reconfigure. if (templateManager[templateName].HasValue(kRequiredAmountField) == false) { reconfigureCost = 0f; return(true); } if (templateManager[templateName].HasValue(kIgnoreMaterialModField)) { materialModifier = 1.0f; } requriredResource = templateManager[templateName].GetValue(kRequiredAmountField); if (string.IsNullOrEmpty(requriredResource) == false) { //An inflatable part that hasn't been inflated yet is an automatic pass. if ((isInflatable && !isDeployed) && deflatedModulesAutoPass) { return(true); } reconfigureCost = float.Parse(requriredResource) * materialModifier * reconfigureCostModifier; double totalResources = ResourceHelper.GetTotalResourceAmount(requiredName, this.part.vessel); //now check to make sure the vessel has enough parts. if (totalResources < reconfigureCost) { canAffordCost = false; } else { canAffordCost = true; } } if (!canAffordCost) { string notEnoughPartsMsg = string.Format(kInsufficientParts, reconfigureCost, requiredName); ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER); return(false); } return(true); }
public override void ToggleInflation() { if (CurrentTemplate.HasValue("requiredResource") == false || HighLogic.LoadedSceneIsEditor) { base.ToggleInflation(); return; } string requiredName = CurrentTemplate.GetValue("requiredResource"); string requiredAmount = CurrentTemplate.GetValue("requiredAmount"); float totalResources = (float)ResourceHelper.GetTotalResourceAmount(requiredName, this.part.vessel); if (string.IsNullOrEmpty(requiredAmount)) { base.ToggleInflation(); return; } float resourceCost = float.Parse(requiredAmount); calculateRemodelCostModifier(); float adjustedPartCost = resourceCost; if (reconfigureCostModifier > 0f) { adjustedPartCost *= reconfigureCostModifier; } //Do we pay for resources? If so, either pay the resources if we're deploying the module, or refund the recycled parts if (WBIMainSettings.PayToReconfigure) { //If we aren't deployed then see if we can afford to pay the resource cost. if (!isDeployed) { //Can we afford it? if (canAffordReconfigure(CurrentTemplateName, false) == false) { return; } //Do we have the skill? if (!hasSufficientSkill(CurrentTemplateName)) { return; } //Yup, we can afford it //Pay the reconfigure cost //reconfigureCost = adjustedPartCost; payPartsCost(CurrentTemplateIndex); // Toggle after payment. base.ToggleInflation(); } //We are deployed, calculate the amount of parts that can be refunded. else { // Toggle first in case deflate confirmation is needed, we'll check the state after the toggle. base.ToggleInflation(); //Recycle what we can. // deflateConfirmed's logic seems backward. if (!HasResources() || (HasResources() && deflateConfirmed == false)) { recoverResourceCost(requiredName, adjustedPartCost * recycleBase); } } } // Not paying for reconfiguration, check for skill requirements else { if (WBIMainSettings.RequiresSkillCheck) { if (hasSufficientSkill(CurrentTemplateName)) { base.ToggleInflation(); } else { return; } } else { base.ToggleInflation(); } } }