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

[WiP] ADD: Contactor Traitor #2372

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Linq;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.Store;
using Content.Shared.Store.Components;

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
{
private GameTicker _gameTicker;

[DataField(required: true)]
public float ContractorPercentage;

public override bool Condition(ListingConditionArgs args)
{
_gameTicker = args.EntityManager.System<GameTicker>();

if (!_gameTicker.IsGameRuleAdded<TraitorRuleComponent>())
return false;

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))
{
first = x;
break;
}
ReeZer2 marked this conversation as resolved.
Show resolved Hide resolved

totalPurchases += first.PurchaseAmount;
}

var ruleEntities = _gameTicker.GetAddedGameRules();

foreach (var ruleEnt in ruleEntities)
{
if (!args.EntityManager.TryGetComponent<TraitorRuleComponent>(ruleEnt, out var traitorComp))
continue;

var maxContractors = Math.Ceiling(traitorComp.TotalTraitors * ContractorPercentage); // round up

return totalPurchases < maxContractors;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ public sealed partial class ContractorPortalOnTriggerComponent : Component

[DataField]
public NetEntity? TargetEntity;

public TimeSpan MaxPortalTime = TimeSpan.FromSeconds(15);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Shared.SS220.Contractor;

Expand All @@ -12,7 +10,7 @@ namespace Content.Shared.SS220.Contractor;
[Serializable, NetSerializable, Prototype("contractorItems")]
public sealed partial class SharedContractorItemPrototype : IPrototype
{
[DataField("items", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, EntityPrototype>))] //TODO: Delete serializer
[DataField("items")]
public Dictionary<string, FixedPoint2> Items = new();

[IdDataField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public override void Update(float frameTime)
{
base.Update(frameTime);

var quary = EntityQueryEnumerator<ContractorTargetComponent>();
var query = EntityQueryEnumerator<ContractorTargetComponent>();

while (quary.MoveNext(out var uid, out var comp))
while (query.MoveNext(out var uid, out var comp))
{
if (comp.EnteredPortalTime == TimeSpan.Zero)
return;
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/SS220/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
blacklist:
tags:
- NukeOpsUplink
#TODO amount kit for 0.25 * traitor count
- !type:ListingStockLimitByTraitorsCondition #amount kit for traitor count / 4
contractorPercentage: 0.25
#ss220 contractor add end

#- type: listing
Expand Down
Loading