-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 antag selection being evil #28197
Merged
EmoGarbage404
merged 15 commits into
space-wizards:master
from
deltanedas:skull-emoji-ops
May 26, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7b24700
fix antag selection being evil
0cf2f88
fix test
12963df
untroll the other tests
0ee3eae
remove role timer troll
f1fdff4
Merge branch 'master' of https://github.com/space-wizards/space-stati…
ElectroJr 34ea5b3
Allow tests to modify antag preferences
ElectroJr 0781d5a
Fix antag selection
ElectroJr 2df3926
Misc test fixes
ElectroJr 3345ade
Add AntagPreferenceTest
ElectroJr 5b25629
Fix lazy mistakes
ElectroJr 11bf290
Merge branch 'master' of https://github.com/space-wizards/space-stati…
ElectroJr 820e6c2
Test cleanup
ElectroJr d329aaf
Try stop players in lobbies from being assigned mid-round antags
ElectroJr 25bc7dc
ranting
ElectroJr d8a0647
I am going insane
ElectroJr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Content.IntegrationTests/Tests/GameRules/AntagPreferenceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#nullable enable | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Content.Server.Antag; | ||
using Content.Server.Antag.Components; | ||
using Content.Server.GameTicking; | ||
using Content.Shared.GameTicking; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.IntegrationTests.Tests.GameRules; | ||
|
||
// Once upon a time, players in the lobby weren't ever considered eligible for antag roles. | ||
// Lets not let that happen again. | ||
[TestFixture] | ||
public sealed class AntagPreferenceTest | ||
{ | ||
[Test] | ||
public async Task TestLobbyPlayersValid() | ||
{ | ||
await using var pair = await PoolManager.GetServerClient(new PoolSettings | ||
{ | ||
DummyTicker = false, | ||
Connected = true, | ||
InLobby = true | ||
}); | ||
|
||
var server = pair.Server; | ||
var client = pair.Client; | ||
var ticker = server.System<GameTicker>(); | ||
var sys = server.System<AntagSelectionSystem>(); | ||
|
||
// Initially in the lobby | ||
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby)); | ||
Assert.That(client.AttachedEntity, Is.Null); | ||
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay)); | ||
|
||
EntityUid uid = default; | ||
await server.WaitPost(() => uid = server.EntMan.Spawn("Traitor")); | ||
var rule = new Entity<AntagSelectionComponent>(uid, server.EntMan.GetComponent<AntagSelectionComponent>(uid)); | ||
var def = rule.Comp.Definitions.Single(); | ||
|
||
// IsSessionValid & IsEntityValid are preference agnostic and should always be true for players in the lobby. | ||
// Though maybe that will change in the future, but then GetPlayerPool() needs to be updated to reflect that. | ||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
|
||
// By default, traitor/antag preferences are disabled, so the pool should be empty. | ||
var sessions = new List<ICommonSession>{pair.Player!}; | ||
var pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(0)); | ||
|
||
// Opt into the traitor role. | ||
await pair.SetAntagPref("Traitor", true); | ||
|
||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(1)); | ||
pool.TryPickAndTake(pair.Server.ResolveDependency<IRobustRandom>(), out var picked); | ||
Assert.That(picked, Is.EqualTo(pair.Player)); | ||
Assert.That(sessions.Count, Is.EqualTo(1)); | ||
|
||
// opt back out | ||
await pair.SetAntagPref("Traitor", false); | ||
|
||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(0)); | ||
|
||
await server.WaitPost(() => server.EntMan.DeleteEntity(uid)); | ||
await pair.CleanReturnAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i was trying to fix this myself i basically did the same thing. My only consairn and why i never made a pr was cause. What happens if we got no one in the prefferedlist or fallbacklist? Are we starting the gamemode without any antags. This resulting in a broken gamerule/greenshift.
Yes i agree this should be intended behavior (#24292). But i don't think we currently have a solution to prevent broken gamerules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok this doesnt cancel it, but nukies should be changed to make spawners if theres not enough players like in my issue
traitors zombies etc doesnt really matter as theres no unused map lying around doing nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik it also picks people at random in game not just in the lobby (look at sleeper agents. There are reports that players get sleeper agent given to them when they never opted in)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this fixes that since it wont pick anyone that didnt opt in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the unwanted list but not the invalid one at least until we have ways of setting up ghost roles and other rules properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the majority of the issue is people that arent opted in getting picked, invalid is only really picked in a dev environment. nukies making ghost roles for missing players wyci