Seed analyzer (#433)

* hey

* added it to vending machine

* added to vending

* лицензия спрайта

* Update SeedAnalyzerWindow.xaml.cs

* fix my recently added bug

* обосрался знатно, пофиксил

* fix всего кроме null проверки

---------

Co-authored-by: melano <VildanMinnakhmetov>
Co-authored-by: KurokoTurbo <92106367+VildanMinnakhmetov@users.noreply.github.com>
This commit is contained in:
KurokoTurbo
2023-10-01 05:55:21 +03:00
committed by Aviu00
parent bb3d54e753
commit fb8834ac63
14 changed files with 515 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
using Content.Shared.Botany;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.SeedAnalyzer.UI
{
[UsedImplicitly]
public sealed class SeedAnalyzerBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private SeedAnalyzerWindow? _window;
public SeedAnalyzerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new SeedAnalyzerWindow
{
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
};
_window.OnClose += Close;
_window.OpenCentered();
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
if (_window == null)
return;
if (message is not SeedAnalyzerScannedUserMessage cast)
return;
_window.Populate(cast);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
if (_window != null)
_window.OnClose -= Close;
_window?.Dispose();
}
}
}

View File

@@ -0,0 +1,9 @@
<DefaultWindow xmlns="https://spacestation14.io"
MinSize="250 100"
SetSize="250 100">
<BoxContainer Orientation="Vertical">
<Label
Name="Diagnostics"
Text="{Loc seed-analyzer-window-no-plant-data-text}"/>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,102 @@
using System.Numerics;
using System.Text;
using Content.Shared.FixedPoint;
using Content.Shared.Botany;
using Robust.Client.AutoGenerated; //probably useless
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Content.Shared.Chemistry.Reagent;
namespace Content.Client.SeedAnalyzer.UI
{
[GenerateTypedNameReferences]
public sealed partial class SeedAnalyzerWindow : DefaultWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public SeedAnalyzerWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
}
public void Populate(SeedAnalyzerScannedUserMessage msg)
{
var text = new StringBuilder();
var entities = IoCManager.Resolve<IEntityManager>(); // maybe bad
if (msg.TargetEntity != null) // this may be bad, maybe && entities.TryGetComponent<SeedComponent>(msg.TargetEntity, out var seed)
{
string entityName = "Unknown"; // без этой строки все ломается и я не знаю почему
if (msg.Viable == false)
{
text.Append($"{Loc.GetString("seed-analyzer-window-entity-viable-text")}\n");
}
if (msg.TurnIntoKudzu == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-turnintokudzu-text")}\n");
}
text.Append($"{Loc.GetString("seed-analyzer-window-entity-endurance-text", ("endurance", msg.Endurance!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-yield-text", ("yield", msg.Yield!))}"); //maybe msg.Yield.HasValue ? "N/A" : $"{msg.Yield}"
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-maturation-text", ("maturation", msg.Maturation!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-production-text", ("production", msg.Production!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-lifespan-text", ("lifespan", msg.Lifespan!))}");
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-potency-text", ("potency", msg.Potency!))}");
int zero = 0;
var zero2 = FixedPoint2.New(zero);
Dictionary<string, FixedPoint2> nodic = new Dictionary<string, FixedPoint2>();
nodic.Add("\nNo chemicals", zero2);
if (msg.Chemicals != nodic && msg.Chemicals != null)
{
//text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-chemicals-text")}");
foreach (var (chemical, amount) in msg.Chemicals!)
{
var localizedName = _prototypeManager.TryIndex(chemical, out ReagentPrototype? p) ? p.LocalizedName : Loc.GetString("seed-analyzer-window-reagent-name-not-found-text"); //maybe Loc.GetString("seed-analyzer-window-reagent-name-not-found-text")
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-chemical-text", ("localizedName", localizedName))}");
text.Append($" {Loc.GetString("seed-analyzer-window-entity-amount-text", ("amount", amount))}");
}
}
if (msg.Ligneous == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-ligneous-text")}");
}
if (msg.CanScream == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-canscream-text")}");
}
if (msg.Slip == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-slip-text")}");
}
if (msg.Bioluminescent == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-bioluminescent-text")}");
}
if (msg.Sentient == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-sentient-text")}");
}
if (msg.Seedless == true)
{
text.Append($"\n{Loc.GetString("seed-analyzer-window-entity-seedless-text")}");
}
Diagnostics.Text = text.ToString();
SetSize = new Vector2(250, 600);
}
else
{
Diagnostics.Text = Loc.GetString("seed-analyzer-window-no-plant-data-text");
SetSize = new Vector2(250, 100);
}
}
}
}

View File

@@ -0,0 +1,32 @@
using Content.Server.UserInterface;
using Content.Shared.Botany;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
namespace Content.Server.Botany.Components
{
/// <summary>
/// After scanning, retrieves the target Uid to use with its related UI.
/// </summary>
[RegisterComponent]
public sealed partial class SeedAnalyzerComponent : Component
{
/// <summary>
/// How long it takes to scan a seed.
/// </summary>
[DataField("scanDelay")]
public float ScanDelay = 0.8f;
/// <summary>
/// Sound played on scanning begin
/// </summary>
[DataField("scanningBeginSound")]
public SoundSpecifier? ScanningBeginSound;
/// <summary>
/// Sound played on scanning end
/// </summary>
[DataField("scanningEndSound")]
public SoundSpecifier? ScanningEndSound;
}
}

View File

@@ -0,0 +1,117 @@
using Content.Server.Botany.Components;
using Content.Server.PowerCell;
using Content.Shared.FixedPoint;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Botany;
using Content.Shared.Mobs.Components; //probably useless
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
namespace Content.Server.Botany
{
public sealed class SeedAnalyzerSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _cell = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SeedAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<SeedAnalyzerComponent, SeedAnalyzerDoAfterEvent>(OnDoAfter);
}
private void OnAfterInteract(EntityUid uid, SeedAnalyzerComponent seedAnalyzer, AfterInteractEvent args)
{
if (args.Target == null || !args.CanReach || !HasComp<PlantHolderComponent>(args.Target) || !_cell.HasActivatableCharge(uid, user: args.User))
return;
_audio.PlayPvs(seedAnalyzer.ScanningBeginSound, uid); // maybe healthAnalyzer.ScanningBeginSound
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, seedAnalyzer.ScanDelay, new SeedAnalyzerDoAfterEvent(), uid, target: args.Target, used: uid) //maybe healthAnalyzer.ScanDelay
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
NeedHand = true
});
}
private void OnDoAfter(EntityUid uid, SeedAnalyzerComponent component, DoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Args.Target == null || !_cell.TryUseActivatableCharge(uid, user: args.User))
return;
_audio.PlayPvs(component.ScanningEndSound, args.Args.User);
UpdateScannedSeed(uid, args.Args.User, args.Args.Target.Value, component);
args.Handled = true;
}
private void OpenUserInterface(EntityUid user, EntityUid seedAnalyzer)
{
if (!TryComp<ActorComponent>(user, out var actor) || !_uiSystem.TryGetUi(seedAnalyzer, SeedAnalyzerUiKey.Key, out var ui))
return;
_uiSystem.OpenUi(ui, actor.PlayerSession);
}
public void UpdateScannedSeed(EntityUid uid, EntityUid user, EntityUid? target, SeedAnalyzerComponent? seedAnalyzer)
{
if (!Resolve(uid, ref seedAnalyzer))
return;
if (target == null || !_uiSystem.TryGetUi(uid, SeedAnalyzerUiKey.Key, out var ui))
return;
if (!TryComp<PlantHolderComponent>(target, out var plant))
return;
if (plant!.Seed == null)
{
return;
}
int zero = 0;
string nonameseed = "None";
Dictionary<string, FixedPoint2> emptydic = new Dictionary<string, FixedPoint2>();
var zero2 = FixedPoint2.New(zero);
emptydic?.Add("No chemicals", zero2!);
Dictionary<string, FixedPoint2> passchems = new Dictionary<string, FixedPoint2>();
if (plant?.Seed?.Chemicals != null)
{
foreach (var (chem, quantity) in plant.Seed.Chemicals)
{
var amount = FixedPoint2.New(quantity.Min);
amount += FixedPoint2.New(plant.Seed.Potency / quantity.PotencyDivisor);
amount = FixedPoint2.New((int) MathHelper.Clamp(amount.Float(), quantity.Min, quantity.Max));
passchems?.Add(chem, amount);
}
}
OpenUserInterface(user, uid);
_uiSystem.SendUiMessage(ui, new SeedAnalyzerScannedUserMessage(GetNetEntity(target),
plant!.Seed?.Yield,
plant != null ? plant.Seed?.Production : float.NaN,
plant != null ? plant.Seed?.Lifespan : float.NaN,
plant != null ? plant.Seed?.Maturation : float.NaN,
plant != null ? plant.Seed?.Endurance : float.NaN,
plant != null ? plant.Seed?.Potency : float.NaN,
plant != null ? plant.Seed?.Viable : false,
plant != null ? plant.Seed?.TurnIntoKudzu : false,
plant != null ? plant.Seed?.Seedless : false,
plant != null ? plant.Seed?.DisplayName : nonameseed,
passchems != null ? passchems : emptydic,
plant != null ? plant.Seed?.Ligneous : false,
plant != null ? plant.Seed?.CanScream : false,
plant != null ? plant.Seed?.Slip : false,
plant != null ? plant.Seed?.Bioluminescent : false,
plant != null ? plant.Seed?.Sentient : false));
}
}
}

View File

@@ -0,0 +1,9 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Botany;
[Serializable, NetSerializable]
public sealed partial class SeedAnalyzerDoAfterEvent : SimpleDoAfterEvent
{
}

View File

@@ -0,0 +1,81 @@
using Robust.Shared.Serialization;
using Content.Shared.FixedPoint;
namespace Content.Shared.Botany;
/// <summary>
/// On interacting with an entity retrieves the entity UID for use with getting the current SeedData of the seed.
/// </summary>
[Serializable, NetSerializable]
public sealed class SeedAnalyzerScannedUserMessage : BoundUserInterfaceMessage
{
public readonly NetEntity? TargetEntity;
public int? Yield;
public float? Production;
public float? Lifespan;
public float? Maturation;
public float? Endurance;
public float? Potency;
public bool? Viable;
public bool? TurnIntoKudzu;
public bool? Seedless;
public Dictionary<string, FixedPoint2>? Chemicals;
public string? DisplayName;
public bool? CanScream;
public bool? Slip;
public bool? Sentient;
public bool? Ligneous;
public bool? Bioluminescent;
public SeedAnalyzerScannedUserMessage(NetEntity? targetEntity,
int? yield,
float? production,
float? lifespan,
float? maturation,
float? endurance,
float? potency,
bool? viable,
bool? turnIntoKudzu,
bool? seedless,
string? displayName,
Dictionary<string, FixedPoint2>? chemicals,
bool? ligneous,
bool? canScream,
bool? slip,
bool? bioluminescent,
bool? sentient)
{
TargetEntity = targetEntity;
DisplayName = displayName; //broken for unknown reason
Viable = viable;
TurnIntoKudzu = turnIntoKudzu;
// general traits
Yield = yield;
Production = production;
Endurance = endurance;
Chemicals = chemicals;
Potency = potency;
Lifespan = lifespan;
Maturation = maturation;
Seedless = seedless;
Endurance = endurance;
Ligneous = ligneous;
// minor traits
//ConsumeGasses = consumeGasses;
//ExudeGasses = exudeGasses;
//NutrientConsumption = nutrientConsumption;
//WaterConsumption = waterConsumption;
//IdealHeat = idealHeat;
//LowPressureTolerance = lowPressureTolerance;
//HighPressureTolerance = highPressureTolerance;
// mutations
CanScream = canScream;
Bioluminescent = bioluminescent;
}
}

View File

@@ -0,0 +1,9 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Botany;
[Serializable, NetSerializable]
public enum SeedAnalyzerUiKey : byte
{
Key
}

View File

@@ -0,0 +1,37 @@
seed-analyzer-window-entity-name-text = Растение: {$name}
seed-analyzer-window-entity-viable-text = Это растение нежизнеспособно, оно скоро погибнет.
seed-analyzer-window-entity-traits-text = Черты:
seed-analyzer-window-entity-traits-text = Нет интересных черт(
seed-analyzer-window-entity-chemicals-text = Химикаты:
seed-analyzer-window-entity-chemical-text = {$localizedName}:
seed-analyzer-window-entity-amount-text = {$amount}u
seed-analyzer-window-entity-consumeGasses-text = Seed: {$name}
seed-analyzer-window-entity-exudeGasses-text = Seed: {$name}
seed-analyzer-window-entity-nutrientConsumption-text = Seed: {$name}
seed-analyzer-window-entity-waterConsumption-text = Seed: {$name}
seed-analyzer-window-entity-seedless-text = Безсемянное
seed-analyzer-window-entity-heatTolerance-text = a
seed-analyzer-window-entity-idealLight-text = b
seed-analyzer-window-entity-toxinsTolerance-text = d
seed-analyzer-window-entity-lowPressureTolerance-text = c
seed-analyzer-window-entity-highPressureTolerance-text = e
seed-analyzer-window-entity-pestTolerance-text = f
seed-analyzer-window-entity-weedTolerance-text = g
seed-analyzer-window-entity-weedHighLevelThreshold-text = h
seed-analyzer-window-entity-endurance-text = Здоровье: {$endurance}
seed-analyzer-window-entity-yield-text = Урожайность: {$yield}
seed-analyzer-window-entity-lifespan-text = Продолжительность жизни: {$lifespan}
seed-analyzer-window-entity-maturation-text = Время роста: {$maturation}
seed-analyzer-window-entity-production-text = Время до урожая: {$production}
seed-analyzer-window-entity-harvestRepeat-text = i
seed-analyzer-window-entity-potency-text = Потенция: {$potency}
seed-analyzer-window-entity-slip-text = Скользкий урожай
seed-analyzer-window-entity-sentient-text = Разумное
seed-analyzer-window-entity-ligneous-text = Древесное
seed-analyzer-window-entity-canscream-text = Кричащее
seed-analyzer-window-entity-bioluminescent-text = Светящийся урожай
seed-analyzer-window-entity-bioluminescentColor-text = j
seed-analyzer-window-entity-turnintokudzu-text = Внимание: аномальная активность сорняков.
seed-analyzer-window-entity-kudzuPrototype-text = k
seed-analyzer-window-no-plant-data-text = Нет данных.
seed-analyzer-window-reagent-name-not-found-text = Неизвестный реагент

View File

@@ -16,3 +16,12 @@ ent-HydroponicsToolSpade = лопатка
ent-PlantBag = сумка для растений
.desc = Сумка для ботаников, чтобы легко переносить свои огромные урожаи.
.suffix = { "" }
ent-HandheldSeedAnalyzerUnpowered = сканер растений (без питания)
.desc = Показывает характеристики растения.
.suffix = { "" }
ent-HandheldSeedAnalyzer = сканер растений
.desc = Показывает характеристики растения.
.suffix = { "" }
ent-HandheldSeedAnalyzerEmpty = сканер растений (пустой)
.desc = Показывает характеристики растения.
.suffix = { "" }

View File

@@ -6,7 +6,8 @@
HydroponicsToolClippers: 4
HydroponicsToolScythe: 4
HydroponicsToolHatchet: 4
PlantBag: 3
PlantBag: 4
HandheldSeedAnalyzer: 4
PlantBGoneSpray: 20
WeedSpray: 20
PestSpray: 20

View File

@@ -0,0 +1,43 @@
- type: entity
id: HandheldSeedAnalyzerUnpowered
parent: BaseItem
name: seed analyzer
description: A hand-held seed scanner capable of deciphering genes of the subject.
components:
- type: Sprite
sprite: Objects/Specific/Hydroponics/seed_analyzer.rsi
state: icon
- type: ActivatableUI
key: enum.SeedAnalyzerUiKey.Key
closeOnHandDeselect: false
- type: UserInterface
interfaces:
- key: enum.SeedAnalyzerUiKey.Key
type: SeedAnalyzerBoundUserInterface
- type: SeedAnalyzer
scanningEndSound:
path: "/Audio/Items/Medical/healthscanner.ogg"
- type: Tag
tags:
- DiscreteHealthAnalyzer
- type: Appearance
- type: entity
id: HandheldSeedAnalyzer
parent: [ HandheldSeedAnalyzerUnpowered, PowerCellSlotSmallItem]
suffix: Powered
components:
- type: PowerCellDraw
drawRate: 0
useRate: 5
- type: ActivatableUIRequiresPowerCell
- type: entity
id: HandheldSeedAnalyzerEmpty
parent: HandheldSeedAnalyzer
suffix: Empty
components:
- type: ItemSlots
slots:
cell_slot:
name: power-cell-slot-component-slot-name-default

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"license": "CC-BY-NC-SA-3.0",
"copyright": "Taken from goonstation",
"states": [
{
"name": "icon"
}
]
}