-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathPolymorphSystem.cs
More file actions
831 lines (709 loc) · 33.5 KB
/
PolymorphSystem.cs
File metadata and controls
831 lines (709 loc) · 33.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
using Content.Server.Actions;
using Content.Server.Humanoid;
using Content.Shared.Humanoid; // ADT-Changeling-Tweak
//ADT-Geras-Tweak-Start
using Content.Shared.ADT.Language;
using Content.Shared.ADT.SpeechBarks;
using Content.Shared.Corvax.TTS;
using Content.Server.Speech.Components;
using Content.Server.Corvax.Speech.Components;
using Content.Shared.Speech.Components;
using Content.Server._CorvaxNext.Speech.Components;
using Content.Shared.Traits.Assorted;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Bed.Sleep;
using Content.Shared.Eye.Blinding.Components;
using Content.Server.Traits.Assorted;
using Content.Shared.Speech.Muting;
using Content.Shared.ADT.Traits;
using Content.Shared.Storage.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Temperature.Systems;
using Content.Shared.Atmos.Components;
using Content.Shared.Temperature.Components;
//ADT-Geras-Tweak-End
using Content.Server.Inventory;
using Content.Server.Polymorph.Components;
using Content.Shared.Buckle;
using Content.Shared.Coordinates;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Destructible;
using Content.Shared.Follower;
using Content.Shared.Follower.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Mind;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition;
using Content.Shared.Polymorph;
using Content.Shared.Popups;
using Robust.Server.Audio;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Content.Shared.Forensics.Components; // ADT-Changeling-Tweak
using Content.Shared.Mindshield.Components; // ADT-Changeling-Tweak
using Robust.Shared.Serialization.Manager;
using Content.Shared.DetailExaminable;
using Content.Shared.ADT.CharecterFlavor; // ADT-Changeling-Tweak
namespace Content.Server.Polymorph.Systems;
public sealed partial class PolymorphSystem : EntitySystem
{
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly ServerInventorySystem _inventory = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly FollowerSystem _follow = default!; // goob edit
[Dependency] private readonly FlammableSystem _flammable = default!; //ADT-Geras-Tweak
[Dependency] private readonly SharedStaminaSystem _stamina = default!; //ADT-Geras-Tweak
[Dependency] private readonly TemperatureSystem _temperatureSystem = default!; //ADT-Geras-Tweak
[Dependency] private readonly ISerializationManager _serialization = default!; // ADT-Changeling-Tweak
private const string RevertPolymorphId = "ActionRevertPolymorph";
public override void Initialize()
{
SubscribeLocalEvent<PolymorphableComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<PolymorphedEntityComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PolymorphableComponent, PolymorphActionEvent>(OnPolymorphActionEvent);
SubscribeLocalEvent<PolymorphedEntityComponent, RevertPolymorphActionEvent>(OnRevertPolymorphActionEvent);
SubscribeLocalEvent<PolymorphedEntityComponent, BeforeFullySlicedEvent>(OnBeforeFullySliced);
SubscribeLocalEvent<PolymorphedEntityComponent, DestructionEventArgs>(OnDestruction);
SubscribeLocalEvent<PolymorphedEntityComponent, EntityTerminatingEvent>(OnPolymorphedTerminating);
InitializeMap();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<PolymorphedEntityComponent>();
while (query.MoveNext(out var uid, out var comp))
{
comp.Time += frameTime;
if (comp.Configuration.Duration != null && comp.Time >= comp.Configuration.Duration)
{
Revert((uid, comp));
continue;
}
if (!TryComp<MobStateComponent>(uid, out var mob))
continue;
if (comp.Configuration.RevertOnDeath && _mobState.IsDead(uid, mob) ||
comp.Configuration.RevertOnCrit && _mobState.IsIncapacitated(uid, mob))
{
Revert((uid, comp));
}
}
}
private void OnComponentStartup(Entity<PolymorphableComponent> ent, ref ComponentStartup args)
{
if (ent.Comp.InnatePolymorphs != null)
{
foreach (var morph in ent.Comp.InnatePolymorphs)
{
CreatePolymorphAction(morph, ent);
}
}
}
private void OnMapInit(Entity<PolymorphedEntityComponent> ent, ref MapInitEvent args)
{
var (uid, component) = ent;
if (component.Configuration.Forced)
return;
if (_actions.AddAction(uid, ref component.Action, out var action, RevertPolymorphId))
{
_actions.SetEntityIcon((component.Action.Value, action), component.Parent);
_actions.SetUseDelay(component.Action.Value, TimeSpan.FromSeconds(component.Configuration.Delay));
}
}
private void OnPolymorphActionEvent(Entity<PolymorphableComponent> ent, ref PolymorphActionEvent args)
{
if (!_proto.Resolve(args.ProtoId, out var prototype) || args.Handled)
return;
PolymorphEntity(ent, prototype.Configuration);
args.Handled = true;
}
private void OnRevertPolymorphActionEvent(Entity<PolymorphedEntityComponent> ent,
ref RevertPolymorphActionEvent args)
{
Revert((ent, ent));
}
private void OnBeforeFullySliced(Entity<PolymorphedEntityComponent> ent, ref BeforeFullySlicedEvent args)
{
if (ent.Comp.Reverted || !ent.Comp.Configuration.RevertOnEat)
return;
args.Cancel();
Revert((ent, ent));
}
/// <summary>
/// It is possible to be polymorphed into an entity that can't "die", but is instead
/// destroyed. This handler ensures that destruction is treated like death.
/// </summary>
private void OnDestruction(Entity<PolymorphedEntityComponent> ent, ref DestructionEventArgs args)
{
if (ent.Comp.Reverted || !ent.Comp.Configuration.RevertOnDeath)
return;
Revert((ent, ent));
}
private void OnPolymorphedTerminating(Entity<PolymorphedEntityComponent> ent, ref EntityTerminatingEvent args)
{
if (ent.Comp.Reverted)
return;
if (ent.Comp.Configuration.RevertOnDelete)
Revert(ent.AsNullable());
// Remove our original entity too
// Note that Revert will set Parent to null, so reverted entities will not be deleted
QueueDel(ent.Comp.Parent);
}
/// <summary>
/// Polymorphs the target entity into the specific polymorph prototype
/// </summary>
/// <param name="uid">The entity that will be transformed</param>
/// <param name="protoId">The id of the polymorph prototype</param>
public EntityUid? PolymorphEntity(EntityUid uid, ProtoId<PolymorphPrototype> protoId)
{
var config = _proto.Index(protoId).Configuration;
return PolymorphEntity(uid, config);
}
/// <summary>
/// Polymorphs the target entity into another.
/// </summary>
/// <param name="uid">The entity that will be transformed</param>
/// <param name="configuration">The new polymorph configuration</param>
/// <returns>The new entity, or null if the polymorph failed.</returns>
public EntityUid? PolymorphEntity(EntityUid uid, PolymorphConfiguration configuration)
{
//ADT-Geras-Tweak-Start
if (configuration.CanNotPolymorphInStorage && HasComp<InsideEntityStorageComponent>(uid))
{
_popup.PopupEntity(Loc.GetString("polymorph-in-storage-forbidden"), uid, uid);
return null;
}
//ADT-Geras-Tweak-End
// if it's already morphed, don't allow it again with this condition active.
if (!configuration.AllowRepeatedMorphs && HasComp<PolymorphedEntityComponent>(uid))
return null;
// If this polymorph has a cooldown, check if that amount of time has passed since the
// last polymorph ended.
if (TryComp<PolymorphableComponent>(uid, out var polymorphableComponent) &&
polymorphableComponent.LastPolymorphEnd != null &&
_gameTiming.CurTime < polymorphableComponent.LastPolymorphEnd + configuration.Cooldown)
return null;
// mostly just for vehicles
_buckle.TryUnbuckle(uid, uid, true);
var targetTransformComp = Transform(uid);
if (configuration.PolymorphSound != null)
_audio.PlayPvs(configuration.PolymorphSound, targetTransformComp.Coordinates);
var child = Spawn(configuration.Entity, _transform.GetMapCoordinates(uid, targetTransformComp), rotation: _transform.GetWorldRotation(uid));
if (configuration.PolymorphPopup != null)
_popup.PopupEntity(Loc.GetString(configuration.PolymorphPopup,
("parent", Identity.Entity(uid, EntityManager)),
("child", Identity.Entity(child, EntityManager))),
child);
_mindSystem.MakeSentient(child);
var polymorphedComp = Factory.GetComponent<PolymorphedEntityComponent>();
polymorphedComp.Parent = uid;
polymorphedComp.Configuration = configuration;
AddComp(child, polymorphedComp);
var childXform = Transform(child);
_transform.SetLocalRotation(child, targetTransformComp.LocalRotation, childXform);
if (_container.TryGetContainingContainer((uid, targetTransformComp, null), out var cont))
_container.Insert(child, cont);
//Transfers all damage from the original to the new one
if (configuration.TransferDamage &&
TryComp<DamageableComponent>(child, out var damageParent) &&
_mobThreshold.GetScaledDamage(uid, child, out var damage) &&
damage != null)
{
_damageable.SetDamage((child, damageParent), damage);
}
if (configuration.Inventory == PolymorphInventoryChange.Transfer)
{
_inventory.TransferEntityInventories(uid, child);
foreach (var hand in _hands.EnumerateHeld(uid))
{
_hands.TryDrop(uid, hand, checkActionBlocker: false);
_hands.TryPickupAnyHand(child, hand);
}
}
else if (configuration.Inventory == PolymorphInventoryChange.Drop)
{
if (_inventory.TryGetContainerSlotEnumerator(uid, out var enumerator))
{
while (enumerator.MoveNext(out var slot))
{
_inventory.TryUnequip(uid, slot.ID, true, true);
}
}
foreach (var held in _hands.EnumerateHeld(uid))
{
_hands.TryDrop(uid, held);
}
}
if (configuration.TransferName && TryComp(uid, out MetaDataComponent? targetMeta))
_metaData.SetEntityName(child, targetMeta.EntityName);
// ADT-Geras-Tweak-Start
if (configuration.TransferLanguageSpeaker && TryComp<LanguageSpeakerComponent>(uid, out var originalLangComp))
{
var childLangComp = EnsureComp<LanguageSpeakerComponent>(child);
childLangComp.Languages = new Dictionary<string, LanguageKnowledge>(originalLangComp.Languages);
childLangComp.CurrentLanguage = originalLangComp.CurrentLanguage;
}
if (configuration.TransferTTS && TryComp<TTSComponent>(uid, out var originalTTSComp))
{
var childTTSComp = EnsureComp<TTSComponent>(child);
childTTSComp.VoicePrototypeId = originalTTSComp.VoicePrototypeId;
}
if (configuration.TransferSpeechBarks && TryComp<SpeechBarksComponent>(uid, out var originalBarksComp))
{
var childBarksComp = EnsureComp<SpeechBarksComponent>(child);
childBarksComp.Data = originalBarksComp.Data;
}
if (configuration.TransferAccents)
{
var accentComponents = new List<Type>
{
typeof(AccentlessComponent),
typeof(BackwardsAccentComponent),
typeof(BarkAccentComponent),
typeof(BleatingAccentComponent),
typeof(DamagedSiliconAccentComponent),
typeof(FrenchAccentComponent),
typeof(GermanAccentComponent),
typeof(GrowlingAccentComponent),
typeof(LizardAccentComponent),
typeof(MobsterAccentComponent),
typeof(MonkeyAccentComponent),
typeof(MothAccentComponent),
typeof(MumbleAccentComponent),
typeof(NyaAccentComponent),
typeof(OwOAccentComponent),
typeof(ParrotAccentComponent),
typeof(PirateAccentComponent),
typeof(ReplacementAccentComponent),
typeof(ResomiAccentComponent),
typeof(RoarAccentComponent),
typeof(RussianAccentComponent),
typeof(ScrambledAccentComponent),
typeof(SkeletonAccentComponent),
typeof(SlurredAccentComponent),
typeof(SouthernAccentComponent),
typeof(SpanishAccentComponent),
typeof(StutteringAccentComponent),
typeof(VoxAccentComponent),
typeof(FrontalLispComponent)
};
foreach (var accentType in accentComponents)
{
if (EntityManager.HasComponent(uid, accentType))
{
var originalAccentComp = EntityManager.GetComponent(uid, accentType);
var childAccentComp = (Component)_serialization.CreateCopy(originalAccentComp, notNullableOverride: true);
EntityManager.AddComponent(child, childAccentComp);
}
}
}
if (configuration.TransferQuirks)
{
var quirkComponents = new List<Type> //Вроде бы все добавил???
{
typeof(PacifiedComponent),
typeof(LightweightDrunkComponent),
typeof(SnoringComponent),
typeof(BlindableComponent),
typeof(PermanentBlindnessComponent),
typeof(BlurryVisionComponent),
typeof(TemporaryBlindnessComponent),
typeof(UncloneableComponent),
typeof(NarcolepsyComponent),
typeof(UnrevivableComponent),
typeof(MutedComponent),
typeof(ParacusiaComponent),
typeof(PainNumbnessComponent),
typeof(HemophiliaComponent),
typeof(DeafTraitComponent),
typeof(MonochromacyComponent),
typeof(FrailComponent),
typeof(SoftWalkComponent),
typeof(FreerunningComponent),
typeof(SprinterComponent),
typeof(FastLockersComponent),
typeof(HardThrowerComponent),
typeof(FoodConsumptionSpeedModifierComponent),
typeof(DrunkenResilienceComponent)
};
foreach (var quirkType in quirkComponents)
{
if (EntityManager.HasComponent(uid, quirkType))
{
var originalQuirkComp = EntityManager.GetComponent(uid, quirkType);
var childQuirkComp = (Component)_serialization.CreateCopy(originalQuirkComp, notNullableOverride: true);
EntityManager.AddComponent(child, childQuirkComp);
}
}
}
if (configuration.TransferFlame && TryComp<FlammableComponent>(uid, out var parentFlame))
{
var childFlame = EnsureComp<FlammableComponent>(child);
_flammable.SetFireStacks(child, parentFlame.FireStacks, childFlame, parentFlame.OnFire);
}
if (configuration.TransferStaminaDamage && TryComp<StaminaComponent>(uid, out var parentStam))
{
var childStam = EnsureComp<StaminaComponent>(child);
var parentEffective = _stamina.GetStaminaDamage(uid, parentStam);
var fraction = parentEffective / parentStam.CritThreshold;
var childTarget = fraction * childStam.CritThreshold;
_stamina.TakeStaminaDamage(child, childTarget, childStam, visual: false, ignoreResist: true);
}
if (configuration.TransferTemperature)
{
if (TryComp<TemperatureComponent>(uid, out var parentTemp))
{
var childTemp = EnsureComp<TemperatureComponent>(child);
_temperatureSystem.ForceChangeTemperature(child, parentTemp.CurrentTemperature, childTemp);
}
}
// ADT-Geras-Tweak-End
if (configuration.TransferHumanoidAppearance)
{
_humanoid.CloneAppearance(uid, child);
}
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
_mindSystem.TransferTo(mindId, child, mind: mind);
SendToPausedMap(uid, targetTransformComp); // ADT-Tweak
// Raise an event to inform anything that wants to know about the entity swap
var ev = new PolymorphedEvent(uid, child, false);
RaiseLocalEvent(uid, ref ev);
// visual effect spawn
if (configuration.EffectProto != null)
SpawnAttachedTo(configuration.EffectProto, child.ToCoordinates());
return child;
}
/// <summary>
/// Polymorphs the target entity into an exact copy of the given PolymorphHumanoidData
/// </summary>
/// <param name="uid">The entity that will be transformed</param>
/// <param name="data">The humanoid data</param>
public EntityUid? PolymorphEntityAsHumanoid(EntityUid uid, PolymorphHumanoidData data)
{
var targetTransformComp = Transform(uid);
var child = data.EntityUid;
RetrievePausedEntity(uid, child);
if (TryComp<HumanoidAppearanceComponent>(child, out var humanoidAppearance))
_humanoid.SetAppearance(data.HumanoidAppearanceComponent, humanoidAppearance);
if (TryComp<DnaComponent>(child, out var dnaComp))
{
dnaComp.DNA = data.DNA;
Dirty(child, dnaComp);
}
//Transfers all damage from the original to the new one
if (TryComp<DamageableComponent>(child, out var damageParent)
&& _mobThreshold.GetScaledDamage(uid, child, out var damage)
&& damage != null)
{
_damageable.SetDamage((child, damageParent), damage);
}
_inventory.TransferEntityInventories(uid, child); // transfer the inventory all the time
foreach (var hand in _hands.EnumerateHeld(uid))
{
if (!_hands.TryPickupAnyHand(child, hand))
_hands.TryDrop(uid, hand, checkActionBlocker: false);
}
// ADT-Changeling-Tweak-End
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
_mindSystem.TransferTo(mindId, child, mind: mind);
EnsurePausedMap();
if (PausedMap != null)
_transform.SetParent(uid, targetTransformComp, PausedMap.Value);
// Raise an event to inform anything that wants to know about the entity swap
var ev = new PolymorphedEvent(uid, child, false);
RaiseLocalEvent(uid, ref ev);
// goob edit
if (TryComp<FollowedComponent>(uid, out var followed))
foreach (var f in followed.Following)
{
_follow.StopFollowingEntity(f, uid);
_follow.StartFollowingEntity(f, child);
}
// goob edit end
return child;
}
// ADT-Changeling-Tweak-Start
/// <summary>
/// Sends the given entity to a pauses map
/// </summary>
public void SendToPausedMap(EntityUid uid, TransformComponent transform)
{
//Ensures a map to banish the entity to
EnsurePausedMap();
if (PausedMap != null)
_transform.SetParent(uid, transform, PausedMap.Value);
}
/// <summary>
/// Retrieves a paused entity (target) at the user's position
/// </summary>
private void RetrievePausedEntity(EntityUid user, EntityUid target)
{
if (Deleted(user))
return;
if (Deleted(target))
return;
var targetTransform = Transform(target);
var userTransform = Transform(user);
_transform.SetParent(target, targetTransform, user);
targetTransform.Coordinates = userTransform.Coordinates;
targetTransform.LocalRotation = userTransform.LocalRotation;
if (_container.TryGetContainingContainer(user, out var cont))
_container.Insert(target, cont);
}
// ADT-Changeling-Tweak-End
/// <summary>
/// Reverts a polymorphed entity back into its original form
/// </summary>
/// <param name="uid">The entityuid of the entity being reverted</param>
/// <param name="component"></param>
public EntityUid? Revert(Entity<PolymorphedEntityComponent?> ent)
{
var (uid, component) = ent;
if (!Resolve(ent, ref component))
return null;
//ADT-Geras-Tweak-Start
if (component.Configuration.CanNotPolymorphInStorage && HasComp<InsideEntityStorageComponent>(uid))
{
_popup.PopupEntity(Loc.GetString("revert-in-storage-forbidden"), uid, uid);
return null;
}
//ADT-Geras-Tweak-End
if (Deleted(uid))
return null;
if (component.Parent is not { } parent)
return null;
if (Deleted(parent))
return null;
var uidXform = Transform(uid);
var parentXform = Transform(parent);
// Don't swap back onto a terminating grid
if (TerminatingOrDeleted(uidXform.ParentUid))
return null;
if (component.Configuration.ExitPolymorphSound != null)
_audio.PlayPvs(component.Configuration.ExitPolymorphSound, uidXform.Coordinates);
_transform.SetParent(parent, parentXform, uidXform.ParentUid);
_transform.SetCoordinates(parent, parentXform, uidXform.Coordinates, uidXform.LocalRotation);
component.Reverted = true;
if (component.Configuration.TransferDamage &&
TryComp<DamageableComponent>(parent, out var damageParent) &&
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&
damage != null)
{
_damageable.SetDamage((parent, damageParent), damage);
}
if (component.Configuration.Inventory == PolymorphInventoryChange.Transfer)
{
_inventory.TransferEntityInventories(uid, parent);
foreach (var held in _hands.EnumerateHeld(uid))
{
_hands.TryDrop(uid, held);
_hands.TryPickupAnyHand(parent, held, checkActionBlocker: false);
}
}
else if (component.Configuration.Inventory == PolymorphInventoryChange.Drop)
{
if (_inventory.TryGetContainerSlotEnumerator(uid, out var enumerator))
{
while (enumerator.MoveNext(out var slot))
{
_inventory.TryUnequip(uid, slot.ID);
}
}
foreach (var held in _hands.EnumerateHeld(uid))
{
_hands.TryDrop(uid, held);
}
}
if (_mindSystem.TryGetMind(uid, out var mindId, out var mind))
_mindSystem.TransferTo(mindId, parent, mind: mind);
if (TryComp<PolymorphableComponent>(parent, out var polymorphableComponent))
polymorphableComponent.LastPolymorphEnd = _gameTiming.CurTime;
//ADT-Geras-Tweak-Start
if (component.Configuration.TransferFlame && TryComp<FlammableComponent>(uid, out var childFlame))
{
var parentFlame = EnsureComp<FlammableComponent>(parent);
_flammable.SetFireStacks(parent, childFlame.FireStacks, parentFlame, childFlame.OnFire);
}
if (component.Configuration.TransferStaminaDamage && TryComp<StaminaComponent>(uid, out var childStam))
{
var parentStam = EnsureComp<StaminaComponent>(parent);
var childEffective = _stamina.GetStaminaDamage(uid, childStam);
var fraction = childEffective / childStam.CritThreshold;
var parentTarget = fraction * parentStam.CritThreshold;
var parentCurrent = _stamina.GetStaminaDamage(parent, parentStam);
var delta = parentTarget - parentCurrent;
_stamina.TakeStaminaDamage(parent, delta, parentStam, visual: false, ignoreResist: true);
}
if (component.Configuration.TransferTemperature)
{
if (TryComp<TemperatureComponent>(uid, out var childTemp))
{
var parentTemp = EnsureComp<TemperatureComponent>(parent);
_temperatureSystem.ForceChangeTemperature(parent, childTemp.CurrentTemperature, parentTemp);
}
}
//ADT-Geras-Tweak-End
// if an item polymorph was picked up, put it back down after reverting
_transform.AttachToGridOrMap(parent, parentXform);
// Raise an event to inform anything that wants to know about the entity swap
var ev = new PolymorphedEvent(uid, parent, true);
RaiseLocalEvent(uid, ref ev);
// visual effect spawn
if (component.Configuration.EffectProto != null)
SpawnAttachedTo(component.Configuration.EffectProto, parent.ToCoordinates());
if (component.Configuration.ExitPolymorphPopup != null)
_popup.PopupEntity(Loc.GetString(component.Configuration.ExitPolymorphPopup,
("parent", Identity.Entity(uid, EntityManager)),
("child", Identity.Entity(parent, EntityManager))),
parent);
QueueDel(uid);
// goob edit
if (TryComp<FollowedComponent>(uid, out var followed))
foreach (var f in followed.Following)
{
_follow.StopFollowingEntity(f, uid);
_follow.StartFollowingEntity(f, parent);
}
// goob edit end
return parent;
}
/// <summary>
/// Creates a sidebar action for an entity to be able to polymorph at will
/// </summary>
/// <param name="id">The string of the id of the polymorph action</param>
/// <param name="target">The entity that will be gaining the action</param>
public void CreatePolymorphAction(ProtoId<PolymorphPrototype> id, Entity<PolymorphableComponent> target)
{
target.Comp.PolymorphActions ??= new();
if (target.Comp.PolymorphActions.ContainsKey(id))
return;
if (!_proto.Resolve(id, out var polyProto))
return;
var entProto = _proto.Index(polyProto.Configuration.Entity);
EntityUid? actionId = default!;
if (!_actions.AddAction(target, ref actionId, RevertPolymorphId, target))
return;
target.Comp.PolymorphActions.Add(id, actionId.Value);
var metaDataCache = MetaData(actionId.Value);
_metaData.SetEntityName(actionId.Value, Loc.GetString("polymorph-self-action-name", ("target", entProto.Name)), metaDataCache);
_metaData.SetEntityDescription(actionId.Value, Loc.GetString("polymorph-self-action-description", ("target", entProto.Name)), metaDataCache);
if (_actions.GetAction(actionId) is not {} action)
return;
_actions.SetIcon((action, action.Comp), new SpriteSpecifier.EntityPrototype(polyProto.Configuration.Entity));
_actions.SetEvent(action, new PolymorphActionEvent(id));
}
public void RemovePolymorphAction(ProtoId<PolymorphPrototype> id, Entity<PolymorphableComponent> target)
{
if (target.Comp.PolymorphActions is not {} actions)
return;
if (actions.TryGetValue(id, out var action))
_actions.RemoveAction(target.Owner, action);
}
// ADT-Changeling-Tweak-Start
/// <summary>
/// Registers PolymorphHumanoidData from an EntityUid, provived they have all the needed components
/// </summary>
/// <param name="source">The source that the humanoid data is referencing from</param>
public PolymorphHumanoidData? TryRegisterPolymorphHumanoidData(EntityUid source)
{
var newHumanoidData = new PolymorphHumanoidData();
if (!TryComp<MetaDataComponent>(source, out var targetMeta))
return null;
if (!TryPrototype(source, out var prototype, targetMeta))
return null;
if (!TryComp<DnaComponent>(source, out var dnaComp))
return null;
if (!TryComp<HumanoidAppearanceComponent>(source, out var targetHumanoidAppearance))
return null;
newHumanoidData.EntityPrototype = prototype;
newHumanoidData.MetaDataComponent = targetMeta;
newHumanoidData.HumanoidAppearanceComponent = _serialization.CreateCopy(targetHumanoidAppearance, notNullableOverride: true);
if (dnaComp.DNA != null)
newHumanoidData.DNA = dnaComp.DNA;
var targetTransformComp = Transform(source);
var newEntityUid = Spawn(newHumanoidData.EntityPrototype.ID, targetTransformComp.Coordinates);
var newEntityUidTransformComp = Transform(newEntityUid);
if (TryComp(source, out MindShieldComponent? mindshieldComp)) // copy over mindshield status
{
var copiedMindshieldComp = (Component) _serialization.CreateCopy(mindshieldComp, notNullableOverride: true);
EntityManager.AddComponent(newEntityUid, copiedMindshieldComp);
}
//ADT-tweak-start
// if (TryComp<DetailExaminableComponent>(source, out var desc))
// {
// var newDesc = EnsureComp<DetailExaminableComponent>(newEntityUid);
// newDesc.Content = desc.Content;
// }
if (TryComp<CharacterFlavorComponent>(source, out var flavor))
{
var newDesc = EnsureComp<CharacterFlavorComponent>(newEntityUid);
newDesc.FlavorText = flavor.FlavorText;
newDesc.OOCNotes = flavor.OOCNotes;
newDesc.HeadshotUrl = flavor.HeadshotUrl;
}
//ADT-tweak-end
SendToPausedMap(newEntityUid, newEntityUidTransformComp);
newHumanoidData.EntityUid = newEntityUid;
_metaData.SetEntityName(newEntityUid, targetMeta.EntityName);
return newHumanoidData;
}
/// <summary>
/// Registers PolymorphHumanoidData from an EntityUid, provived they have all the needed components. This allows you to add a uid as the HumanoidData's EntityUid variable. Does not send the given uid to the pause map.
/// </summary>
/// <param name="source">The source that the humanoid data is referencing from</param>
/// <param name="uid">The uid that will become the newHumanoidData's EntityUid</param>
public PolymorphHumanoidData? TryRegisterPolymorphHumanoidData(EntityUid source, EntityUid uid)
{
var newHumanoidData = new PolymorphHumanoidData();
if (!TryComp<MetaDataComponent>(source, out var targetMeta))
return null;
if (!TryPrototype(source, out var prototype, targetMeta))
return null;
if (!TryComp<DnaComponent>(source, out var dnaComp))
return null;
if (!TryComp<HumanoidAppearanceComponent>(source, out var targetHumanoidAppearance))
return null;
newHumanoidData.EntityPrototype = prototype;
newHumanoidData.MetaDataComponent = targetMeta;
newHumanoidData.HumanoidAppearanceComponent = _serialization.CreateCopy(targetHumanoidAppearance, notNullableOverride: true);
if (dnaComp.DNA != null)
newHumanoidData.DNA = dnaComp.DNA;
newHumanoidData.EntityUid = uid;
return newHumanoidData;
}
public PolymorphHumanoidData CopyPolymorphHumanoidData(PolymorphHumanoidData data)
{
var newHumanoidData = new PolymorphHumanoidData();
var ent = Spawn(data.EntityPrototype.ID);
SendToPausedMap(ent, Transform(ent));
newHumanoidData.EntityPrototype = data.EntityPrototype;
newHumanoidData.MetaDataComponent = data.MetaDataComponent;
newHumanoidData.HumanoidAppearanceComponent = _serialization.CreateCopy(data.HumanoidAppearanceComponent, notNullableOverride: true);;
newHumanoidData.DNA = data.DNA;
newHumanoidData.EntityUid = ent;
_metaData.SetEntityName(ent, data.MetaDataComponent.EntityName);
return newHumanoidData;
}
// ADT-Changeling-Tweak-End
}
// goob edit
public sealed partial class PolymorphRevertEvent : EntityEventArgs { }