-
Notifications
You must be signed in to change notification settings - Fork 154
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||||||||||||||||||||||
|
||||||||||||||||||||||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||||||||||||||||||||||
public int usable = 0; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Добавьте проверку значения usable Поле Рекомендуемые изменения: - public int usable = 0;
+ /// <summary>
+ /// Количество оставшихся использований улучшения.
+ /// </summary>
+ [DataField]
+ [ViewVariables(VVAccess.ReadWrite)]
+ public int usable = 1; 📝 Committable suggestion
Suggested change
|
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); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
There was a problem hiding this comment.
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 для публичных полей).Предлагаемые изменения: