diff --git a/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs b/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs index d5b479b8f710b7..e60a4852da3f3a 100644 --- a/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs +++ b/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs @@ -19,6 +19,7 @@ using Robust.Shared.Random; using System.Linq; using System.Text; +using Robust.Shared.Timing; namespace Content.Server.GameTicking.Rules; @@ -37,6 +38,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem [Dependency] private readonly GameTicker _gameTicker = default!; [Dependency] private readonly SharedRoleSystem _roleSystem = default!; [Dependency] private readonly UplinkSystem _uplink = default!; + [Dependency] private readonly IGameTiming _timing = default!; public override void Initialize() { @@ -165,6 +167,10 @@ public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component) Log.Debug($"MakeTraitor {ToPrettyString(traitor)} - Add traitor briefing components"); AddComp(traitorRole.Value.Owner); Comp(traitorRole.Value.Owner).Briefing = briefing; + + //ss220 time of assignment on traitor for conditions start + traitorRole.Value.Comp2.TimeOfAssignment = _timing.CurTime; + //ss220 time of assignment on traitor for conditions end } else { diff --git a/Content.Server/Roles/TraitorRoleComponent.cs b/Content.Server/Roles/TraitorRoleComponent.cs index a8a11a8f1bd4c6..3ecc4123e9fa33 100644 --- a/Content.Server/Roles/TraitorRoleComponent.cs +++ b/Content.Server/Roles/TraitorRoleComponent.cs @@ -8,4 +8,8 @@ namespace Content.Server.Roles; [RegisterComponent] public sealed partial class TraitorRoleComponent : BaseMindRoleComponent { + //ss220 time of assignment on traitor for conditions start + [DataField] + public TimeSpan? TimeOfAssignment; + //ss220 time of assignment on traitor for conditions end } diff --git a/Content.Server/SS220/Store/Conditions/BuyTimeForListingCondition.cs b/Content.Server/SS220/Store/Conditions/BuyTimeForListingCondition.cs index ce5a483ef39fdb..9b292688a61ce2 100644 --- a/Content.Server/SS220/Store/Conditions/BuyTimeForListingCondition.cs +++ b/Content.Server/SS220/Store/Conditions/BuyTimeForListingCondition.cs @@ -1,16 +1,36 @@ +using Content.Server.Mind; +using Content.Server.Roles; +using Content.Shared.Roles; using Content.Shared.Store; -using Microsoft.CodeAnalysis.Elfie.Serialization; using Robust.Shared.Timing; namespace Content.Server.SS220.Store.Conditions; public sealed partial class BuyTimeForListingCondition : ListingCondition { + private IGameTiming _gameTiming; + private MindSystem _mindSystem; + private SharedRoleSystem _role; + [DataField(required: true)] - public int TimeAmount; + public TimeSpan TimeAmount; public override bool Condition(ListingConditionArgs args) { - return IoCManager.Resolve().CurTime <= TimeSpan.FromSeconds(TimeAmount); //todo fix + _gameTiming = IoCManager.Resolve(); + _mindSystem = args.EntityManager.System(); + _role = args.EntityManager.System(); + + _mindSystem.TryGetMind(args.Buyer, out var mind, out _); + + if (!_role.MindHasRole(mind, out var traitorRoleComponent)) + return false; + + var currentTime = _gameTiming.CurTime; + + var creationTime = traitorRoleComponent.Value.Comp2.TimeOfAssignment; + + return currentTime < creationTime + TimeAmount; + } } diff --git a/Content.Server/SS220/Store/Conditions/ListingLimitedForRuleCondition.cs b/Content.Server/SS220/Store/Conditions/ListingStockLimitByTraitorsCondition.cs similarity index 81% rename from Content.Server/SS220/Store/Conditions/ListingLimitedForRuleCondition.cs rename to Content.Server/SS220/Store/Conditions/ListingStockLimitByTraitorsCondition.cs index 2f381ce2ffe5d0..702aa099df7d6e 100644 --- a/Content.Server/SS220/Store/Conditions/ListingLimitedForRuleCondition.cs +++ b/Content.Server/SS220/Store/Conditions/ListingStockLimitByTraitorsCondition.cs @@ -9,7 +9,7 @@ namespace Content.Server.SS220.Store.Conditions; /// /// Condition that limits the stock availability of a listing based on the percentage of traitors. /// -public sealed partial class ListingStockLimitByTraitorsCondition : ListingCondition +public sealed partial class ListingStockLimitByTraitorsCondition : ListingCondition { private GameTicker _gameTicker; @@ -26,17 +26,13 @@ public override bool Condition(ListingConditionArgs args) var totalPurchases = 0; var storeCounts = args.EntityManager.EntityQuery(); - //count purchases for all stores foreach (var store in storeCounts) { - ListingDataWithCostModifiers first = new(); - foreach (var x in store.FullListingsCatalog.Where(x => x.ID == args.Listing.ID)) + var listing = store.FullListingsCatalog.FirstOrDefault(x => x.ID == args.Listing.ID); + if (listing != null) { - first = x; - break; + totalPurchases += listing.PurchaseAmount; } - - totalPurchases += first.PurchaseAmount; } var ruleEntities = _gameTicker.GetAddedGameRules(); diff --git a/Resources/Prototypes/SS220/Catalog/uplink_catalog.yml b/Resources/Prototypes/SS220/Catalog/uplink_catalog.yml index 4ebe20e440768d..c981095a2f5554 100644 --- a/Resources/Prototypes/SS220/Catalog/uplink_catalog.yml +++ b/Resources/Prototypes/SS220/Catalog/uplink_catalog.yml @@ -259,6 +259,8 @@ - NukeOpsUplink - !type:ListingStockLimitByTraitorsCondition #amount kit for traitor count / 4 contractorPercentage: 0.25 + - !type:BuyTimeForListingCondition #time for buy contractor kit + timeAmount: 10 #ss220 contractor add end #- type: listing