Skip to content

Commit

Permalink
some fixes and buy time for listing
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeZer2 committed Dec 27, 2024
1 parent c9a535f commit 07ebdc8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Robust.Shared.Random;
using System.Linq;
using System.Text;
using Robust.Shared.Timing;

namespace Content.Server.GameTicking.Rules;

Expand All @@ -37,6 +38,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
[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()
{
Expand Down Expand Up @@ -165,6 +167,10 @@ public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component)
Log.Debug($"MakeTraitor {ToPrettyString(traitor)} - Add traitor briefing components");
AddComp<RoleBriefingComponent>(traitorRole.Value.Owner);
Comp<RoleBriefingComponent>(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
{
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Roles/TraitorRoleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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<IGameTiming>().CurTime <= TimeSpan.FromSeconds(TimeAmount); //todo fix
_gameTiming = IoCManager.Resolve<IGameTiming>();
_mindSystem = args.EntityManager.System<MindSystem>();
_role = args.EntityManager.System<SharedRoleSystem>();

_mindSystem.TryGetMind(args.Buyer, out var mind, out _);

if (!_role.MindHasRole<TraitorRoleComponent>(mind, out var traitorRoleComponent))
return false;

var currentTime = _gameTiming.CurTime;

var creationTime = traitorRoleComponent.Value.Comp2.TimeOfAssignment;

return currentTime < creationTime + TimeAmount;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Content.Server.SS220.Store.Conditions;
/// <summary>
/// Condition that limits the stock availability of a listing based on the percentage of traitors.
/// </summary>
public sealed partial class ListingStockLimitByTraitorsCondition : ListingCondition
public sealed partial class ListingStockLimitByTraitorsCondition : ListingCondition
{
private GameTicker _gameTicker;

Expand All @@ -26,17 +26,13 @@ public override bool Condition(ListingConditionArgs args)
var totalPurchases = 0;
var storeCounts = args.EntityManager.EntityQuery<StoreComponent>();

//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();
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/SS220/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07ebdc8

Please sign in to comment.