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

gamemode cops and robbers #1250

Draft
wants to merge 22 commits into
base: dev_2.2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7456d73
Merge pull request #35 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Sep 24, 2024
34cbde6
Merge pull request #37 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Sep 24, 2024
5098de7
cops without abilities
ryuk201198 Sep 24, 2024
824ff5e
cops with abilities (no progress text)
ryuk201198 Sep 27, 2024
c31cb2a
Merge pull request #38 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Sep 27, 2024
4cc0be2
resolve conflicts
ryuk201198 Sep 27, 2024
2649a9a
fix conflict bug
ryuk201198 Sep 27, 2024
37ce095
rename ability radar to k9
ryuk201198 Sep 27, 2024
e14ec44
Merge pull request #39 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Sep 29, 2024
10130c1
Merge branch 'C&R' of https://github.com/ryuk201198/TownofHost-Enhanc…
ryuk201198 Sep 29, 2024
2d2ad86
robbers with abilities
ryuk201198 Oct 1, 2024
e20b21e
Merge pull request #40 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Oct 1, 2024
0b82333
Merge branch 'C&R' of https://github.com/ryuk201198/TownofHost-Enhanc…
ryuk201198 Oct 1, 2024
82c81ab
hide opts, summary and ability descriptions
ryuk201198 Oct 3, 2024
a4402a6
Merge pull request #41 from EnhancedNetwork/DevBuild_2.1.0
ryuk201198 Oct 3, 2024
4a28ba5
Merge branch 'C&R' of https://github.com/ryuk201198/TownofHost-Enhanc…
ryuk201198 Oct 3, 2024
c289b31
add release cd for captured and robber
ryuk201198 Oct 4, 2024
bf2ebb4
add round time
ryuk201198 Oct 4, 2024
ea04363
oop
ryuk201198 Oct 4, 2024
9bb0053
setting show chat in game
ryuk201198 Oct 4, 2024
216d307
change default
ryuk201198 Oct 4, 2024
b50f8db
unhide random spawn mode
ryuk201198 Oct 5, 2024
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
1,342 changes: 1,342 additions & 0 deletions GameModes/CopsAndRobbersManager.cs

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion Modules/CustomRolesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static class CustomRolesHelper
public static readonly Custom_Team[] AllRoleTypes = EnumHelper.GetAllValues<Custom_Team>();
public static CustomRoles GetVNRole(this CustomRoles role) // RoleBase: Impostor, Shapeshifter, Crewmate, Engineer, Scientist
{
//C&R
if (Options.CurrentGameMode is CustomGameMode.CandR && role is CustomRoles.Robber) return CustomRoles.Engineer;

// Vanilla roles
if (role.IsVanilla()) return role;

Expand All @@ -39,7 +42,15 @@ public static CustomRoles GetVNRole(this CustomRoles role) // RoleBase: Impostor

public static RoleTypes GetDYRole(this CustomRoles role) // Role has a kill button (Non-Impostor)
{
if (role is CustomRoles.Killer) return RoleTypes.Impostor; // FFA
switch (Options.CurrentGameMode)
{
case CustomGameMode.FFA: //FFA
if (role is CustomRoles.Killer) return RoleTypes.Impostor;
break;
case CustomGameMode.CandR: //C&R
if (role is CustomRoles.Cop) return RoleTypes.Shapeshifter;
break;
}

return (role.GetStaticRoleClass().ThisRoleBase is CustomRoles.Impostor or CustomRoles.Shapeshifter) && !role.IsImpostor()
? role.GetStaticRoleClass().ThisRoleBase.GetRoleTypes()
Expand All @@ -49,6 +60,7 @@ public static RoleTypes GetDYRole(this CustomRoles role) // Role has a kill butt
/* Needs recode, awaiting phantom role base*/
public static bool HasImpKillButton(this PlayerControl player, bool considerVanillaShift = false)
{
if (Options.CurrentGameMode is CustomGameMode.CandR && player.Is(CustomRoles.Cop)) return true;
if (player == null) return false;
var customRole = player.GetCustomRole();
bool ModSideHasKillButton = customRole.GetDYRole() == RoleTypes.Impostor || customRole.GetVNRole() is CustomRoles.Impostor or CustomRoles.Shapeshifter or CustomRoles.Phantom;
Expand Down
83 changes: 52 additions & 31 deletions Modules/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,11 @@ public static string GetRealName(this PlayerControl player, bool isMeeting = fal
public static bool CanUseKillButton(this PlayerControl pc)
{
if (GameStates.IsLobby) return false;
if (Options.CurrentGameMode is CustomGameMode.CandR) //C&R
{

return (pc.Is(CustomRoles.Cop));
}
if (!pc.IsAlive() || Pelican.IsEaten(pc.PlayerId) || DollMaster.IsDoll(pc.PlayerId)) return false;
if (pc.GetClient().GetHashedPuid() == Main.FirstDiedPrevious && !Options.ShieldedCanUseKillButton.GetBool() && MeetingStates.FirstMeeting) return false;
if (pc.Is(CustomRoles.Killer) || Mastermind.PlayerIsManipulated(pc)) return true;
Expand Down Expand Up @@ -1034,13 +1039,19 @@ public static bool HasKillButton(this PlayerControl pc)
_ => false
};
}
public static bool CanUseVents(this PlayerControl player) => player != null && (player.CanUseImpostorVentButton() || player.GetCustomRole().GetVNRole() == CustomRoles.Engineer);
public static bool CanUseVents(this PlayerControl player) => Options.CurrentGameMode switch
{
CustomGameMode.CandR => player.Is(CustomRoles.Robber) && !CopsAndRobbersManager.captured.ContainsKey(player.PlayerId),
_ => player != null && (player.CanUseImpostorVentButton() || player.GetCustomRole().GetVNRole() == CustomRoles.Engineer)
};

public static bool CantUseVent(this PlayerControl player, int ventId) => player == null || !player.CanUseVents() || (CustomRoleManager.BlockedVentsList.TryGetValue(player.PlayerId, out var blockedVents) && blockedVents.Contains(ventId));
public static bool HasAnyBlockedVent(this PlayerControl player) => player != null && CustomRoleManager.BlockedVentsList.TryGetValue(player.PlayerId, out var blockedVents) && blockedVents.Any();
public static bool NotUnlockVent(this PlayerControl player, int ventId) => player != null && CustomRoleManager.DoNotUnlockVentsList.TryGetValue(player.PlayerId, out var blockedVents) && blockedVents.Contains(ventId);

public static bool CanUseImpostorVentButton(this PlayerControl pc)
{
if (Options.CurrentGameMode is CustomGameMode.CandR) return false;
if (!pc.IsAlive()) return false;
if (GameStates.IsHideNSeek) return true;
if (pc.Is(CustomRoles.Killer) || pc.Is(CustomRoles.Nimble)) return true;
Expand All @@ -1055,6 +1066,7 @@ public static bool CanUseImpostorVentButton(this PlayerControl pc)
}
public static bool CanUseSabotage(this PlayerControl pc)
{
if (Options.CurrentGameMode is CustomGameMode.CandR) return false;
if (pc.Is(Custom_Team.Impostor) && !pc.IsAlive() && Options.DeadImpCantSabotage.GetBool()) return false;

var playerRoleClass = pc.GetRoleClass();
Expand All @@ -1067,44 +1079,53 @@ public static void ResetKillCooldown(this PlayerControl player)
Main.AllPlayerKillCooldown[player.PlayerId] = Options.DefaultKillCooldown;

// FFA
if (player.Is(CustomRoles.Killer))
switch (Options.CurrentGameMode)
{
Main.AllPlayerKillCooldown[player.PlayerId] = FFAManager.FFA_KCD.GetFloat();
}
else
{
player.GetRoleClass()?.SetKillCooldown(player.PlayerId);
}
case CustomGameMode.FFA:
if (player.Is(CustomRoles.Killer))
{
Main.AllPlayerKillCooldown[player.PlayerId] = FFAManager.FFA_KCD.GetFloat();
}
break;
case CustomGameMode.CandR:
if (player.Is(CustomRoles.Cop))
CopsAndRobbersManager.CaptureCooldown(player);
break;

var playerSubRoles = player.GetCustomSubRoles();
default:
player.GetRoleClass()?.SetKillCooldown(player.PlayerId);

if (playerSubRoles.Any())
foreach (var subRole in playerSubRoles)
{
switch (subRole)
{
case CustomRoles.LastImpostor when player.PlayerId == LastImpostor.currentId:
LastImpostor.SetKillCooldown();
break;

case CustomRoles.Mare:
Main.AllPlayerKillCooldown[player.PlayerId] = Mare.KillCooldownInLightsOut.GetFloat();
break;
var playerSubRoles = player.GetCustomSubRoles();

case CustomRoles.Overclocked:
Main.AllPlayerKillCooldown[player.PlayerId] -= Main.AllPlayerKillCooldown[player.PlayerId] * (Overclocked.OverclockedReduction.GetFloat() / 100);
break;
if (playerSubRoles.Any())
foreach (var subRole in playerSubRoles)
{
switch (subRole)
{
case CustomRoles.LastImpostor when player.PlayerId == LastImpostor.currentId:
LastImpostor.SetKillCooldown();
break;

case CustomRoles.Diseased:
Diseased.IncreaseKCD(player);
break;
case CustomRoles.Mare:
Main.AllPlayerKillCooldown[player.PlayerId] = Mare.KillCooldownInLightsOut.GetFloat();
break;

case CustomRoles.Antidote:
Antidote.ReduceKCD(player);
break;
}
}
case CustomRoles.Overclocked:
Main.AllPlayerKillCooldown[player.PlayerId] -= Main.AllPlayerKillCooldown[player.PlayerId] * (Overclocked.OverclockedReduction.GetFloat() / 100);
break;

case CustomRoles.Diseased:
Diseased.IncreaseKCD(player);
break;

case CustomRoles.Antidote:
Antidote.ReduceKCD(player);
break;
}
}
break;
}
if (!player.HasImpKillButton(considerVanillaShift: false))
Main.AllPlayerKillCooldown[player.PlayerId] = 300f;

Expand Down
34 changes: 20 additions & 14 deletions Modules/GameOptionsSender/PlayerGameOptionsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,26 @@ public override IGameOptions BuildGameOptions()
opt.BlackOut(state.IsBlackOut);

CustomRoles role = player.GetCustomRole();
if (Options.CurrentGameMode == CustomGameMode.FFA)
switch (Options.CurrentGameMode)
{
if (FFAManager.FFALowerVisionList.ContainsKey(player.PlayerId))
{
opt.SetVision(true);
opt.SetFloat(FloatOptionNames.CrewLightMod, FFAManager.FFA_LowerVision.GetFloat());
opt.SetFloat(FloatOptionNames.ImpostorLightMod, FFAManager.FFA_LowerVision.GetFloat());
}
else
{
opt.SetVision(true);
opt.SetFloat(FloatOptionNames.CrewLightMod, 1.25f);
opt.SetFloat(FloatOptionNames.ImpostorLightMod, 1.25f);
}
case CustomGameMode.FFA:
if (FFAManager.FFALowerVisionList.ContainsKey(player.PlayerId))
{
opt.SetVision(true);
opt.SetFloat(FloatOptionNames.CrewLightMod, FFAManager.FFA_LowerVision.GetFloat());
opt.SetFloat(FloatOptionNames.ImpostorLightMod, FFAManager.FFA_LowerVision.GetFloat());
}
else
{
opt.SetVision(true);
opt.SetFloat(FloatOptionNames.CrewLightMod, 1.25f);
opt.SetFloat(FloatOptionNames.ImpostorLightMod, 1.25f);
}
break;

case CustomGameMode.CandR:
CopsAndRobbersManager.ApplyGameOptions(ref opt, player);
break;
}

if (player.Is(Custom_Team.Impostor))
Expand Down Expand Up @@ -126,7 +132,7 @@ public override IGameOptions BuildGameOptions()

state.taskState.hasTasks = Utils.HasTasks(player.Data, false);

if (Main.UnShapeShifter.Contains(player.PlayerId))
if (Main.UnShapeShifter.Contains(player.PlayerId) && Options.CurrentGameMode != CustomGameMode.CandR)
{
AURoleOptions.ShapeshifterDuration = 1f;
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/ModUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace TOHE;
public class ModUpdater
{
//private static readonly string URL_2018k = "http://api.tohre.dev";
private static readonly string URL_Github = "https://api.github.com/repos/0xDrMoe/TownofHost-Enhanced";
//private static readonly string URL_Github = "https://api.github.com/repos/0xDrMoe/TownofHost-Enhanced";
private static readonly string URL_Github = "https://api.github.com/repos/EnhancedNetwork/TownofHost-Enhanced";
//public static readonly string downloadTest = "https://github.com/Pietrodjaowjao/TOHEN-Contributions/releases/download/v123123123/TOHE.dll";
public static bool hasUpdate = false;
//public static bool isNewer = false;
Expand Down
34 changes: 28 additions & 6 deletions Modules/OptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum CustomGameMode
{
Standard = 0x01,
FFA = 0x02,
CandR = 0x03,

HidenSeekTOHE = 0x08, // HidenSeekTOHE must be after other game modes
All = int.MaxValue
Expand Down Expand Up @@ -48,14 +49,26 @@ public static CustomGameMode CurrentGameMode
=> GameMode.GetInt() switch
{
1 => CustomGameMode.FFA,
2 => CustomGameMode.HidenSeekTOHE, // HidenSeekTOHE must be after other game modes
2 => CustomGameMode.CandR,
3 => CustomGameMode.HidenSeekTOHE, // HidenSeekTOHE must be after other game modes
_ => CustomGameMode.Standard
};
public static int GetGameModeInt(CustomGameMode mode)
=> mode switch
{
CustomGameMode.FFA => 1,
CustomGameMode.CandR => 2,
CustomGameMode.HidenSeekTOHE => 3, // HidenSeekTOHE must be after other game modes
_ => 0
};


public static readonly string[] gameModes =
[
"Standard",
"FFA",
"C&R",



"Hide&SeekTOHE", // HidenSeekTOHE must be after other game modes
Expand Down Expand Up @@ -987,13 +1000,15 @@ private static System.Collections.IEnumerator CoLoadOptions()
GradientTagsOpt = BooleanOptionItem.Create(60031, "EnableGadientTags", false, TabGroup.SystemSettings, false)
.SetHeader(true);
EnableKillerLeftCommand = BooleanOptionItem.Create(60040, "EnableKillerLeftCommand", true, TabGroup.SystemSettings, false)
.HideInHnS();
.HideInHnS()
.HideInCandR();
ShowMadmatesInLeftCommand = BooleanOptionItem.Create(60042, "ShowMadmatesInLeftCommand", true, TabGroup.SystemSettings, false)
.SetParent(EnableKillerLeftCommand);
ShowApocalypseInLeftCommand = BooleanOptionItem.Create(60043, "ShowApocalypseInLeftCommand", true, TabGroup.SystemSettings, false)
.SetParent(EnableKillerLeftCommand);
SeeEjectedRolesInMeeting = BooleanOptionItem.Create(60041, "SeeEjectedRolesInMeeting", true, TabGroup.SystemSettings, false)
.HideInHnS();
.HideInHnS()
.HideInCandR();

KickLowLevelPlayer = IntegerOptionItem.Create(60050, "KickLowLevelPlayer", new(0, 100, 1), 0, TabGroup.SystemSettings, false)
.SetValueFormat(OptionFormat.Level)
Expand Down Expand Up @@ -1074,9 +1089,11 @@ private static System.Collections.IEnumerator CoLoadOptions()
.SetColor(Color.blue);
HideExileChat = BooleanOptionItem.Create(60292, "HideExileChat", true, TabGroup.SystemSettings, false)
.SetColor(Color.blue)
.HideInHnS();
.HideInHnS()
.HideInCandR();
RemovePetsAtDeadPlayers = BooleanOptionItem.Create(60294, "RemovePetsAtDeadPlayers", false, TabGroup.SystemSettings, false)
.SetColor(Color.magenta);
.SetColor(Color.magenta)
.HideInCandR();

CheatResponses = StringOptionItem.Create(60250, "CheatResponses", CheatResponsesName, 0, TabGroup.SystemSettings, false)
.SetHeader(true);
Expand Down Expand Up @@ -1138,6 +1155,9 @@ private static System.Collections.IEnumerator CoLoadOptions()
//FFA
FFAManager.SetupCustomOption();

//C&R
CopsAndRobbersManager.SetupCustomOption();

// Hide & Seek
TextOptionItem.Create(10000055, "MenuTitle.Hide&Seek", TabGroup.ModSettings)
.SetGameMode(CustomGameMode.HidenSeekTOHE)
Expand Down Expand Up @@ -1756,11 +1776,13 @@ private static System.Collections.IEnumerator CoLoadOptions()
// 其它设定
TextOptionItem.Create(10000031, "MenuTitle.Other", TabGroup.ModSettings)
.HideInFFA()
.HideInCandR()
.SetColor(new Color32(193, 255, 209, byte.MaxValue));
// 梯子摔死
LadderDeath = BooleanOptionItem.Create(60760, "LadderDeath", false, TabGroup.ModSettings, false)
.SetColor(new Color32(193, 255, 209, byte.MaxValue))
.HideInFFA();
.HideInFFA()
.HideInCandR();
LadderDeathChance = StringOptionItem.Create(60761, "LadderDeathChance", EnumHelper.GetAllNames<SpawnChance>()[1..], 0, TabGroup.ModSettings, false)
.SetParent(LadderDeath);

Expand Down
5 changes: 4 additions & 1 deletion Modules/OptionItem/OptionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public abstract class OptionItem
public OptionFormat ValueFormat { get; protected set; }
public CustomGameMode GameMode { get; protected set; }
public CustomGameMode HideOptionInFFA { get; protected set; }
public CustomGameMode HideOptionInCandR { get; protected set; }
public CustomGameMode HideOptionInHnS { get; protected set; }
public bool IsHeader { get; protected set; }
public bool IsHidden { get; protected set; }
Expand Down Expand Up @@ -76,6 +77,7 @@ public OptionItem(int id, string name, int defaultValue, TabGroup tab, bool isSi
ValueFormat = OptionFormat.None;
GameMode = CustomGameMode.All;
HideOptionInFFA = CustomGameMode.All;
HideOptionInCandR = CustomGameMode.All;
HideOptionInHnS = CustomGameMode.All;
IsHeader = false;
IsHidden = false;
Expand Down Expand Up @@ -130,6 +132,7 @@ public OptionItem Do(Action<OptionItem> action)
public OptionItem SetHidden(bool value) => Do(i => i.IsHidden = value);
public OptionItem SetText(bool value) => Do(i => i.IsText = value);
public OptionItem HideInFFA(CustomGameMode value = CustomGameMode.FFA) => Do(i => i.HideOptionInFFA = value);
public OptionItem HideInCandR(CustomGameMode value = CustomGameMode.CandR) => Do(i => i.HideOptionInCandR = value); //C&R
public OptionItem HideInHnS(CustomGameMode value = CustomGameMode.HidenSeekTOHE) => Do(i => i.HideOptionInHnS = value);

public OptionItem SetParent(OptionItem parent) => Do(i =>
Expand Down Expand Up @@ -181,7 +184,7 @@ public virtual string GetString()
// Deprecated IsHidden function
public virtual bool IsHiddenOn(CustomGameMode mode)
{
return IsHidden || this.Parent?.IsHiddenOn(Options.CurrentGameMode) == true || (HideOptionInFFA != CustomGameMode.All && HideOptionInFFA == mode) || (HideOptionInHnS != CustomGameMode.All && HideOptionInHnS == mode) || (GameMode != CustomGameMode.All && GameMode != mode);
return IsHidden || this.Parent?.IsHiddenOn(Options.CurrentGameMode) == true || (HideOptionInCandR != CustomGameMode.All && HideOptionInCandR == mode) || (HideOptionInFFA != CustomGameMode.All && HideOptionInFFA == mode) || (HideOptionInHnS != CustomGameMode.All && HideOptionInHnS == mode) || (GameMode != CustomGameMode.All && GameMode != mode);
}
public string ApplyFormat(string value)
{
Expand Down
4 changes: 4 additions & 0 deletions Modules/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ enum CustomRPC : byte // 185/255 USED
//FFA
SyncFFAPlayer,
SyncFFANameNotify,
SyncCandRData,
}
public enum Sounds
{
Expand Down Expand Up @@ -599,6 +600,9 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] byte c
case CustomRPC.SyncFFAPlayer:
FFAManager.ReceiveRPCSyncFFAPlayer(reader);
break;
case CustomRPC.SyncCandRData:
CopsAndRobbersManager.ReceiveCandRData(reader);
break;
case CustomRPC.SyncAllPlayerNames:
Main.AllPlayerNames.Clear();
Main.AllClientRealNames.Clear();
Expand Down
Loading