From d136ccc3508e84e97f78e0ac0d11c519c4833576 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 28 Oct 2024 20:41:49 +0100 Subject: [PATCH] Don't allow actors to disguise themselves as themselves --- OpenRA.Mods.Cnc/Traits/Disguise.cs | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs index 3d47e58ec7..8fc434f6c5 100644 --- a/OpenRA.Mods.Cnc/Traits/Disguise.cs +++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs @@ -171,19 +171,39 @@ namespace OpenRA.Mods.Cnc.Traits var targetDisguise = target.TraitOrDefault(); if (targetDisguise != null && targetDisguise.Disguised) { - AsPlayer = targetDisguise.AsPlayer; - AsActor = targetDisguise.AsActor; - AsTooltipInfo = targetDisguise.AsTooltipInfo; + // Don't disguise as yourself + if (targetDisguise.AsActor.Name == self.Info.Name && targetDisguise.AsPlayer == self.Owner) + { + AsTooltipInfo = null; + AsPlayer = null; + AsActor = self.Info; + } + else + { + AsPlayer = targetDisguise.AsPlayer; + AsActor = targetDisguise.AsActor; + AsTooltipInfo = targetDisguise.AsTooltipInfo; + } } else { - var tooltip = target.TraitsImplementing().FirstEnabledTraitOrDefault(); - if (tooltip == null) - throw new ArgumentException("Missing tooltip or invalid target.", nameof(target)); + // Don't disguise as yourself + if (target.Info.Name == self.Info.Name && target.Owner == self.Owner) + { + AsTooltipInfo = null; + AsPlayer = null; + AsActor = self.Info; + } + else + { + var tooltip = target.TraitsImplementing().FirstEnabledTraitOrDefault(); + if (tooltip == null) + throw new ArgumentException("Missing tooltip or invalid target.", nameof(target)); - AsPlayer = tooltip.Owner; - AsActor = target.Info; - AsTooltipInfo = tooltip.TooltipInfo; + AsPlayer = tooltip.Owner; + AsActor = target.Info; + AsTooltipInfo = tooltip.TooltipInfo; + } } } else