Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -7,19 +7,19 @@ namespace Barotrauma
{
class AfflictionAction : EventAction
{
[Serialize("", true)]
public string Affliction { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Affliction { get; set; }
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float Strength { get; set; }
[Serialize(LimbType.None, true)]
[Serialize(LimbType.None, IsPropertySaveable.Yes)]
public LimbType LimbType { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public AfflictionAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public AfflictionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
@@ -36,7 +36,7 @@ namespace Barotrauma
public override void Update(float deltaTime)
{
if (isFinished) { return; }
var afflictionPrefab = AfflictionPrefab.List.FirstOrDefault(p => p.Identifier.Equals(Affliction, StringComparison.InvariantCultureIgnoreCase));
var afflictionPrefab = AfflictionPrefab.List.FirstOrDefault(p => p.Identifier == Affliction);
if (afflictionPrefab != null)
{
var targets = ParentEvent.GetTargets(TargetTag);
@@ -44,14 +44,28 @@ namespace Barotrauma
{
if (target != null && target is Character character)
{
var limb = LimbType != LimbType.None ? character.AnimController.GetLimb(LimbType) : null;
if (Strength > 0.0f)
if (LimbType != LimbType.None)
{
character.CharacterHealth.ApplyAffliction(limb, afflictionPrefab.Instantiate(Strength));
var limb = character.AnimController.GetLimb(LimbType);
if (Strength > 0.0f)
{
character.CharacterHealth.ApplyAffliction(limb, afflictionPrefab.Instantiate(Strength));
}
else if (Strength < 0.0f)
{
character.CharacterHealth.ReduceAfflictionOnLimb(limb, Affliction, -Strength);
}
}
else if (Strength < 0.0f)
else
{
character.CharacterHealth.ReduceAffliction(limb, Affliction, -Strength);
if (Strength > 0.0f)
{
character.CharacterHealth.ApplyAffliction(null, afflictionPrefab.Instantiate(Strength));
}
else if (Strength < 0.0f)
{
character.CharacterHealth.ReduceAfflictionOnAllLimbs(Affliction, -Strength);
}
}
}
}
@@ -11,9 +11,9 @@ namespace Barotrauma
public SubactionGroup Failure = null;
protected bool? succeeded = null;
public BinaryOptionAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public BinaryOptionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
foreach (XElement elem in element.Elements())
foreach (var elem in element.Elements())
{
string elemName = elem.Name.LocalName;
if (elemName.Equals("success", StringComparison.InvariantCultureIgnoreCase))
@@ -8,23 +8,23 @@ namespace Barotrauma
{
internal class CheckAfflictionAction : BinaryOptionAction
{
[Serialize("", true)]
public string Identifier { get; set; } = "";
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Identifier { get; set; } = Identifier.Empty;
[Serialize("", true)]
public string TargetTag { get; set; } = "";
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; } = Identifier.Empty;
[Serialize(LimbType.None, true, "Only check afflictions on the specified limb type")]
[Serialize(LimbType.None, IsPropertySaveable.Yes, "Only check afflictions on the specified limb type")]
public LimbType TargetLimb { get; set; }
[Serialize(true, true, "When set to false when TargetLimb is not specified prevent checking limb-specific afflictions")]
[Serialize(true, IsPropertySaveable.Yes, "When set to false when TargetLimb is not specified prevent checking limb-specific afflictions")]
public bool AllowLimbAfflictions { get; set; }
public CheckAfflictionAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public CheckAfflictionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
protected override bool? DetermineSuccess()
{
if (string.IsNullOrWhiteSpace(Identifier) || string.IsNullOrWhiteSpace(TargetTag)) { return false; }
if (Identifier.IsEmpty || TargetTag.IsEmpty) { return false; }
List<Character> targets = ParentEvent.GetTargets(TargetTag).OfType<Character>().ToList();
foreach (var target in targets)
@@ -42,7 +42,7 @@ namespace Barotrauma
return limbType == TargetLimb || true;
});
if (afflictions.Any(a => a.Identifier.Equals(Identifier, StringComparison.OrdinalIgnoreCase))) { return true; }
if (afflictions.Any(a => a.Identifier == Identifier)) { return true; }
}
return false;
}
@@ -1,21 +1,22 @@
#nullable enable
using System;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
{
class CheckDataAction : BinaryOptionAction
{
[Serialize("", true)]
public string Identifier { get; set; } = null!;
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Identifier { get; set; } = Identifier.Empty;
[Serialize("", true)]
public string Condition { get; set; } = null!;
[Serialize("", IsPropertySaveable.Yes)]
public string Condition { get; set; } = "";
[Serialize(false, true, "Forces the comparison to use string instead of attempting to parse it as a boolean or a float first")]
[Serialize(false, IsPropertySaveable.Yes, "Forces the comparison to use string instead of attempting to parse it as a boolean or a float first")]
public bool ForceString { get; set; }
[Serialize(false, true, "Performs the comparison against a metadata by identifier instead of a constant value")]
[Serialize(false, IsPropertySaveable.Yes, "Performs the comparison against a metadata by identifier instead of a constant value")]
public bool CheckAgainstMetadata { get; set; }
protected object? value2;
@@ -23,11 +24,11 @@ namespace Barotrauma
protected PropertyConditional.OperatorType Operator { get; set; }
public CheckDataAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public CheckDataAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (string.IsNullOrEmpty(Condition))
{
Condition = element.GetAttributeString("value", string.Empty);
Condition = element.GetAttributeString("value", string.Empty)!;
if (string.IsNullOrEmpty(Condition))
{
DebugConsole.ThrowError($"Error in scripted event \"{parentEvent.Prefab.Identifier}\". CheckDataAction with no condition set ({element}).");
@@ -43,10 +44,8 @@ namespace Barotrauma
string value = Condition;
if (splitString.Length > 0)
{
for (int i = 1; i < splitString.Length; i++)
{
value = splitString[i] + (i > 1 && i < splitString.Length ? " " : "");
}
#warning Is this correct?
value = string.Join(" ", splitString.Skip(1));
}
else
{
@@ -61,7 +60,7 @@ namespace Barotrauma
if (CheckAgainstMetadata)
{
object? metadata1 = campaignMode.CampaignMetadata.GetValue(Identifier);
object? metadata2 = campaignMode.CampaignMetadata.GetValue(value);
object? metadata2 = campaignMode.CampaignMetadata.GetValue(value.ToIdentifier());
if (metadata1 == null || metadata2 == null)
{
@@ -6,22 +6,22 @@ namespace Barotrauma
{
class CheckItemAction : BinaryOptionAction
{
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string ItemIdentifiers { get; set; }
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string ItemTags { get; set; }
private readonly string[] itemIdentifierSplit;
private readonly string[] itemTags;
private readonly Identifier[] itemIdentifierSplit;
private readonly Identifier[] itemTags;
public CheckItemAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public CheckItemAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
itemIdentifierSplit = ItemIdentifiers.Split(',');
itemTags = ItemTags.Split(",");
itemIdentifierSplit = ItemIdentifiers.Split(',').ToIdentifiers();
itemTags = ItemTags.Split(",").ToIdentifiers();
}
protected override bool? DetermineSuccess()
@@ -4,10 +4,10 @@ namespace Barotrauma
{
class CheckMoneyAction : BinaryOptionAction
{
[Serialize(0, true)]
[Serialize(0, IsPropertySaveable.Yes)]
public int Amount { get; set; }
public CheckMoneyAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public CheckMoneyAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
}
@@ -7,10 +7,10 @@ namespace Barotrauma
{
class CheckReputationAction : CheckDataAction
{
[Serialize(ReputationAction.ReputationType.None, true)]
[Serialize(ReputationAction.ReputationType.None, IsPropertySaveable.Yes)]
public ReputationAction.ReputationType TargetType { get; set; }
public CheckReputationAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public CheckReputationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
protected override float GetFloat(CampaignMode campaignMode)
{
@@ -18,7 +18,7 @@ namespace Barotrauma
{
case ReputationAction.ReputationType.Faction:
{
Faction? faction = campaignMode.Factions.Find(f => f.Prefab.Identifier.Equals(Identifier, StringComparison.OrdinalIgnoreCase));
Faction? faction = campaignMode.Factions.Find(f => f.Prefab.Identifier == Identifier);
if (faction != null) { return faction.Reputation.Value; }
break;
}
@@ -54,7 +54,7 @@ namespace Barotrauma
}
return $"{ToolBox.GetDebugSymbol(succeeded.HasValue)} {nameof(CheckReputationAction)} -> (Type: {TargetType.ColorizeObject()}, " +
$"{(string.IsNullOrWhiteSpace(Identifier) ? string.Empty : $"Identifier: {Identifier.ColorizeObject()}, ")}" +
$"{(Identifier.IsEmpty ? string.Empty : $"Identifier: {Identifier.ColorizeObject()}, ")}" +
$"Success: {succeeded.ColorizeObject()}, Expression: {condition})";
}
}
@@ -4,12 +4,12 @@ namespace Barotrauma
{
class ClearTagAction : EventAction
{
[Serialize("", true)]
public string Tag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Tag { get; set; }
private bool isFinished;
public ClearTagAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public ClearTagAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
public override bool IsFinished(ref string goToLabel) => isFinished;
@@ -22,7 +22,7 @@ namespace Barotrauma
{
if (isFinished) { return; }
if (!string.IsNullOrWhiteSpace(Tag))
if (!Tag.IsEmpty)
{
ParentEvent.RemoveTag(Tag);
}
@@ -7,25 +7,25 @@ namespace Barotrauma
{
class CombatAction : EventAction
{
[Serialize(AIObjectiveCombat.CombatMode.Offensive, true)]
[Serialize(AIObjectiveCombat.CombatMode.Offensive, IsPropertySaveable.Yes)]
public AIObjectiveCombat.CombatMode CombatMode { get; set; }
[Serialize(false, true, description: "Did this NPC start the fight (as an aggressor)?")]
[Serialize(false, IsPropertySaveable.Yes, description: "Did this NPC start the fight (as an aggressor)?")]
public bool IsInstigator { get; set; }
[Serialize(AIObjectiveCombat.CombatMode.None, true)]
[Serialize(AIObjectiveCombat.CombatMode.None, IsPropertySaveable.Yes)]
public AIObjectiveCombat.CombatMode GuardReaction { get; set; }
[Serialize(AIObjectiveCombat.CombatMode.None, true)]
[Serialize(AIObjectiveCombat.CombatMode.None, IsPropertySaveable.Yes)]
public AIObjectiveCombat.CombatMode WitnessReaction { get; set; }
[Serialize("", true)]
public string NPCTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier NPCTag { get; set; }
[Serialize("", true)]
public string EnemyTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier EnemyTag { get; set; }
[Serialize(120.0f, true)]
[Serialize(120.0f, IsPropertySaveable.Yes)]
public float CoolDown { get; set; }
private bool isFinished = false;
@@ -33,7 +33,7 @@ namespace Barotrauma
private IEnumerable<Character> affectedNpcs = null;
public CombatAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public CombatAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
public override void Update(float deltaTime)
{
@@ -26,37 +26,37 @@ namespace Barotrauma
/// </summary>
const float BlockOtherConversationsDuration = 5.0f;
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string Text { get; set; }
[Serialize(0, true)]
[Serialize(0, IsPropertySaveable.Yes)]
public int DefaultOption { get; set; }
[Serialize("", true)]
public string SpeakerTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier SpeakerTag { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool WaitForInteraction { get; set; }
[Serialize("", true, "Tag to assign to whoever invokes the conversation")]
public string InvokerTag { get; set; }
[Serialize("", IsPropertySaveable.Yes, "Tag to assign to whoever invokes the conversation")]
public Identifier InvokerTag { get; set; }
[Serialize(false, true)]
[Serialize(false, IsPropertySaveable.Yes)]
public bool FadeToBlack { get; set; }
[Serialize(true, true, "Should the event end if the conversations is interrupted (e.g. if the speaker dies or falls unconscious mid-conversation). Defaults to true.")]
[Serialize(true, IsPropertySaveable.Yes, "Should the event end if the conversations is interrupted (e.g. if the speaker dies or falls unconscious mid-conversation). Defaults to true.")]
public bool EndEventIfInterrupted { get; set; }
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string EventSprite { get; set; }
[Serialize(DialogTypes.Regular, true)]
[Serialize(DialogTypes.Regular, IsPropertySaveable.Yes)]
public DialogTypes DialogType { get; set; }
[Serialize(false, true)]
[Serialize(false, IsPropertySaveable.Yes)]
public bool ContinueConversation { get; set; }
private Character speaker;
@@ -79,12 +79,12 @@ namespace Barotrauma
private bool interrupt;
public ConversationAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public ConversationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
actionCount++;
Identifier = actionCount;
Options = new List<SubactionGroup>();
foreach (XElement elem in element.Elements())
foreach (var elem in element.Elements())
{
if (elem.Name.LocalName.Equals("option", StringComparison.InvariantCultureIgnoreCase))
{
@@ -230,7 +230,7 @@ namespace Barotrauma
return;
}
if (!string.IsNullOrEmpty(SpeakerTag))
if (!SpeakerTag.IsEmpty)
{
if (speaker != null && !speaker.Removed && speaker.CampaignInteractionType == CampaignMode.InteractionType.Talk && speaker.ActiveConversation?.ParentEvent != this.ParentEvent) { return; }
speaker = ParentEvent.GetTargets(SpeakerTag).FirstOrDefault(e => e is Character) as Character;
@@ -254,7 +254,7 @@ namespace Barotrauma
#if CLIENT
speaker.SetCustomInteract(
TryStartConversation,
TextManager.GetWithVariable("CampaignInteraction.Talk", "[key]", GameMain.Config.KeyBindText(InputType.Use)));
TextManager.GetWithVariable("CampaignInteraction.Talk", "[key]", GameSettings.CurrentConfig.KeyMap.KeyBindText(InputType.Use)));
#else
speaker.SetCustomInteract(
TryStartConversation,
@@ -286,7 +286,7 @@ namespace Barotrauma
private bool ShouldInterrupt()
{
IEnumerable<Entity> targets = Enumerable.Empty<Entity>();
if (!string.IsNullOrEmpty(TargetTag))
if (!TargetTag.IsEmpty)
{
targets = ParentEvent.GetTargets(TargetTag).Where(e => IsValidTarget(e));
if (!targets.Any()) { return true; }
@@ -294,7 +294,7 @@ namespace Barotrauma
if (speaker != null)
{
if (!string.IsNullOrEmpty(TargetTag))
if (!TargetTag.IsEmpty)
{
if (targets.All(t => Vector2.DistanceSquared(t.WorldPosition, speaker.WorldPosition) > InterruptDistance * InterruptDistance)) { return true; }
}
@@ -324,7 +324,7 @@ namespace Barotrauma
private void TryStartConversation(Character speaker, Character targetCharacter = null)
{
IEnumerable<Entity> targets = Enumerable.Empty<Entity>();
if (!string.IsNullOrEmpty(TargetTag))
if (!TargetTag.IsEmpty)
{
targets = ParentEvent.GetTargets(TargetTag).Where(e => IsValidTarget(e));
if (!targets.Any() || IsBlockedByAnotherConversation(targets)) { return; }
@@ -335,8 +335,7 @@ namespace Barotrauma
prevIdleObjective = humanAI.ObjectiveManager.GetObjective<AIObjectiveIdle>();
prevGotoObjective = humanAI.ObjectiveManager.GetObjective<AIObjectiveGoTo>();
humanAI.SetForcedOrder(
Order.PrefabList.Find(o => o.Identifier.Equals("wait", StringComparison.OrdinalIgnoreCase)),
option: string.Empty, orderGiver: null);
new Order(OrderPrefab.Prefabs["wait"], Barotrauma.Identifier.Empty, null, orderGiver: null));
if (targets.Any())
{
Entity closestTarget = null;
@@ -357,7 +356,7 @@ namespace Barotrauma
}
}
if (targetCharacter != null && !string.IsNullOrWhiteSpace(InvokerTag))
if (targetCharacter != null && !InvokerTag.IsEmpty)
{
ParentEvent.AddTarget(InvokerTag, targetCharacter);
}
@@ -28,12 +28,12 @@ namespace Barotrauma
}
}
public SubactionGroup(ScriptedEvent scriptedEvent, XElement elem)
public SubactionGroup(ScriptedEvent scriptedEvent, ContentXElement elem)
{
Text = elem.Attribute("text")?.Value ?? "";
Actions = new List<EventAction>();
EndConversation = elem.GetAttributeBool("endconversation", false);
foreach (XElement e in elem.Elements())
foreach (var e in elem.Elements())
{
if (e.Name.ToString().Equals("statuseffect", StringComparison.OrdinalIgnoreCase))
{
@@ -100,7 +100,7 @@ namespace Barotrauma
public readonly ScriptedEvent ParentEvent;
public EventAction(ScriptedEvent parentEvent, XElement element)
public EventAction(ScriptedEvent parentEvent, ContentXElement element)
{
ParentEvent = parentEvent;
SerializableProperty.DeserializeProperties(this, element);
@@ -132,7 +132,7 @@ namespace Barotrauma
public virtual void Update(float deltaTime) { }
public static EventAction Instantiate(ScriptedEvent scriptedEvent, XElement element)
public static EventAction Instantiate(ScriptedEvent scriptedEvent, ContentXElement element)
{
Type actionType = null;
try
@@ -146,7 +146,7 @@ namespace Barotrauma
return null;
}
ConstructorInfo constructor = actionType.GetConstructor(new[] { typeof(ScriptedEvent), typeof(XElement) });
ConstructorInfo constructor = actionType.GetConstructor(new[] { typeof(ScriptedEvent), typeof(ContentXElement) });
try
{
return constructor.Invoke(new object[] { scriptedEvent, element }) as EventAction;
@@ -8,13 +8,13 @@ namespace Barotrauma
{
class FireAction : EventAction
{
[Serialize(10.0f, true)]
[Serialize(10.0f, IsPropertySaveable.Yes)]
public float Size { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public FireAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public FireAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
@@ -6,18 +6,18 @@ namespace Barotrauma
{
class GiveSkillExpAction : EventAction
{
[Serialize("", true)]
public string Skill { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Skill { get; set; }
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float Amount { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public GiveSkillExpAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public GiveSkillExpAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (string.IsNullOrEmpty(TargetTag))
if (TargetTag.IsEmpty)
{
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": GiveSkillExpAction without a target tag (the action needs to know whose skill to check).");
}
@@ -40,7 +40,7 @@ namespace Barotrauma
var targets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character);
foreach (var target in targets)
{
target.Info?.IncreaseSkillLevel(Skill?.ToLowerInvariant(), Amount);
target.Info?.IncreaseSkillLevel(Skill, Amount);
}
isFinished = true;
}
@@ -4,10 +4,10 @@ namespace Barotrauma
{
class GoTo : EventAction
{
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string Name { get; set; }
public GoTo(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public GoTo(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
public override bool IsFinished(ref string goTo)
{
@@ -7,13 +7,13 @@ namespace Barotrauma
{
class GodModeAction : EventAction
{
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool Enabled { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public GodModeAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public GodModeAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
@@ -4,10 +4,10 @@ namespace Barotrauma
{
class Label : EventAction
{
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string Name { get; set; }
public Label(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public Label(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
public override bool IsFinished(ref string goTo)
{
@@ -8,33 +8,33 @@ namespace Barotrauma
{
class MissionAction : EventAction
{
[Serialize("", true)]
public string MissionIdentifier { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier MissionIdentifier { get; set; }
[Serialize("", true)]
public string MissionTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier MissionTag { get; set; }
[Serialize("", true, description: "The type of the location the mission will be unlocked in (if empty, any location can be selected).")]
[Serialize("", IsPropertySaveable.Yes, description: "The type of the location the mission will be unlocked in (if empty, any location can be selected).")]
public string LocationType { get; set; }
[Serialize(0, true, description: "Minimum distance to the location the mission is unlocked in (1 = one path between locations).")]
[Serialize(0, IsPropertySaveable.Yes, description: "Minimum distance to the location the mission is unlocked in (1 = one path between locations).")]
public int MinLocationDistance { get; set; }
[Serialize(true, true, description: "If true, the mission has to be unlocked in a location further on the campaign map.")]
[Serialize(true, IsPropertySaveable.Yes, description: "If true, the mission has to be unlocked in a location further on the campaign map.")]
public bool UnlockFurtherOnMap { get; set; }
[Serialize(false, true, description: "If true, a suitable location is forced on the map if one isn't found.")]
[Serialize(false, IsPropertySaveable.Yes, description: "If true, a suitable location is forced on the map if one isn't found.")]
public bool CreateLocationIfNotFound { get; set; }
private bool isFinished;
public MissionAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public MissionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (string.IsNullOrEmpty(MissionIdentifier) && string.IsNullOrEmpty(MissionTag))
if (MissionIdentifier.IsEmpty && MissionTag.IsEmpty)
{
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": neither MissionIdentifier or MissionTag has been configured.");
}
if (!string.IsNullOrEmpty(MissionIdentifier) && !string.IsNullOrEmpty(MissionTag))
if (!MissionIdentifier.IsEmpty && !MissionTag.IsEmpty)
{
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": both MissionIdentifier or MissionTag have been configured. The tag will be ignored.");
}
@@ -63,18 +63,18 @@ namespace Barotrauma
var emptyLocation = FindUnlockLocationRecursive(campaign.Map.CurrentLocation, Math.Max(MinLocationDistance, 3), "none", true, new HashSet<Location>());
if (emptyLocation != null)
{
emptyLocation.ChangeType(Barotrauma.LocationType.List.Find(lt => lt.Identifier.Equals(LocationType, StringComparison.OrdinalIgnoreCase)));
emptyLocation.ChangeType(Barotrauma.LocationType.Prefabs[LocationType]);
unlockLocation = emptyLocation;
}
}
if (unlockLocation != null)
{
if (!string.IsNullOrEmpty(MissionIdentifier))
if (!MissionIdentifier.IsEmpty)
{
prefab = unlockLocation.UnlockMissionByIdentifier(MissionIdentifier);
}
else if (!string.IsNullOrEmpty(MissionTag))
else if (!MissionTag.IsEmpty)
{
prefab = unlockLocation.UnlockMissionByTag(MissionTag);
}
@@ -87,7 +87,7 @@ namespace Barotrauma
DebugConsole.NewMessage($"Unlocked mission \"{prefab.Name}\" in the location \"{unlockLocation.Name}\".");
#if CLIENT
new GUIMessageBox(string.Empty, TextManager.GetWithVariable("missionunlocked", "[missionname]", prefab.Name),
new string[0], type: GUIMessageBox.Type.InGame, icon: prefab.Icon, relativeSize: new Vector2(0.3f, 0.15f), minSize: new Point(512, 128))
Array.Empty<LocalizedString>(), type: GUIMessageBox.Type.InGame, icon: prefab.Icon, relativeSize: new Vector2(0.3f, 0.15f), minSize: new Point(512, 128))
{
IconColor = prefab.IconColor
};
@@ -118,7 +118,7 @@ namespace Barotrauma
private Location FindUnlockLocationRecursive(Location currLocation, int currDistance, string locationType, bool unlockFurtherOnMap, HashSet<Location> checkedLocations)
{
var campaign = GameMain.GameSession.GameMode as CampaignMode;
if (currLocation.Type.Identifier.Equals(locationType, StringComparison.OrdinalIgnoreCase) && currDistance >= MinLocationDistance &&
if (currLocation.Type.Identifier == locationType && currDistance >= MinLocationDistance &&
(!unlockFurtherOnMap || currLocation.MapPosition.X > campaign.Map.CurrentLocation.MapPosition.X))
{
return currLocation;
@@ -136,7 +136,7 @@ namespace Barotrauma
public override string ToDebugString()
{
return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionAction)} -> ({(string.IsNullOrEmpty(MissionIdentifier) ? MissionTag : MissionIdentifier)})";
return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionAction)} -> ({(MissionIdentifier.IsEmpty ? MissionTag : MissionIdentifier)})";
}
#if SERVER
@@ -5,9 +5,9 @@ namespace Barotrauma
{
class MoneyAction : EventAction
{
public MoneyAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public MoneyAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
[Serialize(0, true)]
[Serialize(0, IsPropertySaveable.Yes)]
public int Amount { get; set; }
private bool isFinished;
@@ -28,7 +28,7 @@ namespace Barotrauma
if (GameMain.GameSession?.GameMode is CampaignMode campaign)
{
campaign.Money += Amount;
GameAnalyticsManager.AddMoneyGainedEvent(Amount, GameAnalyticsManager.MoneySource.Event, ParentEvent.Prefab.Identifier);
GameAnalyticsManager.AddMoneyGainedEvent(Amount, GameAnalyticsManager.MoneySource.Event, ParentEvent.Prefab.Identifier.Value);
#if SERVER
(campaign as MultiPlayerCampaign).LastUpdateID++;
#endif
@@ -7,18 +7,18 @@ namespace Barotrauma
{
class NPCChangeTeamAction : EventAction
{
[Serialize("", true)]
public string NPCTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier NPCTag { get; set; }
[Serialize(CharacterTeamType.None, true)]
[Serialize(CharacterTeamType.None, IsPropertySaveable.Yes)]
public CharacterTeamType TeamTag { get; set; }
[Serialize(false, true)]
[Serialize(false, IsPropertySaveable.Yes)]
public bool AddToCrew { get; set; }
private bool isFinished = false;
public NPCChangeTeamAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public NPCChangeTeamAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private List<Character> affectedNpcs = null;
@@ -8,18 +8,18 @@ namespace Barotrauma
{
class NPCFollowAction : EventAction
{
[Serialize("", true)]
public string NPCTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier NPCTag { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool Follow { get; set; }
private bool isFinished = false;
public NPCFollowAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public NPCFollowAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private List<Character> affectedNpcs = null;
@@ -6,16 +6,16 @@ namespace Barotrauma
{
class NPCWaitAction : EventAction
{
[Serialize("", true)]
public string NPCTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier NPCTag { get; set; }
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool Wait { get; set; }
private bool isFinished = false;
public NPCWaitAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public NPCWaitAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private IEnumerable<Character> affectedNpcs;
@@ -6,10 +6,10 @@ namespace Barotrauma
{
class RNGAction : BinaryOptionAction
{
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float Chance { get; set; }
public RNGAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public RNGAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (Chance >= 1.0f)
{
@@ -7,20 +7,20 @@ namespace Barotrauma
{
class RemoveItemAction : EventAction
{
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
[Serialize("", true)]
public string ItemIdentifier { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier ItemIdentifier { get; set; }
[Serialize(1, true)]
[Serialize(1, IsPropertySaveable.Yes)]
public int Amount { get; set; }
public RemoveItemAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public RemoveItemAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (string.IsNullOrWhiteSpace(ItemIdentifier))
if (ItemIdentifier.IsEmpty)
{
ItemIdentifier = element.GetAttributeString("itemidentifiers", null) ?? element.GetAttributeString("identifier", "");
ItemIdentifier = element.GetAttributeIdentifier("itemidentifiers", element.GetAttributeIdentifier("identifier", Identifier.Empty));
}
}
@@ -62,17 +62,17 @@ namespace Barotrauma
var item = inventory.FindItem(it =>
it != null &&
!removedItems.Contains(it) &&
(string.IsNullOrEmpty(ItemIdentifier) || it.Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase)), recursive: true);
(ItemIdentifier.IsEmpty || it.Prefab.Identifier == ItemIdentifier), recursive: true);
if (item == null) { break; }
Entity.Spawner.AddToRemoveQueue(item);
Entity.Spawner.AddItemToRemoveQueue(item);
removedItems.Add(item);
}
}
else if (target is Item item)
{
if (string.IsNullOrEmpty(ItemIdentifier) || item.Prefab.Identifier.Equals(ItemIdentifier, StringComparison.InvariantCultureIgnoreCase))
if (ItemIdentifier.IsEmpty || item.Prefab.Identifier == ItemIdentifier)
{
Entity.Spawner.AddToRemoveQueue(item);
Entity.Spawner.AddItemToRemoveQueue(item);
removedItems.Add(item);
if (removedItems.Count >= Amount) { break; }
}
@@ -15,15 +15,15 @@ namespace Barotrauma
Faction
}
public ReputationAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public ReputationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float Increase { get; set; }
[Serialize("", true)]
public string Identifier { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Identifier { get; set; }
[Serialize(ReputationType.None, true)]
[Serialize(ReputationType.None, IsPropertySaveable.Yes)]
public ReputationType TargetType { get; set; }
private bool isFinished;
@@ -47,7 +47,7 @@ namespace Barotrauma
{
case ReputationType.Faction:
{
Faction faction = campaign.Factions.Find(faction1 => faction1.Prefab.Identifier.Equals(Identifier, StringComparison.OrdinalIgnoreCase));
Faction faction = campaign.Factions.Find(faction1 => faction1.Prefab.Identifier == Identifier);
if (faction != null)
{
faction.Reputation.AddReputation(Increase);
@@ -12,16 +12,16 @@ namespace Barotrauma
Add
}
public SetDataAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public SetDataAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
[Serialize(OperationType.Set, true)]
[Serialize(OperationType.Set, IsPropertySaveable.Yes)]
public OperationType Operation { get; set; }
[Serialize(null, true)]
[Serialize(null, IsPropertySaveable.Yes)]
public string Value { get; set; } = null!;
[Serialize("", true)]
public string Identifier { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Identifier { get; set; }
private bool isFinished;
@@ -47,7 +47,7 @@ namespace Barotrauma
isFinished = true;
}
public static void PerformOperation(CampaignMetadata metadata, string identifier, object value, OperationType operation)
public static void PerformOperation(CampaignMetadata metadata, Identifier identifier, object value, OperationType operation)
{
if (metadata == null) { return; }
@@ -19,16 +19,16 @@ namespace Barotrauma
Mechanical
}
[Serialize(1.0f, true)]
[Serialize(1.0f, IsPropertySaveable.Yes)]
public float Multiplier { get; set; }
[Serialize(OperationType.Set, true)]
[Serialize(OperationType.Set, IsPropertySaveable.Yes)]
public OperationType Operation { get; set; }
[Serialize(PriceMultiplierType.Store, true)]
[Serialize(PriceMultiplierType.Store, IsPropertySaveable.Yes)]
public PriceMultiplierType TargetMultiplier { get; set; }
public SetPriceMultiplierAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public SetPriceMultiplierAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
@@ -7,21 +7,21 @@ namespace Barotrauma
{
class SkillCheckAction : BinaryOptionAction
{
[Serialize("", true)]
public string RequiredSkill { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier RequiredSkill { get; set; }
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float RequiredLevel { get; set; }
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool ProbabilityBased { get; set; }
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public SkillCheckAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public SkillCheckAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
if (string.IsNullOrEmpty(TargetTag))
if (TargetTag.IsEmpty)
{
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": SkillCheckAction without a target tag (the action needs to know whose skill to check).");
}
@@ -33,11 +33,11 @@ namespace Barotrauma
if (ProbabilityBased)
{
return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill?.ToLowerInvariant()) / RequiredLevel > Rand.Range(0.0f, 1.0f, Rand.RandSync.Unsynced));
return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill) / RequiredLevel > Rand.Range(0.0f, 1.0f, Rand.RandSync.Unsynced));
}
else
{
return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill?.ToLowerInvariant()) >= RequiredLevel);
return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill) >= RequiredLevel);
}
}
@@ -19,39 +19,39 @@ namespace Barotrauma
BeaconStation
}
[Serialize("", true, description: "Species name of the character to spawn.")]
public string SpeciesName { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Species name of the character to spawn.")]
public Identifier SpeciesName { get; set; }
[Serialize("", true, description: "Identifier of the NPC set to choose from.")]
public string NPCSetIdentifier { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Identifier of the NPC set to choose from.")]
public Identifier NPCSetIdentifier { get; set; }
[Serialize("", true, description: "Identifier of the NPC.")]
public string NPCIdentifier { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Identifier of the NPC.")]
public Identifier NPCIdentifier { get; set; }
[Serialize(true, true, description: "Should taking the items of this npc be considered as stealing?")]
[Serialize(true, IsPropertySaveable.Yes, description: "Should taking the items of this npc be considered as stealing?")]
public bool LootingIsStealing { get; set; }
[Serialize("", true, description: "Identifier of the item to spawn.")]
public string ItemIdentifier { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Identifier of the item to spawn.")]
public Identifier ItemIdentifier { get; set; }
[Serialize("", true, description: "The spawned entity will be assigned this tag. The tag can be used to refer to the entity by other actions of the event.")]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "The spawned entity will be assigned this tag. The tag can be used to refer to the entity by other actions of the event.")]
public Identifier TargetTag { get; set; }
[Serialize("", true, description: "Tag of an entity with an inventory to spawn the item into.")]
public string TargetInventory { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Tag of an entity with an inventory to spawn the item into.")]
public Identifier TargetInventory { get; set; }
[Serialize(SpawnLocationType.MainSub, true)]
[Serialize(SpawnLocationType.MainSub, IsPropertySaveable.Yes)]
public SpawnLocationType SpawnLocation { get; set; }
[Serialize(SpawnType.Human, true)]
[Serialize(SpawnType.Human, IsPropertySaveable.Yes)]
public SpawnType SpawnPointType { get; set; }
[Serialize("", true)]
public string SpawnPointTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier SpawnPointTag { get; set; }
private readonly HashSet<string> targetModuleTags = new HashSet<string>();
private readonly HashSet<Identifier> targetModuleTags = new HashSet<Identifier>();
[Serialize("", true, "What outpost module tags does the entity prefer to spawn in.")]
[Serialize("", IsPropertySaveable.Yes, "What outpost module tags does the entity prefer to spawn in.")]
public string TargetModuleTags
{
get => string.Join(",", targetModuleTags);
@@ -63,13 +63,13 @@ namespace Barotrauma
string[] splitTags = value.Split(',');
foreach (var s in splitTags)
{
targetModuleTags.Add(s);
targetModuleTags.Add(s.ToIdentifier());
}
}
}
}
[Serialize(false, true, description: "Should the AI ignore this item. This will prevent outpost NPCs cleaning up or otherwise using important items intended to be left for the players.")]
[Serialize(false, IsPropertySaveable.Yes, description: "Should the AI ignore this item. This will prevent outpost NPCs cleaning up or otherwise using important items intended to be left for the players.")]
public bool IgnoreByAI { get; set; }
private bool spawned;
@@ -77,7 +77,7 @@ namespace Barotrauma
private readonly bool ignoreSpawnPointType;
public SpawnAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public SpawnAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
ignoreSpawnPointType = !element.Attributes().Any(a => a.Name.ToString().Equals("spawnpointtype", StringComparison.OrdinalIgnoreCase));
}
@@ -104,16 +104,16 @@ namespace Barotrauma
{
if (spawned) { return; }
if (!string.IsNullOrEmpty(NPCSetIdentifier) && !string.IsNullOrEmpty(NPCIdentifier))
if (!NPCSetIdentifier.IsEmpty && !NPCIdentifier.IsEmpty)
{
HumanPrefab humanPrefab = NPCSet.Get(NPCSetIdentifier, NPCIdentifier);
if (humanPrefab != null)
{
ISpatialEntity spawnPos = GetSpawnPos();
Entity.Spawner.AddToSpawnQueue(CharacterPrefab.HumanSpeciesName, OffsetSpawnPos(spawnPos?.WorldPosition ?? Vector2.Zero, 100.0f), humanPrefab.GetCharacterInfo(), onSpawn: newCharacter =>
Entity.Spawner.AddCharacterToSpawnQueue(CharacterPrefab.HumanSpeciesName, OffsetSpawnPos(spawnPos?.WorldPosition ?? Vector2.Zero, 100.0f), humanPrefab.GetCharacterInfo(), onSpawn: newCharacter =>
{
if (newCharacter == null) { return; }
newCharacter.Prefab = humanPrefab;
newCharacter.HumanPrefab = humanPrefab;
newCharacter.TeamID = CharacterTeamType.FriendlyNPC;
newCharacter.EnableDespawn = false;
humanPrefab.GiveItems(newCharacter, newCharacter.Submarine);
@@ -126,7 +126,7 @@ namespace Barotrauma
}
}
humanPrefab.InitializeCharacter(newCharacter, spawnPos);
if (!string.IsNullOrEmpty(TargetTag) && newCharacter != null)
if (!TargetTag.IsEmpty && newCharacter != null)
{
ParentEvent.AddTarget(TargetTag, newCharacter);
}
@@ -134,18 +134,18 @@ namespace Barotrauma
});
}
}
else if (!string.IsNullOrEmpty(SpeciesName))
else if (!SpeciesName.IsEmpty)
{
Entity.Spawner.AddToSpawnQueue(SpeciesName, OffsetSpawnPos(GetSpawnPos()?.WorldPosition ?? Vector2.Zero, 100.0f), onSpawn: newCharacter =>
Entity.Spawner.AddCharacterToSpawnQueue(SpeciesName, OffsetSpawnPos(GetSpawnPos()?.WorldPosition ?? Vector2.Zero, 100.0f), onSpawn: newCharacter =>
{
if (!string.IsNullOrEmpty(TargetTag) && newCharacter != null)
if (!TargetTag.IsEmpty && newCharacter != null)
{
ParentEvent.AddTarget(TargetTag, newCharacter);
}
spawnedEntity = newCharacter;
});
}
else if (!string.IsNullOrEmpty(ItemIdentifier))
else if (!ItemIdentifier.IsEmpty)
{
if (!(MapEntityPrefab.Find(null, identifier: ItemIdentifier) is ItemPrefab itemPrefab))
{
@@ -154,7 +154,7 @@ namespace Barotrauma
else
{
Inventory spawnInventory = null;
if (!string.IsNullOrEmpty(TargetInventory))
if (!TargetInventory.IsEmpty)
{
var targets = ParentEvent.GetTargets(TargetInventory);
if (targets.Any())
@@ -178,17 +178,17 @@ namespace Barotrauma
if (spawnInventory == null)
{
Entity.Spawner.AddToSpawnQueue(itemPrefab, OffsetSpawnPos(GetSpawnPos()?.WorldPosition ?? Vector2.Zero, 100.0f), onSpawned: onSpawned);
Entity.Spawner.AddItemToSpawnQueue(itemPrefab, OffsetSpawnPos(GetSpawnPos()?.WorldPosition ?? Vector2.Zero, 100.0f), onSpawned: onSpawned);
}
else
{
Entity.Spawner.AddToSpawnQueue(itemPrefab, spawnInventory, onSpawned: onSpawned);
Entity.Spawner.AddItemToSpawnQueue(itemPrefab, spawnInventory, onSpawned: onSpawned);
}
void onSpawned(Item newItem)
{
if (newItem != null)
{
if (!string.IsNullOrEmpty(TargetTag))
if (!TargetTag.IsEmpty)
{
ParentEvent.AddTarget(TargetTag, newItem);
}
@@ -221,7 +221,7 @@ namespace Barotrauma
private ISpatialEntity GetSpawnPos()
{
if (!string.IsNullOrWhiteSpace(SpawnPointTag))
if (!SpawnPointTag.IsEmpty)
{
List<Item> potentialItems = SpawnLocation switch
{
@@ -234,10 +234,10 @@ namespace Barotrauma
_ => throw new NotImplementedException()
};
var item = potentialItems.Where(it => it.HasTag(SpawnPointTag)).GetRandom();
var item = potentialItems.Where(it => it.HasTag(SpawnPointTag)).GetRandomUnsynced();
if (item != null) { return item; }
var target = ParentEvent.GetTargets(SpawnPointTag).GetRandom();
var target = ParentEvent.GetTargets(SpawnPointTag).GetRandomUnsynced();
if (target != null) { return target; }
}
@@ -247,7 +247,7 @@ namespace Barotrauma
return GetSpawnPos(SpawnLocation, spawnPointType, targetModuleTags, SpawnPointTag.ToEnumerable());
}
public static WayPoint GetSpawnPos(SpawnLocationType spawnLocation, SpawnType? spawnPointType, IEnumerable<string> moduleFlags = null, IEnumerable<string> spawnpointTags = null, bool asFarAsPossibleFromAirlock = false)
public static WayPoint GetSpawnPos(SpawnLocationType spawnLocation, SpawnType? spawnPointType, IEnumerable<Identifier> moduleFlags = null, IEnumerable<Identifier> spawnpointTags = null, bool asFarAsPossibleFromAirlock = false)
{
List<WayPoint> potentialSpawnPoints = spawnLocation switch
{
@@ -301,7 +301,7 @@ namespace Barotrauma
}
//don't spawn in an airlock module if there are other options
var airlockSpawnPoints = potentialSpawnPoints.Where(wp => wp.CurrentHull?.OutpostModuleTags.Contains("airlock") ?? false);
var airlockSpawnPoints = potentialSpawnPoints.Where(wp => wp.CurrentHull?.OutpostModuleTags.Contains("airlock".ToIdentifier()) ?? false);
if (airlockSpawnPoints.Count() < validSpawnPoints.Count())
{
validSpawnPoints = validSpawnPoints.Except(airlockSpawnPoints);
@@ -310,7 +310,7 @@ namespace Barotrauma
if (!validSpawnPoints.Any())
{
DebugConsole.ThrowError($"Could not find a spawn point of the correct type for a SpawnAction (spawn location: {spawnLocation}, type: {spawnPointType}, module flags: {((moduleFlags == null || !moduleFlags.Any()) ? "none" : string.Join(", ", moduleFlags))})");
return potentialSpawnPoints.GetRandom();
return potentialSpawnPoints.GetRandomUnsynced();
}
//avoid using waypoints if there's any actual spawnpoints available
@@ -346,7 +346,7 @@ namespace Barotrauma
}
else
{
return validSpawnPoints.GetRandom();
return validSpawnPoints.GetRandomUnsynced();
}
}
@@ -9,19 +9,19 @@ namespace Barotrauma
private int actionIndex;
[Serialize("", true)]
public string TargetTag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier TargetTag { get; set; }
public StatusEffectAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public StatusEffectAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
actionIndex = 0;
foreach (XElement subElement in parentEvent.Prefab.ConfigElement.Descendants())
foreach (var subElement in parentEvent.Prefab.ConfigElement.Descendants())
{
if (subElement == element) { break; }
actionIndex++;
}
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
@@ -1,5 +1,9 @@
using Barotrauma.Extensions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma
@@ -8,21 +12,35 @@ namespace Barotrauma
{
public enum SubType { Any = 0, Player = 1, Outpost = 2, Wreck = 4, BeaconStation = 8 }
[Serialize("", true)]
[Serialize("", IsPropertySaveable.Yes)]
public string Criteria { get; set; }
[Serialize("", true)]
public string Tag { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Tag { get; set; }
[Serialize(SubType.Any, true)]
[Serialize(SubType.Any, IsPropertySaveable.Yes)]
public SubType SubmarineType { get; set; }
[Serialize(true, true)]
[Serialize(true, IsPropertySaveable.Yes)]
public bool IgnoreIncapacitatedCharacters { get; set; }
private bool isFinished = false;
public TagAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public TagAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
Taggers = new (string k, Action<Identifier> v)[]
{
("players", v => TagPlayers()),
("player", v => TagPlayers()),
("bot", v => TagBots(playerCrewOnly: false)),
("crew", v => TagCrew()),
("humanprefabidentifier", TagHumansByIdentifier),
("structureidentifier", TagStructuresByIdentifier),
("itemidentifier", TagItemsByIdentifier),
("itemtag", TagItemsByTag),
("hullname", TagHullsByName)
}.Select(t => (t.k.ToIdentifier(), t.v)).ToImmutableDictionary();
}
public override bool IsFinished(ref string goTo)
{
@@ -67,34 +85,34 @@ namespace Barotrauma
#endif
}
private void TagHumansByIdentifier(string identifier)
private void TagHumansByIdentifier(Identifier identifier)
{
foreach (Character c in Character.CharacterList)
{
if (c.Prefab?.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase) ?? false)
if (c.HumanPrefab?.Identifier == identifier)
{
ParentEvent.AddTarget(Tag, c);
}
}
}
private void TagStructuresByIdentifier(string identifier)
private void TagStructuresByIdentifier(Identifier identifier)
{
ParentEvent.AddTargetPredicate(Tag, e => e is Structure s && SubmarineTypeMatches(s.Submarine) && s.Prefab.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase));
ParentEvent.AddTargetPredicate(Tag, e => e is Structure s && SubmarineTypeMatches(s.Submarine) && s.Prefab.Identifier == identifier);
}
private void TagItemsByIdentifier(string identifier)
private void TagItemsByIdentifier(Identifier identifier)
{
ParentEvent.AddTargetPredicate(Tag, e => e is Item it && SubmarineTypeMatches(it.Submarine) && it.Prefab.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase));
ParentEvent.AddTargetPredicate(Tag, e => e is Item it && SubmarineTypeMatches(it.Submarine) && it.Prefab.Identifier == identifier);
}
private void TagItemsByTag(string tag)
private void TagItemsByTag(Identifier tag)
{
ParentEvent.AddTargetPredicate(Tag, e => e is Item it && SubmarineTypeMatches(it.Submarine) && it.HasTag(tag));
}
private void TagHullsByName(string name)
private void TagHullsByName(Identifier name)
{
ParentEvent.AddTargetPredicate(Tag, e => e is Hull h && SubmarineTypeMatches(h.Submarine) && h.RoomName.Contains(name, StringComparison.OrdinalIgnoreCase));
ParentEvent.AddTargetPredicate(Tag, e => e is Hull h && SubmarineTypeMatches(h.Submarine) && h.RoomName.Contains(name.Value, StringComparison.OrdinalIgnoreCase));
}
private bool SubmarineTypeMatches(Submarine sub)
@@ -117,6 +135,8 @@ namespace Barotrauma
}
}
private readonly ImmutableDictionary<Identifier, Action<Identifier>> Taggers;
public override void Update(float deltaTime)
{
if (isFinished) { return; }
@@ -126,32 +146,17 @@ namespace Barotrauma
foreach (string entry in criteriaSplit)
{
string[] kvp = entry.Split(':');
switch (kvp[0].Trim().ToLowerInvariant())
Identifier key = kvp[0].Trim().ToIdentifier();
Identifier value = kvp.Length > 1 ? kvp[1].Trim().ToIdentifier() : Identifier.Empty;
if (Taggers.TryGetValue(key, out Action<Identifier> tagger))
{
case "player":
TagPlayers();
break;
case "bot":
TagBots(playerCrewOnly: false);
break;
case "crew":
TagCrew();
break;
case "humanprefabidentifier":
if (kvp.Length > 1) { TagHumansByIdentifier(kvp[1].Trim()); }
break;
case "structureidentifier":
if (kvp.Length > 1) { TagStructuresByIdentifier(kvp[1].Trim()); }
break;
case "itemidentifier":
if (kvp.Length > 1) { TagItemsByIdentifier(kvp[1].Trim()); }
break;
case "itemtag":
if (kvp.Length > 1) { TagItemsByTag(kvp[1].Trim()); }
break;
case "hullname":
if (kvp.Length > 1) { TagHullsByName(kvp[1].Trim()); }
break;
tagger(value);
}
else
{
string errorMessage = $"Error in TagAction (event \"{ParentEvent.Prefab.Identifier}\") - unrecognized target criteria \"{key}\".";
DebugConsole.ThrowError(errorMessage);
GameAnalyticsManager.AddErrorEventOnce($"TagAction.Update:InvalidCriteria_{ParentEvent.Prefab.Identifier}_{key}", GameAnalyticsManager.ErrorSeverity.Error, errorMessage);
}
}
@@ -8,42 +8,39 @@ namespace Barotrauma
{
class TriggerAction : EventAction
{
[Serialize("", true, description: "Tag of the first entity that will be used for trigger checks.")]
public string Target1Tag { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Tag of the first entity that will be used for trigger checks.")]
public Identifier Target1Tag { get; set; }
[Serialize("", true, description: "Tag of the second entity that will be used for trigger checks.")]
public string Target2Tag { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Tag of the second entity that will be used for trigger checks.")]
public Identifier Target2Tag { get; set; }
[Serialize("", true, description: "If set, the first target has to be within an outpost module of this type.")]
public string TargetModuleType { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "If set, the first target has to be within an outpost module of this type.")]
public Identifier TargetModuleType { get; set; }
[Serialize("", true, description: "Tag to apply to the first entity when the trigger check succeeds.")]
public string ApplyToTarget1 { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Tag to apply to the first entity when the trigger check succeeds.")]
public Identifier ApplyToTarget1 { get; set; }
[Serialize("", true, description: "Tag to apply to the second entity when the trigger check succeeds.")]
public string ApplyToTarget2 { get; set; }
[Serialize("", IsPropertySaveable.Yes, description: "Tag to apply to the second entity when the trigger check succeeds.")]
public Identifier ApplyToTarget2 { get; set; }
[Serialize(0.0f, true, description: "Range both entities must be within to activate the trigger.")]
[Serialize(0.0f, IsPropertySaveable.Yes, description: "Range both entities must be within to activate the trigger.")]
public float Radius { get; set; }
[Serialize(true, true, description: "If true, characters who are being targeted by some enemy cannot trigger the action.")]
[Serialize(true, IsPropertySaveable.Yes, description: "If true, characters who are being targeted by some enemy cannot trigger the action.")]
public bool DisableInCombat { get; set; }
[Serialize(true, true, description: "If true, dead/unconscious characters cannot trigger the action.")]
[Serialize(true, IsPropertySaveable.Yes, description: "If true, dead/unconscious characters cannot trigger the action.")]
public bool DisableIfTargetIncapacitated { get; set; }
[Serialize(false, true, description: "If true, one target must interact with the other to trigger the action.")]
[Serialize(false, IsPropertySaveable.Yes, description: "If true, one target must interact with the other to trigger the action.")]
public bool WaitForInteraction { get; set; }
[Serialize(false, true, description: "If true, the action can be triggered by interacting with any matching target (not just the 1st one).")]
[Serialize(false, IsPropertySaveable.Yes, description: "If true, the action can be triggered by interacting with any matching target (not just the 1st one).")]
public bool AllowMultipleTargets { get; set; }
private float distance;
public TriggerAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
{
TargetModuleType = TargetModuleType?.ToLowerInvariant();
}
public TriggerAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
public override bool IsFinished(ref string goTo)
@@ -74,7 +71,7 @@ namespace Barotrauma
{
if (DisableInCombat && IsInCombat(e1)) { continue; }
if (DisableIfTargetIncapacitated && e1 is Character character1 && (character1.IsDead || character1.IsIncapacitated)) { continue; }
if (!string.IsNullOrEmpty(TargetModuleType))
if (!TargetModuleType.IsEmpty)
{
if (IsCloseEnoughToHull(e1, out Hull hull))
{
@@ -143,7 +140,7 @@ namespace Barotrauma
#if CLIENT
npc.SetCustomInteract(
(speaker, player) => { if (e1 == speaker) { Trigger(speaker, player); } else { Trigger(player, speaker); } },
TextManager.GetWithVariable("CampaignInteraction.Examine", "[key]", GameMain.Config.KeyBindText(InputType.Use)));
TextManager.GetWithVariable("CampaignInteraction.Examine", "[key]", GameSettings.CurrentConfig.KeyMap.KeyBindText(InputType.Use)));
#else
npc.SetCustomInteract(
(speaker, player) => { if (e1 == speaker) { Trigger(speaker, player); } else { Trigger(player, speaker); } },
@@ -226,7 +223,7 @@ namespace Barotrauma
}
else
{
foreach (Hull potentialHull in Hull.hullList)
foreach (Hull potentialHull in Hull.HullList)
{
if (!potentialHull.OutpostModuleTags.Contains(TargetModuleType)) { continue; }
@@ -270,11 +267,11 @@ namespace Barotrauma
private void Trigger(Entity entity1, Entity entity2)
{
ResetTargetIcons();
if (!string.IsNullOrEmpty(ApplyToTarget1))
if (!ApplyToTarget1.IsEmpty)
{
ParentEvent.AddTarget(ApplyToTarget1, entity1);
}
if (!string.IsNullOrEmpty(ApplyToTarget2))
if (!ApplyToTarget2.IsEmpty)
{
ParentEvent.AddTarget(ApplyToTarget2, entity2);
}
@@ -285,7 +282,7 @@ namespace Barotrauma
public override string ToDebugString()
{
if (string.IsNullOrEmpty(TargetModuleType))
if (TargetModuleType.IsEmpty)
{
return
$"{ToolBox.GetDebugSymbol(isFinished, isRunning)} {nameof(TriggerAction)} -> (" +
@@ -4,12 +4,12 @@ namespace Barotrauma
{
class TriggerEventAction : EventAction
{
[Serialize("", true)]
public string Identifier { get; set; }
[Serialize("", IsPropertySaveable.Yes)]
public Identifier Identifier { get; set; }
private bool isFinished;
public TriggerEventAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public TriggerEventAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
public override bool IsFinished(ref string goTo)
{
@@ -9,7 +9,7 @@ namespace Barotrauma
{
class UnlockPathAction : EventAction
{
public UnlockPathAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element) { }
public UnlockPathAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
private bool isFinished = false;
@@ -36,7 +36,7 @@ namespace Barotrauma
NotifyUnlock(connection);
#else
new GUIMessageBox(string.Empty, TextManager.Get("pathunlockedgeneric"),
new string[0], type: GUIMessageBox.Type.InGame, iconStyle: "UnlockPathIcon", relativeSize: new Vector2(0.3f, 0.15f), minSize: new Point(512, 128));
Array.Empty<LocalizedString>(), type: GUIMessageBox.Type.InGame, iconStyle: "UnlockPathIcon", relativeSize: new Vector2(0.3f, 0.15f), minSize: new Point(512, 128));
#endif
}
}
@@ -5,12 +5,12 @@ namespace Barotrauma
{
class WaitAction : EventAction
{
[Serialize(0.0f, true)]
[Serialize(0.0f, IsPropertySaveable.Yes)]
public float Time { get; set; }
private float timeRemaining;
public WaitAction(ScriptedEvent parentEvent, XElement element) : base(parentEvent, element)
public WaitAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
{
timeRemaining = Time;
}