Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests

This commit is contained in:
Evil Factory
2022-04-11 15:58:36 -03:00
38 changed files with 361 additions and 184 deletions
@@ -566,9 +566,13 @@ namespace Barotrauma
#elif SERVER
if (value is { IsDead: true, Wallet: { Balance: var balance } grabbedWallet } && balance > 0)
{
Wallet.Give(balance);
if (GameMain.GameSession.Campaign is MultiPlayerCampaign mpCampaign)
{
mpCampaign.Bank.Give(balance);
}
grabbedWallet.Deduct(balance);
GameServer.Log($"{Name} grabbed {value.Name}'s body and received {grabbedWallet.Balance} mk.", ServerLog.MessageType.Money);
GameServer.Log($"{GameServer.CharacterLogName(this)} grabbed {value.Name}'s body and received {grabbedWallet.Balance} mk.", ServerLog.MessageType.Money);
}
#endif
}
@@ -40,6 +40,12 @@ namespace Barotrauma
[Serialize(Level.PositionType.Wreck, IsPropertySaveable.No)]
public Level.PositionType SpawnPosition { get; private set; }
[Serialize(0, IsPropertySaveable.No)]
public int MinMoney { get; private set; }
[Serialize(0, IsPropertySaveable.No)]
public int MaxMoney { get; private set; }
public CorpsePrefab(ContentXElement element, CorpsesFile file) : base(element, file) { }
public static CorpsePrefab Random(Rand.RandSync sync = Rand.RandSync.Unsynced) => Prefabs.GetRandom(sync);
@@ -165,10 +165,14 @@ namespace Barotrauma
TextManager.Get("missionfailed")).Fallback(
GameSettings.CurrentConfig.Language == TextManager.DefaultLanguage ? element.GetAttributeString("failuremessage", "") : "");
SonarLabel =
TextManager.Get($"MissionSonarLabel.{TextIdentifier}").Fallback(
TextManager.Get($"MissionSonarLabel.{element.GetAttributeString("sonarlabel", "")}")).Fallback(
element.GetAttributeString("sonarlabel", ""));
string sonarLabelTag = element.GetAttributeString("sonarlabel", "");
SonarLabel =
TextManager.Get($"MissionSonarLabel.{sonarLabelTag}")
.Fallback(TextManager.Get(sonarLabelTag))
.Fallback(TextManager.Get($"MissionSonarLabel.{TextIdentifier}"))
.Fallback(element.GetAttributeString("sonarlabel", ""));
SonarIconIdentifier = element.GetAttributeIdentifier("sonaricon", "");
MultiplayerOnly = element.GetAttributeBool("multiplayeronly", false);
@@ -5,6 +5,7 @@ using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Barotrauma.Networking;
#if SERVER
@@ -15,7 +16,9 @@ namespace Barotrauma
{
class PurchasedItem
{
public ItemPrefab ItemPrefab { get; }
public ItemPrefab ItemPrefab => ItemPrefab.Prefabs[ItemPrefabIdentifier];
public Identifier ItemPrefabIdentifier { get; }
public int Quantity { get; set; }
public bool? IsStoreComponentEnabled { get; set; }
@@ -23,7 +26,7 @@ namespace Barotrauma
public PurchasedItem(ItemPrefab itemPrefab, int quantity, int buyerCharacterInfoId)
{
ItemPrefab = itemPrefab;
ItemPrefabIdentifier = itemPrefab.Identifier;
Quantity = quantity;
IsStoreComponentEnabled = null;
BuyerCharacterInfoId = buyerCharacterInfoId;
@@ -34,8 +37,11 @@ namespace Barotrauma
: this(itemPrefab, quantity, buyer: null) { }
#endif
public PurchasedItem(ItemPrefab itemPrefab, int quantity, Client buyer)
: this(itemPrefab.Identifier, quantity, buyer) { }
public PurchasedItem(Identifier itemPrefabId, int quantity, Client buyer)
{
ItemPrefab = itemPrefab;
ItemPrefabIdentifier = itemPrefabId;
Quantity = quantity;
IsStoreComponentEnabled = null;
BuyerCharacterInfoId = buyer?.Character?.Info?.ID ?? Character.Controlled?.Info?.ID ?? 0;
@@ -269,6 +275,24 @@ namespace Barotrauma
OnItemsInSellFromSubCrateChanged?.Invoke();
}
#if SERVER
public void OnNewItemsPurchased(Identifier storeIdentifier, List<PurchasedItem> newItems, Client client)
{
StringBuilder sb = new StringBuilder();
int price = 0;
Dictionary<ItemPrefab, int> buyValues = GetBuyValuesAtCurrentLocation(storeIdentifier, newItems.Select(i => i.ItemPrefab));
foreach (PurchasedItem item in newItems)
{
int itemValue = item.Quantity * buyValues[item.ItemPrefab];
sb.Append($"\n - {item.ItemPrefab.Name} x{item.Quantity}");
price += itemValue;
}
GameServer.Log($"{NetworkMember.ClientLogName(client, client?.Name ?? "Unknown")} purchased {newItems.Count} item(s) for {TextManager.FormatCurrency(price)}{sb.ToString()}", ServerLog.MessageType.Money);
}
#endif
public void PurchaseItems(Identifier storeIdentifier, List<PurchasedItem> itemsToPurchase, bool removeFromCrate, Client client = null)
{
var store = Location.GetStore(storeIdentifier);
@@ -32,7 +32,7 @@ namespace Barotrauma
/// </summary>
internal struct NetWalletUpdate : INetSerializableStruct
{
[NetworkSerialize(ArrayMaxSize = NetConfig.MaxPlayers + 1)]
[NetworkSerialize(ArrayMaxSize = 256)]
public NetWalletTransaction[] Transactions;
}
@@ -73,6 +73,9 @@ namespace Barotrauma
{
other.BalanceChanged = AddOptionalInt(other.BalanceChanged, BalanceChanged);
other.RewardDistributionChanged = AddOptionalInt(other.RewardDistributionChanged, RewardDistributionChanged);
other.BalanceChanged = TurnToNoneIfZero(other.BalanceChanged);
other.RewardDistributionChanged = TurnToNoneIfZero(other.RewardDistributionChanged);
return other;
static Option<int> AddOptionalInt(Option<int> a, Option<int> b)
@@ -94,6 +97,16 @@ namespace Barotrauma
_ => throw new ArgumentOutOfRangeException(nameof(a))
};
}
static Option<int> TurnToNoneIfZero(Option<int> option)
{
return option switch
{
Some<int> s => s.Value == 0 ? Option<int>.None() : option,
None<int> _ => option,
_ => throw new ArgumentOutOfRangeException(nameof(option))
};
}
}
}
@@ -251,7 +251,7 @@ namespace Barotrauma
msg.Write((UInt16)storeItems.Value.Count);
foreach (var item in storeItems.Value)
{
msg.Write(item.ItemPrefab.Identifier);
msg.Write(item.ItemPrefabIdentifier);
msg.WriteRangedInteger(item.Quantity, 0, CargoManager.MaxQuantity);
}
}
@@ -270,7 +270,7 @@ namespace Barotrauma
{
Identifier itemId = msg.ReadIdentifier();
int quantity = msg.ReadRangedInteger(0, CargoManager.MaxQuantity);
items[storeId].Add(new PurchasedItem(ItemPrefab.Prefabs[itemId], quantity, sender));
items[storeId].Add(new PurchasedItem(itemId, quantity, sender));
}
}
return items;
@@ -303,7 +303,7 @@ namespace Barotrauma
Identifier storeId = msg.ReadIdentifier();
soldItems.Add(storeId, new List<SoldItem>());
UInt16 itemCount = msg.ReadUInt16();
for (int j = 0; j < storeCount; j++)
for (int j = 0; j < itemCount; j++)
{
Identifier prefabId = msg.ReadIdentifier();
UInt16 itemId = msg.ReadUInt16();
@@ -187,17 +187,6 @@ namespace Barotrauma.Items.Components
if (!isClient)
{
MoveIngredientsToInputContainer(selectedItem);
if (selectedItem.RequiredMoney > 0 && CanBeFabricated(fabricatedItem, availableIngredients, user))
{
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign)
{
user.Wallet.Deduct(selectedItem.RequiredMoney);
}
else if (GameMain.GameSession?.GameMode is CampaignMode campaign)
{
campaign.Bank.Deduct(selectedItem.RequiredMoney);
}
}
}
requiredTime = GetRequiredTime(fabricatedItem, user);
@@ -211,9 +200,16 @@ namespace Barotrauma.Items.Components
State = FabricatorState.Active;
}
#if SERVER
if (user != null && addToServerLog)
if (user != null && addToServerLog && selectedItem.RequiredMoney == 0)
{
GameServer.Log(GameServer.CharacterLogName(user) + " started fabricating " + selectedItem.DisplayName.Value + " in " + item.Name, ServerLog.MessageType.ItemInteraction);
if (selectedItem.RequiredMoney > 0)
{
GameServer.Log($"{GameServer.CharacterLogName(user)} bought {selectedItem.DisplayName.Value} for {selectedItem.RequiredMoney} mk from {item.Name}", ServerLog.MessageType.Money);
}
else
{
GameServer.Log($"{GameServer.CharacterLogName(user)} started fabricating {selectedItem.DisplayName.Value} in {item.Name}", ServerLog.MessageType.ItemInteraction);
}
}
#endif
}
@@ -328,6 +324,19 @@ namespace Barotrauma.Items.Components
return;
}
if (fabricatedItem.RequiredMoney > 0)
{
if (user == null) { return; }
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign)
{
user.Wallet.Deduct(fabricatedItem.RequiredMoney);
}
else if (GameMain.GameSession?.GameMode is CampaignMode campaign)
{
campaign.Bank.Deduct(fabricatedItem.RequiredMoney);
}
}
bool ingredientsStolen = false;
bool ingredientsAllowStealing = true;
@@ -108,7 +108,8 @@ namespace Barotrauma.Items.Components
foreach (XElement connectionElement in subElement.Elements())
{
string prefabConnectionName = connectionElement.GetAttributeString("name", null);
if (prefabConnectionName == Name)
string[] aliases = connectionElement.GetAttributeStringArray("aliases", Array.Empty<string>());
if (prefabConnectionName == Name || aliases.Contains(Name))
{
displayNameTag = connectionElement.GetAttributeString("displayname", "");
fallbackTag = connectionElement.GetAttributeString("fallbackdisplayname", "");
@@ -2,6 +2,7 @@
using System;
using System.Xml.Linq;
using Barotrauma.Networking;
using Barotrauma.Extensions;
#if CLIENT
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Lights;
@@ -173,7 +174,7 @@ namespace Barotrauma.Items.Components
#if CLIENT
if (Light != null)
{
Light.Color = IsOn ? lightColor : Color.Transparent;
Light.Color = IsOn ? lightColor.Multiply(currentBrightness) : Color.Transparent;
}
#endif
}
@@ -4170,6 +4170,12 @@ namespace Barotrauma
selectedPrefab.GiveItems(corpse, wreck);
corpse.Kill(CauseOfDeathType.Unknown, causeOfDeathAffliction: null, log: false);
corpse.GiveIdCardTags(sp);
#if SERVER
if (selectedPrefab.MinMoney >= 0 && selectedPrefab.MaxMoney > 0)
{
corpse.Wallet.Give(Rand.Range(selectedPrefab.MinMoney, selectedPrefab.MaxMoney, Rand.RandSync.Unsynced));
}
#endif
spawnCounter++;
static CorpsePrefab GetCorpsePrefab(Func<CorpsePrefab, bool> predicate)
@@ -1,5 +1,4 @@
using System;
using System.Xml.Linq;
namespace Barotrauma
{
@@ -1007,19 +1007,6 @@ namespace Barotrauma
}
}
}
else if (attributeName == "move")
{
Vector2 moveAmount = subElement.GetAttributeVector2("move", Vector2.Zero);
if (entity is Structure structure)
{
structure.Move(moveAmount);
}
else if (entity is Item item)
{
item.Move(moveAmount);
}
continue;
}
if (entity.SerializableProperties.TryGetValue(attributeName, out SerializableProperty property))
{
@@ -13,7 +13,7 @@ namespace Barotrauma
public override bool Loaded => nestedStr.Loaded;
public override void RetrieveValue()
{
cachedValue = nestedStr.Value.ToUpper();
cachedValue = nestedStr.Value.ToUpperInvariant();
UpdateLanguage();
}
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma.Networking;
using Barotrauma.Steam;
namespace Barotrauma.IO
{
@@ -31,6 +32,7 @@ namespace Barotrauma.IO
string localModsDir = getFullPath(ContentPackage.LocalModsDir);
string workshopModsDir = getFullPath(ContentPackage.WorkshopModsDir);
#if CLIENT
string workshopStagingDir = getFullPath(SteamManager.Workshop.PublishStagingDir);
string tempDownloadDir = getFullPath(ModReceiver.DownloadFolder);
#endif
@@ -49,6 +51,7 @@ namespace Barotrauma.IO
&& !pathStartsWith(localModsDir)
#if CLIENT
&& !pathStartsWith(tempDownloadDir)
&& !pathStartsWith(workshopStagingDir)
#endif
&& (extension == ".dll" || extension == ".exe" || extension == ".json"))
{
@@ -284,6 +287,11 @@ namespace Barotrauma.IO
//TODO: validate recursion?
System.IO.Directory.Delete(path, recursive);
}
public static DateTime GetLastWriteTime(string path)
{
return System.IO.Directory.GetLastWriteTime(path);
}
}
public static class File