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

[Port] Universal Upgrader #950

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

namespace Content.Server._Special.UniversalUpgrader.Components;

[RegisterComponent]
public sealed partial class UPComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string upgradeName;

[DataField, ViewVariables(VVAccess.ReadWrite)]
public string componentName;

[DataField, ViewVariables(VVAccess.ReadWrite)]
public string upgradeValue;

[DataField, ViewVariables(VVAccess.ReadWrite)]
public string ProtoWhitelist;

Comment on lines +16 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Исправьте именование и добавьте документацию для ProtoWhitelist

Поле ProtoWhitelist нарушает конвенцию именования (Pascal Case для публичных полей).

Предлагаемые изменения:

-    public string ProtoWhitelist;
+    /// <summary>
+    /// Список разрешенных прототипов для улучшения.
+    /// </summary>
+    [DataField]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string? protoWhitelist;

Committable suggestion skipped: line range outside the PR's diff.

[DataField, ViewVariables(VVAccess.ReadWrite)]
public int usable = 0;
}
Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Добавьте проверку значения usable

Поле usable инициализируется нулем, что может привести к неправильному поведению компонента.

Рекомендуемые изменения:

-    public int usable = 0;
+    /// <summary>
+    /// Количество оставшихся использований улучшения.
+    /// </summary>
+    [DataField]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public int usable = 1;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int usable = 0;
}
/// <summary>
/// Количество оставшихся использований улучшения.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public int usable = 1;
}

56 changes: 56 additions & 0 deletions Content.Server/_Special/UniversalUpgrader/Systems/UPSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Linq;
using Content.Server.DoAfter;
using Content.Server._Special.UniversalUpgrader.Components;
using Content.Shared.Interaction;
using Robust.Shared.Prototypes;

namespace Content.Server._Special.UniversalUpgrader.Systems;

public sealed class UPSystem : EntitySystem
{

[Dependency] private readonly EntityManager _ent = default!;
[Dependency] private readonly IComponentFactory _compFact = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<UPComponent, AfterInteractEvent>(OnInteract);
}

private void OnInteract(Entity<UPComponent> entity, ref AfterInteractEvent args)
{
if (!args.CanReach || args.Target is not { Valid: true } target)
return;
if (entity.Comp.ProtoWhitelist != "" && HasComp<MetaDataComponent>(target))
{
var z = _ent.GetComponent<MetaDataComponent>(target);
if (!entity.Comp.ProtoWhitelist.Split(" ").Contains(z.EntityPrototype!.ID))
return;
}

var test = _compFact.GetRegistration(entity.Comp.componentName);

if (_ent.TryGetComponent(target, test.Type, out var comp))
{
var t = entity.Comp.upgradeName.Split(' ').Length;
for (int i = 0; i < t; i++)
{
var un = entity.Comp.upgradeName.Split(' ')[i];
var uv = entity.Comp.upgradeValue.Split(' ')[i];
var h = comp.GetType().GetField(un);

if (h != null && uv != null)
{
h.SetValue(h.FieldType, uv );
}
}

entity.Comp.usable -= 1;
if (entity.Comp.usable < 0) _ent.QueueDeleteEntity(entity);

}
}

}


1 change: 1 addition & 0 deletions Content.Server/_Special/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Loading