Skip to content

Commit 22987fc

Browse files
Wizard Summon Guns/Magic (#32692)
* mostly done but there's a bug with spawning * RandomGlobalSpawnSpellEvent now actually works * Summon Guns/Magic is working * Added sound, cap gun, and auto pick up * Added all requested changes/fixes from reviews * Halving cooldowns
1 parent c7f8352 commit 22987fc

File tree

10 files changed

+326
-22
lines changed

10 files changed

+326
-22
lines changed

Content.Server/Objectives/Systems/KillPersonConditionSystem.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void OnPersonAssigned(EntityUid uid, PickRandomPersonComponent comp, ref
5353
return;
5454

5555
// no other humans to kill
56-
var allHumans = _mind.GetAliveHumansExcept(args.MindId);
56+
var allHumans = _mind.GetAliveHumans(args.MindId);
5757
if (allHumans.Count == 0)
5858
{
5959
args.Cancelled = true;
@@ -77,14 +77,14 @@ private void OnHeadAssigned(EntityUid uid, PickRandomHeadComponent comp, ref Obj
7777
return;
7878

7979
// no other humans to kill
80-
var allHumans = _mind.GetAliveHumansExcept(args.MindId);
80+
var allHumans = _mind.GetAliveHumans(args.MindId);
8181
if (allHumans.Count == 0)
8282
{
8383
args.Cancelled = true;
8484
return;
8585
}
8686

87-
var allHeads = new List<EntityUid>();
87+
var allHeads = new HashSet<Entity<MindComponent>>();
8888
foreach (var person in allHumans)
8989
{
9090
if (TryComp<MindComponent>(person, out var mind) && mind.OwnedEntity is { } ent && HasComp<CommandStaffComponent>(ent))

Content.Server/Store/Systems/StoreSystem.Ui.cs

+5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ private void OnBuyRequest(EntityUid uid, StoreComponent component, StoreBuyListi
256256
RaiseLocalEvent(buyer, listing.ProductEvent);
257257
}
258258

259+
if (listing.DisableRefund)
260+
{
261+
component.RefundAllowed = false;
262+
}
263+
259264
//log dat shit.
260265
_admin.Add(LogType.StorePurchase,
261266
LogImpact.Low,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Content.Shared.Actions;
2+
using Content.Shared.Storage;
3+
using Robust.Shared.Audio;
4+
5+
namespace Content.Shared.Magic.Events;
6+
7+
public sealed partial class RandomGlobalSpawnSpellEvent : InstantActionEvent, ISpeakSpell
8+
{
9+
/// <summary>
10+
/// The list of prototypes this spell can spawn, will select one randomly
11+
/// </summary>
12+
[DataField]
13+
public List<EntitySpawnEntry> Spawns = new();
14+
15+
/// <summary>
16+
/// Sound that will play globally when cast
17+
/// </summary>
18+
[DataField]
19+
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Magic/staff_animation.ogg");
20+
21+
[DataField]
22+
public string? Speech { get; private set; }
23+
}

Content.Shared/Magic/SharedMagicSystem.cs

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Numerics;
1+
using System.Numerics;
22
using Content.Shared.Actions;
33
using Content.Shared.Body.Components;
44
using Content.Shared.Body.Systems;
@@ -7,19 +7,25 @@
77
using Content.Shared.Doors.Systems;
88
using Content.Shared.Hands.Components;
99
using Content.Shared.Hands.EntitySystems;
10+
using Content.Shared.Humanoid;
1011
using Content.Shared.Interaction;
1112
using Content.Shared.Inventory;
1213
using Content.Shared.Lock;
1314
using Content.Shared.Magic.Components;
1415
using Content.Shared.Magic.Events;
1516
using Content.Shared.Maps;
17+
using Content.Shared.Mind;
18+
using Content.Shared.Mind.Components;
19+
using Content.Shared.Mobs.Components;
20+
using Content.Shared.Mobs.Systems;
1621
using Content.Shared.Physics;
1722
using Content.Shared.Popups;
1823
using Content.Shared.Speech.Muting;
1924
using Content.Shared.Storage;
2025
using Content.Shared.Tag;
2126
using Content.Shared.Weapons.Ranged.Components;
2227
using Content.Shared.Weapons.Ranged.Systems;
28+
using Robust.Shared.Audio.Systems;
2329
using Robust.Shared.Map;
2430
using Robust.Shared.Map.Components;
2531
using Robust.Shared.Network;
@@ -53,6 +59,9 @@ public abstract class SharedMagicSystem : EntitySystem
5359
[Dependency] private readonly LockSystem _lock = default!;
5460
[Dependency] private readonly SharedHandsSystem _hands = default!;
5561
[Dependency] private readonly TagSystem _tag = default!;
62+
[Dependency] private readonly MobStateSystem _mobState = default!;
63+
[Dependency] private readonly SharedAudioSystem _audio = default!;
64+
[Dependency] private readonly SharedMindSystem _mind = default!;
5665

5766
public override void Initialize()
5867
{
@@ -67,6 +76,7 @@ public override void Initialize()
6776
SubscribeLocalEvent<SmiteSpellEvent>(OnSmiteSpell);
6877
SubscribeLocalEvent<KnockSpellEvent>(OnKnockSpell);
6978
SubscribeLocalEvent<ChargeSpellEvent>(OnChargeSpell);
79+
SubscribeLocalEvent<RandomGlobalSpawnSpellEvent>(OnRandomGlobalSpawnSpell);
7080

7181
// Spell wishlist
7282
// A wishlish of spells that I'd like to implement or planning on implementing in a future PR
@@ -501,6 +511,37 @@ private void OnChargeSpell(ChargeSpellEvent ev)
501511
_gunSystem.UpdateBasicEntityAmmoCount(wand.Value, basicAmmoComp.Count.Value + ev.Charge, basicAmmoComp);
502512
}
503513
// End Charge Spells
514+
#endregion
515+
#region Global Spells
516+
517+
private void OnRandomGlobalSpawnSpell(RandomGlobalSpawnSpellEvent ev)
518+
{
519+
if (!_net.IsServer || ev.Handled || !PassesSpellPrerequisites(ev.Action, ev.Performer) || ev.Spawns is not { } spawns)
520+
return;
521+
522+
ev.Handled = true;
523+
Speak(ev);
524+
525+
var allHumans = _mind.GetAliveHumans();
526+
527+
foreach (var human in allHumans)
528+
{
529+
if (!human.Comp.OwnedEntity.HasValue)
530+
continue;
531+
532+
var ent = human.Comp.OwnedEntity.Value;
533+
534+
var mapCoords = _transform.GetMapCoordinates(ent);
535+
foreach (var spawn in EntitySpawnCollection.GetSpawns(spawns, _random))
536+
{
537+
var spawned = Spawn(spawn, mapCoords);
538+
_hands.PickupOrDrop(ent, spawned);
539+
}
540+
}
541+
542+
_audio.PlayGlobal(ev.Sound, ev.Performer);
543+
}
544+
504545
#endregion
505546
// End Spells
506547
#endregion

Content.Shared/Mind/SharedMindSystem.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -532,22 +532,19 @@ public string MindOwnerLoggingString(MindComponent mind)
532532
/// <summary>
533533
/// Returns a list of every living humanoid player's minds, except for a single one which is exluded.
534534
/// </summary>
535-
public List<EntityUid> GetAliveHumansExcept(EntityUid exclude)
535+
public HashSet<Entity<MindComponent>> GetAliveHumans(EntityUid? exclude = null)
536536
{
537-
var mindQuery = EntityQuery<MindComponent>();
538-
539-
var allHumans = new List<EntityUid>();
537+
var allHumans = new HashSet<Entity<MindComponent>>();
540538
// HumanoidAppearanceComponent is used to prevent mice, pAIs, etc from being chosen
541-
var query = EntityQueryEnumerator<MindContainerComponent, MobStateComponent, HumanoidAppearanceComponent>();
542-
while (query.MoveNext(out var uid, out var mc, out var mobState, out _))
539+
var query = EntityQueryEnumerator<MobStateComponent, HumanoidAppearanceComponent>();
540+
while (query.MoveNext(out var uid, out var mobState, out _))
543541
{
544-
// the player needs to have a mind and not be the excluded one
545-
if (mc.Mind == null || mc.Mind == exclude)
542+
// the player needs to have a mind and not be the excluded one +
543+
// the player has to be alive
544+
if (!TryGetMind(uid, out var mind, out var mindComp) || mind == exclude || !_mobState.IsAlive(uid, mobState))
546545
continue;
547546

548-
// the player has to be alive
549-
if (_mobState.IsAlive(uid, mobState))
550-
allHumans.Add(mc.Mind.Value);
547+
allHumans.Add(new Entity<MindComponent>(mind, mindComp));
551548
}
552549

553550
return allHumans;

Content.Shared/Store/ListingPrototype.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public ListingData(ListingData other) : this(
3939
other.Categories,
4040
other.OriginalCost,
4141
other.RestockTime,
42-
other.DiscountDownTo
42+
other.DiscountDownTo,
43+
other.DisableRefund
4344
)
4445
{
4546

@@ -63,7 +64,8 @@ public ListingData(
6364
HashSet<ProtoId<StoreCategoryPrototype>> categories,
6465
IReadOnlyDictionary<ProtoId<CurrencyPrototype>, FixedPoint2> originalCost,
6566
TimeSpan restockTime,
66-
Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> dataDiscountDownTo
67+
Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> dataDiscountDownTo,
68+
bool disableRefund
6769
)
6870
{
6971
Name = name;
@@ -84,6 +86,7 @@ Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> dataDiscountDownTo
8486
OriginalCost = originalCost;
8587
RestockTime = restockTime;
8688
DiscountDownTo = new Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2>(dataDiscountDownTo);
89+
DisableRefund = disableRefund;
8790
}
8891

8992
[ViewVariables]
@@ -194,6 +197,12 @@ Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> dataDiscountDownTo
194197
[DataField]
195198
public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> DiscountDownTo = new();
196199

200+
/// <summary>
201+
/// Whether or not to disable refunding for the store when the listing is purchased from it.
202+
/// </summary>
203+
[DataField]
204+
public bool DisableRefund = false;
205+
197206
public bool Equals(ListingData? listing)
198207
{
199208
if (listing == null)
@@ -287,7 +296,8 @@ public ListingDataWithCostModifiers(ListingData listingData)
287296
listingData.Categories,
288297
listingData.OriginalCost,
289298
listingData.RestockTime,
290-
listingData.DiscountDownTo
299+
listingData.DiscountDownTo,
300+
listingData.DisableRefund
291301
)
292302
{
293303
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
action-speech-spell-forcewall = TARCOL MINTI ZHERI
1+
action-speech-spell-forcewall = TARCOL MINTI ZHERI
22
action-speech-spell-knock = AULIE OXIN FIERA
33
action-speech-spell-smite = EI NATH!
44
action-speech-spell-summon-magicarp = AIE KHUSE EU
55
action-speech-spell-fireball = ONI'SOMA!
6+
action-speech-spell-summon-guns = YOR'NEE VES-KORFA
7+
action-speech-spell-summon-magic = RYGOIN FEMA-VERECO

Resources/Locale/en-US/store/spellbook-catalog.ftl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Spells
1+
# Spells
22
spellbook-fireball-name = Fireball
33
spellbook-fireball-desc = Get most crew exploding with rage when they see this fireball heading toward them!
44
@@ -33,6 +33,12 @@ spellbook-wand-polymorph-carp-description = For when you need a carp filet quick
3333
spellbook-event-summon-ghosts-name = Summon Ghosts
3434
spellbook-event-summon-ghosts-description = Who ya gonna call?
3535
36+
spellbook-event-summon-guns-name = Summon Guns
37+
spellbook-event-summon-guns-description = AK47s for everyone! Places a random gun in front of everybody. Disables refunds when bought!
38+
39+
spellbook-event-summon-magic-name = Summon Magic
40+
spellbook-event-summon-magic-description = Places a random magical item in front of everybody. Nothing could go wrong! Disables refunds when bought!
41+
3642
# Upgrades
3743
spellbook-upgrade-fireball-name = Upgrade Fireball
3844
spellbook-upgrade-fireball-description = Upgrades Fireball to a maximum of level 3!

Resources/Prototypes/Catalog/spellbook_catalog.yml

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Offensive
1+
# Offensive
22
- type: listing
33
id: SpellbookFireball
44
name: spellbook-fireball-name
@@ -132,6 +132,34 @@
132132
- !type:ListingLimitedStockCondition
133133
stock: 1
134134

135+
- type: listing
136+
id: SpellbookEventSummonGuns
137+
name: spellbook-event-summon-guns-name
138+
description: spellbook-event-summon-guns-description
139+
productAction: ActionSummonGuns
140+
cost:
141+
WizCoin: 2
142+
categories:
143+
- SpellbookEvents
144+
conditions:
145+
- !type:ListingLimitedStockCondition
146+
stock: 1
147+
disableRefund: true
148+
149+
- type: listing
150+
id: SpellbookEventSummonMagic
151+
name: spellbook-event-summon-magic-name
152+
description: spellbook-event-summon-magic-description
153+
productAction: ActionSummonMagic
154+
cost:
155+
WizCoin: 2
156+
categories:
157+
- SpellbookEvents
158+
conditions:
159+
- !type:ListingLimitedStockCondition
160+
stock: 1
161+
disableRefund: true
162+
135163
# Upgrades
136164
- type: listing
137165
id: SpellbookFireballUpgrade

0 commit comments

Comments
 (0)