diff --git a/asset_patches/assets/data/Papers.xml b/asset_patches/assets/data/Papers.xml index 3d913e5..738f25e 100644 --- a/asset_patches/assets/data/Papers.xml +++ b/asset_patches/assets/data/Papers.xml @@ -47,6 +47,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/psp-papers-mod/src/Patches/ChatterGuards.cs b/psp-papers-mod/src/Patches/ChatterGuards.cs new file mode 100644 index 0000000..7a057d3 --- /dev/null +++ b/psp-papers-mod/src/Patches/ChatterGuards.cs @@ -0,0 +1,51 @@ +using data; +using HarmonyLib; +using Il2CppSystem; +using play.day.border; +using psp_papers_mod.Twitch; +using System.Collections.Generic; +using System.Linq; + +namespace psp_papers_mod.Patches; + +public class ChatterGuards { + public static ChatterCollection WantToGuardChatters = new (); + public static Chatter[] Guards = new Chatter[5]; + // 0-1: left guards, 2-4: right guards + + public static bool SetGuards() { + if (WantToGuardChatters.Count < 1) return false; + + int[] order = { 2, 3, 4, 0, 1 }; // Prioritize setting the right ones first + + foreach (int i in order) { + for (int j = 0; j < WantToGuardChatters.Count; j++) { + Chatter chatter = WantToGuardChatters.GetRandomChatter(); + + if (!Guards.Contains(chatter)) { + Guards[i] = chatter; + break; + } + } + } + + return true; + } +} + + +[HarmonyPatch(typeof(Person))] +internal class GuardPersonPatch { + + [HarmonyPrefix] + [HarmonyPatch("setAnim", typeof(Anim), typeof(Object))] + private static void PersonSetAnim(Anim anim, Object movingHorizontal, Person __instance) { + if (!anim.death) return; + + // left guards can't die as of rn + if(__instance.id == "guard2") ChatterGuards.Guards[2]?.Shot(); + if(__instance.id == "guard3") ChatterGuards.Guards[3]?.Shot(); + if(__instance.id == "guard4") ChatterGuards.Guards[4]?.Shot(); + + } +} \ No newline at end of file diff --git a/psp-papers-mod/src/Patches/TextPatch.cs b/psp-papers-mod/src/Patches/TextPatch.cs index 8ec8a40..adacab9 100644 --- a/psp-papers-mod/src/Patches/TextPatch.cs +++ b/psp-papers-mod/src/Patches/TextPatch.cs @@ -13,12 +13,28 @@ public static string Process(string text) { } public static void SetMenuTextPrefix(ref string v) { - if (v is not "The day was cut short by a terrorist attack.") return; - - Chatter attacker = TwitchIntegration.ActiveAttacker; - if (attacker == null) return; - - v = v.Replace(".", " by " + attacker.Username + "."); + if (v == null) return; + + if (v is "The day was cut short by a terrorist attack.") { + Chatter attacker = TwitchIntegration.ActiveAttacker; + if (attacker == null) return; + + v = v.Replace(".", " by " + attacker.Username + "."); + return; + } + + if (ChatterGuards.WantToGuardChatters.Count < 1) { + if (v.Contains("__GUARD")) v = ""; + } else { + // hacky, but executes once per day right when it's needed + if (v is "Assigned guards:") ChatterGuards.SetGuards(); + + if (v is "__GUARD0__") v = ChatterGuards.Guards[0]?.Username; + if (v is "__GUARD1__") v = ChatterGuards.Guards[1]?.Username; + if (v is "__GUARD2__") v = ChatterGuards.Guards[2]?.Username; + if (v is "__GUARD3__") v = ChatterGuards.Guards[3]?.Username; + if (v is "__GUARD4__") v = ChatterGuards.Guards[4]?.Username; + } } } diff --git a/psp-papers-mod/src/Twitch/Chatter.cs b/psp-papers-mod/src/Twitch/Chatter.cs index 0f40146..69ee106 100644 --- a/psp-papers-mod/src/Twitch/Chatter.cs +++ b/psp-papers-mod/src/Twitch/Chatter.cs @@ -172,7 +172,10 @@ public int GetWeight(bool attacker = false) { // The active chatter can't be the attacker and vice versa (attacker && TwitchIntegration.ActiveChatter == this) || - (!attacker && TwitchIntegration.ActiveAttacker == this) + (!attacker && TwitchIntegration.ActiveAttacker == this) || + + // Guards can't be active chatters + (ChatterGuards.Guards.Contains(this)) ) return 0; diff --git a/psp-papers-mod/src/Twitch/Commands/Commands.cs b/psp-papers-mod/src/Twitch/Commands/Commands.cs index d40c54c..8cd77b4 100644 --- a/psp-papers-mod/src/Twitch/Commands/Commands.cs +++ b/psp-papers-mod/src/Twitch/Commands/Commands.cs @@ -48,6 +48,19 @@ public static void NoBomb(Chatter sender, ChatMessage chatMessage, string[] args sender.WantsBomb = false; } + [ChatCommand("guard")] + public static void WantsGuard(Chatter sender, ChatMessage chatMessage, string[] args) { + string username = sender.Username; + if (!ChatterGuards.WantToGuardChatters.ContainsKey(username)) { + ChatterGuards.WantToGuardChatters.Add(username, new Chatter(chatMessage)); + + chatMessage.Reply("Thank you for enlisting in the border patrol o7"); + } else { + ChatterGuards.WantToGuardChatters.Remove(username); + chatMessage.Reply("Opted out of being a guard."); + } + } + [ChatCommand("give")] public static void GiveEmote(Chatter sender, ChatMessage chatMessage, string[] args) { if (!sender.IsActiveChatter) return; diff --git a/psp-papers-mod/src/Twitch/TwitchIntegration.cs b/psp-papers-mod/src/Twitch/TwitchIntegration.cs index a938f09..2b3d475 100644 --- a/psp-papers-mod/src/Twitch/TwitchIntegration.cs +++ b/psp-papers-mod/src/Twitch/TwitchIntegration.cs @@ -31,6 +31,7 @@ public class TwitchIntegration { public const float DENIED_WEIGHT_MODIFIER = 0.8f; public ChatterCollection FrequentChatters { get; } + public static Chatter NextChatter { get; set; } @@ -57,6 +58,7 @@ public class TwitchIntegration { public TwitchIntegration() { this.FrequentChatters = new ChatterCollection(); + Task authTask = LocalAuthResponse.Fetch(); authTask.Wait(); diff --git a/psp-papers-mod/src/Utils/SplitUsername.cs b/psp-papers-mod/src/Utils/SplitUsername.cs index dd4a582..18fedd2 100644 --- a/psp-papers-mod/src/Utils/SplitUsername.cs +++ b/psp-papers-mod/src/Utils/SplitUsername.cs @@ -72,8 +72,6 @@ public static (string, string) Process(string username) { // uni1g -> 1g, uni if (username.EndsWith("1g")) { - Console.WriteLine("1g"); - splitIndex = username.LastIndexOf("1g", StringComparison.Ordinal); }