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 <comedian_vs_clown@hotmail.com>
This commit is contained in:
DmitriyRubetskoy
2021-07-01 14:26:44 +03:00
committed by GitHub
parent 427ed72754
commit 5469f8c8b2
4 changed files with 92 additions and 2 deletions

View File

@@ -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<ActionBlockerSystem>().CanInteract(caster)) return;
// TODO: Nix when we get EntityPrototype serializers
if (!IoCManager.Resolve<IPrototypeManager>().HasIndex<EntityPrototype>(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);
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
namespace Content.Shared.Actions
{
/// <summary>
@@ -17,7 +17,8 @@ namespace Content.Shared.Actions
DebugTargetPoint,
DebugTargetPointRepeat,
DebugTargetEntity,
DebugTargetEntityRepeat
DebugTargetEntityRepeat,
SpellPie
}
/// <summary>

View File

@@ -0,0 +1 @@
spell-fail-no-hands = You don't have hands!

View File

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