Skip to content

Commit

Permalink
my god it works
Browse files Browse the repository at this point in the history
  • Loading branch information
lunar-crater-ex committed Aug 26, 2023
1 parent c774034 commit eca0f6e
Show file tree
Hide file tree
Showing 24 changed files with 1,815 additions and 55 deletions.
7 changes: 7 additions & 0 deletions Content.Client/_Citadel/Contracts/ContractInfoControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,15 @@ public void Update(ContractUiState state)
throw new ArgumentOutOfRangeException();
}

if (state.NoStartReason is { } reason)
{
msg.PushNewline();
msg.AddMessage(reason);
}

ContractState.SetMessage(msg);


Description.SetMessage(descMsg);

if (state.Status is ContractStatus.Breached or ContractStatus.Finalized or ContractStatus.Cancelled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public sealed partial class ContractComponent : Component
/// </summary>
[ViewVariables]
public List<Mind.Mind> SubContractors = new();

[DataField("autostart")]
public bool AutoStart = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Server._Citadel.Contracts.Components;

/// <summary>
/// This is used for contract groups. simpl.
/// </summary>
[RegisterComponent]
public sealed partial class ContractGroupsComponent : Component
{
[DataField("groups")]
public HashSet<string> Groups = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Server._Citadel.Contracts.Components;

/// <summary>
/// This is used for contracts that are advanced by finalizing other contracts.
/// </summary>
[RegisterComponent]
public sealed partial class FinalizeContractsCriteriaComponent : Component
{
[DataField("toClear")]
public int ContractsToClear;

public int ContractsCleared;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server._Citadel.Contracts.Criteria.Components;
using Content.Server._Citadel.Contracts.Components;
using Content.Server._Citadel.Contracts.Criteria.Components;
using Content.Shared._Citadel.Contracts.BUI;
using Robust.Shared.Utility;

Expand All @@ -17,6 +18,9 @@ public override void Initialize()

private void OnGetDisplayInfo(EntityUid uid, CriteriaManualComponent component, ref CriteriaGetDisplayInfo args)
{
args.Info = new CriteriaDisplayData(FormattedMessage.FromMarkup(component.Description));
var desc = FormattedMessage.FromMarkup(component.Description);
if (Comp<ContractCriteriaComponent>(uid).Satisfied)
desc.AddText(" [COMPLETE]");
args.Info = new CriteriaDisplayData(desc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public override void Initialize()

private void OnGetDisplayInfo(EntityUid uid, CriteriaNoDeathsComponent component, ref CriteriaGetDisplayInfo args)
{
args.Info = new CriteriaDisplayData(FormattedMessage.FromMarkup(component.Description));
var desc = FormattedMessage.FromMarkup(component.Description);
if (Comp<ContractCriteriaComponent>(uid).Satisfied)
desc.AddText(" [COMPLETE]");
args.Info = new CriteriaDisplayData(desc);
}

private void OnStartTicking(EntityUid uid, CriteriaNoDeathsComponent component, CriteriaStartTickingEvent args)
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/_Citadel/Contracts/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public record struct ContractTryStatusChange(ContractStatus Old, ContractStatus
/// </summary>
/// <target>Contract</target>
/// <broadcast>false</broadcast>
public readonly record struct ContractStatusChangedEvent(ContractStatus Old, ContractStatus New);
public readonly record struct ContractStatusChangedEvent(EntityUid Contract, ContractStatus Old, ContractStatus New);

/// <summary>
/// An event fired when a contract is ready for setup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ private void OnContractStatusChanged(EntityUid contractUid, ContractCriteriaCont
switch (args)
{
// Contract initiated, set up the criteria.
case (ContractStatus.Uninitialized, ContractStatus.Initiating):
case (_, ContractStatus.Uninitialized, ContractStatus.Initiating):
{
OnContractInitiating(contractUid, criteriaControlComponent);
break;
}
// Contract active, set up criteria checking.
case (ContractStatus.Initiating, ContractStatus.Active):
case (_, ContractStatus.Initiating, ContractStatus.Active):
{
OnContractActive(contractUid, criteriaControlComponent);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server._Citadel.Contracts.Components;
using Content.Server._Citadel.Contracts.Prototypes;
using Content.Server.Administration;
using Content.Server.Mind.Components;
using Content.Server._Citadel.Contracts.Components;
using Content.Shared._Citadel.Contracts;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server._Citadel.Contracts.Systems;

/// <summary>
/// This handles managing contracts and processing their completion state.
/// </summary>
public sealed partial class ContractManagementSystem : EntitySystem
public sealed class ContractManagementSystem : EntitySystem
{
[Dependency] private readonly IConsoleHost _consoleHost = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ILogManager _log = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

[Dependency] private readonly ContractCriteriaSystem _contractCriteria = default!;

/// <inheritdoc/>
public override void Initialize()
{
Expand Down Expand Up @@ -65,7 +48,7 @@ public EntityUid CreateUnboundContract(string contractProto)
var contract = Comp<ContractComponent>(contractEnt);
contract.Status = ContractStatus.Initiating;

RaiseLocalEvent(contractEnt, new ContractStatusChangedEvent(ContractStatus.Uninitialized, ContractStatus.Initiating));
RaiseLocalEvent(contractEnt, new ContractStatusChangedEvent(contractEnt, ContractStatus.Uninitialized, ContractStatus.Initiating), broadcast: true);

return contractEnt;
}
Expand All @@ -76,6 +59,11 @@ public void BindContract(EntityUid contractEnt, Mind.Mind contractor)
if (contract.OwningContractor is null)
{
contract.OwningContractor = contractor;
if (contract.AutoStart && contract.Status is ContractStatus.Initiating)
{
if (!TryChangeContractState(contractEnt, contract, ContractStatus.Active))
TryChangeContractState(contractEnt, contract, ContractStatus.Cancelled);
}
}
else
{
Expand All @@ -90,6 +78,7 @@ public EntityUid CreateBoundContract(string contractProto, Mind.Mind owner)
var contractEnt = CreateUnboundContract(contractProto);
BindContract(contractEnt, owner);


return contractEnt;
}

Expand Down Expand Up @@ -118,7 +107,7 @@ private bool TryChangeContractState(EntityUid contractUid, ContractComponent con
return false;

contractComponent.Status = newStatus;
RaiseLocalEvent(contractUid, new ContractStatusChangedEvent(oldStatus, newStatus));
RaiseLocalEvent(contractUid, new ContractStatusChangedEvent(contractUid, oldStatus, newStatus), broadcast: true);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Server._Citadel.Contracts.Components;
using Content.Shared._Citadel.Contracts;

namespace Content.Server._Citadel.Contracts.Systems;

// SHITCODESHITCODESHITCODESHITCODESHITCODE
// Whoever touches this next, REPLACE IT.
public sealed class DefaultContractSpawningSystem : EntitySystem
{
[Dependency] private readonly ContractManagementSystem _contract = default!;

public Dictionary<string, EntityUid> Contracts = new ()
{
{"CitadelMiningVesselContract", EntityUid.Invalid},
{"CitadelPlasmaMiningContract", EntityUid.Invalid},
};

public override void Update(float frameTime)
{
foreach (var (contract, ent) in Contracts)
{
if (Deleted(ent) ||
Comp<ContractComponent>(ent).Status is not ContractStatus.Initiating and not ContractStatus.Uninitialized)
{
Contracts[contract] = _contract.CreateUnboundContract(contract);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Linq;
using Content.Server._Citadel.Contracts.Components;
using Content.Shared._Citadel.Contracts;
using Content.Shared._Citadel.Contracts.BUI;
using Robust.Shared.Utility;

namespace Content.Server._Citadel.Contracts.Systems;

/// <summary>
/// This handles...
/// </summary>
public sealed class FinalizeContractsCriteriaSystem : EntitySystem
{
[Dependency] private readonly ContractCriteriaSystem _criteria = default!;


/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ContractStatusChangedEvent>(Handler);
SubscribeLocalEvent<FinalizeContractsCriteriaComponent, CriteriaGetDisplayInfo>(OnGetDisplayInfo);
}

private void OnGetDisplayInfo(EntityUid uid, FinalizeContractsCriteriaComponent component, ref CriteriaGetDisplayInfo args)
{
var desc = FormattedMessage.FromMarkup($"Complete {component.ContractsToClear} contracts successfully while this one is active.");
if (Comp<ContractCriteriaComponent>(uid).Satisfied)
desc.AddText(" [COMPLETE]");
args.Info = new CriteriaDisplayData(desc);
}

private void Handler(ContractStatusChangedEvent ev)
{
var contractComp = Comp<ContractComponent>(ev.Contract);

if (ev.New != ContractStatus.Finalized)
return;

foreach (var contractor in contractComp.SubContractors.Append(contractComp.OwningContractor))
{
var contracts = contractor!.Contracts.SelectMany(x => Comp<ContractCriteriaControlComponent>(x).Criteria.Values)
.SelectMany(x => x)
.Where(HasComp<FinalizeContractsCriteriaComponent>);

foreach (var contract in contracts)
{
var finalize = Comp<FinalizeContractsCriteriaComponent>(contract);
finalize.ContractsCleared++;
if (finalize.ContractsCleared >= finalize.ContractsToClear)
_criteria.SetCriteriaStatus(contract, true, Comp<ContractCriteriaComponent>(contract));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Server._Citadel.Contracts.Systems;
using Content.Server._Citadel.MiningContracts.Criteria.Components;
using Content.Server._Citadel.VesselContracts.Components;
using Content.Server._Citadel.VesselContracts.Systems;
using Content.Server.Materials;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
Expand All @@ -21,6 +22,7 @@ public sealed class CriteriaMaterialStorageHasMaterialsSystem : EntitySystem
[Dependency] private readonly ContractCriteriaSystem _criteria = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly MaterialStorageSystem _material = default!;
[Dependency] private readonly ContractVesselManagementSystem _contractVessel = default!;
[Dependency] private readonly IRobustRandom _random = default!;

/// <inheritdoc/>
Expand All @@ -38,11 +40,16 @@ private void OnComponentStartup(EntityUid uid, CriteriaMaterialStorageHasMateria

private void OnGetDisplayInfo(EntityUid uid, CriteriaMaterialStorageHasMaterialsComponent component, ref CriteriaGetDisplayInfo args)
{
args.Info = new CriteriaDisplayData(FormattedMessage.FromMarkup(
var desc = FormattedMessage.FromMarkup(
Loc.GetString("criteria-material-storage-has-materials-component-display-description",
("material", component.Material),
("amount", component.Amount))
));
);

if (Comp<ContractCriteriaComponent>(uid).Satisfied)
desc.AddText(" [COMPLETE]");

args.Info = new CriteriaDisplayData(desc);
}

private void OnStartTicking(EntityUid uid, CriteriaMaterialStorageHasMaterialsComponent component, CriteriaStartTickingEvent args)
Expand All @@ -58,11 +65,17 @@ public override void Update(float frameTime)

while (q.MoveNext(out var uid, out var cc, out var criteria))
{
var vessel = vesselContractQuery.GetComponent(cc.OwningContract);
if (Comp<ContractComponent>(cc.OwningContract).OwningContractor is not {} owningContractor)
continue;

if (criteria.Ticking is false || criteria.Satisfied || vessel.Vessel is null)
if (_contractVessel.LocateUserVesselContract(owningContractor) is not
{ } vesselUid)
continue;

var vessel = vesselContractQuery.GetComponent(vesselUid);

if (criteria.Ticking is false || criteria.Satisfied || vessel.Vessel is null)
continue;

var gridMaybe = _station.GetLargestGrid(Comp<StationDataComponent>(vessel.Vessel!.Value));

Expand Down
Loading

0 comments on commit eca0f6e

Please sign in to comment.