From eb97369b32afbc6b39ef5e98a465dbdc05437d8e Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:47:19 +0700 Subject: [PATCH] live chat check --- ILEditing/ILChangesLoading.cs | 1 + ILEditing/MechanicILChanges.cs | 28 +++++++++++++++++++ .../Mods.CalamityMod.Items.Accessories.hjson | 14 ++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 2cf0c90e80..109b245104 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -85,6 +85,7 @@ namespace CalamityMod.ILEditing On_NPC.DoDeathEvents_BeforeLoot += PreventFoveanatorDefeatMessageIfNotKilledLast; On_NPC.DoDeathEvents_CelebrateBossDeath += TripletsDefeatTextOverride; On_TileDrawing.DrawSingleTile += GlowMaskTileRender; + On_Main.DoUpdate_HandleChat += SpawnPunchCard; // Mana Burn (Chaos Stone) and Chalice of the Blood God IL_Player.ApplyLifeAndOrMana += ManaSicknessAndChaliceBufferHeal; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 2170b6a14c..002dfcae11 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -36,6 +36,7 @@ using Mono.Cecil.Cil; using MonoMod.Cil; using ReLogic.Content; using Terraria; +using Terraria.Audio; using Terraria.Chat; using Terraria.DataStructures; using Terraria.GameContent; @@ -76,6 +77,33 @@ namespace CalamityMod.ILEditing public static event Func ExtraColorChangeConditions; + #region Punch Card Spawning Command + private static void SpawnPunchCard(Terraria.On_Main.orig_DoUpdate_HandleChat orig) + { + // Any of these conditions should result in normal behaviour + if (!Main.drawingPlayerChat || Main.CurrentInputTextTakerOverride != null || Main.editSign || PlayerInput.UsingGamepad) + { + orig(); + return; + } + + // Find 2 specific sets of text from the live chat box (as the player is typing) + // Gives the item to you and abruptly shuts the chat box down if both parts are found + string text = Main.chatText.ToLower(); + string prefix = "Items.Accessories.PunchCard.SpawnText"; + if ((text.Contains(CalamityUtils.GetTextValue($"{prefix}1")) || text.Contains(CalamityUtils.GetTextValue($"{prefix}1Alt"))) && text.Contains(CalamityUtils.GetTextValue($"{prefix}2"))) + { + Main.player[Main.myPlayer].QuickSpawnItem(Player.GetSource_None(), ModContent.ItemType(), 1); + Main.chatText = ""; + Main.ClosePlayerChat(); + Main.chatRelease = false; + SoundEngine.PlaySound(SoundID.MenuClose); + return; + } + orig(); + } + #endregion + #region Dash Fixes and Improvements private static void MakeShieldSlamIFramesConsistent(ILContext il) { diff --git a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson index 94a1758fcd..59cc6ccec9 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson @@ -2045,11 +2045,6 @@ GhostBracelet: { Tooltip: Wow.... It looks at me with its hollow eyes full of curiosity } -PunchCard: { - DisplayName: Punch Card - Tooltip: "[c/842593:'Please... please get world record...']" -} - HapuFruit: { DisplayName: Ha-pu Fruit Tooltip: "'A fruit that calms your nerves (may have unintended side effects)'" @@ -2068,3 +2063,12 @@ Popo: { 'Don't let the demons steal your nose' ''' } + +PunchCard: { + DisplayName: Punch Card + Tooltip: "[c/842593:'Please... please get world record...']" + // These are used to spawn the item via chat -- both must be all lower case for the detection to work + SpawnText1: it's late + SpawnText1Alt: its late + SpawnText2: go to bed +} \ No newline at end of file