v0.19.8.0

This commit is contained in:
Juan Pablo Arce
2022-09-28 21:30:52 -03:00
parent fec8131243
commit 3ca584f2fc
152 changed files with 1931 additions and 1071 deletions
@@ -329,21 +329,14 @@ namespace Barotrauma
}
public override void End()
protected override bool DetermineCompleted()
{
completed = State > 0 && State != HostagesKilledState;
if (completed)
{
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
GiveReward();
}
else
{
failed = requireRescue.Any(r => r.Removed || r.IsDead);
}
return State > 0 && State != HostagesKilledState;
}
protected override void EndMissionSpecific(bool completed)
{
failed = !completed && requireRescue.Any(r => r.Removed || r.IsDead);
}
}
}
@@ -156,22 +156,21 @@ namespace Barotrauma
return true;
}
private bool IsItemDestroyed(Item item) => item == null || item.Removed || item.Condition <= 0.0f;
private static bool IsItemDestroyed(Item item) => item == null || item.Removed || item.Condition <= 0.0f;
private bool IsEnemyDefeated(Character enemy) => enemy == null ||enemy.Removed || enemy.IsDead;
private static bool IsEnemyDefeated(Character enemy) => enemy == null ||enemy.Removed || enemy.IsDead;
public override void End()
protected override bool DetermineCompleted()
{
bool exitingLevel = GameMain.GameSession?.GameMode is CampaignMode campaign ?
campaign.GetAvailableTransition() != CampaignMode.TransitionType.None :
Submarine.MainSub is { } sub && (sub.AtEndExit || sub.AtStartExit);
if (State > 0 && exitingLevel)
{
GiveReward();
completed = true;
}
return State > 0 && exitingLevel;
}
protected override void EndMissionSpecific(bool completed)
{
failed = !completed && State > 0;
}
}
@@ -163,20 +163,16 @@ namespace Barotrauma
#endif
}
public override void End()
protected override bool DetermineCompleted()
{
completed = level.CheckBeaconActive();
if (completed)
return level.CheckBeaconActive();
}
protected override void EndMissionSpecific(bool completed)
{
if (completed && level.LevelData != null)
{
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
GiveReward();
if (level.LevelData != null)
{
level.LevelData.IsBeaconActive = true;
}
level.LevelData.IsBeaconActive = true;
}
}
@@ -219,7 +219,7 @@ namespace Barotrauma
else if (sub != this.currentSub || missionsChanged)
{
this.currentSub = sub;
this.nextRoundSubInfo = sub.Info;
this.nextRoundSubInfo = sub?.Info;
DetermineCargo();
}
@@ -294,22 +294,21 @@ namespace Barotrauma
}
}
public override void End()
protected override bool DetermineCompleted()
{
if (Submarine.MainSub != null && Submarine.MainSub.AtEndExit)
{
int deliveredItemCount = items.Count(it => IsItemDelivered(it));
if (deliveredItemCount / (float)items.Count >= requiredDeliveryAmount)
{
GiveReward();
completed = true;
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
return true;
}
}
return false;
}
protected override void EndMissionSpecific(bool completed)
{
foreach (Item item in items)
{
if (!item.Removed) { item.Remove(); }
@@ -318,7 +317,7 @@ namespace Barotrauma
failed = !completed;
}
private bool IsItemDelivered(Item item)
private static bool IsItemDelivered(Item item)
{
if (item.Removed || item.Condition <= 0.0f || Submarine.MainSub == null) { return false; }
var submarine = item.Submarine ?? item.GetRootContainer()?.Submarine;
@@ -113,15 +113,9 @@ namespace Barotrauma
#endif
}
public override void End()
protected override bool DetermineCompleted()
{
if (GameMain.NetworkMember == null) { return; }
if (Winner != CharacterTeamType.None)
{
GiveReward();
completed = true;
}
return Winner != CharacterTeamType.None;
}
}
}
@@ -305,7 +305,7 @@ namespace Barotrauma
return character.LockHands && character.HasTeamChange(TerroristTeamChangeIdentifier);
}
public override void End()
protected override bool DetermineCompleted()
{
if (Submarine.MainSub != null && Submarine.MainSub.AtEndExit)
{
@@ -321,11 +321,14 @@ namespace Barotrauma
if (friendliesSurvived && !terroristsSurvived && !vipDied)
{
GiveReward();
completed = true;
return true;
}
}
return false;
}
protected override void EndMissionSpecific(bool completed)
{
if (!IsClient)
{
foreach (Character character in characters)
@@ -1,6 +1,4 @@
using Barotrauma.Networking;
namespace Barotrauma
namespace Barotrauma
{
partial class GoToMission : Mission
{
@@ -11,7 +9,22 @@ namespace Barotrauma
protected override void UpdateMissionSpecific(float deltaTime)
{
State = 1;
if (Level.Loaded?.Type == LevelData.LevelType.Outpost)
{
State = 1;
}
}
protected override bool DetermineCompleted()
{
if (Level.Loaded?.Type == LevelData.LevelType.Outpost)
{
return true;
}
else
{
return Submarine.MainSub is { AtEndExit: true };
}
}
}
}
@@ -131,13 +131,13 @@ namespace Barotrauma
foreach ((Identifier identifier, ResourceCluster cluster) in resourceClusters)
{
if (!(MapEntityPrefab.FindByIdentifier(identifier) is ItemPrefab prefab))
if (MapEntityPrefab.FindByIdentifier(identifier) is not ItemPrefab prefab)
{
DebugConsole.ThrowError($"Error in MineralMission: couldn't find an item prefab (identifier: \"{identifier}\")");
continue;
}
var spawnedResources = level.GenerateMissionResources(prefab, cluster.Amount, positionType, out float rotation);
var spawnedResources = level.GenerateMissionResources(prefab, cluster.Amount, positionType, out float rotation, caves);
if (spawnedResources.Count < cluster.Amount)
{
DebugConsole.ThrowError($"Error in MineralMission: spawned only {spawnedResources.Count}/{cluster.Amount} of {prefab.Name}");
@@ -181,14 +181,16 @@ namespace Barotrauma
}
}
public override void End()
protected override bool DetermineCompleted()
{
if (EnoughHaveBeenCollected())
return EnoughHaveBeenCollected();
}
protected override void EndMissionSpecific(bool completed)
{
failed = !completed && state > 0;
if (completed)
{
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
if (!IsClient)
{
// When mission is completed successfully, half of the resources will be removed from the player (i.e. given to the outpost as a part of the mission)
@@ -198,7 +200,7 @@ namespace Barotrauma
if (relevantLevelResources.TryGetValue(identifier, out var availableResources))
{
var collectedResources = availableResources.Where(HasBeenCollected);
if (collectedResources.Count() < 1) { continue; }
if (!collectedResources.Any()) { continue; }
int handoverCount = (int)MathF.Round(resourceHandoverAmount * collectedResources.Count());
for (int i = 0; i < handoverCount; i++)
{
@@ -211,8 +213,6 @@ namespace Barotrauma
resource.Remove();
}
}
GiveReward();
completed = true;
}
foreach (var kvp in spawnedResources)
{
@@ -227,7 +227,6 @@ namespace Barotrauma
spawnedResources.Clear();
relevantLevelResources.Clear();
missionClusterPositions.Clear();
failed = !completed && state > 0;
}
private void FindRelevantLevelResources()
@@ -13,7 +13,8 @@ namespace Barotrauma
abstract partial class Mission
{
public readonly MissionPrefab Prefab;
protected bool completed, failed;
private bool completed;
protected bool failed;
protected Level level;
@@ -36,7 +37,9 @@ namespace Barotrauma
}
}
protected bool IsClient => GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient;
protected static bool IsClient => GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient;
private readonly CheckDataAction completeCheckDataAction;
public readonly ImmutableArray<LocalizedString> Headers;
public readonly ImmutableArray<LocalizedString> Messages;
@@ -156,6 +159,12 @@ namespace Barotrauma
Locations = locations;
var endConditionElement = prefab.ConfigElement.GetChildElement(nameof(completeCheckDataAction));
if (endConditionElement != null)
{
completeCheckDataAction = new CheckDataAction(endConditionElement, $"Mission ({prefab.Identifier.ToString()})");
}
for (int n = 0; n < 2; n++)
{
string locationName = $"‖color:gui.orange‖{locations[n].Name}‖end‖";
@@ -334,19 +343,27 @@ namespace Barotrauma
/// <summary>
/// End the mission and give a reward if it was completed successfully
/// </summary>
public virtual void End()
public void End()
{
completed = true;
completed =
DetermineCompleted() &&
(completeCheckDataAction == null ||completeCheckDataAction.GetSuccess());
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
GiveReward();
EndMissionSpecific(completed);
}
public void GiveReward()
protected abstract bool DetermineCompleted();
protected virtual void EndMissionSpecific(bool completed) { }
private void GiveReward()
{
if (!(GameMain.GameSession.GameMode is CampaignMode campaign)) { return; }
if (GameMain.GameSession.GameMode is not CampaignMode campaign) { return; }
int reward = GetReward(Submarine.MainSub);
float baseExperienceGain = reward * 0.09f;
@@ -146,14 +146,24 @@ namespace Barotrauma
tags = element.GetAttributeStringArray("tags", Array.Empty<string>(), convertToLowerInvariant: true);
Name =
TextManager.Get($"MissionName.{TextIdentifier}")
.Fallback(TextManager.Get(element.GetAttributeString("name", "")))
.Fallback(element.GetAttributeString("name", ""));
Description =
TextManager.Get($"MissionDescription.{TextIdentifier}")
.Fallback(TextManager.Get(element.GetAttributeString("description", "")))
.Fallback(element.GetAttributeString("description", ""));
string nameTag = element.GetAttributeString("name", "");
Name = TextManager.Get($"MissionName.{TextIdentifier}");
if (!string.IsNullOrEmpty(nameTag))
{
Name = Name
.Fallback(TextManager.Get(nameTag))
.Fallback(nameTag);
}
string descriptionTag = element.GetAttributeString("description", "");
Description =
TextManager.Get($"MissionDescription.{TextIdentifier}");
if (!string.IsNullOrEmpty(descriptionTag))
{
Description = Description
.Fallback(TextManager.Get(descriptionTag))
.Fallback(descriptionTag);
}
Reward = element.GetAttributeInt("reward", 1);
AllowRetry = element.GetAttributeBool("allowretry", false);
@@ -167,23 +177,35 @@ namespace Barotrauma
Difficulty = Math.Clamp(difficulty, MinDifficulty, MaxDifficulty);
}
SuccessMessage =
TextManager.Get($"MissionSuccess.{TextIdentifier}")
.Fallback(TextManager.Get(element.GetAttributeString("successmessage", "")))
.Fallback(element.GetAttributeString("successmessage", "Mission completed successfully"));
FailureMessage =
TextManager.Get($"MissionFailure.{TextIdentifier}")
.Fallback(TextManager.Get(element.GetAttributeString("missionfailed", "")))
.Fallback(TextManager.Get("missionfailed"))
.Fallback(GameSettings.CurrentConfig.Language == TextManager.DefaultLanguage ? element.GetAttributeString("failuremessage", "") : "");
string successMessageTag = element.GetAttributeString("successmessage", "");
SuccessMessage = TextManager.Get($"MissionSuccess.{TextIdentifier}");
if (!string.IsNullOrEmpty(successMessageTag))
{
SuccessMessage = SuccessMessage
.Fallback(TextManager.Get(successMessageTag))
.Fallback(successMessageTag);
}
SuccessMessage = SuccessMessage.Fallback(TextManager.Get("missioncompleted"));
string failureMessageTag = element.GetAttributeString("failuremessage", "");
FailureMessage = TextManager.Get($"MissionFailure.{TextIdentifier}");
if (!string.IsNullOrEmpty(failureMessageTag))
{
FailureMessage = FailureMessage
.Fallback(TextManager.Get(failureMessageTag))
.Fallback(failureMessageTag);
}
FailureMessage = FailureMessage.Fallback(TextManager.Get("missionfailed"));
string sonarLabelTag = element.GetAttributeString("sonarlabel", "");
SonarLabel =
SonarLabel =
TextManager.Get($"MissionSonarLabel.{sonarLabelTag}")
.Fallback(TextManager.Get(sonarLabelTag))
.Fallback(TextManager.Get($"MissionSonarLabel.{TextIdentifier}"))
.Fallback(element.GetAttributeString("sonarlabel", ""));
.Fallback(TextManager.Get($"MissionSonarLabel.{TextIdentifier}"));
if (!string.IsNullOrEmpty(sonarLabelTag))
{
SonarLabel = SonarLabel.Fallback(sonarLabelTag);
}
SonarIconIdentifier = element.GetAttributeIdentifier("sonaricon", "");
@@ -223,26 +223,26 @@ namespace Barotrauma
break;
}
}
public override void End()
protected override bool DetermineCompleted()
{
return state > 0;
}
protected override void EndMissionSpecific(bool completed)
{
tempSonarPositions.Clear();
monsters.Clear();
if (State < 1) { return; }
if (Prefab.LocationTypeChangeOnCompleted != null)
if (completed)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
GiveReward();
completed = true;
if (level?.LevelData != null && Prefab.Tags.Any(t => t.Equals("huntinggrounds", StringComparison.OrdinalIgnoreCase)))
{
level.LevelData.HasHuntingGrounds = false;
if (level?.LevelData != null && Prefab.Tags.Contains("huntinggrounds"))
{
level.LevelData.HasHuntingGrounds = false;
}
}
}
public bool IsEliminated(Character enemy) =>
public static bool IsEliminated(Character enemy) =>
enemy == null ||
enemy.Removed ||
enemy.IsDead ||
@@ -305,20 +305,13 @@ namespace Barotrauma
return true;
}
public override void End()
protected override bool DetermineCompleted()
{
return AllItemsDestroyedOrRetrieved();
}
protected override void EndMissionSpecific(bool completed)
{
if (AllItemsDestroyedOrRetrieved())
{
GiveReward();
completed = true;
if (completed)
{
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
}
}
foreach (Item item in items)
{
if (item != null && !item.Removed)
@@ -401,13 +401,13 @@ namespace Barotrauma
return character == null || character.Removed || character.Submarine == null || (character.LockHands && character.Submarine == Submarine.MainSub) || character.IsIncapacitated;
}
public override void End()
protected override bool DetermineCompleted()
{
return state == 2;
}
protected override void EndMissionSpecific(bool completed)
{
if (state == 2)
{
GiveReward();
completed = true;
}
characters.Clear();
characterItems.Clear();
failed = !completed;
@@ -242,7 +242,7 @@ namespace Barotrauma
Submarine parentSub = item.CurrentHull?.Submarine ?? item.GetRootInventoryOwner()?.Submarine;
if (parentSub == null || parentSub.Info.Type != SubmarineType.Player)
{
return;
return;
}
}
State = 1;
@@ -254,23 +254,16 @@ namespace Barotrauma
}
}
public override void End()
protected override bool DetermineCompleted()
{
var root = item?.GetRootContainer() ?? item;
if (root?.CurrentHull?.Submarine == null || (!root.CurrentHull.Submarine.AtEndExit && !root.CurrentHull.Submarine.AtStartExit) || item.Removed)
{
return;
}
if (Prefab.LocationTypeChangeOnCompleted != null)
{
ChangeLocationType(Prefab.LocationTypeChangeOnCompleted);
}
return root?.CurrentHull?.Submarine != null && (root.CurrentHull.Submarine.AtEndExit || root.CurrentHull.Submarine.AtStartExit) && !item.Removed;
}
protected override void EndMissionSpecific(bool completed)
{
item?.Remove();
item = null;
GiveReward();
completed = true;
failed = !completed && state > 0;
}
}
@@ -247,24 +247,9 @@ namespace Barotrauma
}
}
public override void End()
protected override bool DetermineCompleted()
{
if (State == 2 && AllScannersReturned())
{
GiveReward();
completed = true;
}
foreach (var scanner in scanners)
{
if (scanner.Item != null && !scanner.Item.Removed)
{
scanner.OnScanStarted -= OnScanStarted;
scanner.OnScanCompleted -= OnScanCompleted;
scanner.Item.Remove();
}
}
Reset();
failed = !completed && state > 0;
return State == 2 && AllScannersReturned();
bool AllScannersReturned()
{
@@ -285,5 +270,20 @@ namespace Barotrauma
return true;
}
}
protected override void EndMissionSpecific(bool completed)
{
foreach (var scanner in scanners)
{
if (scanner.Item != null && !scanner.Item.Removed)
{
scanner.OnScanStarted -= OnScanStarted;
scanner.OnScanCompleted -= OnScanCompleted;
scanner.Item.Remove();
}
}
Reset();
failed = !completed && state > 0;
}
}
}