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

Fix Trapper Information gain as it "should be" #492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions TheOtherRoles/Objects/Trap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
using UnityEngine;

namespace TheOtherRoles.Objects {
record TrapInfo {
public PlayerControl player;
public string roleWhenInTrap;
}

class Trap {
public static List<Trap> traps = new List<Trap>();
public static Dictionary<byte, Trap> trapPlayerIdMap = new Dictionary<byte, Trap>();
Expand All @@ -18,7 +23,7 @@ class Trap {
public bool triggerable = false;
private int usedCount = 0;
private int neededCount = Trapper.trapCountToReveal;
public List<PlayerControl> trappedPlayer = new List<PlayerControl>();
public List<TrapInfo> trappedPlayer = new List<TrapInfo>();
private Arrow arrow = new Arrow(Color.blue);

private static Sprite trapSprite;
Expand Down Expand Up @@ -95,11 +100,12 @@ public static void triggerTrap(byte playerId, byte trapId) {
}
})));

if (t.usedCount == t.neededCount) {
if (t.usedCount == t.neededCount)
{
t.revealed = true;
}

t.trappedPlayer.Add(player);
t.trappedPlayer.Add(new TrapInfo { player = player, roleWhenInTrap = RoleInfo.GetRolesString(player, false, false, true)});
t.triggerable = true;

}
Expand All @@ -115,7 +121,7 @@ public static void Update() {
Trap target = null;
foreach (Trap trap in traps) {
if (trap.arrow.arrow.active) trap.arrow.Update();
if (trap.revealed || !trap.triggerable || trap.trappedPlayer.Contains(player.PlayerControl)) continue;
if (trap.revealed || !trap.triggerable || trap.trappedPlayer.Any(tp => tp.player == player.PlayerControl)) continue;
if (player.PlayerControl.inVent || !player.PlayerControl.CanMove) continue;
float distance = Vector2.Distance(trap.trap.transform.position, player.PlayerControl.GetTruePosition());
if (distance <= ud && distance < closestDistance) {
Expand Down
6 changes: 4 additions & 2 deletions TheOtherRoles/Patches/MeetingPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,10 @@ public static void Prefix(PlayerControl __instance, [HarmonyArgument(0)]GameData
if (!trap.revealed) continue;
string message = $"Trap {trap.instanceId}: \n";
trap.trappedPlayer = trap.trappedPlayer.OrderBy(x => rnd.Next()).ToList();
foreach (PlayerControl p in trap.trappedPlayer) {
if (Trapper.infoType == 0) message += RoleInfo.GetRolesString(p, false, false, true) + "\n";
foreach (TrapInfo trapInfo in trap.trappedPlayer)
{
PlayerControl p = trapInfo.player;
if (Trapper.infoType == 0) message += trapInfo.roleWhenInTrap + "\n";
else if (Trapper.infoType == 1) {
if (Helpers.isNeutral(p) || p.Data.Role.IsImpostor) message += "Evil Role \n";
else message += "Good Role \n";
Expand Down