Skip to content

Commit

Permalink
Fix blob tile count (#693)
Browse files Browse the repository at this point in the history
* All blob tiles now summed up

Все блоб тайлы всех блобов считаются вместе при смене уровня блоба, за ненадобностью удалён ивент BlobChangelevelEvent

* Max 2 blob carriers in BlobSpawn event

Теперь блоб мышь не может вылезти во время ивента с вентиляциями, максимальное количество блобов для спавна уменьшено с 3 до 2, а сам BlobSpawnRule появляется лишь 1 раз за раунд

* fix previous

* Revert "All blob tiles now summed up"

This reverts commit 0d18ed8.

* Sum up blob tiles fixed

* Fix values

* Fix announce

* Fix blobCores in BlobChangeLevelEvent

* oops

* cleanup

* Update BlobbernautSystem.cs

---------

Co-authored-by: Zack Backmen <[email protected]>
  • Loading branch information
Roudenn and Rxup authored Jul 22, 2024
1 parent 04e9425 commit f4b8158
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 54 deletions.
7 changes: 6 additions & 1 deletion Content.Client/Backmen/Blob/BlobbernautSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public override void Initialize()
SubscribeLocalEvent<BlobbernautComponent, AfterAutoHandleStateEvent>(OnBlobTileHandleState);
}

private static readonly DamageStateVisualLayers[] Layers =
[
DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded,
];

private void UpdateAppearance(EntityUid id, BlobbernautComponent blobbernaut, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (!Resolve(id, ref appearance, ref sprite))
return;

foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
foreach (var key in Layers)
{
if (!sprite.LayerMapTryGet(key, out _))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ namespace Content.Server.Backmen.Blob.Components;
[RegisterComponent]
public sealed partial class StationBlobConfigComponent : Component
{
public const int DefaultStageBegin = 30;
public const int DefaultStageCritical = 400;
public const int DefaultStageEnd = 800;

[DataField("stageBegin")]
public int StageBegin { get; set; } = 30;
public int StageBegin { get; set; } = DefaultStageBegin;

[DataField("stageCritical")]
public int StageCritical { get; set; } = 400;
public int StageCritical { get; set; } = DefaultStageCritical;

[DataField("stageTheEnd")]
public int StageTheEnd { get; set; } = DefaultStageEnd;
Expand Down
5 changes: 4 additions & 1 deletion Content.Server/Backmen/Blob/Rule/BlobChangeLevelEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ namespace Content.Server.Backmen.Blob.Rule;

public sealed class BlobChangeLevelEvent : EntityEventArgs
{
public Entity<BlobCoreComponent> BlobCore;
/// <summary>
/// List of all cores from one station.
/// </summary>
public HashSet<Entity<BlobCoreComponent>>? BlobCore;
public EntityUid Station;
public BlobStage Level;
}
85 changes: 45 additions & 40 deletions Content.Server/Backmen/GameTicking/Rules/BlobRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ public sealed class BlobRuleSystem : GameRuleSystem<BlobRuleComponent>
[Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!;
[Dependency] private readonly IChatManager _chatManager = default!;



private static readonly SoundPathSpecifier BlobDetectAudio = new SoundPathSpecifier("/Audio/Corvax/Adminbuse/Outbreak5.ogg");

public override void Initialize()
{
base.Initialize();
}
private static readonly SoundPathSpecifier BlobDetectAudio = new ("/Audio/Corvax/Adminbuse/Outbreak5.ogg");

protected override void Started(EntityUid uid, BlobRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
Expand All @@ -64,33 +57,23 @@ protected override void ActiveTick(EntityUid uid, BlobRuleComponent component, G

component.Accumulator = 0;

// Each station has HashSet of all Blob Cores.
var blobCores = new Dictionary<EntityUid, HashSet<Entity<BlobCoreComponent>>>();

var blobCoreQuery = EntityQueryEnumerator<BlobCoreComponent, MetaDataComponent>();
while (blobCoreQuery.MoveNext(out var ent, out var comp, out _))
{
if (TerminatingOrDeleted(ent))
if (TerminatingOrDeleted(ent) || !CheckBlobInStation(ent, out var stationUid))
{
continue;
}

if (comp.BlobTiles.Count >= 50)
{
if (_roundEndSystem.ExpectedCountdownEnd != null)
{
_roundEndSystem.CancelRoundEndCountdown(checkCooldown: false);
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("blob-alert-recall-shuttle"),
Loc.GetString("Station"),
false,
null,
Color.Red);
}
}

if (!CheckBlobInStation(ent, out var stationUid))
{
continue;
}

CheckChangeStage((ent, comp), stationUid.Value, component);
if(!blobCores.TryAdd(stationUid.Value, [(ent, comp)]))
blobCores[stationUid.Value].Add((ent, comp));
}
foreach (var (station, cores) in blobCores)
{
CheckChangeStage(station, component, cores);
}
}

Expand All @@ -112,30 +95,52 @@ private bool CheckBlobInStation(EntityUid blobCore, [NotNullWhen(true)] out Enti
private const string StationGamma = "gamma";
private const string StationSigma = "sigma";

private void CheckChangeStage(Entity<BlobCoreComponent> blobCore, Entity<StationBlobConfigComponent?> stationUid, BlobRuleComponent blobRuleComp)
private void CheckChangeStage(
Entity<StationBlobConfigComponent?> stationUid,
BlobRuleComponent blobRuleComp,
HashSet<Entity<BlobCoreComponent>> blobCores)
{
Resolve(stationUid, ref stationUid.Comp, false);

var blobTilesCount = blobCores.Sum(blobCore => blobCore.Comp.BlobTiles.Count);

if (blobTilesCount >= (stationUid.Comp?.StageBegin ?? StationBlobConfigComponent.DefaultStageBegin)
&& _roundEndSystem.ExpectedCountdownEnd != null)
{
_roundEndSystem.CancelRoundEndCountdown(checkCooldown: false);
_chatSystem.DispatchStationAnnouncement(stationUid,
Loc.GetString("blob-alert-recall-shuttle"),
Loc.GetString("Station"),
false,
null,
Color.Red);
}

switch (blobRuleComp.Stage)
{
case BlobStage.Default when blobCore.Comp.BlobTiles.Count >= (stationUid.Comp?.StageBegin ?? 30):
case BlobStage.Default when blobTilesCount >= (stationUid.Comp?.StageBegin ?? StationBlobConfigComponent.DefaultStageBegin):
blobRuleComp.Stage = BlobStage.Begin;

_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("blob-alert-detect"),
Loc.GetString("Station"), true, BlobDetectAudio, Color.Red);
_chatSystem.DispatchStationAnnouncement(stationUid,
Loc.GetString("blob-alert-detect"),
Loc.GetString("Station"),
true,
BlobDetectAudio,
Color.Red);
_alertLevelSystem.SetLevel(stationUid, StationSigma, true, true, true, true);

RaiseLocalEvent(stationUid, new BlobChangeLevelEvent
{
BlobCore = blobCore,
BlobCore = blobCores,
Station = stationUid,
Level = blobRuleComp.Stage
}, broadcast: true);
return;
case BlobStage.Begin when blobCore.Comp.BlobTiles.Count >= (stationUid.Comp?.StageCritical ?? 400):
case BlobStage.Begin when blobTilesCount >= (stationUid.Comp?.StageCritical ?? StationBlobConfigComponent.DefaultStageCritical):
{
blobRuleComp.Stage = BlobStage.Critical;
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("blob-alert-critical"),
_chatSystem.DispatchStationAnnouncement(stationUid,
Loc.GetString("blob-alert-critical"),
Loc.GetString("Station"),
true,
blobRuleComp.AlertAudio,
Expand All @@ -144,23 +149,23 @@ private void CheckChangeStage(Entity<BlobCoreComponent> blobCore, Entity<Station
_nukeCode.SendNukeCodes(stationUid);
_alertLevelSystem.SetLevel(stationUid, StationGamma, true, true, true, true);

RaiseLocalEvent(stationUid, new BlobChangeLevelEvent
RaiseLocalEvent(stationUid,
new BlobChangeLevelEvent
{
BlobCore = blobCore,
BlobCore = blobCores,
Station = stationUid,
Level = blobRuleComp.Stage
}, broadcast: true);
return;
}
case BlobStage.Critical when blobCore.Comp.BlobTiles.Count >= (stationUid.Comp?.StageTheEnd ?? StationBlobConfigComponent.DefaultStageEnd):
case BlobStage.Critical when blobTilesCount >= (stationUid.Comp?.StageTheEnd ?? StationBlobConfigComponent.DefaultStageEnd):
{
blobRuleComp.Stage = BlobStage.TheEnd;
blobCore.Comp.Points = 99999;
_roundEndSystem.EndRound();

RaiseLocalEvent(stationUid, new BlobChangeLevelEvent
{
BlobCore = blobCore,
BlobCore = blobCores,
Station = stationUid,
Level = blobRuleComp.Stage
}, broadcast: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ public sealed partial class BlobSpawnRuleComponent : Component
[DataField("carrierBlobProtos", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public List<string> CarrierBlobProtos = new()
{
"MobMouseCancer"
//"MobMouse",
//"MobMouse1",
//"MobMouse2"
"SpawnPointGhostBlobRat"
};

[ViewVariables(VVAccess.ReadOnly), DataField("playersPerCarrierBlob")]
public int PlayersPerCarrierBlob = 30;

[ViewVariables(VVAccess.ReadOnly), DataField("maxCarrierBlob")]
public int MaxCarrierBlob = 3;
public int MaxCarrierBlob = 2;
}
4 changes: 0 additions & 4 deletions Resources/Prototypes/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@
prob: 0.02
- id: MobMouse2
prob: 0.02
- id: MobMouseCancer
prob: 0.001
# Events always spawn a critter regardless of Probability https://github.com/space-wizards/space-station-14/issues/28480 I added the Rat King to their own event with a player cap.

- type: entity
Expand All @@ -289,8 +287,6 @@
prob: 0.02
- id: MobMouse2
prob: 0.02
- id: MobMouseCancer
prob: 0.001
specialEntries:
- id: SpawnPointGhostRatKing
prob: 0.001
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/_Backmen/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
duration: 1
earliestStart: 50
minimumPlayers: 20
maxOccurrences: 1 # can only happen once per round
- type: BlobSpawnRule
carrierBlobProtos:
- SpawnPointGhostBlobRat
playersPerCarrierBlob: 30
maxCarrierBlob: 3
maxCarrierBlob: 2

- type: entity
id: BluespaceGoat
Expand Down

0 comments on commit f4b8158

Please sign in to comment.