Skip to content

Commit

Permalink
Merge branch 'master' into mug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
YmepIIIij-TeRorIst authored Nov 10, 2024
2 parents 1e7f649 + 84e07c1 commit 72469a2
Show file tree
Hide file tree
Showing 21 changed files with 262 additions and 128 deletions.
83 changes: 40 additions & 43 deletions Content.Shared/_CP14/MagicSpell/CP14SharedMagicSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
[Dependency] private readonly SharedActionsSystem _action = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;

private EntityQuery<CP14MagicEnergyContainerComponent> _magicContainerQuery;
public override void Initialize()
{
base.Initialize();
InitializeActions();
InitializeAspects();
InitializeSlowdown();

_magicContainerQuery = GetEntityQuery<CP14MagicEnergyContainerComponent>();

SubscribeLocalEvent<CP14MagicEffectComponent, MapInitEvent>(OnMagicEffectInit);
SubscribeLocalEvent<CP14MagicEffectComponent, CP14CastMagicEffectAttemptEvent>(OnBeforeCastMagicEffect);

Expand Down Expand Up @@ -92,40 +95,27 @@ private bool CanCastSpell(Entity<CP14MagicEffectComponent> ent, EntityUid perfor
/// </summary>
private void OnBeforeCastMagicEffect(Entity<CP14MagicEffectComponent> ent, ref CP14CastMagicEffectAttemptEvent args)
{
if (ent.Comp.SpellStorage is null) //Dont have spellStorage, we use mana from caster
{
if (!TryComp<CP14MagicEnergyContainerComponent>(args.Performer, out var magicContainer))
{
args.Cancel();
return;
}
var requiredMana = CalculateManacost(ent, args.Performer);

var manaCost = CalculateManacost(ent, args.Performer);

if (!_magicEnergy.HasEnergy(args.Performer, manaCost, magicContainer, ent.Comp.Safe))
{
args.PushReason(Loc.GetString("cp14-magic-spell-not-enough-mana"));
args.Cancel();
}
else if(!_magicEnergy.HasEnergy(args.Performer, manaCost, magicContainer, true) && _net.IsServer) //фу какой некрасивый хардкод
{ // \/
_popup.PopupEntity(Loc.GetString("cp14-magic-spell-not-enough-mana-cast-warning-"+_random.Next(5)), args.Performer, args.Performer, PopupType.SmallCaution);
}
}
else //We HAVE SpellStorage, use mana from spellStorage
if (ent.Comp.SpellStorage is not null)
{
if (!TryComp<CP14MagicEnergyContainerComponent>(ent.Comp.SpellStorage, out var magicContainer))
if (_magicContainerQuery.TryComp(ent.Comp.SpellStorage, out var magicContainer)) // We have item that provides this spell
requiredMana = MathF.Max(0, (float)(requiredMana - magicContainer.Energy));

if (!ent.Comp.SpellStorage.Value.Comp.CanUseCasterMana && requiredMana > 0)
{
args.PushReason(Loc.GetString("cp14-magic-spell-not-enough-mana-item"));
args.Cancel();
return;
}
}

var manaCost = CalculateManacost(ent, ent.Comp.SpellStorage.Value);

if (!_magicEnergy.HasEnergy(ent.Comp.SpellStorage.Value, manaCost, magicContainer, true))
if (requiredMana > 0 && _magicContainerQuery.TryComp(args.Performer, out var playerMana))
{
if (!_magicEnergy.HasEnergy(args.Performer, requiredMana, playerMana, true) && _net.IsServer)
{
args.PushReason(Loc.GetString("cp14-magic-spell-not-enough-mana-item", ("item", MetaData(ent.Comp.SpellStorage.Value).EntityName)));
args.Cancel();
_popup.PopupEntity(Loc.GetString("cp14-magic-spell-not-enough-mana-cast-warning-"+_random.Next(5)), args.Performer, args.Performer, PopupType.SmallCaution);
}
}
}
Expand All @@ -143,6 +133,8 @@ private void CastTelegraphy(Entity<CP14MagicEffectComponent> ent, CP14SpellEffec

private bool TryCastSpellDelayed(ICP14DelayedMagicEffect delayedEffect, DoAfterEvent doAfter, Entity<CP14MagicEffectComponent> action, EntityUid performer)
{
var fromItem = action.Comp.SpellStorage is not null;

var doAfterEventArgs = new DoAfterArgs(EntityManager, performer, delayedEffect.CastDelay, doAfter, action, used: action.Comp.SpellStorage)
{
BreakOnMove = delayedEffect.BreakOnMove,
Expand All @@ -151,8 +143,8 @@ private bool TryCastSpellDelayed(ICP14DelayedMagicEffect delayedEffect, DoAfterE
DistanceThreshold = 100f,
CancelDuplicate = true,
BlockDuplicate = true,
BreakOnDropItem = true,
NeedHand = true,
BreakOnDropItem = fromItem,
NeedHand = fromItem,
};

return _doAfter.TryStartDoAfter(doAfterEventArgs);
Expand All @@ -179,35 +171,40 @@ private void OnAfterCastMagicEffect(Entity<CP14MagicEffectComponent> ent, ref CP
if (_net.IsClient)
return;

if (ent.Comp.SpellStorage is null) //We pickup mana from player
{
if (!HasComp<CP14MagicEnergyContainerComponent>(args.Performer))
return;
var requiredMana = CalculateManacost(ent, args.Performer);

var manaCost = CalculateManacost(ent, args.Performer.Value);
_magicEnergy.TryConsumeEnergy(args.Performer.Value, manaCost, safe: ent.Comp.Safe);
}
else //We pickup mana from SpellStorage
if (ent.Comp.SpellStorage is not null &&
_magicContainerQuery.TryComp(ent.Comp.SpellStorage, out var magicStorage))
{
if (!HasComp<CP14MagicEnergyContainerComponent>(ent.Comp.SpellStorage))
return;
var spellEv = new CP14SpellFromSpellStorageUsedEvent(args.Performer, ent, requiredMana);
RaiseLocalEvent(ent.Comp.SpellStorage.Value, ref spellEv);

var manaCost = CalculateManacost(ent, ent.Comp.SpellStorage.Value);
_magicEnergy.TryConsumeEnergy(ent.Comp.SpellStorage.Value, manaCost, safe: ent.Comp.Safe);
if (magicStorage.Energy > 0)
{
//TODO: FIX THIS SHIT
var cashedEnergy = magicStorage.Energy;
_magicEnergy.TryConsumeEnergy(ent.Comp.SpellStorage.Value, requiredMana, magicStorage, false);
requiredMana = MathF.Max(0, (float)(requiredMana - cashedEnergy));
}
}

var spellEv = new CP14SpellFromSpellStorageUsedEvent(args.Performer, ent, manaCost);
RaiseLocalEvent(ent.Comp.SpellStorage.Value, ref spellEv);
if (requiredMana > 0 &&
_magicContainerQuery.TryComp(args.Performer, out var playerMana))
{
_magicEnergy.TryConsumeEnergy(args.Performer.Value, requiredMana, safe: false);
}
}

private FixedPoint2 CalculateManacost(Entity<CP14MagicEffectComponent> ent, EntityUid caster)
private FixedPoint2 CalculateManacost(Entity<CP14MagicEffectComponent> ent, EntityUid? caster)
{
var manaCost = ent.Comp.ManaCost;

if (ent.Comp.CanModifyManacost)
{
var manaEv = new CP14CalculateManacostEvent(caster, ent.Comp.ManaCost, ent.Comp.MagicType);
RaiseLocalEvent(caster, manaEv);

if (caster is not null)
RaiseLocalEvent(caster.Value, manaEv);

if (ent.Comp.SpellStorage is not null)
RaiseLocalEvent(ent.Comp.SpellStorage.Value, manaEv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public sealed partial class CP14MagicEffectComponent : Component
[DataField]
public bool CanModifyManacost = true;

[DataField]
public bool Safe = false;

/// <summary>
/// Effects that will trigger at the beginning of the cast, before mana is spent. Should have no gameplay importance, just special effects, popups and sounds.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public sealed class CP14CalculateManacostEvent : EntityEventArgs, IInventoryRela
public FixedPoint2 Manacost = 0f;

public float Multiplier = 1f;
public EntityUid Performer;
public EntityUid? Performer;
public ProtoId<CP14MagicTypePrototype>? MagicType;

public CP14CalculateManacostEvent(EntityUid performer, FixedPoint2 initialManacost, ProtoId<CP14MagicTypePrototype>? magicType)
public CP14CalculateManacostEvent(EntityUid? performer, FixedPoint2 initialManacost, ProtoId<CP14MagicTypePrototype>? magicType)
{
Performer = performer;
Manacost = initialManacost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public sealed partial class CP14SpellStorageComponent : Component
/// </summary>
[DataField]
public List<EntityUid> SpellEntities = new();

/// <summary>
/// allows you to use an caster's mana to create spells.
/// </summary>
[DataField]
public bool CanUseCasterMana = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@
lifetime: 1.2
- type: SpawnOnDespawn
prototype: CP14WallDirt

- type: entity
parent: CP14BaseSpellScrollEarth
id: CP14SpellScrollEarthWall
name: earth wall spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellEarthWall
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,13 @@
cPAnimationLength: 0.15
- type: IgnitionSource
temperature: 400
ignited: true
ignited: true

- type: entity
parent: CP14BaseSpellScrollFire
id: CP14SpellScrollFlameCreation
name: flame creation spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellFlameCreation
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@
totalIntensity: 15
intensitySlope: 1
maxIntensity: 6
canCreateVacuum: false
canCreateVacuum: false

- type: entity
parent: CP14BaseSpellScrollFire
id: CP14SpellScrollFireball
name: fireball spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellFireball
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@
- type: Sprite
layers:
- state: wave_up
color: "#5e427e"
color: "#5e427e"

- type: entity
parent: CP14BaseSpellScrollGate
id: CP14SpellScrollShadowStep
name: shadow step spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellShadowStep
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@
layers:
- state: particles_up
color: "#79b330"
shader: unshaded
shader: unshaded

- type: entity
parent: CP14BaseSpellScrollHealing
id: CP14SpellScrollCureWounds
name: cure wounds spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellCureWounds
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@
- type: TimedDespawn
lifetime: 0.5

- type: entity
parent: CP14BaseSpellScrollLightDarkness
id: CP14SpellScrollFlashLight
name: flash light spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellFlashLight
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@
params:
variation: 0.250
volume: -12

- type: entity
parent: CP14BaseSpellScrollLightDarkness
id: CP14SpellScrollSphereOfLight
name: sphere of light spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellSphereOfLight
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- CP14MagicEnergyCrystalSlot
itemIconStyle: BigAction
interactOnMiss: false
canTargetSelf: false
sound: !type:SoundPathSpecifier
path: /Audio/Magic/rumble.ogg
icon:
Expand Down Expand Up @@ -67,4 +68,13 @@
layers:
- state: particles_up
color: "#5096d4"
shader: unshaded
shader: unshaded

- type: entity
parent: CP14BaseSpellScrollMeta
id: CP14SpellScrollManaGift
name: mana gift spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellManaGift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@
- type: Sprite
layers:
- state: particles_up
color: "#5e427e"
color: "#5e427e"

- type: entity
parent: CP14BaseSpellScrollMovement
id: CP14SpellScrollShadowGrab
name: shadow grab spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellShadowGrab
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@
sound:
collection: GlassBreak
- !type:DoActsBehavior
acts: ["Destruction"]
acts: ["Destruction"]

- type: entity
parent: CP14BaseSpellScrollWater
id: CP14SpellScrollIceDagger
name: ice dagger spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellIceDagger
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@
sprite: _CP14/Objects/Weapons/Melee/Dagger/ice_dagger.rsi
layers:
- state: shard
shader: unshaded
shader: unshaded

- type: entity
parent: CP14BaseSpellScrollWater
id: CP14SpellScrollIceShards
name: ice shards spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellIceShards
Loading

0 comments on commit 72469a2

Please sign in to comment.