Skip to content
Merged
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
5 changes: 2 additions & 3 deletions ChaosTokens/ChaosTokens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>

<Authors>Chipseq</Authors>
<Version>1.1.3</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AllOfUs.MiraAPI" Version="0.3.0" />
<PackageReference Include="Reactor" Version="2.3.1" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" Private="false" ExcludeAssets="runtime;native" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.9.9" PrivateAssets="all" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2025.3.31" PrivateAssets="all" />

<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all"/>
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" ExcludeAssets="runtime"/>
Expand Down
66 changes: 36 additions & 30 deletions ChaosTokens/ChaosTokensRpc.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Linq;
using AmongUs.GameOptions;
using ChaosTokens.Modifiers;
using ChaosTokens.Modifiers.Effects;
using ChaosTokens.Options;
Expand Down Expand Up @@ -34,16 +33,17 @@ public enum RpcCalls : uint
Roll,
IncreaseTokens,
DecreaseTokens,

TokenPosSwap,
TokenRoleSwap,
TokenRevive,
}

public static class ChaosTokensRpc
{
private static int _revealsLeft = (int)OptionGroupSingleton<BalanceOptions>.Instance.MaxRoleReveals;

public static int RevealsLeft { get; set; }
public static int SwapsLeft { get; set; }

[MethodRpc((uint)RpcCalls.Roll)]
public static void RpcRoll(this PlayerControl player)
{
Expand All @@ -54,27 +54,26 @@ public static void RpcRoll(this PlayerControl player)
{
return;
}
bool reroll = true;

bool reroll;
do
{
reroll = false;
int random = Random.RandomRangeInt(0, Enum.GetValues<ChaosEffects>().Length);
//Logger<ChaosTokensPlugin>.Warning($"Rolled effect for {player.Data.PlayerName} - {(ChaosEffects)random}");
reroll = ApplyEffect(player, (ChaosEffects)random);

} while (reroll);

RpcDecreaseTokens(player, 1);
player.RpcDecreaseTokens(1);
}

[MethodRpc((uint)RpcCalls.IncreaseTokens)]
public static void RpcIncreaseTokens(this PlayerControl player, int amount, bool showNotification = false)
{
if (!player.TryGetModifier<ChaosTokenModifier>(out var chaosTokenModifier))
{
//Logger<ChaosTokensPlugin>.Error($"Cannot increase tokens: player {player.Data.PlayerName} has no modifier, adding one");
chaosTokenModifier = player.AddModifier<ChaosTokenModifier>(amount, showNotification);
player.AddModifier<ChaosTokenModifier>(amount, showNotification);
}
else
{
Expand All @@ -90,30 +89,30 @@ public static void RpcDecreaseTokens(this PlayerControl player, int amount)
Logger<ChaosTokensPlugin>.Error($"Cannot decrease tokens: player {player.Data.PlayerName} has no modifier");
return;
}

chaosTokenModifier.DecreaseTokens(amount);
}

[MethodRpc((uint)RpcCalls.TokenPosSwap)]
public static void RpcTokenPositionSwap(PlayerControl player, PlayerControl victim)
{
Vector3 pos1 = player.GetTruePosition();
Vector3 pos2 = victim.GetTruePosition();

TransporterRole.Transport(player, pos2);
TransporterRole.Transport(victim, pos1);

if (player.AmOwner)
{
Utils.Notification("<b>You swapped positions with someone!</b>");
}

if (victim.AmOwner)
{
Utils.Notification("<b>Someone swapped positions with you!</b>");
}
}

[MethodRpc((uint)RpcCalls.TokenRoleSwap)]
public static void RpcTokenRoleSwap(PlayerControl player, PlayerControl victim)
{
Expand All @@ -125,9 +124,9 @@ public static void RpcTokenRoleSwap(PlayerControl player, PlayerControl victim)
{
Utils.Notification("<b>Someone swapped roles with you!</b>");
}
RoleTypes role1 = player.Data.Role.Role;
RoleTypes role2 = victim.Data.Role.Role;

var role1 = player.Data.Role.Role;
var role2 = victim.Data.Role.Role;

player.ChangeRole((ushort)role2);
victim.ChangeRole((ushort)role1);
Expand Down Expand Up @@ -157,7 +156,7 @@ void Reroll()
{
reroll = true;
}

var playerRole = player.Data.Role;
switch (effect)
{
Expand Down Expand Up @@ -238,7 +237,7 @@ void Reroll()
Reroll();
break;
}

if (!Utils.GetUncompletedTasks(player).Any())
{
Reroll();
Expand Down Expand Up @@ -292,14 +291,14 @@ void Reroll()
Reroll();
break;
}
if (_revealsLeft <= 0)
if (RevealsLeft <= 0)
{
Reroll();
break;
}

player.RpcAddModifier<TokenReveal>(player.Data.Role.Role, player.Data.PlayerId);
_revealsLeft--;
RevealsLeft--;
break;
case ChaosEffects.Death:
if (player.HasModifier<TokenDeath>())
Expand Down Expand Up @@ -340,8 +339,8 @@ void Reroll()
Reroll();
break;
}
if (_revealsLeft <= 0)

if (RevealsLeft <= 0)
{
Reroll();
break;
Expand All @@ -351,7 +350,7 @@ void Reroll()
.Where(r => r.Team != player.GetTownOfUsRole()?.Team)
.Select(r => (r as RoleBehaviour).Role);
player.RpcAddModifier<TokenReveal>(validRoles.Random(), player.Data.PlayerId);
_revealsLeft--;
RevealsLeft--;
break;
case ChaosEffects.Hyperactive:
if (player.HasModifier<TokenHyperactive>())
Expand Down Expand Up @@ -410,7 +409,7 @@ void Reroll()
*/

case ChaosEffects.RevealRandom:
if (_revealsLeft <= 0)
if (RevealsLeft <= 0)
{
Reroll();
break;
Expand All @@ -429,7 +428,7 @@ void Reroll()

var revealVictim = revealVictims.Random();
revealVictim.RpcAddModifier<TokenReveal>(revealVictim.Data.Role.Role, player.PlayerId);
_revealsLeft--;
RevealsLeft--;
break;
case ChaosEffects.PositionSwap:
var swapVictim = Helpers.GetAlivePlayers()
Expand All @@ -439,6 +438,12 @@ void Reroll()
RpcTokenPositionSwap(player, swapVictim);
break;
case ChaosEffects.RoleSwap:
if (SwapsLeft <= 0)
{
Reroll();
break;
}

// This will be annoying as hell but the players have to be on the same team so it's kind of balanced
ModdedRoleTeams playerTeam;
if (playerRole is ICustomRole customRole)
Expand Down Expand Up @@ -473,14 +478,15 @@ void Reroll()
}

RpcTokenRoleSwap(player, roleSwapVictims.Random());
SwapsLeft--;
break;
case ChaosEffects.Revive:
if (OptionGroupSingleton<BalanceOptions>.Instance.ReviveDisabled)
{
Reroll();
break;
}

var canBeRevived = PlayerControl.AllPlayerControls
.ToArray()
.Where(x => x.Data.IsDead && !x.Data.Disconnected)
Expand Down Expand Up @@ -513,15 +519,15 @@ void Reroll()

player.RpcAddModifier<TokenNoSkip>();
break;

default:
Reroll();
break;
}

return reroll;
}

public static IEnumerator CoRevivePlayer(PlayerControl dead)
{
var roleWhenAlive = dead.GetRoleWhenAlive();
Expand Down
Loading
Loading