Skip to content

Commit

Permalink
Merge pull request #13 from mam0nt222/master
Browse files Browse the repository at this point in the history
Gamemode: Planetary Warfare
  • Loading branch information
JerryImMouse authored Jan 12, 2025
2 parents 2b0d319 + f12afd8 commit 4a82067
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Content.Server/_WH14K/Altar/AltarComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server._WH14K.Altar;

[RegisterComponent]
public sealed partial class AltarComponent : Component
{
// TODO: this is shit, remake it soon
[DataField]
public bool Exploded = false;
}
18 changes: 18 additions & 0 deletions Content.Server/_WH14K/Altar/AltarSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Content.Server._WH14K.GameTicking.Rules;

namespace Content.Server._WH14K.Altar;

public sealed partial class AltarSystem : EntitySystem
{
[Dependency] private readonly PlanetaryWarfareRuleSystem _pw = default!;
public override void Initialize()
{
base.Initialize();
}

private void AltarExploded(AltarComponent component)
{
component.Exploded = true;
_pw.CheckRoundShouldEnd();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server._WH14K.GameTicking.Rules;

[RegisterComponent]
public sealed partial class CommandIGComponent : Component
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Content.Server._WH14K.GameTicking.Rules;

[RegisterComponent, Access(typeof(PlanetaryWarfareRuleSystem))]
public sealed partial class PlanetaryWarfareRuleComponent : Component
{
[DataField]
public WinTypePW WinTypePW = WinTypePW.Neutral;
}

public enum WinTypePW : byte
{
AllCommandDead,
WarpStormSummoned,
Neutral,
AllAltarExploded
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Content.Server.Antag;
using Content.Server.Communications;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.RoundEnd;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Popups;
using Content.Server._WH14K.WarpShtorm;
using Content.Server._WH14K.Altar;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.GameTicking.Components;
using Robust.Shared.Utility;
using Robust.Shared.Map.Components;
using Content.Shared.Mind;
using Robust.Server.Player;

namespace Content.Server._WH14K.GameTicking.Rules;

public sealed partial class PlanetaryWarfareRuleSystem : GameRuleSystem<PlanetaryWarfareRuleComponent>
{
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly IPlayerManager _player = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CommandIGComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<CommandIGComponent, MobStateChangedEvent>(OnMobStateChanged);
}

protected override void AppendRoundEndText(EntityUid uid, PlanetaryWarfareRuleComponent component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent args)
{
switch (component.WinTypePW)
{
case WinTypePW.WarpStormSummoned:
args.AddLine(Loc.GetString("pw-chaos-win"));
args.AddLine(Loc.GetString("pw-warp-storm-summoned-desc"));
break;
case WinTypePW.AllCommandDead:
args.AddLine(Loc.GetString("pw-chaos-win"));
args.AddLine(Loc.GetString("pw-all-command-dead-desc"));
break;
case WinTypePW.AllAltarExploded:
args.AddLine(Loc.GetString("pw-ig-win"));
args.AddLine(Loc.GetString("pw-all-altars-exploded-desc"));
break;
default:
break;
}

var igCommand = EntityQuery<CommandIGComponent, MindComponent>(true);
foreach (var (ig, mind) in igCommand)
{
if (mind is null || mind.CharacterName is null || mind.OriginalOwnerUserId is null)
return;

_player.TryGetPlayerData(mind.OriginalOwnerUserId.Value, out var data);

if (data == null)
return;
args.AddLine(Loc.GetString("ig-command-list-start"));

args.AddLine(Loc.GetString("ig-command-list-name-user", ("name", mind.CharacterName), ("user", data.UserName)));
}
}

private void OnComponentRemove(EntityUid uid, CommandIGComponent component, ComponentRemove args)
{
CheckRoundShouldEnd();
}

private void OnMobStateChanged(EntityUid uid, CommandIGComponent component, MobStateChangedEvent ev)
{
if (ev.NewMobState == MobState.Dead)
CheckRoundShouldEnd();
}

public void CheckRoundShouldEnd()
{
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out _, out var pw, out _))
{
WarpStormSummoned((uid, pw));
AllCommandDead((uid, pw));
AllAltarExploded((uid, pw));
}
}

private void AllCommandDead(Entity<PlanetaryWarfareRuleComponent> ent)
{
var igCommand = EntityQuery<CommandIGComponent, MobStateComponent>(true);

foreach (var (ig, igMobState) in igCommand)
{
if (igMobState.CurrentState == MobState.Alive)
{
return;
}
}

ent.Comp.WinTypePW = WinTypePW.AllCommandDead;
_roundEndSystem.EndRound();
}

private void AllAltarExploded(Entity<PlanetaryWarfareRuleComponent> ent)
{
var altars = EntityQuery<AltarComponent>(true);

foreach (var altar in altars)
{
if (!altar.Exploded)
{
return;
}
}

ent.Comp.WinTypePW = WinTypePW.AllAltarExploded;
_roundEndSystem.EndRound();
}

private void WarpStormSummoned(Entity<PlanetaryWarfareRuleComponent> ent)
{
var warpStorms = EntityQuery<WarpStormComponent>();
foreach (var warpStorm in warpStorms)
{
var mapQuery = EntityQueryEnumerator<MapLightComponent>();
while (mapQuery.MoveNext(out var uid, out var map))
{
map.AmbientLightColor = Color.FromHex("#e82a2a");
Dirty(uid, map);
}

ent.Comp.WinTypePW = WinTypePW.WarpStormSummoned;
_roundEndSystem.EndRound();
}
}
}
6 changes: 6 additions & 0 deletions Content.Server/_WH14K/WarpShtorm/WarpStormComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server._WH14K.WarpShtorm;

[RegisterComponent]
public sealed partial class WarpStormComponent : Component
{
}
17 changes: 17 additions & 0 deletions Content.Server/_WH14K/WarpShtorm/WarpStormSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Server._WH14K.GameTicking.Rules;

namespace Content.Server._WH14K.WarpShtorm;

public sealed partial class WarpStormSystem : EntitySystem
{
[Dependency] private readonly PlanetaryWarfareRuleSystem _pw = default!;
public override void Initialize()
{
base.Initialize();
}

private void Summon()
{
_pw.CheckRoundShouldEnd();
}
}
11 changes: 11 additions & 0 deletions Resources/Locale/en-US/_WH14K/pw.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pw-title = Планетарное Сражение
pw-description = режим
pw-ig-win = [color=gold][font size=16][bold]Победа Империума[/bold][/font][/color]
pw-chaos-win = [color=#9B2D30][font size=16][bold]Победа Хаоса[/bold][/font][/color]
pw-all-command-dead-desc = Хаос смог захватить крейсер Имперской Гвардии, что вкупе с орудиями планетарной обороны позволит еретикам укрепить свое влияние в секторе.
pw-all-altars-exploded-desc = Силы Империума сумели уничтожить все алтари Темных Богов, предотвратив Варп-Шторм. Это спасло миллиарды жизней, но это только одна из тысяч планет под угрозой.
pw-warp-storm-summoned-desc = Катастрофа космического масштаба, разразившаяся в центре этой планеты, погубила триллионы жизней
ig-command-list-start = Командирами Империума были:
5 changes: 5 additions & 0 deletions Resources/Prototypes/_WH14K/GameRules/roundstart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- type: entity
parent: BaseGameRule
id: PlanetaryWarfareRule
components:
- type: PlanetaryWarfareRule
7 changes: 7 additions & 0 deletions Resources/Prototypes/_WH14K/game_presets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- type: gamePreset
id: PlanetaryWarfare
name: pw-title
showInVote: true
description: pw-description
rules:
- PlanetaryWarfareRule

0 comments on commit 4a82067

Please sign in to comment.