Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -18,6 +18,7 @@ namespace Barotrauma
string FilePath,
Option<SerializableDateTime> SaveTime,
string SubmarineName,
RespawnMode RespawnMode,
ImmutableArray<string> EnabledContentPackageNames) : INetSerializableStruct;
public const int MaxMoney = int.MaxValue / 2; //about 1 billion
@@ -33,6 +34,20 @@ namespace Barotrauma
public enum InteractionType { None, Talk, Examine, Map, Crew, Store, Upgrade, PurchaseSub, MedicalClinic, Cargo }
/// <summary>
/// Should the interaction be disabled if the character's faction is hostile towards the players?
/// </summary>
public static bool HostileFactionDisablesInteraction(InteractionType interactionType)
{
return
interactionType != InteractionType.None &&
//allow interacting with stores, otherwise you could get softlocked
//(no way to get enough resources from a hostile outpost to make it to the next one?)
interactionType != InteractionType.Store &&
//examining is triggered by events, and there may be events that are intended to allow interaction with a hostile NPC.
interactionType != InteractionType.Examine;
}
public static bool BlocksInteraction(InteractionType interactionType)
{
return interactionType != InteractionType.None && interactionType != InteractionType.Cargo;
@@ -103,6 +118,9 @@ namespace Barotrauma
get { return map; }
}
/// <summary>
/// Which missions have been selected for the current round?
/// </summary>
public override IEnumerable<Mission> Missions
{
get
@@ -112,10 +130,13 @@ namespace Barotrauma
{
if (Map.CurrentLocation != null)
{
var currentLevelData = Level.Loaded?.LevelData ?? GameMain.GameSession?.LevelData;
foreach (Mission mission in map.CurrentLocation.SelectedMissions)
{
if (mission.Locations[0] == mission.Locations[1] ||
mission.Locations.Contains(Map.SelectedLocation))
if (//mission takes place in current location
mission.Locations[0] == mission.Locations[1] ||
//mission takes place between two locations, and we're in the level between those locations
mission.Locations.Contains(Map.SelectedLocation) && currentLevelData is { Type: LevelData.LevelType.LocationConnection })
{
yield return mission;
}
@@ -156,10 +177,28 @@ namespace Barotrauma
if (GameMain.NetworkMember.GameStarted)
{
//allow managing if no-one with permissions is alive and in-game
return GameMain.NetworkMember.ConnectedClients.None(c =>
c.InGame && c.Character is { IsIncapacitated: false, IsDead: false } &&
(IsOwner(c) || c.HasPermission(permissions)));
bool someOneHasPermissions = GameMain.NetworkMember.ConnectedClients.Any(c => IsOwner(c) || c.HasPermission(permissions));
if (someOneHasPermissions)
{
if (GameMain.GameSession != null && GameMain.GameSession.RoundDuration < 60.0f)
{
//round has been going on for less than a minute, don't allow anyone to manage just yet,
//the people with permissions might still be loading or doing something in the lobby
return false;
}
else
{
//allow managing if the round has been going on for a while, and no-one with permissions is alive and in-game
return GameMain.NetworkMember.ConnectedClients.None(c =>
c.InGame && c.Character is { IsIncapacitated: false, IsDead: false } &&
(IsOwner(c) || c.HasPermission(permissions)));
}
}
else
{
//no-one in the server with permissions, allow anyone to manage
return true;
}
}
else
{
@@ -170,6 +209,7 @@ namespace Barotrauma
protected CampaignMode(GameModePreset preset, CampaignSettings settings)
: base(preset)
{
Settings = settings;
Bank = new Wallet(Option<Character>.None())
{
Balance = settings.InitialMoney
@@ -246,7 +286,7 @@ namespace Barotrauma
sub != leavingSub &&
!leavingSub.DockedTo.Contains(sub) &&
sub.Info.Type == SubmarineType.Player && sub.TeamID == CharacterTeamType.Team1 && // pirate subs are currently tagged as player subs as well
sub != GameMain.NetworkMember?.RespawnManager?.RespawnShuttle &&
!sub.IsRespawnShuttle &&
(sub.AtEndExit != leavingSub.AtEndExit || sub.AtStartExit != leavingSub.AtStartExit));
}
@@ -401,9 +441,9 @@ namespace Barotrauma
currentLocation.DeselectMission(mission);
}
}
if (levelData.HasBeaconStation && !levelData.IsBeaconActive && Missions.None(m => m.Prefab.Type == MissionType.Beacon))
if (levelData.HasBeaconStation && !levelData.IsBeaconActive && Missions.None(m => m.Prefab.Type == Tags.MissionTypeBeacon))
{
var beaconMissionPrefabs = MissionPrefab.Prefabs.Where(m => m.IsSideObjective && m.Type == MissionType.Beacon);
var beaconMissionPrefabs = MissionPrefab.Prefabs.Where(m => m.IsSideObjective && m.Type == Tags.MissionTypeBeacon);
if (beaconMissionPrefabs.Any())
{
var filteredMissions = beaconMissionPrefabs.Where(m => levelData.Difficulty >= m.MinLevelDifficulty && levelData.Difficulty <= m.MaxLevelDifficulty);
@@ -490,7 +530,7 @@ namespace Barotrauma
if (missionPrefabs.Any())
{
var missionPrefab = ToolBox.SelectWeightedRandom(missionPrefabs, p => p.Commonness, rand);
if (missionPrefab.Type == MissionType.Pirate && Missions.Any(m => m.Prefab.Type == MissionType.Pirate))
if (missionPrefab.Type == Tags.MissionTypePirate && Missions.Any(m => m.Prefab.Type == Tags.MissionTypePirate))
{
continue;
}
@@ -769,7 +809,7 @@ namespace Barotrauma
{
foreach (var dockedSub in Level.Loaded.StartOutpost.DockedTo)
{
if (dockedSub == GameMain.NetworkMember?.RespawnManager?.RespawnShuttle || dockedSub.TeamID != submarineTeam) { continue; }
if (dockedSub.IsRespawnShuttle || dockedSub.TeamID != submarineTeam) { continue; }
return dockedSub.DockedTo.Contains(Submarine.MainSub) ? Submarine.MainSub : dockedSub;
}
}
@@ -809,7 +849,7 @@ namespace Barotrauma
{
foreach (var dockedSub in Level.Loaded.EndOutpost.DockedTo)
{
if (dockedSub == GameMain.NetworkMember?.RespawnManager?.RespawnShuttle || dockedSub.TeamID != submarineTeam) { continue; }
if (dockedSub.IsRespawnShuttle || dockedSub.TeamID != submarineTeam) { continue; }
return dockedSub.DockedTo.Contains(Submarine.MainSub) ? Submarine.MainSub : dockedSub;
}
}
@@ -941,7 +981,9 @@ namespace Barotrauma
{
UpdateStoreStock();
}
GameMain.GameSession.EventManager?.RegisterEventHistory(registerFinishedOnly: true);
GameMain.GameSession.EndMissions();
GameMain.GameSession.EventManager?.StoreEventDataAtRoundEnd(registerFinishedOnly: true);
}
/// <summary>
@@ -1067,13 +1109,24 @@ namespace Barotrauma
return false;
}
}
var price = buyingNewCharacter ? NewCharacterCost(characterInfo) : HireManager.GetSalaryFor(characterInfo);
int price = buyingNewCharacter ? NewCharacterCost(characterInfo) : HireManager.GetSalaryFor(characterInfo);
if (takeMoney && !TryPurchase(client, price)) { return false; }
characterInfo.IsNewHire = true;
characterInfo.Title = null;
location.RemoveHireableCharacter(characterInfo);
CrewManager.AddCharacterInfo(characterInfo);
if (GameMain.GameSession?.Campaign is MultiPlayerCampaign)
{
#if SERVER
CrewManager.ToggleReserveBenchStatus(characterInfo, client, pendingHire: true, confirmPendingHire: true, sendUpdate: false);
#endif
}
else
{
CrewManager.AddCharacterInfo(characterInfo);
}
GameAnalyticsManager.AddMoneySpentEvent(characterInfo.Salary, GameAnalyticsManager.MoneySink.Crew, characterInfo.Job?.Prefab.Identifier.Value ?? "unknown");
return true;
}
@@ -1092,6 +1145,7 @@ namespace Barotrauma
private void NPCInteract(Character npc, Character interactor)
{
if (!npc.AllowCustomInteract) { return; }
if (npc.AIController is HumanAIController humanAi && !humanAi.AllowCampaignInteraction()) { return; }
NPCInteractProjSpecific(npc, interactor);
string coroutineName = "DoCharacterWait." + (npc?.ID ?? Entity.NullEntityID);
if (!CoroutineManager.IsCoroutineRunning(coroutineName))
@@ -1287,7 +1341,7 @@ namespace Barotrauma
return Faction.GetPlayerAffiliationStatus(faction);
}
public abstract void Save(XElement element);
public abstract void Save(XElement element, bool isSavingOnLoading);
protected void LoadStats(XElement element)
{
@@ -140,13 +140,14 @@ namespace Barotrauma
private static readonly Dictionary<string, MultiplierSettings> _multiplierSettings = new Dictionary<string, MultiplierSettings>
{
{ "default", new MultiplierSettings { Min = 0.2f, Max = 2.0f, Step = 0.1f } },
{ nameof(CrewVitalityMultiplier), new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
{ nameof(NonCrewVitalityMultiplier),new MultiplierSettings { Min = 0.5f, Max = 3.0f, Step = 0.1f } },
{ nameof(MissionRewardMultiplier), new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
{ nameof(RepairFailMultiplier), new MultiplierSettings { Min = 0.5f, Max = 5.0f, Step = 0.5f } },
{ nameof(ShopPriceMultiplier), new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } },
{ nameof(ShipyardPriceMultiplier), new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } }
{ "default", new MultiplierSettings { Min = 0.2f, Max = 2.0f, Step = 0.1f } },
{ nameof(CrewVitalityMultiplier), new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
{ nameof(NonCrewVitalityMultiplier), new MultiplierSettings { Min = 0.5f, Max = 3.0f, Step = 0.1f } },
{ nameof(MissionRewardMultiplier), new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
{ nameof(ExperienceRewardMultiplier), new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
{ nameof(RepairFailMultiplier), new MultiplierSettings { Min = 0.5f, Max = 5.0f, Step = 0.5f } },
{ nameof(ShopPriceMultiplier), new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } },
{ nameof(ShipyardPriceMultiplier), new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } }
// Add overrides for default values here
};
@@ -165,6 +166,9 @@ namespace Barotrauma
[Serialize(1.0f, IsPropertySaveable.Yes), NetworkSerialize]
public float MissionRewardMultiplier { get; set; }
[Serialize(1.0f, IsPropertySaveable.Yes), NetworkSerialize]
public float ExperienceRewardMultiplier { get; set; }
[Serialize(1.0f, IsPropertySaveable.Yes), NetworkSerialize]
public float ShopPriceMultiplier { get; set; }
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
namespace Barotrauma
{
@@ -7,6 +6,6 @@ namespace Barotrauma
{
public CoOpMode(GameModePreset preset, IEnumerable<MissionPrefab> missionPrefabs) : base(preset, ValidateMissionPrefabs(missionPrefabs, MissionPrefab.CoOpMissionClasses)) { }
public CoOpMode(GameModePreset preset, MissionType missionType, string seed) : base(preset, ValidateMissionType(missionType, MissionPrefab.CoOpMissionClasses), seed) { }
public CoOpMode(GameModePreset preset, IEnumerable<Identifier> missionTypes, string seed) : base(preset, ValidateMissionTypes(missionTypes, MissionPrefab.CoOpMissionClasses), seed) { }
}
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -25,42 +26,37 @@ namespace Barotrauma
}
}
public MissionMode(GameModePreset preset, MissionType missionType, string seed)
public MissionMode(GameModePreset preset, IEnumerable<Identifier> missionTypes, string seed)
: base(preset)
{
Location[] locations = { GameMain.GameSession.StartLocation, GameMain.GameSession.EndLocation };
var mission = Mission.LoadRandom(locations, seed, requireCorrectLocationType: false, missionType, difficultyLevel: GameMain.NetworkMember.ServerSettings.SelectedLevelDifficulty);
var mission = Mission.LoadRandom(locations, seed, requireCorrectLocationType: false, missionTypes, difficultyLevel: GameMain.NetworkMember.ServerSettings.SelectedLevelDifficulty);
if (mission != null)
{
missions.Add(mission);
}
}
protected static IEnumerable<MissionPrefab> ValidateMissionPrefabs(IEnumerable<MissionPrefab> missionPrefabs, Dictionary<MissionType, Type> missionClasses)
protected static IEnumerable<MissionPrefab> ValidateMissionPrefabs(IEnumerable<MissionPrefab> missionPrefabs, Dictionary<Identifier, Type> missionClasses)
{
foreach (MissionPrefab missionPrefab in missionPrefabs)
{
if (ValidateMissionType(missionPrefab.Type, missionClasses) != missionPrefab.Type)
if (!missionClasses.ContainsValue(missionPrefab.MissionClass))
{
throw new InvalidOperationException("Cannot start gamemode with mission type " + missionPrefab.Type);
throw new InvalidOperationException($"Cannot start gamemode with a {missionPrefab.MissionClass} mission.");
}
}
return missionPrefabs;
}
protected static MissionType ValidateMissionType(MissionType missionType, Dictionary<MissionType, Type> missionClasses)
/// <summary>
/// Returns the mission types that are valid for the given mission classes (e.g. all mission types suitable for the PvP mission classes).
/// </summary>
public static IEnumerable<Identifier> ValidateMissionTypes(IEnumerable<Identifier> missionTypes, Dictionary<Identifier, Type> missionClasses)
{
var missionTypes = (MissionType[])Enum.GetValues(typeof(MissionType));
for (int i = 0; i < missionTypes.Length; i++)
{
var type = missionTypes[i];
if (type == MissionType.None || type == MissionType.All) { continue; }
if (!missionClasses.ContainsKey(type))
{
missionType &= ~(type);
}
}
return missionType;
return missionTypes.Where(type =>
MissionPrefab.Prefabs.OrderBy(missionPrefab => missionPrefab.UintIdentifier)
.Any(missionPrefab => missionPrefab.Type == type && missionClasses.ContainsValue(missionPrefab.MissionClass)));
}
}
}
@@ -92,6 +92,11 @@ namespace Barotrauma
get; set;
}
public byte RoundID
{
get; set;
}
private MultiPlayerCampaign(CampaignSettings settings) : base(GameModePreset.MultiPlayerCampaign, settings)
{
currentCampaignID++;
@@ -116,7 +121,6 @@ namespace Barotrauma
//only the server generates the map, the clients load it from a save file
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
campaign.Settings = settings;
campaign.map = new Map(campaign, mapSeed);
}
campaign.InitProjSpecific();
@@ -133,16 +137,24 @@ namespace Barotrauma
}
partial void InitProjSpecific();
public static string GetCharacterDataSavePath(string savePath)
public static string GetCharacterDataSavePath(string loadPath)
{
return Path.Combine(Path.GetDirectoryName(savePath), Path.GetFileNameWithoutExtension(savePath) + "_CharacterData.xml");
string directory = Path.GetDirectoryName(loadPath);
string fileName = Path.GetFileNameWithoutExtension(loadPath);
if (CampaignDataPath.IsBackupPath(loadPath, out uint backupIndex))
{
string trimmedFileName = Path.GetFileNameWithoutExtension(fileName);
return Path.Combine(directory, $"{trimmedFileName}_CharacterData{SaveUtil.BackupCharacterDataExtensionStart}{backupIndex}");
}
return Path.Combine(directory, $"{fileName}_CharacterData.xml");
}
public static string GetCharacterDataSavePath()
{
return GetCharacterDataSavePath(GameMain.GameSession.SavePath);
}
public static string GetCharacterDataPathForLoading()
=> GetCharacterDataSavePath(GameMain.GameSession.DataPath.LoadPath);
public static string GetCharacterDataPathForSaving()
=> GetCharacterDataSavePath(GameMain.GameSession.DataPath.SavePath);
/// <summary>
/// Loads the campaign from an XML element. Creates the map if it hasn't been created yet, otherwise updates the state of the map.
@@ -254,7 +266,7 @@ namespace Barotrauma
#if SERVER
characterData.Clear();
string characterDataPath = GetCharacterDataSavePath();
string characterDataPath = GetCharacterDataPathForLoading();
if (!File.Exists(characterDataPath))
{
DebugConsole.ThrowError($"Failed to load the character data for the campaign. Could not find the file \"{characterDataPath}\".");
@@ -1,50 +1,27 @@
using Barotrauma.Extensions;
using Barotrauma.Extensions;
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
class PvPMode : MissionMode
partial class PvPMode : MissionMode
{
public PvPMode(GameModePreset preset, IEnumerable<MissionPrefab> missionPrefabs) : base(preset, ValidateMissionPrefabs(missionPrefabs, MissionPrefab.PvPMissionClasses)) { }
public PvPMode(GameModePreset preset, MissionType missionType, string seed) : base(preset, ValidateMissionType(missionType, MissionPrefab.PvPMissionClasses), seed) { }
public void AssignTeamIDs(IEnumerable<Client> clients)
public PvPMode(GameModePreset preset, IEnumerable<MissionPrefab> missionPrefabs) :
base(preset, ValidateMissionPrefabs(missionPrefabs, MissionPrefab.PvPMissionClasses))
{
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 (Missions.None())
{
if (unassignedClients[i].PreferredTeam == CharacterTeamType.Team1 ||
unassignedClients[i].PreferredTeam == CharacterTeamType.Team2)
{
assignTeam(unassignedClients[i], unassignedClients[i].PreferredTeam);
i--;
}
}
//assign the rest of the clients to the team that has the least players
while (unassignedClients.Any())
{
var randomClient = unassignedClients.GetRandom(Rand.RandSync.Unsynced);
assignTeam(randomClient, team1Count < team2Count ? CharacterTeamType.Team1 : CharacterTeamType.Team2);
throw new System.Exception($"Attempted to start {nameof(PvPMode)} without a mission.");
}
}
void assignTeam(Client client, CharacterTeamType team)
public PvPMode(GameModePreset preset, IEnumerable<Identifier> missionTypes, string seed) :
base(preset, ValidateMissionTypes(missionTypes, MissionPrefab.PvPMissionClasses), seed)
{
if (Missions.None())
{
client.TeamID = team;
unassignedClients.Remove(client);
if (team == CharacterTeamType.Team1)
{
team1Count++;
}
else
{
team2Count++;
}
throw new System.Exception($"Attempted to start {nameof(PvPMode)} without a mission.");
}
}
}
@@ -0,0 +1,19 @@
using System.Linq;
namespace Barotrauma
{
partial class TestGameMode : GameMode
{
public TestGameMode(GameModePreset preset) : base(preset)
{
foreach (JobPrefab jobPrefab in JobPrefab.Prefabs.OrderBy(p => p.Identifier))
{
for (int i = 0; i < jobPrefab.InitialCount; i++)
{
var variant = Rand.Range(0, jobPrefab.Variants);
CrewManager.AddCharacterInfo(new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobOrJobPrefab: jobPrefab, variant: variant));
}
}
}
}
}