Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Message LookTargets' Faction to Determine if it Should be Hidden #505

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading