Skip to content

Commit

Permalink
Check message looktargets to determine if a player should see it
Browse files Browse the repository at this point in the history
  • Loading branch information
SaberShip committed Sep 3, 2024
1 parent f0221d0 commit 24d2a76
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Source/Client/Patches/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,33 @@ static bool Prefix(ref FleckCreationData fleckData)
[HarmonyPatch(typeof(Messages), nameof(Messages.Message), new[] { typeof(Message), typeof(bool) })]
static class SilenceMessagesNotTargetedAtMe
{
static bool Prefix(bool historical)
static bool Prefix(Message msg, bool historical)
{
bool cancel = Multiplayer.Client != null && !historical && Multiplayer.ExecutingCmds && !TickPatch.currentExecutingCmdIssuedBySelf;
bool cancel = Multiplayer.Client != null && !IsMessageRelevant(msg);
return !cancel;
}

static bool IsMessageRelevant(Message message) {
if (message.lookTargets.IsValid()) {
GlobalTargetInfo target = message.lookTargets.PrimaryTarget;
if (target.HasThing) {
return target.Thing.Faction == Multiplayer.RealPlayerFaction ||
target.Thing.Map.ParentFaction == Multiplayer.RealPlayerFaction;
}
else if (target.HasWorldObject) {
return target.WorldObject.Faction == Multiplayer.RealPlayerFaction ||
Find.Maps.Find(map => map.Tile == target.Tile).ParentFaction == Multiplayer.RealPlayerFaction;
} else if (target.Tile >= 0) {
return Find.Maps.Find(map => map.Tile == target.Tile).ParentFaction == Multiplayer.RealPlayerFaction;
}

// Default assume target is relevant
return true;
}

// Without a target we must assume the message is relevant
return true;
}
}

[HarmonyPatch(typeof(DesignatorManager), nameof(DesignatorManager.Deselect))]
Expand Down

0 comments on commit 24d2a76

Please sign in to comment.