public SwitcherSubtypeDescriptionGenerator(ModuleB9PartSwitch module) { module.ThrowIfNullArgument(nameof(module)); this.module = module; Part partPrefab = module.part.GetPrefab(); float prefabMass = partPrefab.mass; partDryMass = prefabMass + module.part.GetModuleMass(prefabMass); partWetMass = partDryMass + module.part.GetResourceMassMax(); baseDryMass = partDryMass - module.GetDryMass(module.CurrentSubtype) - module.GetParentDryMass(module.CurrentSubtype); baseWetMass = partWetMass - module.GetWetMass(module.CurrentSubtype) - module.GetParentWetMass(module.CurrentSubtype); float prefabCost = module.part.partInfo.cost; partWetCost = prefabCost + module.part.GetModuleCosts(prefabCost); partDryCost = partWetCost - module.part.GetResourceCostMax(); baseDryCost = partDryCost - module.GetDryCost(module.CurrentSubtype) - module.GetParentDryCost(module.CurrentSubtype); baseWetCost = partWetCost - module.GetWetCost(module.CurrentSubtype) - module.GetParentWetCost(module.CurrentSubtype); showWetMass = module.ChangesResourceMass; showWetMass |= module.Parent?.CurrentTankType.ChangesResourceMass ?? false; showDryMass = showWetMass; showDryMass |= module.ChangesDryMass; showDryMass |= (module.Parent?.CurrentTankType.tankMass ?? 0) != 0; showWetCost = module.ChangesResourceCost; showWetCost |= module.Parent?.CurrentTankType.ChangesResourceCost ?? false; showDryCost = showWetCost; showDryCost |= module.ChangesDryCost; showDryCost |= (module.Parent?.CurrentTankType.tankCost ?? 0) != 0; showMaxTemp = module.HasPartAspectLock("maxTemp"); showSkinMaxTemp = module.HasPartAspectLock("skinMaxTemp"); showCrashTolerance = module.HasPartAspectLock("crashTolerance"); prefabMaxTemp = (float)partPrefab.maxTemp; prefabSkinMaxTemp = (float)partPrefab.skinMaxTemp; prefabCrashTolerance = partPrefab.crashTolerance; currentMaxTemp = (float)module.part.maxTemp; currentSkinMaxTemp = (float)module.part.skinMaxTemp; currentCrashTolerance = module.part.crashTolerance; float currentParentVolume = module.Parent?.GetTotalVolume(module.Parent.CurrentSubtype) ?? 0; baseParentVolume = currentParentVolume - (module.CurrentSubtype.volumeAddedToParent * module.VolumeScale); parentResources = new KeyValuePair <TankResource, float> [module.Parent?.CurrentTankType.resources.Count ?? 0]; for (int i = 0; i < parentResources.Length; i++) { TankResource resource = module.Parent.CurrentTankType[i]; parentResources[i] = new KeyValuePair <TankResource, float>(resource, resource.unitsPerVolume * currentParentVolume); } }
private void GetFullSubtypeDescriptionInternal(PartSubtype subtype) { if (!subtype.descriptionSummary.IsNullOrEmpty()) { stringBuilder.AppendLine(subtype.descriptionSummary); } stringBuilder.BeginGroup(); if (subtype.tankType.resources.Count > 0 || parentResources.Length > 0) { stringBuilder.AppendLine("<b>{0}:</b>", SwitcherSubtypeDescriptionGenerator_Resources); foreach (TankResource resource in subtype.tankType) { stringBuilder.AppendLine(" <color=#bfff3f>- {0}</color>: {1:0.#}", resource.resourceDefinition.displayName, resource.unitsPerVolume * module.GetTotalVolume(subtype)); } float parentVolume = baseParentVolume + (subtype.volumeAddedToParent * module.VolumeScale); foreach (KeyValuePair <TankResource, float> resourceAndAmount in parentResources) { float amount = resourceAndAmount.Key.unitsPerVolume * parentVolume; float difference = amount - resourceAndAmount.Value; stringBuilder.Append(" <color=#bfff3f>- {0}</color>: {1:0.#}", resourceAndAmount.Key.resourceDefinition.displayName, amount); if (!ApproximatelyZero(difference)) { stringBuilder.Append(FormatResourceDifference(difference)); } stringBuilder.AppendLine(); } } float dryMass = baseDryMass + module.GetDryMass(subtype) + module.GetParentDryMass(subtype); float wetMass = baseWetMass + module.GetWetMass(subtype) + module.GetParentWetMass(subtype); float dryMassDifference = dryMass - partDryMass; float wetMassDifference = wetMass - partWetMass; float dryCost = baseDryCost + module.GetDryCost(subtype) + module.GetParentDryCost(subtype); float wetCost = baseWetCost + module.GetWetCost(subtype) + module.GetParentWetCost(subtype); float dryCostDifference = dryCost - partDryCost; float wetCostDifference = wetCost - partWetCost; stringBuilder.BeginGroup(); if (showWetMass) { stringBuilder.Append("<b>{0}:</b> {1} {2}", SwitcherSubtypeDescriptionGenerator_Mass, SwitcherSubypeDescriptionGenerator_MassTons(dryMass, "0.###"), SwitcherSubtypeDescriptionGenerator_TankEmpty); if (!ApproximatelyZero(dryMassDifference) && !ApproximatelyEqual(dryMassDifference, wetMassDifference)) { stringBuilder.Append(FormatMassDifference(dryMassDifference)); } stringBuilder.Append(" / {0} {1}", SwitcherSubypeDescriptionGenerator_MassTons(wetMass, "0.###"), SwitcherSubtypeDescriptionGenerator_TankFull); if (!ApproximatelyZero(wetMassDifference)) { stringBuilder.Append(FormatMassDifference(wetMassDifference)); } stringBuilder.AppendLine(); } else if (showDryMass) { stringBuilder.Append("<b>{0}:</b> {1}", SwitcherSubtypeDescriptionGenerator_Mass, SwitcherSubypeDescriptionGenerator_MassTons(dryMass, "0.###")); if (!ApproximatelyZero(dryMassDifference)) { stringBuilder.Append(FormatMassDifference(dryMassDifference)); } stringBuilder.AppendLine(); } if (showWetCost) { stringBuilder.Append("<b>{0}:</b> <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1> {1:0.#} {2}", SwitcherSubtypeDescriptionGenerator_Cost, dryCost, SwitcherSubtypeDescriptionGenerator_TankEmpty); if (!ApproximatelyZero(dryCostDifference) && !ApproximatelyEqual(dryCostDifference, wetCostDifference)) { stringBuilder.Append(FormatCostDifference(dryCostDifference)); } stringBuilder.Append(" / <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1> {0:0.#} {1}", wetCost, SwitcherSubtypeDescriptionGenerator_TankFull); if (!ApproximatelyZero(wetCostDifference)) { stringBuilder.Append(FormatCostDifference(wetCostDifference)); } stringBuilder.AppendLine(); } else if (showDryCost) { stringBuilder.Append("<b>{0}:</b> <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1> {1:#.#}", SwitcherSubtypeDescriptionGenerator_Cost, dryCost); if (!ApproximatelyZero(dryCostDifference)) { stringBuilder.Append(FormatCostDifference(dryCostDifference)); } stringBuilder.AppendLine(); } if (showMaxTemp) { float maxTemp = subtype.maxTemp > 0 ? subtype.maxTemp : prefabMaxTemp; stringBuilder.Append("<b>{0}:</b> {1}", SwitcherSubtypeDescriptionGenerator_MaxTemp, SwitcherSubypeDescriptionGenerator_TemperatureKelvins(maxTemp, "#")); if (!ApproximatelyEqual(maxTemp, currentMaxTemp)) { stringBuilder.Append(FormatTemperatureDifference(maxTemp - currentMaxTemp)); } stringBuilder.AppendLine(); } if (showSkinMaxTemp) { float skinMaxTemp = subtype.skinMaxTemp > 0 ? subtype.skinMaxTemp : prefabSkinMaxTemp; stringBuilder.Append("<b>{0}:</b> {1}", SwitcherSubtypeDescriptionGenerator_MaxSkinTemp, SwitcherSubypeDescriptionGenerator_TemperatureKelvins(skinMaxTemp, "#")); if (!ApproximatelyEqual(skinMaxTemp, currentSkinMaxTemp)) { stringBuilder.Append(FormatTemperatureDifference(skinMaxTemp - currentSkinMaxTemp)); } stringBuilder.AppendLine(); } if (showCrashTolerance) { float crashTolerance = subtype.crashTolerance > 0 ? subtype.crashTolerance : prefabCrashTolerance; stringBuilder.Append("<b>{0}:</b> {1}", SwitcherSubtypeDescriptionGenerator_CrashTolerance, SwitcherSubypeDescriptionGenerator_SpeedMetersPerSecond(crashTolerance, "#")); if (!ApproximatelyEqual(crashTolerance, currentCrashTolerance)) { stringBuilder.Append(FormatSpeedDifference(crashTolerance - currentCrashTolerance)); } stringBuilder.AppendLine(); } stringBuilder.BeginGroup(); if (!subtype.descriptionDetail.IsNullOrEmpty()) { stringBuilder.AppendLine(subtype.descriptionDetail); } }