Skip to content
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

Partners #40

Merged
merged 4 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics.CodeAnalysis;
using Content.Client.Corvax.Sponsors;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Shared.Preferences.Loadouts.Effects;

public sealed partial class PartnerLoadoutEffect : LoadoutEffect
{
[DataField(required: true)]
public float MinTier = 1f;

public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection,
[NotNullWhen(false)] out FormattedMessage? reason)
{
var manager = collection.Resolve<SponsorsManager>();
reason = FormattedMessage.FromUnformatted(Loc.GetString("loadout-group-partner-tier-restriction"));
if (!manager.TryGetInfo(out var sponsorInfo) || sponsorInfo.Tier < MinTier)
{
return false;
}

return true;
}
}
9 changes: 6 additions & 3 deletions Content.Server/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Numerics;
using Content.Server.Corvax.Sponsors;
using Content.Server.Database;
using Content.Server.GameTicking;
using Content.Server.Ghost.Components;
Expand Down Expand Up @@ -31,7 +32,7 @@ namespace Content.Server.Ghost
public sealed class GhostSystem : SharedGhostSystem
{
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IPartnersManager _partners = default!;
[Dependency] private readonly SponsorsManager _partners = default!;
[Dependency] private readonly SharedEyeSystem _eye = default!;
[Dependency] private readonly FollowerSystem _followerSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
Expand Down Expand Up @@ -450,8 +451,10 @@ private bool IsValidSpawnPosition(EntityCoordinates? spawnPosition)
return null;
}

_partners.TryGetInfo(mind.Comp.UserId, out var sponsorInfo); // STORIES - start
var proto = sponsorInfo == null || sponsorInfo.GhostSkin == null ? GameTicker.ObserverPrototypeName : sponsorInfo.GhostSkin;
var proto = GameTicker.ObserverPrototypeName; // STORIES - start

if (mind.Comp.UserId != null && _partners.TryGetInfo(mind.Comp.UserId.Value, out var sponsorInfo))
proto = sponsorInfo.GhostSkin;

var ghost = SpawnAtPosition(proto, spawnPosition.Value); // STORIES - end
var ghostComponent = Comp<GhostComponent>(ghost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class OpenAntagSelectCommand : IConsoleCommand
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPartnersManager _db = default!;
[Dependency] private readonly SponsorsManager _partners = default!;
public string Command => "openantagselect";
public string Description => "Открыть меню выдачи антагов.";
public string Help => "Usage: pickantag dragon";
Expand All @@ -31,7 +31,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
var antagSelectSystem = _entityManager.System<AntagSelectSystem>();
var playerEntity = shell.Player.AttachedEntity.Value;

if (_db.TryGetInfo(shell.Player.UserId, out var sponsor) && sponsor.AllowedAntags != null)
if (_partners.TryGetInfo(shell.Player.UserId, out var sponsor) && sponsor.AllowedAntags != null)
{
uiSystem.OpenUi(playerEntity, AntagSelectUiKey.Key, shell.Player);
var random = _random.Pick(sponsor.AllowedAntags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
if (!antagSelectSystem.IssuedSponsorRoles.TryAdd(proto.Key, 1))
antagSelectSystem.IssuedSponsorRoles[proto.Key] += 1;

_db.SetAntagPicked(shell.Player.UserId);
// _db.SetAntagPicked(shell.Player.UserId);
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions Content.Server/Stories/Partners/Managers/PartnersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Content.Server.Database;
public interface IPartnersManager
{
void Init();
bool TryGetInfo(NetUserId? userId, [NotNullWhen(true)] out DbSponsorInfo? sponsor);
void SetAntagPicked(NetUserId userId);
}
public sealed class PartnersManager : IPartnersManager
Expand All @@ -29,50 +28,6 @@ public void SetAntagPicked(NetUserId userId)
using NpgsqlCommand cmd = new NpgsqlCommand($"""UPDATE partners SET "last_day_taking_antag" = {DateTime.Now.DayOfYear} WHERE partners.net_id = '{userId.UserId.ToString()}'""", _db);
using NpgsqlDataReader reader = cmd.ExecuteReader();
}
public bool TryGetInfo(NetUserId? userId, [NotNullWhen(true)] out DbSponsorInfo? sponsor)
{
// Init();

sponsor = null;

if (userId == null)
return false;

if (_db.FullState == System.Data.ConnectionState.Closed || _db.FullState == System.Data.ConnectionState.Broken)
return false;

try
{
using NpgsqlCommand cmd = new NpgsqlCommand($"""SELECT * FROM partners WHERE partners.net_id = '{userId.Value.UserId.ToString()}'""", _db);
using NpgsqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
DateTime? dateValue = (DateTime)reader[10];
if (dateValue != null && dateValue?.AddDays(30) < DateTime.Now)
return false;

sponsor = new DbSponsorInfo()
{
Tier = (short)reader[3],
OOCColor = (string)reader[4],
HavePriorityJoin = (bool)reader[5],
ExtraSlots = (short)reader[6],
RoleTimeBypass = (bool)reader[11],
AllowedAntags = (string[])reader[12],
GhostSkin = (string)reader[13],
LastDayTakingAntag = (short)reader[14]
};
return true;
}
}
catch (Exception e)
{
_sawmill.Error($"Error while getting partner info: {e}");
return false;
}
return false;
}
public void Init()
{
_sawmill = Logger.GetSawmill("partners");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public sealed class AntagSelectSystem : EntitySystem
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
[Dependency] private readonly IConsoleHost _host = default!;
[Dependency] private readonly IPartnersManager _db = default!;
[Dependency] private readonly SponsorsManager _partners = default!;
private const string DefaultRevsRule = "Revolutionary";
private const string DefaultThiefRule = "Thief";
private const string DefaultTraitorRule = "Traitor";
Expand Down Expand Up @@ -115,7 +116,7 @@ private void OnCanPick(CanPickAttemptEvent args) // TODO: Сделать луч
var uid = args.EntityUid;
var proto = args.Prototype;

if (!_db.TryGetInfo(args.Session.UserId, out var sponsorData) || sponsorData.AllowedAntags != null && !sponsorData.AllowedAntags.Contains(proto.ID) || sponsorData.LastDayTakingAntag == DateTime.Now.DayOfYear)
if (!_partners.TryGetInfo(args.Session.UserId, out var sponsorData) || sponsorData.AllowedAntags != null && !sponsorData.AllowedAntags.Contains(proto.ID) || sponsorData.LastDayTakingAntag == DateTime.Now.DayOfYear)
args.Cancel();

if (!_mind.TryGetMind(uid, out var mindId, out var mind))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics.CodeAnalysis;
using Content.Server.Corvax.Sponsors;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Shared.Preferences.Loadouts.Effects;

public sealed partial class PartnerLoadoutEffect : LoadoutEffect
{
[DataField(required: true)]
public float MinTier = 1f;

public override bool Validate(HumanoidCharacterProfile profile, RoleLoadout loadout, ICommonSession? session, IDependencyCollection collection,
[NotNullWhen(false)] out FormattedMessage? reason)
{
var manager = collection.Resolve<SponsorsManager>();
reason = FormattedMessage.FromUnformatted(Loc.GetString("loadout-group-partner-tier-restriction"));
if (!manager.TryGetInfo(session!.UserId, out var sponsorInfo) || sponsorInfo.Tier < MinTier)
{
return false;
}

return true;
}
}
21 changes: 7 additions & 14 deletions Content.Shared/Corvax/Sponsors/MsgSponsorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@

namespace Content.Shared.Corvax.Sponsors;

[Serializable, NetSerializable]
public sealed class DbSponsorInfo
{
public int? Tier { get; set; }
public string? OOCColor { get; set; }
public bool HavePriorityJoin { get; set; } = false;
public int ExtraSlots { get; set; }
public bool RoleTimeBypass { get; set; } = false;
public string[]? AllowedAntags { get; set; } = Array.Empty<string>();
public string? GhostSkin { get; set; }
public int LastDayTakingAntag { get; set; }
}

[Serializable, NetSerializable]
public sealed class SponsorInfo
{
Expand All @@ -41,8 +28,14 @@ public sealed class SponsorInfo
[JsonPropertyName("roleTimeBypass")]
public bool RoleTimeBypass { get; set; } = false;

[JsonPropertyName("ghost_skin")]
public string GhostSkin { get; set; } = "MobObserver";

[JsonPropertyName("allowed_antags")]
public string[]? AllowedAntags { get; set; } = Array.Empty<string>();
public string[] AllowedAntags { get; set; } = Array.Empty<string>();

[JsonPropertyName("last_day_taking_antag")]
public int LastDayTakingAntag { get; set; } = 0;
}


Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/preferences/loadout-groups.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,5 @@ loadout-group-paramedic-shoes = Парамедик, обувь
loadout-group-reporter-jumpsuit = Репортёр, комбинезон
loadout-group-boxer-jumpsuit = Боксёр, комбинезон
loadout-group-boxer-gloves = Боксёр, перчатки

loadout-group-partner-tier-restriction = Вы не партнёр или ваша подписка слишком мала!
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/stories/antag-select.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ antag-spaceninja = Космический ниндзя
antag-loneops = Одинокий оперативник
antag-headrev = Глава революции
antag-inquisitor = Инквизитор
antag-kylo = Инквизитор [Кайло Рен]
antag-dragon = Космический дракон
antag-terminator = Экстерминатор
ui-escape-antagselect = Выбор антагониста
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ entities:
- uid: 1
components:
- type: MetaData
name: grid
name: TIE Fighter
- type: Transform
pos: 14.424668,-2.4065256
parent: invalid
Expand Down Expand Up @@ -807,8 +807,6 @@ entities:
- 0
- type: Physics
bodyType: Static
- type: AtmosDevice
joinedGrid: 1
- proto: AirlockGlassShuttleSyndicate
entities:
- uid: 57
Expand All @@ -834,9 +832,6 @@ entities:
rot: -1.5707963267948966 rad
pos: 9.5,1.5
parent: 1
- type: Apc
lastExternalState: Low
lastChargeState: Full
- type: PowerNetworkBattery
loadingNetworkDemand: 560
currentReceiving: 559.9241
Expand All @@ -848,9 +843,6 @@ entities:
rot: -1.5707963267948966 rad
pos: 1.5,2.5
parent: 1
- type: Apc
lastExternalState: Low
lastChargeState: Full
- type: PowerNetworkBattery
loadingNetworkDemand: 10500
currentReceiving: 10500.042
Expand All @@ -861,9 +853,6 @@ entities:
rot: 1.5707963267948966 rad
pos: 11.5,2.5
parent: 1
- type: Apc
lastExternalState: Low
lastChargeState: Full
- type: PowerNetworkBattery
loadingNetworkDemand: 10500
currentReceiving: 10500.042
Expand Down Expand Up @@ -892,9 +881,6 @@ entities:
- type: DeviceNetwork
address: 6725-F016
receiveFrequency: 1280
- type: DeviceLinkSink
links:
- 9
- uid: 135
components:
- type: Transform
Expand All @@ -910,9 +896,6 @@ entities:
- type: DeviceNetwork
address: 20DD-0301
receiveFrequency: 1280
- type: DeviceLinkSink
links:
- 9
- uid: 137
components:
- type: Transform
Expand All @@ -928,9 +911,6 @@ entities:
- type: DeviceNetwork
address: 21E1-A433
receiveFrequency: 1280
- type: DeviceLinkSink
links:
- 9
- uid: 176
components:
- type: Transform
Expand All @@ -946,9 +926,6 @@ entities:
- type: DeviceNetwork
address: 63E7-DC26
receiveFrequency: 1280
- type: DeviceLinkSink
links:
- 9
- uid: 178
components:
- type: Transform
Expand All @@ -964,9 +941,6 @@ entities:
- type: DeviceNetwork
address: 66B3-94FF
receiveFrequency: 1280
- type: DeviceLinkSink
links:
- 9
- proto: C4
entities:
- uid: 129
Expand Down Expand Up @@ -1558,6 +1532,10 @@ entities:
occludes: True
ents:
- 107
disk_slot: !type:ContainerSlot
showEnts: False
occludes: True
ent: null
- proto: CrowbarRed
entities:
- uid: 188
Expand Down Expand Up @@ -1802,8 +1780,6 @@ entities:
rot: 3.141592653589793 rad
pos: 12.5,0.5
parent: 1
- type: AtmosDevice
joinedGrid: 1
- proto: GasVentPump
entities:
- uid: 131
Expand All @@ -1816,8 +1792,6 @@ entities:
address: Вент-4052-54D7
transmitFrequency: 1621
receiveFrequency: 1621
- type: AtmosDevice
joinedGrid: 1
- type: AtmosMonitor
trippedThresholds:
- Temperature
Expand Down Expand Up @@ -2653,9 +2627,9 @@ entities:
- type: Transform
pos: 5.5,-1.5
parent: 1
- proto: SpawnPointGhostSith
- proto: SpawnPointNukies
entities:
- uid: 351
- uid: 193
components:
- type: Transform
pos: 6.5,1.5
Expand Down Expand Up @@ -2695,6 +2669,13 @@ entities:
parent: 144
- type: Physics
canCollide: False
- proto: SyndicateIDCard
entities:
- uid: 65
components:
- type: Transform
pos: 7.5,-0.5
parent: 1
- proto: SyndicateShuttleConsoleCircuitboard
entities:
- uid: 107
Expand Down
Loading
Loading