Sharedization of entityEffects and crystals slots system
This commit is contained in:
@@ -11,128 +11,4 @@ namespace Content.Server._CP14.MagicEnergy;
|
||||
|
||||
public sealed class CP14MagicEnergyCrystalSlotSystem : SharedCP14MagicEnergyCrystalSlotSystem
|
||||
{
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
|
||||
[Dependency] private readonly CP14MagicEnergySystem _magicEnergy = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalComponent, CP14MagicEnergyLevelChangeEvent>(OnEnergyChanged);
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, CP14SlotCrystalChangedEvent>(OnCrystalChanged);
|
||||
}
|
||||
|
||||
private void OnCrystalChanged(Entity<CP14MagicEnergyCrystalSlotComponent> ent, ref CP14SlotCrystalChangedEvent args)
|
||||
{
|
||||
var realPowered = TryGetEnergyCrystalFromSlot((ent, ent), out var energyComp);
|
||||
if (energyComp is not null)
|
||||
realPowered = energyComp.Value.Comp.Energy > 0;
|
||||
|
||||
if (ent.Comp.Powered == realPowered)
|
||||
return;
|
||||
|
||||
ent.Comp.Powered = realPowered;
|
||||
_appearance.SetData(ent, CP14MagicSlotVisuals.Powered, realPowered);
|
||||
|
||||
RaiseLocalEvent(ent, new CP14SlotCrystalPowerChangedEvent(realPowered));
|
||||
}
|
||||
|
||||
private void OnEnergyChanged(Entity<CP14MagicEnergyCrystalComponent> crystal, ref CP14MagicEnergyLevelChangeEvent args)
|
||||
{
|
||||
if (!_container.TryGetContainingContainer((crystal.Owner, null, null), out var container))
|
||||
return;
|
||||
|
||||
if (!TryComp(container.Owner, out CP14MagicEnergyCrystalSlotComponent? slot))
|
||||
return;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(container.Owner, slot.SlotId, out var itemSlot))
|
||||
return;
|
||||
|
||||
if (itemSlot.Item != crystal)
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(container.Owner, new CP14SlotCrystalChangedEvent(false));
|
||||
}
|
||||
|
||||
private void OnExamined(Entity<CP14MagicEnergyCrystalSlotComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot((ent, ent), out var energyEnt))
|
||||
return;
|
||||
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
// TODO: scan energy ability
|
||||
// var scanEvent = new CP14MagicEnergyScanEvent();
|
||||
// RaiseLocalEvent(args.Examiner, scanEvent);
|
||||
//
|
||||
// if (!scanEvent.CanScan)
|
||||
// return;
|
||||
|
||||
args.PushMarkup(_magicEnergy.GetEnergyExaminedText((energyEnt.Value, energyEnt)));
|
||||
}
|
||||
|
||||
public bool TryGetEnergyCrystalFromSlot(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
[NotNullWhen(true)] out Entity<CP14MagicEnergyContainerComponent>? energyEnt)
|
||||
{
|
||||
energyEnt = null;
|
||||
|
||||
if (!Resolve(ent, ref ent.Comp, false))
|
||||
return false;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(ent, ent.Comp.SlotId, out var slot))
|
||||
return false;
|
||||
|
||||
if (slot.Item is null)
|
||||
return false;
|
||||
|
||||
if (!TryComp<CP14MagicEnergyContainerComponent>(slot.Item, out var energyComp))
|
||||
return false;
|
||||
|
||||
energyEnt = (slot.Item.Value, energyComp);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasEnergy(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
FixedPoint2 energy,
|
||||
EntityUid? user = null)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot(ent, out var energyEnt))
|
||||
{
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-no-crystal"), ent,user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (energyEnt.Value.Comp.Energy >= energy)
|
||||
return true;
|
||||
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-insufficient"), ent, user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryChangeEnergy(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
FixedPoint2 energy,
|
||||
EntityUid? user = null,
|
||||
bool safe = false)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot(ent, out var energyEnt))
|
||||
{
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-no-crystal"), ent, user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_magicEnergy.ChangeEnergy((energyEnt.Value, energyEnt.Value), energy, out _, out _, safe);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using Content.Shared.EntityEffects;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Chemistry.ReagentEffect;
|
||||
namespace Content.Shared._CP14.Chemistry.ReagentEffect;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
@@ -12,8 +12,7 @@ public sealed partial class CP14AffectSolutionTemperature : EntityEffect
|
||||
/// Temperature added to the solution. If negative, the solution is cooling.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
private float AddTemperature = -300f;
|
||||
|
||||
public float AddTemperature = -300f;
|
||||
|
||||
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.EntityEffects;
|
||||
@@ -6,7 +5,7 @@ using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Chemistry.ReagentEffect;
|
||||
namespace Content.Shared._CP14.Chemistry.ReagentEffect;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
@@ -14,6 +13,7 @@ public sealed partial class CP14InverseEffect : EntityEffect
|
||||
{
|
||||
[DataField]
|
||||
public Dictionary<ProtoId<ReagentPrototype>, ProtoId<ReagentPrototype>> Inversion = new();
|
||||
|
||||
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
return Loc.GetString("cp14-reagent-effect-guidebook-inverse-effect", ("chance", Probability));
|
||||
@@ -1,11 +1,11 @@
|
||||
using Content.Server._CP14.MagicEnergy;
|
||||
using Content.Shared._CP14.MagicEnergy;
|
||||
using Content.Shared._CP14.MagicEnergy.Components;
|
||||
using Content.Shared.EntityEffects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Chemistry.ReagentEffect;
|
||||
namespace Content.Shared._CP14.Chemistry.ReagentEffect;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
@@ -35,7 +35,7 @@ public sealed partial class CP14ManaChange : EntityEffect
|
||||
if (args is EntityEffectReagentArgs reagentArgs)
|
||||
scale = ScaleByQuantity ? reagentArgs.Quantity * reagentArgs.Scale : reagentArgs.Scale;
|
||||
|
||||
var magicSystem = entityManager.System<CP14MagicEnergySystem>();
|
||||
var magicSystem = entityManager.System<SharedCP14MagicEnergySystem>();
|
||||
magicSystem.ChangeEnergy(args.TargetEntity, ManaDelta * scale, out var changed, out var overload, safe: Safe);
|
||||
|
||||
scale -= FixedPoint2.Abs(changed + overload);
|
||||
@@ -43,7 +43,7 @@ public sealed partial class CP14ManaChange : EntityEffect
|
||||
if (!args.EntityManager.TryGetComponent<CP14MagicEnergyCrystalSlotComponent>(args.TargetEntity, out var crystalSlot))
|
||||
return;
|
||||
|
||||
var slotSystem = entityManager.System<CP14MagicEnergyCrystalSlotSystem>();
|
||||
var slotSystem = entityManager.System<SharedCP14MagicEnergyCrystalSlotSystem>();
|
||||
slotSystem.TryChangeEnergy((args.TargetEntity, crystalSlot), ManaDelta * scale);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Content.Shared.EntityEffects;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Chemistry.ReagentEffect;
|
||||
namespace Content.Shared._CP14.Chemistry.ReagentEffect;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
@@ -1,5 +1,9 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared._CP14.MagicEnergy.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Shared._CP14.MagicEnergy;
|
||||
@@ -7,6 +11,10 @@ namespace Content.Shared._CP14.MagicEnergy;
|
||||
public abstract class SharedCP14MagicEnergyCrystalSlotSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
|
||||
[Dependency] private readonly SharedCP14MagicEnergySystem _magicEnergy = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -14,6 +22,11 @@ public abstract class SharedCP14MagicEnergyCrystalSlotSystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, EntInsertedIntoContainerMessage>(OnCrystalInserted);
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, EntRemovedFromContainerMessage>(OnCrystalRemoved);
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalComponent, CP14MagicEnergyLevelChangeEvent>(OnEnergyChanged);
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<CP14MagicEnergyCrystalSlotComponent, CP14SlotCrystalChangedEvent>(OnCrystalChanged);
|
||||
}
|
||||
|
||||
private void OnCrystalRemoved(Entity<CP14MagicEnergyCrystalSlotComponent> slot, ref EntRemovedFromContainerMessage args)
|
||||
@@ -37,4 +50,105 @@ public abstract class SharedCP14MagicEnergyCrystalSlotSystem : EntitySystem
|
||||
_appearance.SetData(slot, CP14MagicSlotVisuals.Inserted, true);
|
||||
RaiseLocalEvent(slot, new CP14SlotCrystalChangedEvent(false));
|
||||
}
|
||||
|
||||
public bool TryGetEnergyCrystalFromSlot(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
[NotNullWhen(true)] out Entity<CP14MagicEnergyContainerComponent>? energyEnt)
|
||||
{
|
||||
energyEnt = null;
|
||||
|
||||
if (!Resolve(ent, ref ent.Comp, false))
|
||||
return false;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(ent, ent.Comp.SlotId, out var slot))
|
||||
return false;
|
||||
|
||||
if (slot.Item is null)
|
||||
return false;
|
||||
|
||||
if (!TryComp<CP14MagicEnergyContainerComponent>(slot.Item, out var energyComp))
|
||||
return false;
|
||||
|
||||
energyEnt = (slot.Item.Value, energyComp);
|
||||
return true;
|
||||
}
|
||||
public bool HasEnergy(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
FixedPoint2 energy,
|
||||
EntityUid? user = null)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot(ent, out var energyEnt))
|
||||
{
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-no-crystal"), ent,user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (energyEnt.Value.Comp.Energy >= energy)
|
||||
return true;
|
||||
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-insufficient"), ent, user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryChangeEnergy(Entity<CP14MagicEnergyCrystalSlotComponent?> ent,
|
||||
FixedPoint2 energy,
|
||||
EntityUid? user = null,
|
||||
bool safe = false)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot(ent, out var energyEnt))
|
||||
{
|
||||
if (user is not null)
|
||||
_popup.PopupEntity(Loc.GetString("cp14-magic-energy-no-crystal"), ent, user.Value);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_magicEnergy.ChangeEnergy((energyEnt.Value, energyEnt.Value), energy, out _, out _, safe);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnCrystalChanged(Entity<CP14MagicEnergyCrystalSlotComponent> ent, ref CP14SlotCrystalChangedEvent args)
|
||||
{
|
||||
var realPowered = TryGetEnergyCrystalFromSlot((ent, ent), out var energyComp);
|
||||
if (energyComp is not null)
|
||||
realPowered = energyComp.Value.Comp.Energy > 0;
|
||||
|
||||
if (ent.Comp.Powered == realPowered)
|
||||
return;
|
||||
|
||||
ent.Comp.Powered = realPowered;
|
||||
_appearance.SetData(ent, CP14MagicSlotVisuals.Powered, realPowered);
|
||||
|
||||
RaiseLocalEvent(ent, new CP14SlotCrystalPowerChangedEvent(realPowered));
|
||||
}
|
||||
|
||||
private void OnEnergyChanged(Entity<CP14MagicEnergyCrystalComponent> crystal, ref CP14MagicEnergyLevelChangeEvent args)
|
||||
{
|
||||
if (!_container.TryGetContainingContainer((crystal.Owner, null, null), out var container))
|
||||
return;
|
||||
|
||||
if (!TryComp(container.Owner, out CP14MagicEnergyCrystalSlotComponent? slot))
|
||||
return;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(container.Owner, slot.SlotId, out var itemSlot))
|
||||
return;
|
||||
|
||||
if (itemSlot.Item != crystal)
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(container.Owner, new CP14SlotCrystalChangedEvent(false));
|
||||
}
|
||||
|
||||
private void OnExamined(Entity<CP14MagicEnergyCrystalSlotComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
if (!TryGetEnergyCrystalFromSlot((ent, ent), out var energyEnt))
|
||||
return;
|
||||
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
args.PushMarkup(_magicEnergy.GetEnergyExaminedText((energyEnt.Value, energyEnt)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user