This commit is contained in:
haiwwkes
2024-10-13 04:40:40 +05:00
committed by GitHub
parent 59767baf3c
commit 3944c5421b
4 changed files with 65 additions and 17 deletions

View File

@@ -1,27 +1,35 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
namespace Content.Server.Antag; namespace Content.Server.Antag;
public sealed class AntagSelectionPlayerPool (List<List<ICommonSession>> orderedPools) public sealed class AntagSelectionPlayerPool
{ {
private readonly List<ICommonSession> _premiumPool;
private readonly List<ICommonSession> _defaultPool;
public AntagSelectionPlayerPool(List<List<ICommonSession>> orderedPools)
{
_premiumPool = orderedPools[0];
_defaultPool = orderedPools[1];
}
public bool TryPickAndTake(IRobustRandom random, [NotNullWhen(true)] out ICommonSession? session) public bool TryPickAndTake(IRobustRandom random, [NotNullWhen(true)] out ICommonSession? session)
{ {
session = null; session = null;
foreach (var pool in orderedPools) if (_premiumPool.Count > 0)
{ {
if (pool.Count == 0) session = random.PickAndTake(_premiumPool);
continue; }
else if (_defaultPool.Count > 0)
session = random.PickAndTake(pool); {
break; session = random.PickAndTake(_defaultPool);
} }
return session != null; return session != null;
} }
public int Count => orderedPools.Sum(p => p.Count); public int Count => _premiumPool.Count + _defaultPool.Count;
} }

View File

@@ -26,6 +26,7 @@ using Robust.Shared.Map;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Content.Server._Miracle.GulagSystem; using Content.Server._Miracle.GulagSystem;
using Content.Server._White.Sponsors;
using Content.Server.Inventory; using Content.Server.Inventory;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -45,6 +46,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
[Dependency] private readonly TransformSystem _transform = default!; [Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly GulagSystem _gulag = default!; // WD [Dependency] private readonly GulagSystem _gulag = default!; // WD
[Dependency] private readonly ServerInventorySystem _inventory = default!; // WD [Dependency] private readonly ServerInventorySystem _inventory = default!; // WD
[Dependency] private readonly SponsorsManager _sponsors = default!; // WD
// arbitrary random number to give late joining some mild interest. // arbitrary random number to give late joining some mild interest.
public const float LateJoinRandomChance = 0.5f; public const float LateJoinRandomChance = 0.5f;
@@ -333,8 +335,9 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
/// </summary> /// </summary>
public AntagSelectionPlayerPool GetPlayerPool(Entity<AntagSelectionComponent> ent, IList<ICommonSession> sessions, AntagSelectionDefinition def) public AntagSelectionPlayerPool GetPlayerPool(Entity<AntagSelectionComponent> ent, IList<ICommonSession> sessions, AntagSelectionDefinition def)
{ {
var preferredList = new List<ICommonSession>(); var premiumPool = new List<ICommonSession>();
var fallbackList = new List<ICommonSession>(); var defaultPool = new List<ICommonSession>();
foreach (var session in sessions) foreach (var session in sessions)
{ {
if (!IsSessionValid(ent, session, def) || if (!IsSessionValid(ent, session, def) ||
@@ -342,17 +345,36 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
continue; continue;
var pref = (HumanoidCharacterProfile) _pref.GetPreferences(session.UserId).SelectedCharacter; var pref = (HumanoidCharacterProfile) _pref.GetPreferences(session.UserId).SelectedCharacter;
if (def.PrefRoles.Count != 0 && pref.AntagPreferences.Any(p => def.PrefRoles.Contains(p))) var hasPreference = def.PrefRoles.Count != 0 && pref.AntagPreferences.Any(p => def.PrefRoles.Contains(p));
var hasFallbackPreference = def.FallbackRoles.Count != 0 && pref.AntagPreferences.Any(p => def.FallbackRoles.Contains(p));
if (RobustRandom.Prob(GetPremiumPoolChance(session)))
{ {
preferredList.Add(session); if (hasPreference || hasFallbackPreference)
premiumPool.Add(session);
} }
else if (def.FallbackRoles.Count != 0 && pref.AntagPreferences.Any(p => def.FallbackRoles.Contains(p))) else
{ {
fallbackList.Add(session); if (hasPreference)
defaultPool.Add(session);
else if (hasFallbackPreference)
defaultPool.Add(session);
} }
} }
return new AntagSelectionPlayerPool(new() { preferredList, fallbackList });
if (premiumPool.Count == 0 && defaultPool.Count == 0)
{
foreach (var session in sessions)
{
if (IsSessionValid(ent, session, def) && IsEntityValid(session.AttachedEntity, def))
{
defaultPool.Add(session);
}
}
}
return new AntagSelectionPlayerPool(new() { premiumPool, defaultPool });
} }
/// <summary> /// <summary>
@@ -432,6 +454,20 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
return true; return true;
} }
public float GetPremiumPoolChance(ICommonSession session)
{
if (!_sponsors.TryGetInfo(session.UserId, out var info))
return 0f;
var antagChance = info.AntagChance;
// Ensure antagChance is within 0-100 range
antagChance = Math.Clamp(antagChance, 0, 100);
// Convert clamped antagChance from 0-100 range to 0-1 range
return antagChance / 100f;
}
} }
/// <summary> /// <summary>

View File

@@ -73,7 +73,8 @@ public sealed class MeatyOreStoreSystem : EntitySystem
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnPostRoundCleanup); SubscribeLocalEvent<RoundRestartCleanupEvent>(OnPostRoundCleanup);
SubscribeNetworkEvent<MeatyOreShopRequestEvent>(OnShopRequested); SubscribeNetworkEvent<MeatyOreShopRequestEvent>(OnShopRequested);
SubscribeLocalEvent<GetVerbsEvent<Verb>>(MeatyOreVerbs);
// SubscribeLocalEvent<GetVerbsEvent<Verb>>(MeatyOreVerbs);
} }
private void MeatyOreVerbs(GetVerbsEvent<Verb> ev) private void MeatyOreVerbs(GetVerbsEvent<Verb> ev)

View File

@@ -36,6 +36,9 @@ public sealed class SponsorInfo
[JsonPropertyName("MeatyOreCoin")] [JsonPropertyName("MeatyOreCoin")]
public int MeatyOreCoin { get; set; } public int MeatyOreCoin { get; set; }
[JsonPropertyName("antagChance")]
public int AntagChance { get; set; }
} }
/// <summary> /// <summary>