aaaaa (#733)
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
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)
|
||||
{
|
||||
session = null;
|
||||
|
||||
foreach (var pool in orderedPools)
|
||||
if (_premiumPool.Count > 0)
|
||||
{
|
||||
if (pool.Count == 0)
|
||||
continue;
|
||||
|
||||
session = random.PickAndTake(pool);
|
||||
break;
|
||||
session = random.PickAndTake(_premiumPool);
|
||||
}
|
||||
else if (_defaultPool.Count > 0)
|
||||
{
|
||||
session = random.PickAndTake(_defaultPool);
|
||||
}
|
||||
|
||||
return session != null;
|
||||
}
|
||||
|
||||
public int Count => orderedPools.Sum(p => p.Count);
|
||||
public int Count => _premiumPool.Count + _defaultPool.Count;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Server._Miracle.GulagSystem;
|
||||
using Content.Server._White.Sponsors;
|
||||
using Content.Server.Inventory;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -45,6 +46,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly GulagSystem _gulag = 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.
|
||||
public const float LateJoinRandomChance = 0.5f;
|
||||
@@ -333,8 +335,9 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
|
||||
/// </summary>
|
||||
public AntagSelectionPlayerPool GetPlayerPool(Entity<AntagSelectionComponent> ent, IList<ICommonSession> sessions, AntagSelectionDefinition def)
|
||||
{
|
||||
var preferredList = new List<ICommonSession>();
|
||||
var fallbackList = new List<ICommonSession>();
|
||||
var premiumPool = new List<ICommonSession>();
|
||||
var defaultPool = new List<ICommonSession>();
|
||||
|
||||
foreach (var session in sessions)
|
||||
{
|
||||
if (!IsSessionValid(ent, session, def) ||
|
||||
@@ -342,17 +345,36 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
|
||||
continue;
|
||||
|
||||
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>
|
||||
@@ -432,6 +454,20 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
|
||||
|
||||
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>
|
||||
|
||||
@@ -73,7 +73,8 @@ public sealed class MeatyOreStoreSystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnPostRoundCleanup);
|
||||
SubscribeNetworkEvent<MeatyOreShopRequestEvent>(OnShopRequested);
|
||||
SubscribeLocalEvent<GetVerbsEvent<Verb>>(MeatyOreVerbs);
|
||||
|
||||
// SubscribeLocalEvent<GetVerbsEvent<Verb>>(MeatyOreVerbs);
|
||||
}
|
||||
|
||||
private void MeatyOreVerbs(GetVerbsEvent<Verb> ev)
|
||||
|
||||
@@ -36,6 +36,9 @@ public sealed class SponsorInfo
|
||||
|
||||
[JsonPropertyName("MeatyOreCoin")]
|
||||
public int MeatyOreCoin { get; set; }
|
||||
|
||||
[JsonPropertyName("antagChance")]
|
||||
public int AntagChance { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user