Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup committed Mar 2, 2024
1 parent 5610405 commit 3e8ac18
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 91 deletions.
15 changes: 6 additions & 9 deletions Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void AddAntagVerbs(GetVerbsEvent<Verb> args)
Icon = new SpriteSpecifier.Rsi(new("/Textures/Backmen/Interface/Actions/blob.rsi"), "blobFactory"),
Act = () =>
{
EnsureComp<Shared.Backmen.Blob.BlobCarrierComponent>(args.Target).HasMind = targetMindComp.HasMind;
EnsureComp<Shared.Backmen.Blob.BlobCarrierComponent>(args.Target).HasMind = HasComp<ActorComponent>(args.Target);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-text-make-blob"),
Expand All @@ -71,11 +71,11 @@ private void AddAntagVerbs(GetVerbsEvent<Verb> args)
Icon = new SpriteSpecifier.Rsi(new("/Textures/Structures/flesh_heart.rsi"), "base_heart"),
Act = () =>
{
if (!_minds.TryGetSession(targetMindComp.Mind, out var session))
if (!TryComp<ActorComponent>(args.Target, out var actor))
return;

EntityManager.System<Content.Server.Backmen.GameTicking.Rules.FleshCultRuleSystem>()
.MakeCultist(session);
.MakeCultist(actor.PlayerSession);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-text-make-flesh-leader-cultist"),
Expand All @@ -89,11 +89,11 @@ private void AddAntagVerbs(GetVerbsEvent<Verb> args)
Icon = new SpriteSpecifier.Rsi(new("/Textures/Mobs/Aliens/FleshCult/flesh_cult_mobs.rsi"), "worm"),
Act = () =>
{
if (!_minds.TryGetSession(targetMindComp.Mind, out var session))
if (!TryComp<ActorComponent>(args.Target, out var actor))
return;

EntityManager.System<Content.Server.Backmen.GameTicking.Rules.FleshCultRuleSystem>()
.MakeCultist(session);
.MakeCultist(actor.PlayerSession);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-text-make-flesh-cultist"),
Expand All @@ -108,11 +108,8 @@ private void AddAntagVerbs(GetVerbsEvent<Verb> args)
"poster3_legit"),
Act = () =>
{
if (!_minds.TryGetSession(targetMindComp.Mind, out var session))
return;

EntityManager.System<Content.Server.Backmen.EvilTwin.EvilTwinSystem>()
.MakeTwin(out _, session.AttachedEntity);
.MakeTwin(out _, args.Target);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-make-eviltwin"),
Expand Down
7 changes: 6 additions & 1 deletion Content.Server/Backmen/Blob/Rule/BlobGameRuleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace Content.Server.Backmen.Blob.Rule;
using Robust.Shared.Audio;

namespace Content.Server.Backmen.Blob.Rule;

[RegisterComponent]
public sealed partial class BlobGameRuleComponent : Component
{
public int TotalBlobs = 0;

[DataField]
public SoundSpecifier InitialInfectedSound = new SoundPathSpecifier("/Audio/Backmen/Ambience/Antag/blob_start.ogg");
}
69 changes: 32 additions & 37 deletions Content.Server/Backmen/Blob/Rule/BlobRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Mind;
using Content.Shared.Actions;
using Content.Shared.Antag;
using Content.Shared.Backmen.Blob;
using Content.Shared.Backmen.CCVar;
using Content.Shared.Humanoid;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
Expand All @@ -31,6 +35,8 @@ public sealed class BlobGameRuleSystem : GameRuleSystem<BlobGameRuleComponent>
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly AntagSelectionSystem _antagSelection = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;


public override void Initialize()
Expand All @@ -46,25 +52,16 @@ public override void Initialize()

private void HandleLatejoin(PlayerSpawnCompleteEvent ev)
{
var query = EntityQueryEnumerator<BlobGameRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var blob, out var gameRule))
var query = QueryActiveRules();
while (query.MoveNext(out _, out var blob, out var gameRule))
{
if (!GameTicker.IsGameRuleAdded(uid, gameRule))
continue;

if (blob.TotalBlobs >= MaxBlob)
continue;

if (!ev.LateJoin)
continue;

if (!ev.Profile.AntagPreferences.Contains(Blob))
continue;

if (ev.JobId == null || !_prototypeManager.TryIndex<JobPrototype>(ev.JobId, out var job))
continue;

if (!job.CanBeAntag)
if (!_antagSelection.IsPlayerEligible(ev.Player, Blob, acceptableAntags: AntagAcceptability.NotExclusive, allowNonHumanoids: false))
continue;

// the nth player we adjust our probabilities around
Expand All @@ -89,54 +86,52 @@ private void HandleLatejoin(PlayerSpawnCompleteEvent ev)
// You get one shot.
if (_random.Prob(chance) && ev.Player.AttachedEntity.HasValue)
{
MakeBlob(blob, ev.Player);
MakeBlob(blob, ev.Player.AttachedEntity.Value);
_antagSelection.SendBriefing(ev.Player, Loc.GetString("blob-carrier-role-greeting"), Color.Plum, blob.InitialInfectedSound);
}
}
}

private void MakeBlob(BlobGameRuleComponent blob, ICommonSession player)
private void MakeBlob(BlobGameRuleComponent blob, EntityUid player)
{
if (!player.AttachedEntity.HasValue)
return;

blob.TotalBlobs++;
EnsureComp<BlobCarrierComponent>(player.AttachedEntity.Value).HasMind = true;
var comp = EnsureComp<BlobCarrierComponent>(player);
comp.HasMind = HasComp<ActorComponent>(player);
comp.TransformationDelay = 10 * 60; // 10min
_actions.SetCooldown(comp.TransformToBlob, TimeSpan.FromMinutes(5));
}

private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
{
var query = EntityQueryEnumerator<BlobGameRuleComponent, GameRuleComponent>();
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out var blob, out var gameRule))
{
var plr = new Dictionary<ICommonSession, HumanoidCharacterProfile>();
var eligiblePlayers = _antagSelection.GetEligiblePlayers(
ev.Players, Blob,
acceptableAntags: AntagAcceptability.None,
allowNonHumanoids: false, includeAllJobs: false);

if (!GameTicker.IsGameRuleAdded(uid, gameRule))
if (eligiblePlayers.Count == 0)
{
//Log.Warning($"No eligible thieves found, ending game rule {ToPrettyString(uid):rule}");
//GameTicker.EndGameRule(uid, gameRule);
continue;
}

foreach (var player in ev.Players)
{
if (!ev.Profiles.ContainsKey(player.UserId))
continue;
var initialInfectedCount = _antagSelection.CalculateAntagCount(_playerManager.PlayerCount, PlayersPerBlob, MaxBlob);

plr.Add(player, ev.Profiles[player.UserId]);
}
var blobs = _antagSelection.ChooseAntags(initialInfectedCount, eligiblePlayers);

DoBlobStart(blobs, blob);

DoBlobStart(blob, plr);
_antagSelection.SendBriefing(blobs, Loc.GetString("blob-carrier-role-greeting"), Color.Plum, blob.InitialInfectedSound);
}
}

private void DoBlobStart(BlobGameRuleComponent blob,
Dictionary<ICommonSession, HumanoidCharacterProfile> startCandidates)
private void DoBlobStart(List<EntityUid> selectedTraitors, BlobGameRuleComponent blob)
{
var numTraitors = MathHelper.Clamp(startCandidates.Count / PlayersPerBlob, 1, MaxBlob);
var traitorPool = _antagSelection.FindPotentialAntags(startCandidates, Blob);
var selectedTraitors = _antagSelection.PickAntag(numTraitors, traitorPool);

foreach (var traitor in selectedTraitors)
{
if (!traitor.AttachedEntity.HasValue)
continue;

MakeBlob(blob, traitor);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Content.Server.Backmen.Vampiric;
using Robust.Shared.Audio;

namespace Content.Server.Backmen.Vampiric;

[RegisterComponent]
public sealed partial class BloodsuckerRuleComponent : Component
Expand All @@ -16,4 +18,7 @@ public sealed partial class BloodsuckerRuleComponent : Component
"Vox",
"HumanoidFoxes",
};

[DataField]
public SoundSpecifier InitialInfectedSound = new SoundPathSpecifier("/Audio/Backmen/Ambience/Antag/vampier_start.ogg");
}
97 changes: 54 additions & 43 deletions Content.Server/Backmen/Vampiric/Rule/BloodsuckerRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Mind;
using Content.Server.Objectives;
using Content.Shared.Antag;
using Content.Shared.Backmen.CCVar;
using Content.Shared.Backmen.Vampiric;
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mobs.Components;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Server.Placement;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
Expand All @@ -38,6 +42,7 @@ public sealed class BloodsuckerRuleSystem : GameRuleSystem<BloodsuckerRuleCompon
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -69,28 +74,28 @@ protected override void Added(EntityUid uid, BloodsuckerRuleComponent component,

private void HandleLatejoin(PlayerSpawnCompleteEvent ev)
{
var query = EntityQueryEnumerator<BloodsuckerRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var vpmRule, out var gameRule))
var query = QueryActiveRules();
while (query.MoveNext(out _, out var vpmRule, out _))
{
if (!GameTicker.IsGameRuleAdded(uid, gameRule))
continue;

if (vpmRule.TotalBloodsuckers >= MaxBloodsuckers)
continue;

if (!ev.LateJoin)
continue;

if (!ev.Profile.AntagPreferences.Contains(Bloodsucker))
continue;

if (ev.JobId == null || !_prototypeManager.TryIndex<JobPrototype>(ev.JobId, out var job))
continue;

if (!job.CanBeAntag)
continue;

if(!vpmRule.SpeciesWhitelist.Contains(ev.Profile.Species))
var whitelistSpecies = vpmRule.SpeciesWhitelist;
if (!_antagSelection.IsPlayerEligible(ev.Player, Bloodsucker, acceptableAntags: AntagAcceptability.NotExclusive,
allowNonHumanoids: false,
customExcludeCondition: ent =>
{
if (HasComp<BibleUserComponent>(ent))
{
return true;
}

return TryComp<HumanoidAppearanceComponent>(ent, out var humanoidAppearanceComponent) &&
!whitelistSpecies.Contains(humanoidAppearanceComponent.Species.Id);
}))
continue;

// the nth player we adjust our probabilities around
Expand All @@ -115,65 +120,71 @@ private void HandleLatejoin(PlayerSpawnCompleteEvent ev)
// You get one shot.
if (_random.Prob(chance) && ev.Player.AttachedEntity.HasValue)
{
if(HasComp<BibleUserComponent>(ev.Player.AttachedEntity))
continue;
_bloodSuckerSystem.ConvertToVampire(ev.Player.AttachedEntity.Value);
vpmRule.TotalBloodsuckers++;
if (_mindSystem.TryGetMind(ev.Player, out var mindId, out _))
{
vpmRule.Elders.Add(MetaData(ev.Player.AttachedEntity.Value).EntityName,mindId);
}
_antagSelection.SendBriefing(ev.Player, Loc.GetString("vampire-role-greeting"), Color.Plum, vpmRule.InitialInfectedSound);
}
}
}

private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
{
var query = EntityQueryEnumerator<BloodsuckerRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var vpmRule, out var gameRule))
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out _, out var comp, out var gameRule))
{
var plr = new Dictionary<ICommonSession, HumanoidCharacterProfile>();
//Get all players eligible for this role, allow selecting existing antags
//TO DO: When voxes specifies are added, increase their chance of becoming a thief by 4 times >:)
var whitelistSpecies = comp.SpeciesWhitelist;
var eligiblePlayers = _antagSelection.GetEligiblePlayers(
ev.Players, Bloodsucker,
acceptableAntags: AntagAcceptability.NotExclusive,
allowNonHumanoids: false,
customExcludeCondition: ent =>
{
if (HasComp<BibleUserComponent>(ent))
{
return true;
}

if (!GameTicker.IsGameRuleAdded(uid, gameRule))
continue;
return TryComp<HumanoidAppearanceComponent>(ent, out var humanoidAppearanceComponent) &&
!whitelistSpecies.Contains(humanoidAppearanceComponent.Species.Id);
});

foreach (var player in ev.Players)
//Abort if there are none
if (eligiblePlayers.Count == 0)
{
if (!ev.Profiles.ContainsKey(player.UserId))
continue;
//Log.Warning($"No eligible thieves found, ending game rule {ToPrettyString(uid):rule}");
//GameTicker.EndGameRule(uid, gameRule);
continue;
}

if(!vpmRule.SpeciesWhitelist.Contains(ev.Profiles[player.UserId].Species))
continue;
var initialInfectedCount = _antagSelection.CalculateAntagCount(_playerManager.PlayerCount, PlayersPerBloodsucker, MaxBloodsuckers);

if (player.AttachedEntity.HasValue && HasComp<BibleUserComponent>(player.AttachedEntity))
continue;
//Select our theives
var thieves = _antagSelection.ChooseAntags(initialInfectedCount, eligiblePlayers);

plr.Add(player, ev.Profiles[player.UserId]);
}
DoVampirStart(thieves, comp);

DoVampirStart(vpmRule, plr);
_antagSelection.SendBriefing(thieves, Loc.GetString("vampire-role-greeting"), Color.Plum, comp.InitialInfectedSound);
}
}

[ValidatePrototypeId<AntagPrototype>]
private const string Bloodsucker = "Bloodsucker";

private void DoVampirStart(BloodsuckerRuleComponent vpmRule, Dictionary<ICommonSession, HumanoidCharacterProfile> startCandidates)
private void DoVampirStart(List<EntityUid> startCandidates, BloodsuckerRuleComponent vpmRule)
{
var numTraitors = MathHelper.Clamp(startCandidates.Count / PlayersPerBloodsucker, 1, MaxBloodsuckers);
var traitorPool = _antagSelection.FindPotentialAntags(startCandidates, Bloodsucker);
var selectedTraitors = _antagSelection.PickAntag(numTraitors, traitorPool);

foreach (var traitor in selectedTraitors)
foreach (var traitor in startCandidates)
{
if (!traitor.AttachedEntity.HasValue)
continue;

_bloodSuckerSystem.ConvertToVampire(traitor.AttachedEntity.Value);
_bloodSuckerSystem.ConvertToVampire(traitor);
vpmRule.TotalBloodsuckers++;
if (_mindSystem.TryGetMind(traitor, out var mindId, out _))
{
vpmRule.Elders.Add(MetaData(traitor.AttachedEntity.Value).EntityName,mindId);
vpmRule.Elders.Add(MetaData(traitor).EntityName,mindId);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>

private ISawmill _sawmill = default!;

[Dependency] private readonly Backmen.Arrivals.CentcommSystem _centcommSystem = default!; // backmen: centcom

[ValidatePrototypeId<CurrencyPrototype>]
private const string TelecrystalCurrencyPrototype = "Telecrystal";

Expand Down
Loading

0 comments on commit 3e8ac18

Please sign in to comment.