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

This commit is contained in:
EvilFactory
2022-09-29 12:13:55 -03:00
602 changed files with 19759 additions and 16312 deletions
@@ -34,7 +34,7 @@ namespace Barotrauma
public double TotalPlayTime;
public int TotalPassedLevels;
public enum InteractionType { None, Talk, Examine, Map, Crew, Store, Repair, Upgrade, PurchaseSub, MedicalClinic, Cargo }
public enum InteractionType { None, Talk, Examine, Map, Crew, Store, Upgrade, PurchaseSub, MedicalClinic, Cargo }
public static bool BlocksInteraction(InteractionType interactionType)
{
@@ -85,7 +85,9 @@ namespace Barotrauma
public bool CheatsEnabled;
public const int HullRepairCost = 500, ItemRepairCost = 500, ShuttleReplaceCost = 1000;
public const float HullRepairCostPerDamage = 0.5f, ItemRepairCostPerRepairDuration = 1.0f;
public const int ShuttleReplaceCost = 1000;
public const int MaxHullRepairCost = 2000, MaxItemRepairCost = 2000;
protected bool wasDocked;
@@ -131,6 +133,8 @@ namespace Barotrauma
protected set;
}
public bool PurchasedLostShuttlesInLatestSave, PurchasedHullRepairsInLatestSave, PurchasedItemRepairsInLatestSave;
public virtual bool PurchasedHullRepairs { get; set; }
public virtual bool PurchasedLostShuttles { get; set; }
public virtual bool PurchasedItemRepairs { get; set; }
@@ -152,8 +156,9 @@ namespace Barotrauma
{
if (!(e.ChangedData.BalanceChanged is Some<int> { Value: var changed })) { return; }
bool isGain = changed > 0;
if (changed != 0) { return; }
bool isGain = changed > 0;
Color clr = isGain ? GUIStyle.Yellow : GUIStyle.Red;
switch (e.Owner)
@@ -225,7 +230,8 @@ namespace Barotrauma
#if CLIENT
prevCampaignUIAutoOpenType = TransitionType.None;
#endif
if (PurchasedHullRepairs)
if (PurchasedHullRepairsInLatestSave)
{
foreach (Structure wall in Structure.WallList)
{
@@ -238,9 +244,9 @@ namespace Barotrauma
}
}
}
PurchasedHullRepairs = false;
PurchasedHullRepairsInLatestSave = PurchasedHullRepairs = false;
}
if (PurchasedItemRepairs)
if (PurchasedItemRepairsInLatestSave)
{
foreach (Item item in Item.ItemList)
{
@@ -253,13 +259,46 @@ namespace Barotrauma
}
}
}
PurchasedItemRepairs = false;
PurchasedItemRepairsInLatestSave = PurchasedItemRepairs = false;
}
PurchasedLostShuttles = false;
PurchasedLostShuttlesInLatestSave = PurchasedLostShuttles = false;
var connectedSubs = Submarine.MainSub.GetConnectedSubs();
wasDocked = Level.Loaded.StartOutpost != null && connectedSubs.Contains(Level.Loaded.StartOutpost);
}
public int GetHullRepairCost()
{
float totalDamage = 0;
foreach (Structure wall in Structure.WallList)
{
if (wall.Submarine == null || wall.Submarine.Info.Type != SubmarineType.Player) { continue; }
if (wall.Submarine == Submarine.MainSub || Submarine.MainSub.DockedTo.Contains(wall.Submarine))
{
for (int i = 0; i < wall.SectionCount; i++)
{
totalDamage += wall.SectionDamage(i);
}
}
}
return (int)Math.Min(totalDamage * HullRepairCostPerDamage, MaxHullRepairCost);
}
public int GetItemRepairCost()
{
float totalRepairDuration = 0.0f;
foreach (Item item in Item.ItemList)
{
if (item.Submarine == null || item.Submarine.Info.Type != SubmarineType.Player) { continue; }
if (item.Submarine == Submarine.MainSub || Submarine.MainSub.DockedTo.Contains(item.Submarine))
{
var repairable = item.GetComponent<Repairable>();
if (repairable == null) { continue; }
totalRepairDuration += repairable.FixDurationHighSkill * (1.0f - item.Condition / item.MaxCondition);
}
}
return (int)Math.Min(totalRepairDuration * ItemRepairCostPerRepairDuration, MaxItemRepairCost);
}
public void InitCampaignData()
{
Factions = new List<Faction>();
@@ -689,7 +728,7 @@ namespace Barotrauma
}
foreach (LocationConnection connection in Map.Connections)
{
connection.Difficulty = connection.Biome.MaxDifficulty;
connection.Difficulty = connection.Biome.AdjustedMaxDifficulty;
connection.LevelData = new LevelData(connection)
{
IsBeaconActive = false
@@ -698,7 +737,7 @@ namespace Barotrauma
}
foreach (Location location in Map.Locations)
{
location.LevelData = new LevelData(location, location.Biome.MaxDifficulty);
location.LevelData = new LevelData(location, location.Biome.AdjustedMaxDifficulty);
location.Reset();
}
Map.SetLocation(Map.Locations.IndexOf(Map.StartLocation));
@@ -1,27 +1,16 @@
using System.Xml.Linq;
using Barotrauma.Networking;
namespace Barotrauma
{
partial class CharacterCampaignData
{
public CharacterInfo CharacterInfo
{
get;
private set;
}
public readonly CharacterInfo CharacterInfo;
public readonly string Name;
public string ClientEndPoint
{
get;
private set;
}
public ulong SteamID
{
get;
private set;
}
public readonly Address ClientAddress;
public readonly Option<AccountId> AccountId;
private XElement itemData;
private XElement healthData;
@@ -10,8 +10,6 @@ namespace Barotrauma
{
partial class MultiPlayerCampaign : CampaignMode
{
public const int MinimumInitialMoney = 500;
[Flags]
public enum NetFlags : UInt16
{
@@ -151,9 +149,9 @@ namespace Barotrauma
/// </summary>
private void Load(XElement element)
{
PurchasedLostShuttles = element.GetAttributeBool("purchasedlostshuttles", false);
PurchasedHullRepairs = element.GetAttributeBool("purchasedhullrepairs", false);
PurchasedItemRepairs = element.GetAttributeBool("purchaseditemrepairs", false);
PurchasedLostShuttlesInLatestSave = element.GetAttributeBool("purchasedlostshuttles", false);
PurchasedHullRepairsInLatestSave = element.GetAttributeBool("purchasedhullrepairs", false);
PurchasedItemRepairsInLatestSave = element.GetAttributeBool("purchaseditemrepairs", false);
CheatsEnabled = element.GetAttributeBool("cheatsenabled", false);
if (CheatsEnabled)
{
@@ -294,14 +292,14 @@ namespace Barotrauma
private static void WriteItems(IWriteMessage msg, Dictionary<Identifier, List<PurchasedItem>> purchasedItems)
{
msg.Write((byte)purchasedItems.Count);
msg.WriteByte((byte)purchasedItems.Count);
foreach (var storeItems in purchasedItems)
{
msg.Write(storeItems.Key);
msg.Write((UInt16)storeItems.Value.Count);
msg.WriteIdentifier(storeItems.Key);
msg.WriteUInt16((UInt16)storeItems.Value.Count);
foreach (var item in storeItems.Value)
{
msg.Write(item.ItemPrefabIdentifier);
msg.WriteIdentifier(item.ItemPrefabIdentifier);
msg.WriteRangedInteger(item.Quantity, 0, CargoManager.MaxQuantity);
}
}
@@ -328,18 +326,18 @@ namespace Barotrauma
private static void WriteItems(IWriteMessage msg, Dictionary<Identifier, List<SoldItem>> soldItems)
{
msg.Write((byte)soldItems.Count);
msg.WriteByte((byte)soldItems.Count);
foreach (var storeItems in soldItems)
{
msg.Write(storeItems.Key);
msg.Write((UInt16)storeItems.Value.Count);
msg.WriteIdentifier(storeItems.Key);
msg.WriteUInt16((UInt16)storeItems.Value.Count);
foreach (var item in storeItems.Value)
{
msg.Write(item.ItemPrefab.Identifier);
msg.Write((UInt16)item.ID);
msg.Write(item.Removed);
msg.Write(item.SellerID);
msg.Write((byte)item.Origin);
msg.WriteIdentifier(item.ItemPrefab.Identifier);
msg.WriteUInt16((UInt16)item.ID);
msg.WriteBoolean(item.Removed);
msg.WriteByte(item.SellerID);
msg.WriteByte((byte)item.Origin);
}
}
}
@@ -1,5 +1,7 @@
using Barotrauma.Extensions;
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -11,37 +13,37 @@ namespace Barotrauma
public void AssignTeamIDs(IEnumerable<Client> clients)
{
int teamWeight = 0;
List<Client> randList = new List<Client>(clients);
for (int i = 0; i < randList.Count; i++)
int team1Count = 0, team2Count = 0;
//if a client has a preference, assign them to that team
List<Client> unassignedClients = new List<Client>(clients);
for (int i = 0; i < unassignedClients.Count; i++)
{
if (randList[i].PreferredTeam == CharacterTeamType.Team1 ||
randList[i].PreferredTeam == CharacterTeamType.Team2)
if (unassignedClients[i].PreferredTeam == CharacterTeamType.Team1 ||
unassignedClients[i].PreferredTeam == CharacterTeamType.Team2)
{
randList[i].TeamID = randList[i].PreferredTeam;
teamWeight += randList[i].PreferredTeam == CharacterTeamType.Team1 ? -1 : 1;
randList.RemoveAt(i);
assignTeam(unassignedClients[i], unassignedClients[i].PreferredTeam);
i--;
}
}
for (int i = 0; i<randList.Count; i++)
{
Client a = randList[i];
int oi = Rand.Range(0, randList.Count - 1);
Client b = randList[oi];
randList[i] = b;
randList[oi] = a;
}
int halfPlayers = (randList.Count / 2) + teamWeight;
for (int i = 0; i < randList.Count; i++)
//assign the rest of the clients to the team that has the least players
while (unassignedClients.Any())
{
if (i < halfPlayers)
var randomClient = unassignedClients.GetRandom(Rand.RandSync.Unsynced);
assignTeam(randomClient, team1Count < team2Count ? CharacterTeamType.Team1 : CharacterTeamType.Team2);
}
void assignTeam(Client client, CharacterTeamType team)
{
client.TeamID = team;
unassignedClients.Remove(client);
if (team == CharacterTeamType.Team1)
{
randList[i].TeamID = CharacterTeamType.Team1;
team1Count++;
}
else
{
randList[i].TeamID = CharacterTeamType.Team2;
team2Count++;
}
}
}
@@ -0,0 +1,90 @@
using System.Collections.Immutable;
using System.Linq;
namespace Barotrauma
{
class TutorialPrefab : Prefab
{
public static readonly PrefabCollection<TutorialPrefab> Prefabs =
#if CLIENT
new PrefabCollection<TutorialPrefab>(onSort: MainMenuScreen.UpdateInstanceTutorialButtons);
#else
new PrefabCollection<TutorialPrefab>();
#endif
public readonly int Order;
public readonly bool DisableBotConversations;
public readonly bool AllowCharacterSwitch;
public readonly ContentPath SubmarinePath = ContentPath.FromRaw("Content/Tutorials/Dugong_Tutorial.sub");
public readonly ContentPath OutpostPath = ContentPath.FromRaw("Content/Tutorials/TutorialOutpost.sub");
public readonly string LevelSeed;
public readonly string LevelParams;
private readonly ContentXElement tutorialCharacterElement;
public readonly ImmutableArray<Identifier> StartingItemTags;
public readonly Identifier EventIdentifier;
public readonly Sprite Banner;
public TutorialPrefab(ContentFile file, ContentXElement element) : base(file, element.GetAttributeIdentifier("identifier", ""))
{
Order = element.GetAttributeInt("order", int.MaxValue);
DisableBotConversations = element.GetAttributeBool("disablebotconversations", true);
AllowCharacterSwitch = element.GetAttributeBool("allowcharacterswitch", false);
SubmarinePath = element.GetAttributeContentPath("submarinepath") ?? SubmarinePath;
OutpostPath = element.GetAttributeContentPath("outpostpath") ?? OutpostPath;
LevelSeed = element.GetAttributeString("levelseed", "nLoZLLtza");
LevelParams = element.GetAttributeString("levelparams", "ColdCavernsTutorial");
tutorialCharacterElement = element.GetChildElement("characterinfo");
if (tutorialCharacterElement != null)
{
StartingItemTags = tutorialCharacterElement
.GetAttributeIdentifierArray("startingitemtags", new Identifier[0])
.ToImmutableArray();
}
else
{
StartingItemTags = ImmutableArray<Identifier>.Empty;
}
var bannerElement = element.GetChildElement("banner");
if (bannerElement != null)
{
Banner = new Sprite(bannerElement, lazyLoad: true);
}
EventIdentifier = element.GetChildElement("scriptedevent")?.GetAttributeIdentifier("identifier", "") ?? Identifier.Empty;
}
public CharacterInfo GetTutorialCharacterInfo()
{
if (tutorialCharacterElement == null)
{
return null;
}
Identifier speciesName = tutorialCharacterElement.GetAttributeIdentifier("speciesname", CharacterPrefab.HumanSpeciesName);
Identifier jobPrefabIdentifier = tutorialCharacterElement.GetAttributeIdentifier("jobidentifier", "assistant");
if (!JobPrefab.Prefabs.TryGet(jobPrefabIdentifier, out var jobPrefab))
{
jobPrefab = JobPrefab.Prefabs.First();
}
int jobVariant = tutorialCharacterElement.GetAttributeInt("variant", 0);
var characterInfo = new CharacterInfo(speciesName, jobOrJobPrefab: jobPrefab, variant: jobVariant);
foreach (var skillElement in tutorialCharacterElement.GetChildElements("skill"))
{
Identifier skillIdentifier = skillElement.GetAttributeIdentifier("identifier", "");
if (skillIdentifier.IsEmpty) { continue; }
float level = skillElement.GetAttributeFloat("level", 0.0f);
characterInfo.SetSkillLevel(skillIdentifier, level);
}
return characterInfo;
}
public override void Dispose() { }
}
}