From bd646fb23ed4c8f20d1d3455a189bac67c20e835 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sat, 16 Dec 2017 19:52:25 +0300 Subject: [PATCH] Implements identity system! If your mask hides your face (e.g. oxygen mask, clown mask and diving suit), the game will either use the name of the ID card owner in your ID card slot or will give you a "?" name. This only affects "DisplayName". The reason why I can't completely override the .Name for the client from server is due to how crew manifest and CharacterInfo classes are handled - it would require a major rework of many Character-related systems and interactions to truly make this "hack-proof". Server hosts will have to stay on their toes I guess. --- .../Source/Characters/Character.cs | 7 +++-- .../Source/Characters/CharacterHUD.cs | 2 +- .../Source/Items/Inventory.cs | 21 ++++++++++++-- .../Content/Items/Diving/divinggear.xml | 4 +-- .../Content/Items/Jobgear/misc.xml | 1 + .../Content/Items/Tools/tools.xml | 4 +-- .../Source/Characters/Character.cs | 15 ++++++++++ .../Source/Characters/CharacterInfo.cs | 29 ++++++++++++++++++- .../Source/Characters/Jobs/Job.cs | 3 +- 9 files changed, 74 insertions(+), 12 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 8d54f0a0d..2d73f742c 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -298,15 +298,16 @@ namespace Barotrauma if (info != null) { - Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom; + string name = Info.DisplayName; + Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(name) * 0.5f / cam.Zoom; Color nameColor = Color.White; if (Character.Controlled != null && TeamID != Character.Controlled.TeamID) { nameColor = Color.Red; } - GUI.Font.DrawString(spriteBatch, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f); - GUI.Font.DrawString(spriteBatch, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f); + GUI.Font.DrawString(spriteBatch, name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f); + GUI.Font.DrawString(spriteBatch, name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f); if (GameMain.DebugDraw) { diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs index 9a3ac7b23..8a9f1ebc4 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs @@ -208,7 +208,7 @@ namespace Barotrauma string focusName = character.FocusedCharacter.SpeciesName; if (character.FocusedCharacter.Info != null) { - focusName = character.FocusedCharacter.Info.Name; + focusName = character.FocusedCharacter.Info.DisplayName; } Vector2 textPos = startPos; textPos -= new Vector2(GUI.Font.MeasureString(focusName).X / 2, 20); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs index 8130dea44..b5204a9f0 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs @@ -296,9 +296,26 @@ namespace Barotrauma } else { - toolTip = string.IsNullOrEmpty(Items[i].Description) ? + string description = Items[i].Description; + if (Items[i].Name == "ID Card") + { + string[] readTags = Items[i].Tags.Split(','); + string idName = null; + string idJob = null; + foreach (string tag in readTags) + { + string[] s = tag.Split(':'); + if (s[0] == "name") + idName = s[1]; + if (s[0] == "job") + idJob = s[1]; + } + if (idName != null) + description = "This belongs to " + idName + (idJob != null ? ", the " + idJob + ".\n" : ".\n") + description; + } + toolTip = string.IsNullOrEmpty(description) ? Items[i].Name : - Items[i].Name + '\n' + Items[i].Description; + Items[i].Name + '\n' + description; } DrawToolTip(spriteBatch, toolTip, slots[i].Rect); diff --git a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml index 238988d26..9cbd1a043 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml @@ -41,7 +41,7 @@ - + @@ -92,7 +92,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml index 5a8c593f1..cdb8cb115 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml @@ -38,6 +38,7 @@ + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml index 882767d30..79c955152 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml @@ -197,8 +197,8 @@ - + aimpos="50,0" handle1="-5,0" holdangle="30" reload="1.7"> + diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 85e74eb6b..702b737f7 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -139,6 +139,19 @@ namespace Barotrauma } } + private float hideFaceTimer; + public bool HideFace + { + get + { + return hideFaceTimer > 0.0f; + } + set + { + hideFaceTimer = MathHelper.Clamp(hideFaceTimer + (value ? 1.0f : -0.5f), 0.0f, 10.0f); + } + } + public string ConfigPath { get; @@ -1406,6 +1419,8 @@ namespace Barotrauma item.Submarine = Submarine; } } + + HideFace = false; if (isDead) return; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaShared/Source/Characters/CharacterInfo.cs index dd6d8133f..12e5d93c4 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/CharacterInfo.cs @@ -12,7 +12,34 @@ namespace Barotrauma partial class CharacterInfo { public string Name; - + public string DisplayName + { + get { + string disguiseName = "?"; + if (Character != null && Character.HideFace) + { + if (Character.Inventory != null) + { + var idCard = Character.Inventory.FindItem("ID Card"); + if (idCard != null && Character.Inventory.IsInLimbSlot(idCard, InvSlotType.Card)) //Disguise as the ID card name if it's equipped + { + string[] readTags = idCard.Tags.Split(','); + foreach (string tag in readTags) + { + string[] s = tag.Split(':'); + if (s[0] == "name") + { + disguiseName = s[1]; + break; + } + } + } + } + return disguiseName; + } + return Name; + } + } public Character Character; public readonly string File; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs b/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs index d2b3e28e8..865e6bcbc 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs @@ -130,7 +130,8 @@ namespace Barotrauma { item.AddTag(s); } - item.Description = "This belongs to " + character.Name + ", the " + Name + "."; + item.AddTag("name:" + character.Name); + item.AddTag("job:" + Name); } if (parentItem != null) parentItem.Combine(item);