Release 1.9.7.0 - Summer Update 2025

This commit is contained in:
Regalis11
2025-06-17 16:38:11 +03:00
parent 22227f13e5
commit ea5a2bc693
297 changed files with 7344 additions and 2421 deletions
@@ -169,12 +169,14 @@ namespace Barotrauma
/// Purchased upgrades are temporarily stored in <see cref="PendingUpgrades"/> and they are applied
/// after the next round starts similarly how items are spawned in the stowage room after the round starts.
/// </remarks>
public void PurchaseUpgrade(UpgradePrefab prefab, UpgradeCategory category, bool force = false, Client? client = null)
public bool TryPurchaseUpgrade(UpgradePrefab prefab, UpgradeCategory category, bool force = false, Client? client = null)
{
if (!HasPermissionToManageUpgrades(client)) { return false; }
if (!CanUpgradeSub())
{
DebugConsole.ThrowError("Cannot upgrade when switching to another submarine.");
return;
return false;
}
int price = prefab.Price.GetBuyPrice(prefab, GetUpgradeLevel(prefab, category), Campaign.Map?.CurrentLocation);
@@ -185,7 +187,7 @@ namespace Barotrauma
if (currentLevel + 1 > maxLevel)
{
DebugConsole.ThrowError($"Tried to purchase \"{prefab.Name}\" over the max level! ({newLevel} > {maxLevel}). The transaction has been cancelled.");
return;
return false;
}
bool TryTakeResources(Character character)
@@ -203,17 +205,17 @@ namespace Barotrauma
switch (GameMain.NetworkMember)
{
case null when Character.Controlled is { } controlled: // singleplayer
if (!TryTakeResources(controlled)) { return; }
if (!TryTakeResources(controlled)) { return false; }
break;
case { IsClient: true }:
if (!prefab.HasResourcesToUpgrade(Character.Controlled, newLevel)) { return; }
if (!prefab.HasResourcesToUpgrade(Character.Controlled, newLevel)) { return false; }
break;
case { IsServer: true } when client?.Character is { } character:
if (!TryTakeResources(character)) { return; }
if (!TryTakeResources(character)) { return false; }
break;
default:
DebugConsole.ThrowError($"Tried to purchase \"{prefab.Name}\" without a player.");
return;
return false;
}
}
@@ -270,11 +272,15 @@ namespace Barotrauma
PurchasedUpgrades.Add(new PurchasedUpgrade(prefab, category));
#endif
OnUpgradesChanged?.Invoke(this);
return true;
}
else
{
DebugConsole.ThrowError("Tried to purchase an upgrade with insufficient funds, the transaction has not been completed.\n" +
$"Upgrade: {prefab.Name}, Cost: {price}, Have: {Campaign.GetWallet(client).Balance}");
return false;
}
}
@@ -297,6 +303,8 @@ namespace Barotrauma
/// </summary>
public void PurchaseItemSwap(Item itemToRemove, ItemPrefab itemToInstall, bool isNetworkMessage = false, Client? client = null)
{
if (!HasPermissionToManageUpgrades(client)) { return; }
if (!CanUpgradeSub())
{
DebugConsole.ThrowError("Cannot swap items when switching to another submarine.");
@@ -398,8 +406,10 @@ namespace Barotrauma
/// <summary>
/// Cancels the currently pending item swap, or uninstalls the item if there's no swap pending
/// </summary>
public void CancelItemSwap(Item itemToRemove, bool force = false)
public void CancelItemSwap(Item itemToRemove, bool force = false, Client? client = null)
{
if (!HasPermissionToManageUpgrades(client)) { return; }
if (!CanUpgradeSub())
{
DebugConsole.ThrowError("Cannot swap items when switching to another submarine.");
@@ -757,6 +767,18 @@ namespace Barotrauma
Campaign.PendingSubmarineSwitch.Name == Submarine.MainSub.Info.Name;
}
public bool HasPermissionToManageUpgrades(Client? client = null)
{
if (!GameMain.IsMultiplayer) { return true; }
#if SERVER
if (client is null) { return false; }
return CampaignMode.AllowedToManageCampaign(client, ClientPermissions.ManageCampaign);
#elif CLIENT
return CampaignMode.AllowedToManageCampaign(ClientPermissions.ManageCampaign);
#endif
}
public void Save(XElement? parent)
{
if (parent == null) { return; }