Next spellStorage experiment (#572)

* scroll spells

* refactor magic system

* Update spawners.yml

* safe use

* Update magic-spells.ftl

* fix magic containers

* fix mole

* all scrolls

* remove shadow step ring

* fix scrolls
This commit is contained in:
Ed
2024-11-10 16:15:08 +03:00
committed by GitHub
parent c8ab937cf0
commit 84e07c1ded
21 changed files with 265 additions and 131 deletions

View File

@@ -31,6 +31,7 @@ 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();
@@ -38,6 +39,8 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
InitializeAspects();
InitializeSlowdown();
_magicContainerQuery = GetEntityQuery<CP14MagicEnergyContainerComponent>();
SubscribeLocalEvent<CP14MagicEffectComponent, MapInitEvent>(OnMagicEffectInit);
SubscribeLocalEvent<CP14MagicEffectComponent, CP14CastMagicEffectAttemptEvent>(OnBeforeCastMagicEffect);
@@ -92,40 +95,27 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
/// </summary>
private void OnBeforeCastMagicEffect(Entity<CP14MagicEffectComponent> ent, ref CP14CastMagicEffectAttemptEvent args)
{
if (ent.Comp.SpellStorage is null) //Dont have spellStorage, we use mana from caster
var requiredMana = CalculateManacost(ent, args.Performer);
if (ent.Comp.SpellStorage is not null)
{
if (!TryComp<CP14MagicEnergyContainerComponent>(args.Performer, 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, 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 (requiredMana > 0 && _magicContainerQuery.TryComp(args.Performer, out var playerMana))
{
if (!TryComp<CP14MagicEnergyContainerComponent>(ent.Comp.SpellStorage, out var magicContainer))
if (!_magicEnergy.HasEnergy(args.Performer, requiredMana, playerMana, true) && _net.IsServer)
{
args.Cancel();
return;
}
var manaCost = CalculateManacost(ent, ent.Comp.SpellStorage.Value);
if (!_magicEnergy.HasEnergy(ent.Comp.SpellStorage.Value, manaCost, magicContainer, true))
{
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);
}
}
}
@@ -143,6 +133,8 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
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,
@@ -151,8 +143,8 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
DistanceThreshold = 100f,
CancelDuplicate = true,
BlockDuplicate = true,
BreakOnDropItem = true,
NeedHand = true,
BreakOnDropItem = fromItem,
NeedHand = fromItem,
};
return _doAfter.TryStartDoAfter(doAfterEventArgs);
@@ -179,35 +171,40 @@ public abstract partial class CP14SharedMagicSystem : EntitySystem
if (_net.IsClient)
return;
if (ent.Comp.SpellStorage is null) //We pickup mana from player
var requiredMana = CalculateManacost(ent, args.Performer);
if (ent.Comp.SpellStorage is not null &&
_magicContainerQuery.TryComp(ent.Comp.SpellStorage, out var magicStorage))
{
if (!HasComp<CP14MagicEnergyContainerComponent>(args.Performer))
return;
var manaCost = CalculateManacost(ent, args.Performer.Value);
_magicEnergy.TryConsumeEnergy(args.Performer.Value, manaCost, safe: ent.Comp.Safe);
}
else //We pickup mana from SpellStorage
{
if (!HasComp<CP14MagicEnergyContainerComponent>(ent.Comp.SpellStorage))
return;
var manaCost = CalculateManacost(ent, ent.Comp.SpellStorage.Value);
_magicEnergy.TryConsumeEnergy(ent.Comp.SpellStorage.Value, manaCost, safe: ent.Comp.Safe);
var spellEv = new CP14SpellFromSpellStorageUsedEvent(args.Performer, ent, manaCost);
var spellEv = new CP14SpellFromSpellStorageUsedEvent(args.Performer, ent, requiredMana);
RaiseLocalEvent(ent.Comp.SpellStorage.Value, ref spellEv);
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));
}
}
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);

View File

@@ -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>

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -33,6 +33,7 @@
- CP14MagicEnergyCrystalSlot
itemIconStyle: BigAction
interactOnMiss: false
canTargetSelf: false
sound: !type:SoundPathSpecifier
path: /Audio/Magic/rumble.ogg
icon:
@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -8,10 +8,6 @@
components:
- type: Sprite
sprite: _CP14/Objects/Bureaucracy/paper.rsi
layers:
- state: paper_filled
- state: magic
shader: unshaded
- type: Item
size: Tiny
- type: Flammable
@@ -28,7 +24,7 @@
thresholds:
- trigger:
!type:DamageTrigger
damage: 1
damage: 15
behaviors:
- !type:SpawnEntitiesBehavior
spawn:
@@ -67,37 +63,97 @@
- type: CP14MagicUnsafeDamage
- type: entity
abstract: true
id: CP14BaseSpellScrollEarth
parent: CP14BaseSpellScroll
id: CP14SpellScrollFireball
name: fireball spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellFireball
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#70533f"
- type: entity
abstract: true
id: CP14BaseSpellScrollFire
parent: CP14BaseSpellScroll
id: CP14SpellScrollCureWounds
name: cure wound spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellCureWounds
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#d9741c"
- type: entity
abstract: true
id: CP14BaseSpellScrollGate
parent: CP14BaseSpellScroll
id: CP14SpellScrollIceShards
name: ice shards spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellIceShards
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#32597d"
- type: entity
abstract: true
id: CP14BaseSpellScrollHealing
parent: CP14BaseSpellScroll
id: CP14SpellScrollManaGift
name: mana gift spell scroll
components:
- type: CP14SpellStorage
spells:
- CP14ActionSpellManaGift
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#89e04f"
- type: entity
abstract: true
id: CP14BaseSpellScrollLightDarkness
parent: CP14BaseSpellScroll
components:
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#ba97b8"
- type: entity
abstract: true
id: CP14BaseSpellScrollMeta
parent: CP14BaseSpellScroll
components:
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#dcffdb"
- type: entity
abstract: true
id: CP14BaseSpellScrollMovement
parent: CP14BaseSpellScroll
components:
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#63ceff"
- type: entity
abstract: true
id: CP14BaseSpellScrollWater
parent: CP14BaseSpellScroll
components:
- type: Sprite
layers:
- state: paper_filled
- state: magic
shader: unshaded
color: "#1c94d9"

View File

@@ -11,11 +11,6 @@
- ring
- type: Sprite
sprite: _CP14/Clothing/Rings/rings.rsi
- type: CP14MagicEnergyExaminable
- type: CP14MagicEnergyContainer
energy: 50
maxEnergy: 50
- type: CP14MagicUnsafeDamage
- type: entity
id: CP14ClothingRingIceDagger
@@ -97,22 +92,6 @@
spells:
- CP14ActionSpellFireball
- type: entity
id: CP14ClothingRingShadowStep
parent: CP14ClothingRingBase
name: shadow step conductive ring
description: A standard mana-conductive ring that allows the user to step throught shadows.
suffix: Shadow step
components:
- type: Sprite
layers:
- state: brass_ring
- state: amethyst_stone_small
- type: CP14SpellStorageAccessWearing
- type: CP14SpellStorage
spells:
- CP14ActionSpellShadowStep
- type: entity
id: CP14ClothingRingShadowGrab
parent: CP14ClothingRingBase

View File

@@ -34,25 +34,25 @@
weight: 1
- !type:GroupSelector
children:
- id: CP14SpellScrollFireball
- id: CP14SpellScrollCureWounds
- id: CP14SpellScrollIceShards
- id: CP14SpellScrollIceDagger
- id: CP14SpellScrollShadowGrab
- id: CP14SpellScrollManaGift
- !type:GroupSelector
children:
- id: CP14DyeRed
- id: CP14DyeYellow
- id: CP14DyeBlue
- id: CP14DyeGreen
- id: CP14DyePurple
- id: CP14DyeBlack
- id: CP14SpellScrollSphereOfLight
- id: CP14SpellScrollCureWounds
- id: CP14SpellScrollShadowStep
- id: CP14SpellScrollFireball
- id: CP14SpellScrollFlameCreation
- id: CP14SpellScrollEarthWall
- id: CP14SpellScrollFlashLight
- id: CP14EnergyCrystalSmall
- id: CP14Bucket
- id: CP14CrystalLampBlueEmpty
- id: CP14Scissors
- id: CP14BaseSharpeningStone
- id: CP14Rope
weight: 2
- id: CP14GlassShard
- id: CP14Paper
# Rare
- !type:GroupSelector
weight: 25
@@ -84,7 +84,6 @@
- id: CP14ClothingRingFlameCreation
- id: CP14ClothingRingFireball
- id: CP14MagicHealingStaff
- id: CP14ClothingRingShadowStep
- id: CP14ClothingRingShadowGrab
- id: CP14ClothingRingEarthWall
- id: CP14ClothingRingManaGift

View File

@@ -1,17 +1,17 @@
- type: magicType
id: Earth
name: cp14-magic-type-earth
color: "#70533f"
- type: magicType
id: Fire
name: cp14-magic-type-fire
color: "#d9741c"
- type: magicType
id: Water
name: cp14-magic-type-water
color: "#1c94d9"
- type: magicType
id: Earth
name: cp14-magic-type-earth
color: "#70533f"
id: Gate
name: cp14-magic-type-gate
color: "#32597d"
- type: magicType
id: Healing
@@ -28,12 +28,12 @@
name: cp14-magic-type-meta
color: "#dcffdb"
- type: magicType
id: Gate
name: cp14-magic-type-gate
color: "#32597d"
- type: magicType
id: Movement
name: cp14-magic-type-movement
color: "#63ceff"
color: "#63ceff"
- type: magicType
id: Water
name: cp14-magic-type-water
color: "#1c94d9"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 210 B

View File

@@ -126,6 +126,7 @@ CP14ClothingRingIceFloor: CP14ClothingRingManaGift
#2024-11-05
CP14ClothingRingCureWounds: CP14MagicHealingStaff
CP14ClothingRingShadowStep: CP14ClothingRingManaGift
# <---> CrystallPunk migration zone end