Build 0.18.0.0

This commit is contained in:
Markus Isberg
2022-05-13 00:55:52 +09:00
parent 15d18e6ff6
commit 7547a9b78a
218 changed files with 3881 additions and 2192 deletions
@@ -53,8 +53,9 @@ namespace Barotrauma
}
}
public override void Init(bool affectSubImmediately)
public override void Init(EventSet parentSet)
{
base.Init(parentSet);
spawnPos = Level.Loaded.GetRandomItemPos(
(Rand.Value(Rand.RandSync.ServerAndClient) < 0.5f) ?
Level.PositionType.MainPath | Level.PositionType.SidePath :
@@ -111,7 +112,7 @@ namespace Barotrauma
case 1:
if (!Submarine.MainSub.AtEndExit && !Submarine.MainSub.AtStartExit) return;
Finished();
Finish();
state = 2;
break;
}
@@ -5,13 +5,16 @@ using System.Collections.Generic;
namespace Barotrauma
{
class Event
{
{
public event Action Finished;
protected bool isFinished;
protected readonly EventPrefab prefab;
public EventPrefab Prefab => prefab;
public EventSet ParentSet { get; private set; }
public Func<Level.InterestingPosition, bool> SpawnPosFilter;
public bool IsFinished
@@ -42,23 +45,20 @@ namespace Barotrauma
yield break;
}
public virtual void Init(bool affectSubImmediately)
public virtual void Init(EventSet parentSet = null)
{
ParentSet = parentSet;
}
public virtual void Update(float deltaTime)
{
}
public virtual void Finished()
public virtual void Finish()
{
isFinished = true;
}
public virtual bool CanAffectSubImmediately(Level level)
{
return true;
}
Finished?.Invoke();
}
public virtual bool LevelMeetsRequirements()
{
@@ -117,6 +117,8 @@ namespace Barotrauma
public bool Enabled = true;
private MTRandom rand;
public void StartRound(Level level)
{
this.level = level;
@@ -147,7 +149,7 @@ namespace Barotrauma
seed ^= ToolBox.IdentifierToInt(previousEvent.Identifier);
}
}
MTRandom rand = new MTRandom(seed);
rand = new MTRandom(seed);
EventSet initialEventSet = SelectRandomEvents(EventSet.Prefabs.ToList(), requireCampaignSet: GameMain.GameSession?.GameMode is CampaignMode, rand);
EventSet additiveSet = null;
@@ -159,12 +161,12 @@ namespace Barotrauma
if (initialEventSet != null)
{
pendingEventSets.Add(initialEventSet);
CreateEvents(initialEventSet, rand);
CreateEvents(initialEventSet);
}
if (additiveSet != null)
{
pendingEventSets.Add(additiveSet);
CreateEvents(additiveSet, rand);
CreateEvents(additiveSet);
}
if (level?.LevelData?.Type == LevelData.LevelType.Outpost)
@@ -183,7 +185,7 @@ namespace Barotrauma
if (unlockPathEventPrefab != null)
{
var newEvent = unlockPathEventPrefab.CreateInstance();
newEvent.Init(true);
newEvent.Init();
ActiveEvents.Add(newEvent);
}
else
@@ -362,8 +364,9 @@ namespace Barotrauma
return retVal;
}
private void CreateEvents(EventSet eventSet, Random rand)
private void CreateEvents(EventSet eventSet)
{
selectedEvents.Remove(eventSet);
if (level == null) { return; }
if (level.LevelData.HasHuntingGrounds && eventSet.DisableInHuntingGrounds) { return; }
DebugConsole.NewMessage($"Loading event set {eventSet.Identifier}", Color.LightBlue, debugOnly: true);
@@ -421,7 +424,7 @@ namespace Barotrauma
var newEvent = eventPrefab.CreateInstance();
if (newEvent == null) { continue; }
newEvent.Init(true);
newEvent.Init(eventSet);
if (i < spawnPosFilter.Count) { newEvent.SpawnPosFilter = spawnPosFilter[i]; }
DebugConsole.NewMessage($"Initialized event {newEvent}", debugOnly: true);
if (!selectedEvents.ContainsKey(eventSet))
@@ -438,7 +441,7 @@ namespace Barotrauma
var newEventSet = SelectRandomEvents(eventSet.ChildSets, random: rand);
if (newEventSet != null)
{
CreateEvents(newEventSet, rand);
CreateEvents(newEventSet);
}
}
}
@@ -451,7 +454,7 @@ namespace Barotrauma
var eventPrefab = ToolBox.SelectWeightedRandom(eventPrefabs.Where(isPrefabSuitable), e => e.Commonness, rand);
var newEvent = eventPrefab.CreateInstance();
if (newEvent == null) { continue; }
newEvent.Init(true);
newEvent.Init(eventSet);
DebugConsole.NewMessage($"Initialized event {newEvent}", debugOnly: true);
if (!selectedEvents.ContainsKey(eventSet))
{
@@ -465,7 +468,7 @@ namespace Barotrauma
{
if (!IsValidForLevel(childEventSet, level)) { continue; }
if (location != null && !IsValidForLocation(childEventSet, location)) { continue; }
CreateEvents(childEventSet, rand);
CreateEvents(childEventSet);
}
}
}
@@ -666,6 +669,14 @@ namespace Barotrauma
{
eventCoolDown = settings.EventCooldown;
}
if (eventSet.ResetTime > 0)
{
ev.Finished += () =>
{
pendingEventSets.Add(eventSet);
CreateEvents(eventSet);
};
}
}
}
@@ -58,7 +58,7 @@ namespace Barotrauma
}
#endif
public static List<EventPrefab> GetAllEventPrefabs()
public static List<EventPrefab> GetAllEventPrefabs()
{
List<EventPrefab> eventPrefabs = EventPrefab.Prefabs.ToList();
foreach (var eventSet in Prefabs)
@@ -118,6 +118,8 @@ namespace Barotrauma
public readonly float DefaultCommonness;
public readonly ImmutableDictionary<Identifier, float> OverrideCommonness;
public readonly float ResetTime;
public readonly struct SubEventPrefab
{
public SubEventPrefab(Either<Identifier[], EventPrefab> prefabOrIdentifiers, float? commonness, float? probability)
@@ -244,6 +246,7 @@ namespace Barotrauma
OncePerOutpost = element.GetAttributeBool("onceperoutpost", false);
TriggerEventCooldown = element.GetAttributeBool("triggereventcooldown", true);
IsCampaignSet = element.GetAttributeBool("campaign", LevelType == LevelData.LevelType.Outpost || (parentSet?.IsCampaignSet ?? false));
ResetTime = element.GetAttributeFloat("resettime", 0);
DefaultCommonness = 1.0f;
foreach (var subElement in element.Elements())
@@ -454,7 +457,6 @@ namespace Barotrauma
{
childSet.Dispose();
}
}
}
}
@@ -39,13 +39,9 @@ namespace Barotrauma
targetItemIdentifiers = prefab.ConfigElement.GetAttributeIdentifierArray("itemidentifiers", Array.Empty<Identifier>());
}
public override bool CanAffectSubImmediately(Level level)
{
return Item.ItemList.Count(i => i.Condition > 0.0f && targetItemIdentifiers.Contains(i.Prefab.Identifier)) >= maxItemAmount;
}
public override void Init(bool affectSubImmediately)
public override void Init(EventSet parentSet)
{
base.Init(parentSet);
var matchingItems = Item.ItemList.FindAll(i => i.Condition > 0.0f && targetItemIdentifiers.Contains(i.Prefab.Identifier));
int itemAmount = Rand.Range(minItemAmount, maxItemAmount, Rand.RandSync.ServerAndClient);
for (int i = 0; i < itemAmount; i++)
@@ -60,7 +56,7 @@ namespace Barotrauma
if (isFinished) return;
if (targetItems.Count == 0 || timer >= duration)
{
Finished();
Finish();
return;
}
@@ -323,7 +323,7 @@ namespace Barotrauma
{
var newEvent = eventPrefab.CreateInstance();
GameMain.GameSession.EventManager.ActiveEvents.Add(newEvent);
newEvent.Init(true);
newEvent.Init();
}
}
@@ -382,7 +382,8 @@ namespace Barotrauma
#if SERVER
totalReward = DistributeRewardsToCrew(GameSession.GetSessionCrewCharacters(CharacterType.Player), totalReward);
#endif
if (totalReward > 0)
bool isSingleplayerOrServer = GameMain.IsSingleplayer || GameMain.NetworkMember is { IsServer: true };
if (isSingleplayerOrServer && totalReward > 0)
{
campaign.Bank.Give(totalReward);
}
@@ -146,8 +146,15 @@ namespace Barotrauma
tags = element.GetAttributeStringArray("tags", Array.Empty<string>(), convertToLowerInvariant: true);
Name = TextManager.Get($"MissionName.{TextIdentifier}").Fallback(element.GetAttributeString("name", ""));
Description = TextManager.Get($"MissionDescription.{TextIdentifier}").Fallback(element.GetAttributeString("description", ""));
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", ""));
Reward = element.GetAttributeInt("reward", 1);
AllowRetry = element.GetAttributeBool("allowretry", false);
IsSideObjective = element.GetAttributeBool("sideobjective", false);
@@ -160,10 +167,15 @@ namespace Barotrauma
Difficulty = Math.Clamp(difficulty, MinDifficulty, MaxDifficulty);
}
SuccessMessage = TextManager.Get($"MissionSuccess.{TextIdentifier}").Fallback(element.GetAttributeString("successmessage", "Mission completed successfully"));
FailureMessage = TextManager.Get($"MissionFailure.{TextIdentifier}").Fallback(
TextManager.Get("missionfailed")).Fallback(
GameSettings.CurrentConfig.Language == TextManager.DefaultLanguage ? element.GetAttributeString("failuremessage", "") : "");
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 sonarLabelTag = element.GetAttributeString("sonarlabel", "");
@@ -208,8 +220,14 @@ namespace Barotrauma
headers.Add(string.Empty);
messages.Add(string.Empty);
}
headers[messageIndex] = TextManager.Get($"MissionHeader{messageIndex}.{TextIdentifier}").Fallback(subElement.GetAttributeString("header", ""));
messages[messageIndex] = TextManager.Get($"MissionMessage{messageIndex}.{TextIdentifier}").Fallback(subElement.GetAttributeString("text", ""));
headers[messageIndex] =
TextManager.Get($"MissionHeader{messageIndex}.{TextIdentifier}")
.Fallback(TextManager.Get(subElement.GetAttributeString("header", "")))
.Fallback(subElement.GetAttributeString("header", ""));
messages[messageIndex] =
TextManager.Get($"MissionMessage{messageIndex}.{TextIdentifier}")
.Fallback(TextManager.Get(subElement.GetAttributeString("text", "")))
.Fallback(subElement.GetAttributeString("text", ""));
messageIndex++;
break;
case "locationtype":
@@ -270,7 +270,7 @@ namespace Barotrauma
foreach (Item item in spawnedCharacter.Inventory.AllItems)
{
if (item?.Prefab.Identifier == "idcard")
if (item?.GetComponent<IdCard>() != null)
{
item.AddTag("id_pirate");
}
@@ -16,6 +16,8 @@ namespace Barotrauma
private readonly float scatter;
private readonly float offset;
private readonly float delayBetweenSpawns;
private float resetTime;
private float resetTimer;
private Vector2? spawnPos;
@@ -24,7 +26,7 @@ namespace Barotrauma
public readonly Level.PositionType SpawnPosType;
private readonly string spawnPointTag;
private bool spawnPending;
private bool spawnPending, spawnReady;
public readonly int MaxAmountPerLevel = int.MaxValue;
@@ -96,6 +98,7 @@ namespace Barotrauma
offset = prefab.ConfigElement.GetAttributeFloat("offset", 0);
scatter = Math.Clamp(prefab.ConfigElement.GetAttributeFloat("scatter", 500), 0, 3000);
delayBetweenSpawns = prefab.ConfigElement.GetAttributeFloat("delaybetweenspawns", 0.1f);
resetTime = prefab.ConfigElement.GetAttributeFloat("resettime", 0);
if (GameMain.NetworkMember != null)
{
@@ -131,14 +134,14 @@ namespace Barotrauma
}
}
public override bool CanAffectSubImmediately(Level level)
{
float maxRange = Sonar.DefaultSonarRange * 0.8f;
return GetAvailableSpawnPositions().Any(p => Vector2.DistanceSquared(p.Position.ToVector2(), GetReferenceSub().WorldPosition) < maxRange * maxRange);
}
public override void Init(bool affectSubImmediately)
public override void Init(EventSet parentSet)
{
base.Init(parentSet);
if (parentSet != null && resetTime == 0)
{
// Use the parent reset time only if there's no reset time defined for the event.
resetTime = parentSet.ResetTime;
}
if (GameSettings.CurrentConfig.VerboseLogging)
{
DebugConsole.NewMessage("Initialized MonsterEvent (" + SpeciesName + ")", Color.White);
@@ -199,7 +202,7 @@ namespace Barotrauma
{
//no suitable position found, disable the event
spawnPos = null;
Finished();
Finish();
return;
}
Submarine refSub = GetReferenceSub();
@@ -267,22 +270,17 @@ namespace Barotrauma
if (!isRuinOrWreck)
{
float minDistance = 20000;
var refSub = GetReferenceSub();
availablePositions.RemoveAll(p => Vector2.DistanceSquared(refSub.WorldPosition, p.Position.ToVector2()) < minDistance * minDistance);
if (Submarine.MainSubs.Length > 1)
for (int i = 0; i < Submarine.MainSubs.Length; i++)
{
for (int i = 1; i < Submarine.MainSubs.Length; i++)
{
if (Submarine.MainSubs[i] == null) { continue; }
availablePositions.RemoveAll(p => Vector2.DistanceSquared(Submarine.MainSubs[i].WorldPosition, p.Position.ToVector2()) < minDistance * minDistance);
}
if (Submarine.MainSubs[i] == null) { continue; }
availablePositions.RemoveAll(p => Vector2.DistanceSquared(Submarine.MainSubs[i].WorldPosition, p.Position.ToVector2()) < minDistance * minDistance);
}
}
if (availablePositions.None())
{
//no suitable position found, disable the event
spawnPos = null;
Finished();
Finish();
return;
}
chosenPosition = availablePositions.GetRandomUnsynced();
@@ -306,7 +304,7 @@ namespace Barotrauma
{
//no suitable position found, disable the event
spawnPos = null;
Finished();
Finish();
return;
}
}
@@ -344,7 +342,7 @@ namespace Barotrauma
{
//no suitable position found, disable the event
spawnPos = null;
Finished();
Finish();
return;
}
}
@@ -352,20 +350,42 @@ namespace Barotrauma
}
}
private float GetMinDistanceToSub(Submarine submarine)
private float GetMinDistanceToSub(Submarine submarine)
{
return Math.Max(Math.Max(submarine.Borders.Width, submarine.Borders.Height), Sonar.DefaultSonarRange * 0.9f);
float minDist = Math.Max(Math.Max(submarine.Borders.Width, submarine.Borders.Height), Sonar.DefaultSonarRange * 0.9f);
if (SpawnPosType.HasFlag(Level.PositionType.Abyss))
{
minDist *= 2;
}
return minDist;
}
public override void Update(float deltaTime)
{
if (disallowed)
{
Finished();
Finish();
return;
}
if (isFinished) { return; }
if (resetTimer > 0)
{
resetTimer -= deltaTime;
if (resetTimer <= 0)
{
if (ParentSet?.ResetTime > 0)
{
// If parent has reset time defined, the set is recreated. Otherwise we'll just reset this event.
Finish();
}
else
{
spawnReady = false;
spawnPos = null;
}
}
return;
}
if (spawnPos == null)
{
@@ -373,7 +393,11 @@ namespace Barotrauma
{
if (Character.CharacterList.Count(c => c.SpeciesName == SpeciesName) >= MaxAmountPerLevel)
{
disallowed = true;
// If the event is set to reset, let's just wait until the old corpse is removed (after being disabled).
if (resetTime == 0)
{
disallowed = true;
}
return;
}
}
@@ -384,9 +408,14 @@ namespace Barotrauma
spawnPending = true;
}
bool spawnReady = false;
if (spawnPending)
{
System.Diagnostics.Debug.Assert(spawnPos.HasValue);
if (spawnPos == null)
{
Finish();
return;
}
//wait until there are no submarines at the spawnpos
if (SpawnPosType.HasFlag(Level.PositionType.MainPath) || SpawnPosType.HasFlag(Level.PositionType.SidePath) || SpawnPosType.HasFlag(Level.PositionType.Abyss))
{
@@ -554,28 +583,24 @@ namespace Barotrauma
}
}
if (!spawnReady) { return; }
Entity targetEntity = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter);
#if CLIENT
if (Character.Controlled != null) { targetEntity = Character.Controlled; }
#endif
bool monstersDead = true;
foreach (Character monster in monsters)
if (spawnReady)
{
if (!monster.IsDead)
if (monsters.None())
{
monstersDead = false;
if (targetEntity != null && Vector2.DistanceSquared(monster.WorldPosition, targetEntity.WorldPosition) < 5000.0f * 5000.0f)
Finish();
}
else if (monsters.All(m => m.IsDead))
{
if (resetTime > 0)
{
break;
resetTimer = resetTime;
}
else
{
Finish();
}
}
}
if (monstersDead) { Finished(); }
}
}
}
@@ -173,14 +173,14 @@ namespace Barotrauma
if (!Actions.Any())
{
Finished();
Finish();
return;
}
var currentAction = Actions[CurrentActionIndex];
if (!currentAction.CanBeFinished())
{
Finished();
Finish();
return;
}
@@ -207,7 +207,7 @@ namespace Barotrauma
if (CurrentActionIndex >= Actions.Count || CurrentActionIndex < 0)
{
Finished();
Finish();
}
}
else
@@ -232,9 +232,9 @@ namespace Barotrauma
return false;
}
public override void Finished()
public override void Finish()
{
base.Finished();
base.Finish();
GameAnalyticsManager.AddDesignEvent($"ScriptedEvent:{prefab.Identifier}:Finished:{CurrentActionIndex}");
}
}