Unstable 0.17.1.0

This commit is contained in:
Markus Isberg
2022-03-17 01:25:04 +09:00
parent 3974067915
commit 6d410cc1b7
302 changed files with 5878 additions and 3317 deletions
@@ -63,6 +63,8 @@ namespace Barotrauma
}
}
public virtual Wallet Wallet => GetWallet();
public override void ShowStartMessage()
{
foreach (Mission mission in Missions.ToList())
@@ -310,7 +312,7 @@ namespace Barotrauma
if (ShowCampaignUI || ForceMapUI)
{
campaignUIContainer?.AddToGUIUpdateList();
if (CampaignUI?.UpgradeStore?.HoveredItem != null)
if (CampaignUI?.UpgradeStore?.HoveredEntity != null)
{
if (CampaignUI.SelectedTab != InteractionType.Upgrade) { return; }
CampaignUI?.UpgradeStore?.ItemInfoFrame.AddToGUIUpdateList(order: 1);
@@ -1,113 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Barotrauma
{
internal partial class CampaignMetadata
{
private const int MaxDrawnElements = 12;
public void DebugDraw(SpriteBatch spriteBatch, Vector2 pos, int debugDrawMetadataOffset, string[] ignoredMetadataInfo)
{
var campaignData = data;
foreach (string ignored in ignoredMetadataInfo)
{
if (!string.IsNullOrWhiteSpace(ignored))
{
campaignData = campaignData.Where(pair => !pair.Key.StartsWith(ignored)).ToDictionary(i => i.Key, i => i.Value);
}
}
int offset = 0;;
if (campaignData.Count > 0)
{
offset = debugDrawMetadataOffset % campaignData.Count;
if (offset < 0) { offset += campaignData.Count; }
}
var text = "Campaign metadata:\n";
int max = 0;
for (int i = offset; i < campaignData.Count + offset; i++)
{
int index = i;
if (index >= campaignData.Count) { index -= campaignData.Count; }
var (key, value) = campaignData.ElementAt(index);
if (max < MaxDrawnElements)
{
text += $"{key.ColorizeObject()}: {value.ColorizeObject()}\n";
max++;
}
else
{
text += "Use arrow keys to scroll";
break;
}
}
text = text.TrimEnd('\n');
ImmutableArray<RichTextData>? richTextDatas = RichTextData.GetRichTextData(text, out text);
Vector2 size = GUIStyle.SmallFont.MeasureString(text);
Vector2 infoPos = new Vector2(GameMain.GraphicsWidth - size.X - 16, pos.Y + 8);
Rectangle infoRect = new Rectangle(infoPos.ToPoint(), size.ToPoint());
infoRect.Inflate(8, 8);
GUI.DrawRectangle(spriteBatch, infoRect, Color.Black * 0.8f, isFilled: true);
GUI.DrawRectangle(spriteBatch, infoRect, Color.White * 0.8f);
if (richTextDatas != null && richTextDatas.Value.Any())
{
GUI.DrawStringWithColors(spriteBatch, infoPos, text, Color.White, richTextDatas.Value, font: GUIStyle.SmallFont);
}
else
{
GUI.DrawString(spriteBatch, infoPos, text, Color.White, font: GUIStyle.SmallFont);
}
float y = infoRect.Bottom + 16;
if (Campaign.Factions != null)
{
const string factionHeader = "Reputations";
Vector2 factionHeaderSize = GUIStyle.SubHeadingFont.MeasureString(factionHeader);
Vector2 factionPos = new Vector2(GameMain.GraphicsWidth - (264 / 2) - factionHeaderSize.X / 2, y);
GUI.DrawString(spriteBatch, factionPos, factionHeader, Color.White, font: GUIStyle.SubHeadingFont);
y += factionHeaderSize.Y + 8;
foreach (Faction faction in Campaign.Factions)
{
LocalizedString name = faction.Prefab.Name;
Vector2 nameSize = GUIStyle.SmallFont.MeasureString(name);
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 264, y), name, Color.White, font: GUIStyle.SmallFont);
y += nameSize.Y + 5;
Color color = ToolBox.GradientLerp(faction.Reputation.NormalizedValue, Color.Red, Color.Yellow, Color.LightGreen);
GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int) y, (int)(faction.Reputation.NormalizedValue * 255), 10), color, isFilled: true);
GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int) y, 256, 10), Color.White);
y += 15;
}
}
Location location = Campaign.Map?.CurrentLocation;
if (location?.Reputation != null)
{
string name = Campaign.Map?.CurrentLocation.Name;
Vector2 nameSize = GUIStyle.SmallFont.MeasureString(name);
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth - 264, y), name, Color.White, font: GUIStyle.SmallFont);
y += nameSize.Y + 5;
float normalizedReputation = MathUtils.InverseLerp(location.Reputation.MinReputation, location.Reputation.MaxReputation, location.Reputation.Value);
Color color = ToolBox.GradientLerp(normalizedReputation, Color.Red, Color.Yellow, Color.LightGreen);
GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int) y, (int)(normalizedReputation * 255), 10), color, isFilled: true);
GUI.DrawRectangle(spriteBatch, new Rectangle(GameMain.GraphicsWidth - 264, (int) y, 256, 10), Color.White);
}
}
}
}
@@ -21,7 +21,7 @@ namespace Barotrauma
private UInt16 pendingSaveID = 1;
public UInt16 PendingSaveID
{
get
get
{
return pendingSaveID;
}
@@ -34,6 +34,14 @@ namespace Barotrauma
}
}
public Wallet PersonalWallet => Character.Controlled?.Wallet ?? Wallet.Invalid;
public override Wallet Wallet => GetWallet();
public override Wallet GetWallet(Client client = null)
{
return PersonalWallet;
}
public static void StartCampaignSetup(IEnumerable<string> saveFiles)
{
var parent = GameMain.NetLobbyScreen.CampaignSetupFrame;
@@ -195,6 +203,11 @@ namespace Barotrauma
yield return CoroutineStatus.Running;
}
if (GameMain.Client == null)
{
yield return CoroutineStatus.Failure;
}
if (GameMain.Client.LateCampaignJoin)
{
GameMain.Client.LateCampaignJoin = false;
@@ -618,7 +631,6 @@ namespace Barotrauma
bool forceMapUI = msg.ReadBoolean();
int money = msg.ReadInt32();
bool purchasedHullRepairs = msg.ReadBoolean();
bool purchasedItemRepairs = msg.ReadBoolean();
bool purchasedLostShuttles = msg.ReadBoolean();
@@ -812,12 +824,10 @@ namespace Barotrauma
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
}
bool shouldRefresh = campaign.Money != money ||
campaign.PurchasedHullRepairs != purchasedHullRepairs ||
bool shouldRefresh = campaign.PurchasedHullRepairs != purchasedHullRepairs ||
campaign.PurchasedItemRepairs != purchasedItemRepairs ||
campaign.PurchasedLostShuttles != purchasedLostShuttles;
campaign.Money = money;
campaign.PurchasedHullRepairs = purchasedHullRepairs;
campaign.PurchasedItemRepairs = purchasedItemRepairs;
campaign.PurchasedLostShuttles = purchasedLostShuttles;
@@ -896,6 +906,43 @@ namespace Barotrauma
}
}
public void ClientReadMoney(IReadMessage inc)
{
NetWalletUpdate update = INetSerializableStruct.Read<NetWalletUpdate>(inc);
foreach (NetWalletTransaction transaction in update.Transactions)
{
WalletInfo info = transaction.Info;
switch (transaction.CharacterID)
{
case Some<ushort> { Value: var charID}:
{
Character targetCharacter = Character.CharacterList?.FirstOrDefault(c => c.ID == charID);
if (targetCharacter is null) { break; }
Wallet wallet = targetCharacter.Wallet;
wallet.Balance = info.Balance;
wallet.RewardDistribution = info.RewardDistribution;
TryInvokeEvent(wallet, transaction.ChangedData, info);
break;
}
case None<ushort> _:
{
Bank.Balance = info.Balance;
TryInvokeEvent(Bank, transaction.ChangedData, info);
break;
}
}
}
void TryInvokeEvent(Wallet wallet, WalletChangedData data, WalletInfo info)
{
if (data.BalanceChanged.IsSome() || data.RewardDistributionChanged.IsSome())
{
OnMoneyChanged.Invoke(new WalletChangedEvent(wallet, data, info));
}
}
}
public override void Save(XElement element)
{
//do nothing, the clients get the save files from the server
@@ -908,10 +955,10 @@ namespace Barotrauma
string gamesessionDocPath = Path.Combine(SaveUtil.TempPath, "gamesession.xml");
XDocument doc = XMLExtensions.TryLoadXml(gamesessionDocPath);
if (doc == null)
if (doc == null)
{
DebugConsole.ThrowError($"Failed to load the state of a multiplayer campaign. Could not open the file \"{gamesessionDocPath}\".");
return;
return;
}
Load(doc.Root.Element("MultiPlayerCampaign"));
GameMain.GameSession.OwnedSubmarines = SaveUtil.LoadOwnedSubmarines(doc, out SubmarineInfo selectedSub);
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Barotrauma.Networking;
namespace Barotrauma
{
@@ -108,6 +109,9 @@ namespace Barotrauma
case "pets":
petsElement = subElement;
break;
case Wallet.LowerCaseSaveElementName:
Bank = new Wallet(subElement);
break;
case "stats":
LoadStats(subElement);
break;
@@ -121,7 +125,15 @@ namespace Barotrauma
InitUI();
Money = element.GetAttributeInt("money", 0);
int oldMoney = element.GetAttributeInt("money", 0);
if (oldMoney > 0)
{
Bank = new Wallet
{
Balance = oldMoney
};
}
PurchasedLostShuttles = element.GetAttributeBool("purchasedlostshuttles", false);
PurchasedHullRepairs = element.GetAttributeBool("purchasedhullrepairs", false);
PurchasedItemRepairs = element.GetAttributeBool("purchaseditemrepairs", false);
@@ -729,7 +741,6 @@ namespace Barotrauma
public override void Save(XElement element)
{
XElement modeElement = new XElement("SinglePlayerCampaign",
new XAttribute("money", Money),
new XAttribute("purchasedlostshuttles", PurchasedLostShuttles),
new XAttribute("purchasedhullrepairs", PurchasedHullRepairs),
new XAttribute("purchaseditemrepairs", PurchasedItemRepairs),
@@ -756,13 +767,14 @@ namespace Barotrauma
petsElement = new XElement("pets");
PetBehavior.SavePets(petsElement);
modeElement.Add(petsElement);
modeElement.Add(petsElement);
CrewManager.Save(modeElement);
CampaignMetadata.Save(modeElement);
Map.Save(modeElement);
CargoManager?.SavePurchasedItems(modeElement);
UpgradeManager?.Save(modeElement);
modeElement.Add(Bank.Save());
element.Add(modeElement);
}
}
@@ -24,7 +24,7 @@ namespace Barotrauma
public TestGameMode(GameModePreset preset) : base(preset)
{
foreach (JobPrefab jobPrefab in JobPrefab.Prefabs)
foreach (JobPrefab jobPrefab in JobPrefab.Prefabs.OrderBy(p => p.Identifier))
{
for (int i = 0; i < jobPrefab.InitialCount; i++)
{