Skip to content

Commit

Permalink
TechBalance (#507)
Browse files Browse the repository at this point in the history
* TechBalance

* Update disk.yml
  • Loading branch information
dvir001 authored Oct 29, 2023
1 parent 520b8cd commit d166353
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Content.Client/Research/UI/DiskConsoleBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ protected override void Open()
{
SendMessage(new DiskConsolePrintDiskMessage());
};
_menu.OnPrintRareButtonPressed += () =>
{
SendMessage(new DiskConsolePrintRareDiskMessage());
};
}

protected override void Dispose(bool disposing)
Expand Down
14 changes: 9 additions & 5 deletions Content.Client/Research/UI/DiskConsoleMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'tech-disk-ui-name'}"
Expand All @@ -19,14 +19,18 @@
<Label Name="TotalLabel"
HorizontalAlignment="Center">
</Label>
<Label Name="CostLabel"
HorizontalAlignment="Center">
</Label>
<BoxContainer MinHeight="20"></BoxContainer>
<Button
Name="PrintButton"
Text="{Loc 'tech-disk-ui-print-button'}"
MaxWidth="120"
MaxWidth="240"
HorizontalAlignment="Center"
VerticalExpand="False">
</Button>
<Button
Name="PrintRareButton"
Text="{Loc 'tech-disk-ui-print-rare-button'}"
MaxWidth="240"
HorizontalAlignment="Center"
VerticalExpand="False">
</Button>
Expand Down
7 changes: 6 additions & 1 deletion Content.Client/Research/UI/DiskConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ public sealed partial class DiskConsoleMenu : FancyWindow
{
public event Action? OnServerButtonPressed;
public event Action? OnPrintButtonPressed;
public event Action? OnPrintRareButtonPressed; // Frontier - Added for mass point use

public DiskConsoleMenu()
{
RobustXamlLoader.Load(this);

ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke();
PrintButton.OnPressed += _ => OnPrintButtonPressed?.Invoke();
PrintRareButton.OnPressed += _ => OnPrintRareButtonPressed?.Invoke(); // Frontier - Added for mass point use
}

public void Update(DiskConsoleBoundUserInterfaceState state)
{
PrintButton.Disabled = !state.CanPrint;
PrintRareButton.Disabled = !state.CanPrintRare; // Frontier - Added for mass point use
TotalLabel.Text = Loc.GetString("tech-disk-ui-total-label", ("amount", state.ServerPoints));
CostLabel.Text = Loc.GetString("tech-disk-ui-cost-label", ("amount", state.PointCost));
//CostLabel.Text = Loc.GetString("tech-disk-ui-cost-label", ("amount", state.PointCost));
PrintButton.Text = Loc.GetString("tech-disk-ui-print-button", ("amount", state.PointCost)); // Frontier
PrintRareButton.Text = Loc.GetString("tech-disk-ui-print-rare-button", ("amount", state.PointCostRare)); // Frontier
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

Expand All @@ -11,14 +11,26 @@ public sealed partial class DiskConsoleComponent : Component
/// How much it costs to print a disk
/// </summary>
[DataField("pricePerDisk"), ViewVariables(VVAccess.ReadWrite)]
public int PricePerDisk = 1000;
public int PricePerDisk = 10000;

/// <summary>
/// How much it costs to print a rare disk
/// </summary>
[DataField("pricePerRareDisk"), ViewVariables(VVAccess.ReadWrite)]
public int PricePerRareDisk = 13000;

/// <summary>
/// The prototype of what's being printed
/// </summary>
[DataField("diskPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string DiskPrototype = "TechnologyDisk";

[DataField("diskPrototypeRare", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string DiskPrototypeRare = "TechnologyDiskRare";

[DataField("diskRare"), ViewVariables(VVAccess.ReadWrite)]
public bool DiskRare = false;

/// <summary>
/// How long it takes to print <see cref="DiskPrototype"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Shared.Random;
using Content.Shared.Random;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Research.TechnologyDisk.Components;
Expand All @@ -12,9 +12,21 @@ public sealed partial class TechnologyDiskComponent : Component
[DataField("recipes")]
public List<string>? Recipes;

/// <summary>
/// The recipe that will be added. If null, one will be randomly generated
/// </summary>
[DataField("recipesRare")]
public List<string>? RecipesRare;

/// <summary>
/// A weighted random prototype for how rare each tier should be.
/// </summary>
[DataField("tierWeightPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomPrototype>))]
public string TierWeightPrototype = "TechDiskTierWeights";

/// <summary>
/// A weighted random prototype for how rare each tier should be.
/// </summary>
[DataField("tierWeightPrototypeRare", customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomPrototype>))]
public string TierWeightPrototypeRare = "RareTechDiskTierWeights";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Research.Systems;
using Content.Server.Research.Systems;
using Content.Server.Research.TechnologyDisk.Components;
using Content.Server.UserInterface;
using Content.Shared.Research;
Expand All @@ -19,6 +19,7 @@ public sealed class DiskConsoleSystem : EntitySystem
public override void Initialize()
{
SubscribeLocalEvent<DiskConsoleComponent, DiskConsolePrintDiskMessage>(OnPrintDisk);
SubscribeLocalEvent<DiskConsoleComponent, DiskConsolePrintRareDiskMessage>(OnPrintRareDisk); // Frontier
SubscribeLocalEvent<DiskConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
SubscribeLocalEvent<DiskConsoleComponent, ResearchRegistrationChangedEvent>(OnRegistrationChanged);
SubscribeLocalEvent<DiskConsoleComponent, BeforeActivatableUIOpenEvent>(OnBeforeUiOpen);
Expand All @@ -37,7 +38,10 @@ public override void Update(float frameTime)
continue;

RemComp(uid, printing);
Spawn(console.DiskPrototype, xform.Coordinates);
if (!console.DiskRare)
Spawn(console.DiskPrototype, xform.Coordinates);
else
Spawn(console.DiskPrototypeRare, xform.Coordinates);
}
}

Expand All @@ -57,6 +61,27 @@ private void OnPrintDisk(EntityUid uid, DiskConsoleComponent component, DiskCons

var printing = EnsureComp<DiskConsolePrintingComponent>(uid);
printing.FinishTime = _timing.CurTime + component.PrintDuration;
component.DiskRare = false;
UpdateUserInterface(uid, component);
}

private void OnPrintRareDisk(EntityUid uid, DiskConsoleComponent component, DiskConsolePrintRareDiskMessage args) // Frontier
{
if (HasComp<DiskConsolePrintingComponent>(uid))
return;

if (!_research.TryGetClientServer(uid, out var server, out var serverComp))
return;

if (serverComp.Points < component.PricePerRareDisk)
return;

_research.ModifyServerPoints(server.Value, -component.PricePerRareDisk, serverComp);
_audio.PlayPvs(component.PrintSound, uid);

var printing = EnsureComp<DiskConsolePrintingComponent>(uid);
printing.FinishTime = _timing.CurTime + component.PrintDuration;
component.DiskRare = true;
UpdateUserInterface(uid, component);
}

Expand Down Expand Up @@ -89,7 +114,10 @@ public void UpdateUserInterface(EntityUid uid, DiskConsoleComponent? component =
var canPrint = !(TryComp<DiskConsolePrintingComponent>(uid, out var printing) && printing.FinishTime >= _timing.CurTime) &&
totalPoints >= component.PricePerDisk;

var state = new DiskConsoleBoundUserInterfaceState(totalPoints, component.PricePerDisk, canPrint);
var canPrintRare = !(TryComp<DiskConsolePrintingComponent>(uid, out var printingRare) && printingRare.FinishTime >= _timing.CurTime) &&
totalPoints >= component.PricePerRareDisk;

var state = new DiskConsoleBoundUserInterfaceState(totalPoints, component.PricePerDisk, component.PricePerRareDisk, canPrint, canPrintRare);
_ui.TrySetUiState(uid, DiskConsoleUiKey.Key, state);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.Popups;
using Content.Server.Research.Systems;
using Content.Server.Research.TechnologyDisk.Components;
Expand Down Expand Up @@ -88,5 +88,28 @@ private void OnMapInit(EntityUid uid, TechnologyDiskComponent component, MapInit
//pick one
component.Recipes = new();
component.Recipes.Add(_random.Pick(techs));

if (component.RecipesRare != null)
return;

var weightedRandomRare = _prototype.Index<WeightedRandomPrototype>(component.TierWeightPrototypeRare);
var tierRare = int.Parse(weightedRandomRare.Pick(_random));

var techsRare = new List<ProtoId<LatheRecipePrototype>>();
foreach (var techRare in _prototype.EnumeratePrototypes<TechnologyPrototype>())
{
if (techRare.Tier != tierRare)
continue;

techsRare.AddRange(techRare.RecipeUnlocks);
}
techsRare = techsRare.Distinct().ToList();

if (!techsRare.Any())
return;

//pick one
component.RecipesRare = new();
component.RecipesRare.Add(_random.Pick(techsRare));
}
}
14 changes: 12 additions & 2 deletions Content.Shared/Research/SharedDiskConsole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Serialization;
using Robust.Shared.Serialization;

namespace Content.Shared.Research;

Expand All @@ -12,13 +12,17 @@ public enum DiskConsoleUiKey : byte
public sealed class DiskConsoleBoundUserInterfaceState : BoundUserInterfaceState
{
public bool CanPrint;
public bool CanPrintRare;
public int PointCost;
public int PointCostRare;
public int ServerPoints;

public DiskConsoleBoundUserInterfaceState(int serverPoints, int pointCost, bool canPrint)
public DiskConsoleBoundUserInterfaceState(int serverPoints, int pointCost, int pointCostRare, bool canPrint, bool canPrintRare)
{
CanPrint = canPrint;
CanPrintRare = canPrintRare;
PointCost = pointCost;
PointCostRare = pointCostRare;
ServerPoints = serverPoints;
}
}
Expand All @@ -28,3 +32,9 @@ public sealed class DiskConsolePrintDiskMessage : BoundUserInterfaceMessage
{

}

[Serializable, NetSerializable]
public sealed class DiskConsolePrintRareDiskMessage : BoundUserInterfaceMessage
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ tech-disk-examine-more = There are more images printed, but they're too small to
tech-disk-ui-name = technology disk terminal
tech-disk-ui-total-label = There are {$amount} points on the selected server
tech-disk-ui-cost-label = Each disk costs {$amount} points to print
tech-disk-ui-print-button = Print Disk
tech-disk-ui-print-button = Print Disk ({$amount})
tech-disk-ui-print-rare-button = Print Rare Disk ({$amount})
10 changes: 5 additions & 5 deletions Resources/Prototypes/Entities/Objects/Specific/Research/disk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- type: ResearchDisk
points: 5000
- type: StaticPrice
price: 200 # Why was this worth nothing, NT want to buy this!
price: 1500 # Frontier - To be fair, its worth half a tech disk, but we still require tech to print it so its lower.

- type: entity
parent: ResearchDisk
Expand All @@ -32,7 +32,7 @@
- type: ResearchDisk
points: 10000
- type: StaticPrice
price: 400 # Why was this worth nothing, NT want to buy this!
price: 3000 # Frontier - To be fair, its worth a tech disk, but we still require tech to print it so its lower.

- type: entity
parent: ResearchDisk
Expand Down Expand Up @@ -61,14 +61,14 @@
- enum.DamageStateVisualLayers.Base:
datadisk_base: Sixteen
- type: TechnologyDisk
tierWeightPrototype: TechDiskTierWeights # Frontier
- type: StaticPrice
price: 550 # It's still need to be worth it, but as it was stranding (1000) it was too much
price: 5000 # Frontier - Rebalance

- type: entity
parent: TechnologyDisk
id: TechnologyDiskRare
suffix: rare.
components:
- type: TechnologyDisk
tierWeightPrototype: RareTechDiskTierWeights
price: 750 # It's still need to be worth it, but as it was stranding (1000) it was too much
tierWeightPrototype: RareTechDiskTierWeights # Frontier

0 comments on commit d166353

Please sign in to comment.