-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ToolsForGateDungeon #2494
base: master
Are you sure you want to change the base?
ToolsForGateDungeon #2494
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
using Robust.Shared.Map; | ||
|
||
namespace Content.Server.SS220.GateDungeon; | ||
|
||
/// <summary> | ||
/// This handles creates a new map from the list and connects them with teleports. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class GateDungeonComponent : Component | ||
{ | ||
public bool IsCharging = true; | ||
|
||
public MapId MapId; | ||
|
||
public TimeSpan ChargingTime = TimeSpan.FromMinutes(5); | ||
|
||
[DataField] | ||
public List<string>? PathDungeon; | ||
|
||
public List<EntityUid>? GateStart = new(); | ||
public List<EntityUid>? GateMedium = new(); | ||
public List<EntityUid>? GateEnd = new(); | ||
public List<EntityUid>? GateEndToStation = new(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
using Content.Server.Popups; | ||
using Content.Shared.Gateway; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Tag; | ||
using Content.Shared.Teleportation.Components; | ||
using Content.Shared.Teleportation.Systems; | ||
using Robust.Server.GameObjects; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Random; | ||
using Timer = Robust.Shared.Timing.Timer; | ||
|
||
namespace Content.Server.SS220.GateDungeon; | ||
|
||
/// <summary> | ||
/// This handles creates a new map from the list and connects them with teleports. | ||
/// To work correctly from the place where teleportation takes place, two entities with a GateDungeonComponent are required | ||
/// one must have the StartDungeon tag, the other must have the EndToStationDungeon tag. | ||
/// The created map requires two entities with GateDungeonComp with tag, one must have the MediumDungeon tag, | ||
/// the other must have the EndDungeon tag | ||
/// </summary> | ||
public sealed class GateDungeonSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedMapSystem _map = default!; | ||
[Dependency] private readonly IMapManager _mapManager = default!; | ||
[Dependency] private readonly MapLoaderSystem _loader = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
[Dependency] private readonly TagSystem _tagSystem = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly LinkedEntitySystem _linked = default!; | ||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<GateDungeonComponent, ComponentStartup>(OnCreateDungeon); | ||
SubscribeLocalEvent<GateDungeonComponent, InteractHandEvent>(OnInteract); | ||
} | ||
|
||
private void OnCreateDungeon(Entity<GateDungeonComponent> ent, ref ComponentStartup args) | ||
{ | ||
if(!_tagSystem.HasTag(ent.Owner, "StartDungeon")) | ||
return; | ||
|
||
_appearance.SetData(ent.Owner, GatewayVisuals.Active, false); //should be turned off at the beginning | ||
|
||
if(ent.Comp.PathDungeon == null) | ||
return; | ||
|
||
var mapDungeon = _random.Pick(ent.Comp.PathDungeon); | ||
|
||
_map.CreateMap(out var mapId); | ||
_loader.TryLoad(mapId, mapDungeon, out _); | ||
_mapManager.SetMapPaused(mapId, true); | ||
|
||
ent.Comp.MapId = mapId; | ||
|
||
Timer.Spawn(ent.Comp.ChargingTime,() => ChargingDone(ent.Owner)); | ||
|
||
var gates = EntityQueryEnumerator<GateDungeonComponent>(); | ||
|
||
var entGates = new List<EntityUid>(); | ||
|
||
while (gates.MoveNext(out var entDungeon, out _)) | ||
{ | ||
entGates.Add(entDungeon); | ||
} | ||
|
||
if(ent.Comp.GateStart == null || | ||
ent.Comp.GateMedium == null || | ||
ent.Comp.GateEndToStation == null || | ||
ent.Comp.GateEnd == null) | ||
return; | ||
|
||
foreach (var gate in entGates) | ||
{ | ||
if (_tagSystem.HasTag(gate, "StartDungeon")) | ||
ent.Comp.GateStart.Add(gate); | ||
|
||
if (_tagSystem.HasTag(gate, "MediumDungeon")) | ||
ent.Comp.GateMedium.Add(gate); | ||
|
||
if(_tagSystem.HasTag(gate, "EndDungeon")) | ||
ent.Comp.GateEnd.Add(gate); | ||
|
||
if(_tagSystem.HasTag(gate, "EndToStationDungeon")) | ||
ent.Comp.GateEndToStation.Add(gate); | ||
} | ||
Comment on lines
+69
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Проклято |
||
} | ||
|
||
private void ChargingDone(EntityUid ent) | ||
{ | ||
if (!TryComp<GateDungeonComponent>(ent, out var gateComp)) | ||
return; | ||
|
||
_mapManager.SetMapPaused(gateComp.MapId, false); | ||
|
||
gateComp.IsCharging = false; | ||
|
||
var currentGateStart = PickRandom(gateComp.GateStart); | ||
if (currentGateStart == default) | ||
return; | ||
|
||
var currentGateMedium = PickRandom(gateComp.GateMedium); | ||
if (currentGateMedium == default) | ||
return; | ||
|
||
var currentGateEnd = PickRandom(gateComp.GateEnd); | ||
if (currentGateEnd == default) | ||
return; | ||
|
||
var currentGateEndToStation = PickRandom(gateComp.GateEndToStation); | ||
if(currentGateEndToStation == default) | ||
return; | ||
|
||
_appearance.SetData(ent, GatewayVisuals.Active, true); | ||
|
||
EnsureComp<PortalComponent>(currentGateStart, out var portalStartComp); | ||
EnsureComp<PortalComponent>(currentGateEnd, out var portalMediumComp); | ||
|
||
portalStartComp.CanTeleportToOtherMaps = true; | ||
portalMediumComp.CanTeleportToOtherMaps = true; | ||
|
||
EnsureComp<LinkedEntityComponent>(currentGateStart, out _); | ||
EnsureComp<LinkedEntityComponent>(currentGateEnd, out _); | ||
Comment on lines
+124
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем, если в TryLink эншурит этот компонент? |
||
|
||
_linked.TryLink(currentGateStart, currentGateMedium); | ||
_linked.TryLink(currentGateEnd, currentGateEndToStation); | ||
} | ||
|
||
private void OnInteract(Entity<GateDungeonComponent> ent, ref InteractHandEvent args) | ||
{ | ||
if(!_tagSystem.HasTag(ent.Owner, "StartDungeon")) | ||
return; | ||
|
||
_popup.PopupEntity(ent.Comp.IsCharging | ||
? Loc.GetString("gate-dungeon-is-charging") | ||
: Loc.GetString("gate-dungeon-already-charged"), | ||
ent.Owner, | ||
args.User); | ||
} | ||
|
||
private T? PickRandom<T>(IReadOnlyList<T>? list) | ||
{ | ||
if (list == null || list.Count == 0) | ||
return default; | ||
|
||
return _random.Pick(list); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
namespace Content.Shared.SS220.GateGunDungeon; | ||
|
||
/// <summary> | ||
/// This handles long-range weapons, prohibits shooting if the player is at the station. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class GateGunDungeonComponent : Component | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
using Content.Shared.Station.Components; | ||
using Content.Shared.Weapons.Ranged.Events; | ||
|
||
namespace Content.Shared.SS220.GateGunDungeon; | ||
|
||
/// <summary> | ||
/// This handles long-range weapons, prohibits shooting if the player is at the station. | ||
/// </summary> | ||
public sealed class GateGunDungeonSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<GateGunDungeonComponent, ShotAttemptedEvent>(OnShoot); | ||
} | ||
|
||
private void OnShoot(Entity<GateGunDungeonComponent> ent, ref ShotAttemptedEvent args) | ||
{ | ||
var gridUid = _transform.GetGrid(ent.Owner); | ||
|
||
if(gridUid == null) | ||
return; | ||
|
||
if (!HasComp<StationMemberComponent>(gridUid)) | ||
return; | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так он на шаттлах тогда разве не будет работать? |
||
|
||
args.Cancel(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ent-GatewayDungeonStart = { ent-BaseGateway } | ||
.desc = { ent-BaseGateway.desc } | ||
|
||
ent-GatewayDungeonMedium = { ent-BaseGateway } | ||
.desc = { ent-BaseGateway.desc } | ||
|
||
ent-GatewayDungeonEnd = { ent-BaseGateway } | ||
.desc = { ent-BaseGateway.desc } | ||
|
||
ent-GatewayDungeonEndToStation = { ent-BaseGateway } | ||
.desc = { ent-BaseGateway.desc } | ||
|
||
gate-dungeon-is-charging = врата еще заряжаются | ||
gate-dungeon-already-charged = врата уже заряжены |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
- type: entity | ||
parent: BaseGateway | ||
id: GatewayDungeonStart | ||
suffix: Start on station | ||
components: | ||
- type: GateDungeon | ||
pathDungeon: | ||
- Maps/Shuttles/arrivals.yml #for example, del this later | ||
- type: Tag | ||
tags: | ||
- StartDungeon | ||
|
||
- type: entity | ||
parent: BaseGateway | ||
id: GatewayDungeonMedium | ||
suffix: Start dungeon | ||
components: | ||
- type: GateDungeon | ||
- type: Sprite | ||
sprite: SS220/Structures/Machines/gate_dungeon.rsi | ||
layers: | ||
- state: framebroken | ||
- type: Tag | ||
tags: | ||
- MediumDungeon | ||
|
||
- type: entity | ||
parent: BaseGateway | ||
id: GatewayDungeonEnd | ||
suffix: End dungeon | ||
components: | ||
- type: GateDungeon | ||
- type: Tag | ||
tags: | ||
- EndDungeon | ||
|
||
- type: entity | ||
parent: MarkerBase | ||
id: GatewayDungeonEndToStation | ||
suffix: Teleport on station | ||
components: | ||
- type: GateDungeon | ||
- type: Sprite | ||
sprite: Markers/jobs.rsi | ||
layers: | ||
- state: green | ||
- type: Tag | ||
tags: | ||
- EndToStationDungeon |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||
{ | ||||||
"version": 1, | ||||||
"license": "EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt", | ||||||
"copyright": "by vimenant2(discord) for SS220", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"size": { | ||||||
"x": 96, | ||||||
"y": 96 | ||||||
}, | ||||||
"states": [ | ||||||
{ | ||||||
"name": "framebroken" | ||||||
} | ||||||
] | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вместо использования тегов думаю лучше сделать перечисление, например:
И в компоненте хранить списки энтити в одном поле через словарь
Dictionary<GateType, List<EntityUid>>
P.S.: Перечисление лучше писать вне класса в этом же неймспейсе (или в неймспейсе системы)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И зачем кста хранить этот список в компоненте каждого гейта?
Разве он не общий будет у всех?