From 5469f8c8b2198d306d2ed4bb8a6dd3839b656a32 Mon Sep 17 00:00:00 2001 From: DmitriyRubetskoy <75271456+DmitriyRubetskoy@users.noreply.github.com> Date: Thu, 1 Jul 2021 14:26:44 +0300 Subject: [PATCH] Give Item spell (#4241) * Cherry-picked summonspell * Renamed the script for clarity * Fixed Spell type error in yaml * Fixed Sound issues and increased the cooldown * Newline * Major script change * Fixed Namespace * Validation fixed, TryGet replaced * Typo again * Allowed for proper localisation * Typo fixed Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Adressed changes * Review cleanup Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth --- .../Actions/Spells/GiveItemSpell.cs | 75 +++++++++++++++++++ Content.Shared/Actions/ActionType.cs | 5 +- .../Locale/en-US/actions/actions/spells.ftl | 1 + Resources/Prototypes/Actions/spells.yml | 13 ++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Content.Server/Actions/Spells/GiveItemSpell.cs create mode 100644 Resources/Locale/en-US/actions/actions/spells.ftl create mode 100644 Resources/Prototypes/Actions/spells.yml diff --git a/Content.Server/Actions/Spells/GiveItemSpell.cs b/Content.Server/Actions/Spells/GiveItemSpell.cs new file mode 100644 index 0000000000..d7cac3a1b2 --- /dev/null +++ b/Content.Server/Actions/Spells/GiveItemSpell.cs @@ -0,0 +1,75 @@ +using Content.Server.Hands.Components; +using Content.Server.Items; +using Content.Server.Notification; +using Content.Shared.ActionBlocker; +using Content.Shared.Actions.Behaviors; +using Content.Shared.Actions.Components; +using Content.Shared.Cooldown; +using Content.Shared.Notification.Managers; +using JetBrains.Annotations; +using Robust.Shared.Audio; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Log; +using Robust.Shared.Player; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Content.Server.Actions.Spells +{ + [UsedImplicitly] + [DataDefinition] + public class GiveItemSpell : IInstantAction + { //TODO: Needs to be an EntityPrototype for proper validation + [ViewVariables] [DataField("castMessage")] public string? CastMessage { get; set; } = default!; + [ViewVariables] [DataField("cooldown")] public float CoolDown { get; set; } = 1f; + [ViewVariables] [DataField("spellItem")] public string ItemProto { get; set; } = default!; + + [ViewVariables] [DataField("castSound")] public string? CastSound { get; set; } = default!; + + //Rubber-band snapping items into player's hands, originally was a workaround, later found it works quite well with stuns + //Not sure if needs fixing + + public void DoInstantAction(InstantActionEventArgs args) + { + var caster = args.Performer; + + if (!caster.TryGetComponent(out HandsComponent? handsComponent)) + { + caster.PopupMessage(Loc.GetString("spell-fail-no-hands")); + return; + } + + if (!EntitySystem.Get().CanInteract(caster)) return; + + // TODO: Nix when we get EntityPrototype serializers + if (!IoCManager.Resolve().HasIndex(ItemProto)) + { + Logger.Error($"Invalid prototype {ItemProto} supplied for {nameof(GiveItemSpell)}"); + return; + } + + // TODO: Look this is shitty and ideally a test would do it + var spawnedProto = caster.EntityManager.SpawnEntity(ItemProto, caster.Transform.MapPosition); + + if (!spawnedProto.TryGetComponent(out ItemComponent? itemComponent)) + { + Logger.Error($"Tried to use {nameof(GiveItemSpell)} but prototype has no {nameof(ItemComponent)}?"); + spawnedProto.Delete(); + return; + } + + args.PerformerActions?.Cooldown(args.ActionType, Cooldowns.SecondsFromNow(CoolDown)); + + if (CastMessage != null) + caster.PopupMessageEveryone(CastMessage); + + handsComponent.PutInHandOrDrop(itemComponent); + + if (CastSound != null) + SoundSystem.Play(Filter.Pvs(caster), CastSound, caster); + } + } +} diff --git a/Content.Shared/Actions/ActionType.cs b/Content.Shared/Actions/ActionType.cs index beb5e6136d..fdca3780ea 100644 --- a/Content.Shared/Actions/ActionType.cs +++ b/Content.Shared/Actions/ActionType.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable namespace Content.Shared.Actions { /// @@ -17,7 +17,8 @@ namespace Content.Shared.Actions DebugTargetPoint, DebugTargetPointRepeat, DebugTargetEntity, - DebugTargetEntityRepeat + DebugTargetEntityRepeat, + SpellPie } /// diff --git a/Resources/Locale/en-US/actions/actions/spells.ftl b/Resources/Locale/en-US/actions/actions/spells.ftl new file mode 100644 index 0000000000..186e6e7fec --- /dev/null +++ b/Resources/Locale/en-US/actions/actions/spells.ftl @@ -0,0 +1 @@ +spell-fail-no-hands = You don't have hands! diff --git a/Resources/Prototypes/Actions/spells.yml b/Resources/Prototypes/Actions/spells.yml new file mode 100644 index 0000000000..cfcb1709ce --- /dev/null +++ b/Resources/Prototypes/Actions/spells.yml @@ -0,0 +1,13 @@ +- type: action + actionType: SpellPie + icon: Objects/Consumable/Food/Baked/pie.rsi/plain.png + name: "Pie" + filters: + - spells + description: "Give me a pie, I dare you!" + behaviorType: Instant + behavior: !type:GiveItemSpell + spellItem: FoodPieBananaCream + castMessage: I NEED A PIE! + cooldown: 15 + castSound: /Audio/Items/bikehorn.ogg