From 2ea58c58a766276e4d7e7964ecb67cf1adea632f Mon Sep 17 00:00:00 2001 From: Markus Isberg Date: Fri, 20 Oct 2023 18:17:33 +0300 Subject: [PATCH] Hotfix 1.1.18.1 (real this time) --- ...htAction.cs => TutorialHighlightAction.cs} | 23 +++++----- .../ClientSource/Items/Item.cs | 17 -------- .../Events/EventActions/HighlightAction.cs | 24 ----------- .../ServerSource/Items/Item.cs | 14 ------ .../ServerSource/Items/ItemEventData.cs | 21 +-------- .../Events/EventActions/EventAction.cs | 6 +-- .../Events/EventActions/HighlightAction.cs | 43 ------------------- .../EventActions/TutorialHighlightAction.cs | 33 ++++++++++++++ .../Extensions/IEnumerableExtensions.cs | 5 --- .../SharedSource/Items/ItemEventData.cs | 3 +- 10 files changed, 49 insertions(+), 140 deletions(-) rename Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/{HighlightAction.cs => TutorialHighlightAction.cs} (69%) delete mode 100644 Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs delete mode 100644 Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs create mode 100644 Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs diff --git a/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs b/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs similarity index 69% rename from Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs rename to Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs index cce9ce464..732c1a480 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs @@ -1,19 +1,22 @@ -#nullable enable using Microsoft.Xna.Framework; -using System.Collections.Generic; -using System.Linq; namespace Barotrauma; -partial class HighlightAction : EventAction +partial class TutorialHighlightAction : EventAction { - partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters) - { - if (targetCharacters != null && !targetCharacters.Contains(Character.Controlled)) - { - return; - } + private static readonly Color highlightColor = Color.Orange; + partial void UpdateProjSpecific() + { + if (GameMain.GameSession?.GameMode is not TutorialMode) { return; } + foreach (var target in ParentEvent.GetTargets(TargetTag)) + { + SetHighlight(target); + } + } + + private void SetHighlight(Entity entity) + { if (entity is Item i) { SetItemHighlight(i); diff --git a/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs b/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs index 7706baa04..0f42a313c 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs @@ -1540,23 +1540,6 @@ namespace Barotrauma RemoveFromDroppedStack(allowClientExecute: true); } break; - case EventType.SetHighlight: - bool isTargetedForThisClient = msg.ReadBoolean(); - if (isTargetedForThisClient) - { - bool highlight = msg.ReadBoolean(); - ExternalHighlight = highlight; - if (highlight) - { - Color highlightColor = msg.ReadColorR8G8B8A8(); - HighlightColor = highlightColor; - } - else - { - HighlightColor = null; - } - } - break; default: throw new Exception($"Malformed incoming item event: unsupported event type {eventType}"); } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs b/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs deleted file mode 100644 index 98c06c3f9..000000000 --- a/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs +++ /dev/null @@ -1,24 +0,0 @@ -#nullable enable -using Barotrauma.Networking; -using System.Collections.Generic; -using System.Linq; - -namespace Barotrauma; - -partial class HighlightAction : EventAction -{ - partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters) - { - if (entity is Item item && GameMain.Server != null) - { - IEnumerable? targetClients = null; - if (targetCharacters != null) - { - targetClients = targetCharacters - .Select(c => GameMain.Server.ConnectedClients.FirstOrDefault(client => client.Character == c)) - .Where(c => c != null)!; - } - GameMain.Server?.CreateEntityEvent(item, new Item.SetHighlightEventData(State, highlightColor, targetClients)); - } - } -} \ No newline at end of file diff --git a/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs b/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs index 62c2477a1..f59311120 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs @@ -161,20 +161,6 @@ namespace Barotrauma msg.WriteUInt16(droppedItem.ID); } break; - case SetHighlightEventData highlightEventData: - bool isTargetedForClient = - highlightEventData.TargetClients.IsEmpty || - highlightEventData.TargetClients.Contains(c); - msg.WriteBoolean(isTargetedForClient); - if (isTargetedForClient) - { - msg.WriteBoolean(highlightEventData.Highlighted); - if (highlightEventData.Highlighted) - { - msg.WriteColorR8G8B8A8(highlightEventData.Color); - } - } - break; default: throw error($"Unsupported event type {itemEventData.GetType().Name}"); } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs b/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs index a37508ccf..b2a6b0dda 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs @@ -1,7 +1,4 @@ -#nullable enable -using Barotrauma.Networking; -using Microsoft.Xna.Framework; -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -19,20 +16,4 @@ partial class Item Items = items.Distinct().ToImmutableArray(); } } - - public readonly struct SetHighlightEventData : IEventData - { - public EventType EventType => EventType.SetHighlight; - public readonly bool Highlighted; - public readonly Color Color; - - public readonly ImmutableArray TargetClients; - - public SetHighlightEventData(bool highlighted, Color color, IEnumerable? targetClients) - { - Highlighted = highlighted; - Color = color; - TargetClients = (targetClients ?? Enumerable.Empty()).ToImmutableArray(); - } - } } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs index fddeb4d54..dd086ec74 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs @@ -140,11 +140,7 @@ namespace Barotrauma Identifier typeName = element.Name.ToString().ToIdentifier(); if (typeName == "TutorialSegmentAction") { - typeName = nameof(EventObjectiveAction).ToIdentifier(); - } - else if (typeName == "TutorialHighlightAction") - { - typeName = nameof(HighlightAction).ToIdentifier(); + typeName = "EventObjectiveAction".ToIdentifier(); } actionType = Type.GetType("Barotrauma." + typeName, throwOnError: true, ignoreCase: true); if (actionType == null) { throw new NullReferenceException(); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs deleted file mode 100644 index 8900299ea..000000000 --- a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs +++ /dev/null @@ -1,43 +0,0 @@ -#nullable enable -using Microsoft.Xna.Framework; -using System.Collections.Generic; -using System.Linq; - -namespace Barotrauma; - -partial class HighlightAction : EventAction -{ - private static readonly Color highlightColor = Color.Orange; - - [Serialize("", IsPropertySaveable.Yes)] - public Identifier TargetTag { get; set; } - - [Serialize("", IsPropertySaveable.Yes, description: "Only the player controlling this character will see the highlight. If empty, all players will see it.")] - public Identifier TargetCharacter { get; set; } - - [Serialize(true, IsPropertySaveable.Yes)] - public bool State { get; set; } - - private bool isFinished; - - public HighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) - { - } - - public override void Update(float deltaTime) - { - if (isFinished) { return; } - var targetCharacters = TargetCharacter.IsEmpty ? null : ParentEvent.GetTargets(TargetCharacter).OfType(); - foreach (var target in ParentEvent.GetTargets(TargetTag)) - { - SetHighlightProjSpecific(target, targetCharacters); - } - isFinished = true; - } - - partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters); - - public override bool IsFinished(ref string goToLabel) => isFinished; - - public override void Reset() => isFinished = false; -} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs new file mode 100644 index 000000000..190f7fdc0 --- /dev/null +++ b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs @@ -0,0 +1,33 @@ +namespace Barotrauma; + +partial class TutorialHighlightAction : EventAction +{ + [Serialize("", IsPropertySaveable.Yes)] + public Identifier TargetTag { get; set; } + + [Serialize(true, IsPropertySaveable.Yes)] + public bool State { get; set; } + + private bool isFinished; + + public TutorialHighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) + { + if (GameMain.NetworkMember != null) + { + DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": {nameof(TutorialHighlightAction)} is not supported in multiplayer."); + } + } + + public override void Update(float deltaTime) + { + if (isFinished) { return; } + UpdateProjSpecific(); + isFinished = true; + } + + partial void UpdateProjSpecific(); + + public override bool IsFinished(ref string goToLabel) => isFinished; + + public override void Reset() => isFinished = false; +} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs index 6453c4d52..abbb65f70 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs @@ -294,11 +294,6 @@ namespace Barotrauma.Extensions .Where(nullable => nullable.HasValue) .Select(nullable => nullable.Value); - public static IEnumerable NotNull(this IEnumerable source) where T : class - => source - .Where(nullable => nullable != null) - .Select(nullable => nullable!); - public static IEnumerable NotNone(this IEnumerable> source) { foreach (var o in source) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs index e0bf2763e..fecfef994 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs @@ -23,10 +23,9 @@ namespace Barotrauma Upgrade = 8, ItemStat = 9, DroppedStack = 10, - SetHighlight = 11, MinValue = 0, - MaxValue = 11 + MaxValue = 10 } public interface IEventData : NetEntityEvent.IData