Build 1.1.4.0

This commit is contained in:
Markus Isberg
2023-03-31 18:40:44 +03:00
parent efba17e0ff
commit 9470edead3
483 changed files with 17487 additions and 8548 deletions
@@ -43,15 +43,32 @@ namespace Barotrauma
}
}
public int GetBuyPrice(int level, Location? location = null)
public int GetBuyPrice(int level, Location? location = null, ImmutableHashSet<Character>? characterList = null)
{
int maxLevel = Prefab.GetMaxLevelForCurrentSub();
float price = BasePrice;
if (level > maxLevel) { maxLevel = level; }
int maxLevel = Prefab.MaxLevel;
int price = BasePrice;
price += (int)(price * MathHelper.Lerp(IncreaseLow, IncreaseHigh, level / (float)maxLevel) / 100);
return location?.GetAdjustedMechanicalCost(price) ?? price;
float lerpAmount = maxLevel is 0
? level // avoid division by 0
: level / (float)maxLevel;
float priceMultiplier = MathHelper.Lerp(IncreaseLow, IncreaseHigh, lerpAmount);
price += price * (priceMultiplier / 100f);
price = location?.GetAdjustedMechanicalCost((int)price) ?? price;
characterList ??= GameSession.GetSessionCrewCharacters(CharacterType.Both);
if (characterList.Any())
{
if (location?.Faction is { } faction && Faction.GetPlayerAffiliationStatus(faction) is FactionAffiliation.Positive)
{
price *= 1f - characterList.Max(static c => c.GetStatValue(StatTypes.ShipyardBuyMultiplierAffiliated));
}
price *= 1f - characterList.Max(static c => c.GetStatValue(StatTypes.ShipyardBuyMultiplier));
}
return (int)price;
}
}
@@ -194,11 +211,10 @@ namespace Barotrauma
_ => throw new ArgumentOutOfRangeException()
};
public bool AppliesTo(SubmarineInfo sub)
public bool AppliesTo(SubmarineClass subClass, int subTier)
{
if (type is MaxLevelModType.Invalid) { return false; }
int subTier = sub.Tier;
if (GameMain.GameSession?.Campaign?.CampaignMetadata is { } metadata)
{
int modifier = metadata.GetInt(new Identifier("tiermodifieroverride"), 0);
@@ -211,9 +227,9 @@ namespace Barotrauma
return subTier == tier;
}
if (tierOrClass.TryGet(out SubmarineClass subClass))
if (tierOrClass.TryGet(out SubmarineClass targetClass))
{
return sub.SubmarineClass == subClass;
return subClass == targetClass;
}
return false;
@@ -492,15 +508,19 @@ namespace Barotrauma
{
int level = MaxLevel;
foreach (UpgradeMaxLevelMod mod in MaxLevelsMods)
{
if (mod.AppliesTo(info)) { level = mod.GetLevelAfter(level); }
}
int tier = info.Tier;
if (GameMain.GameSession?.Campaign?.CampaignMetadata is { } metadata)
{
int modifier = metadata.GetInt(new Identifier($"tiermodifiers.{Identifier}"), 0);
level += modifier;
tier += modifier;
}
tier = Math.Clamp(tier, 1, SubmarineInfo.HighestTier);
foreach (UpgradeMaxLevelMod mod in MaxLevelsMods)
{
if (mod.AppliesTo(info.SubmarineClass, tier)) { level = mod.GetLevelAfter(level); }
}
return level;
@@ -518,23 +538,25 @@ namespace Barotrauma
if (character is null) { return false; }
if (!ResourceCosts.Any()) { return true; }
List<Item> allItems = character.Inventory.FindAllItems(recursive: true);
var allItems = CargoManager.FindAllItemsOnPlayerAndSub(character);
return ResourceCosts.Where(cost => cost.AppliesForLevel(currentLevel)).All(cost => cost.Amount <= allItems.Count(cost.MatchesItem));
}
// ReSharper disable PossibleMultipleEnumeration
public bool TryTakeResources(Character character, int currentLevel)
{
IEnumerable<UpgradeResourceCost> costs = ResourceCosts.Where(cost => cost.AppliesForLevel(currentLevel));
var costs = ResourceCosts.Where(cost => cost.AppliesForLevel(currentLevel));
if (!costs.Any()) { return true; }
List<Item> allItems = character.Inventory.FindAllItems(recursive: true);
var inventoryItems = CargoManager.FindAllItemsOnPlayerAndSub(character);
HashSet<Item> itemsToRemove = new HashSet<Item>();
foreach (UpgradeResourceCost cost in costs)
{
int amountNeeded = cost.Amount;
foreach (Item item in allItems.Where(cost.MatchesItem))
foreach (Item item in inventoryItems.Where(cost.MatchesItem))
{
itemsToRemove.Add(item);
amountNeeded--;