Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

WIP: Allow toggling loving impostor #301

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Anusien
Copy link
Contributor

@Anusien Anusien commented Aug 5, 2021

This is just a first draft. I'm not able to test it yet nor have I figured out how to add unit tests. If someone can point me toward contributing guidelines, I'm happy to flesh this out more fully.

@@ -71,22 +71,22 @@ public static void Gen(List<PlayerControl> crewmates, List<PlayerControl> impost
{
//System.Console.WriteLine("LOVER2");
if (crewmates.Count <= 0) return;
if (crewmates.Count <= 1 && impostors.Count < 1) return;
if (crewmates.Count <= 1 && (impostors.Count < 1 || !CustomGameOptions.AllowLovingImpostor)) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (crewmates.Count <= 1 && (impostors.Count < 1 || !CustomGameOptions.AllowLovingImpostor)) return;
if (crewmates.Count <= 1 && (!CustomGameOptions.AllowLovingImpostor || impostors.Count < 1)) return;

@NotSugden
Copy link
Contributor

NotSugden commented Aug 5, 2021

if you want to test this, build the project (either using dotnet build in the command line, or building in visual studio) then in source\bin\Debug\netstandard2.1 will be the compiled TownOfUs.dll plugin file, replace the same file in the BepInEx/plugins folder in your modded among us folder 👍

(it would previously be automatically moved to an AmongUs folder in the root dir of the project, but that was accidentally removed in 2.2.0, see #294)

@@ -71,22 +71,22 @@ public static void Gen(List<PlayerControl> crewmates, List<PlayerControl> impost
{
//System.Console.WriteLine("LOVER2");
if (crewmates.Count <= 0) return;
if (crewmates.Count <= 1 && impostors.Count < 1) return;
if (crewmates.Count <= 1 && (impostors.Count < 1 || !CustomGameOptions.AllowLovingImpostor)) return;

//System.Console.WriteLine("LOVER3");
var b = Random.RandomRangeInt(0, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly out of scope i know, but could b be changed to just be the lovingImpostor boolean?

seems it was originally just meant to be 1 or 0 indicating if a loving impostor should be generated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to, but it urns out at 1am after like 5 hours of Among Us, my brain couldn't figure out how. I've attempted to rewrite this whole section to not reassign stuff to the same variable.

@Anusien
Copy link
Contributor Author

Anusien commented Aug 5, 2021

I haven't touched C# in a while; I've been doing Java for the past 7 years. I also prefer a more verbose, more risk averse coding style. So I avoided var in favor of actually typing the variables and used curly braces even for one line blocks following an if clause. I also attempted to add XML style comments and added some documentation in places where I had to go to do some research.

If you'd prefer another coding style, or if this isn't idiomatic C#, feel free to ask for changes.

@@ -9,24 +9,31 @@ namespace TownOfUs.Roles
{
public class Lover : Role
{
public Lover(PlayerControl player, int num, bool loverImpostor) : base(player)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention where num == 2 for impostor seemed really brittle to me. So I changed it to always specify.

}

public Lover OtherLover { get; set; }
public bool LoveCoupleWins { get; set; }
public int Num { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find where this was used?

Copy link
Contributor

@NotSugden NotSugden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the sake of consistency, should probably use var, and remove the docstring comments, but other than that LGTM

@@ -67,26 +74,29 @@ protected override string NameText(PlayerVoteArea player = null)
return Player.name + "\n" + "Lover";
}

private static readonly int LOVING_IMPOSTOR_CHANCE = 25;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static readonly int LOVING_IMPOSTOR_CHANCE = 25;
private const int LOVING_IMPOSTOR_CHANCE = 25;

writer.Write(b);
var lover1 = new Lover(player1, 1, b == 0);
var lover2 = new Lover(player2, 2, b == 0);
writer.Write(lovingImpostor ? 0 : 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theres a writer.WriteBoolean method

Copy link
Contributor

@NotSugden NotSugden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would also be nice to have an option to change the chance of a loving impostor (possibly replacing the toggle?)

@@ -284,6 +285,8 @@ public static void GenerateAll()
Lovers =
new CustomHeaderOption(num++, "<color=#FF66CCFF>Lovers</color>");
BothLoversDie = new CustomToggleOption(num++, "Both Lovers Die");
LovingImpostorOn = new CustomNumberOption(num++, "Allow Loving Impostor",25f, 0f, 100f, 10f,
Copy link
Contributor

@NotSugden NotSugden Aug 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LovingImpostorOn = new CustomNumberOption(num++, "Allow Loving Impostor",25f, 0f, 100f, 10f,
LovingImpostorOn = new CustomNumberOption(num++, "Loving Impostor Chance", 25f, 0f, 100f, 10f,

var lovingImpostorEnabled = Random.RandomRangeInt(1, 101) <= CustomGameOptions.LovingImpostorOn;

var canMakeCrewCrewLovers = crewmates.Count >= 2;
var canMakeCrewImpostorLovers = crewmates.Count >= 1 && impostors.Count >= 2 && lovingImpostorEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var canMakeCrewImpostorLovers = crewmates.Count >= 1 && impostors.Count >= 2 && lovingImpostorEnabled;
var canMakeCrewImpostorLovers = crewmates.Count >= 1 && impostors.Count >= 1 && lovingImpostorEnabled;

there would only need to be one impostor free

@@ -338,12 +338,12 @@ public static void Postfix([HarmonyArgument(0)] byte callId, [HarmonyArgument(1)
case CustomRPC.SetCouple:
var id = reader.ReadByte();
var id2 = reader.ReadByte();
var b1 = reader.ReadByte();
bool lovingImpostor = reader.ReadByte() == 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool lovingImpostor = reader.ReadByte() == 0;
var lovingImpostor = reader.ReadByte() == 0;


### Game Options
| Name | Description | Type | Default |
|----------|:-------------:|:------:|:------:|
| Lovers | The percentage probability of the Lovers appearing | Percentage | 0% |
| Both Lovers Die | Whether the other Lover automatically dies if the other does | Toggle | True |
| Allow Loving Impostor | Whether one of the Lovers can be an Impostor | Percentage | 25% |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Allow Loving Impostor | Whether one of the Lovers can be an Impostor | Percentage | 25% |
| Loving Impostor Chance | The percentage probability of a Loving Impostor appearing | Percentage | 25% |

@stale
Copy link

stale bot commented Sep 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants