Files
crystall-punk-14/Content.Shared/_CP14/MagicEnergy/SharedCP14MagicEnergyCrystalSlotSystem.cs
Red 4debb114e5 Magic system refactor part 1 (#1709)
* Refactor pacified block logic to action system

Moved pacified block functionality from magic spell components to the new CP14ActionSystem and related components. Removed CP14MagicEffectPacifiedBlockComponent and its logic, and introduced CP14ActionDangerousComponent for handling pacified checks. Updated examine and checks logic to use the new action-based components, improving separation of concerns between magic and action systems.

* finish pacified

* mobtargetstate refactor

* skillpoint cost refactor

* somaticAspect refactor

* material cost refactor

* mana cost now

* stamina cost

* SSD + verbal aspect

* religion

* music tool refactor

* vampire

* get rid of this event

* manacost refac

* Remove magicType field from spell definitions

Eliminated the 'magicType' property from all CP14MagicEffect components in spell YAML files across Electric, Fire, Life, Light, and Water categories. This streamlines spell configuration and may reflect a change in how magic types are handled in the system.

* Remove mana cost reduction effects from skill tiers

Eliminated the ModifyManacost effects from tier 2 and tier 3 skills in electromancy, healing, hydrosophistry, illusion, and pyrokinetic. This change standardizes skill progression and may be part of a balance update to mana cost mechanics.

* comment out T3 tiers

* namespace refactor

* fix hands
2025-08-25 20:40:10 +03:00

155 lines
5.5 KiB
C#

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;
public abstract class SharedCP14MagicEnergyCrystalSlotSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly CP14SharedMagicEnergySystem _magicEnergy = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
public override void Initialize()
{
base.Initialize();
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)
{
if (args.Container.ID != slot.Comp.SlotId)
return;
_appearance.SetData(slot, CP14MagicSlotVisuals.Inserted, false);
_appearance.SetData(slot, CP14MagicSlotVisuals.Powered, false);
RaiseLocalEvent(slot, new CP14SlotCrystalChangedEvent(true));
}
private void OnCrystalInserted(Entity<CP14MagicEnergyCrystalSlotComponent> slot, ref EntInsertedIntoContainerMessage args)
{
if (!slot.Comp.Initialized)
return;
if (args.Container.ID != slot.Comp.SlotId)
return;
_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)));
}
}