@@ -19,52 +19,45 @@ public class WraithCallerNpc(IntPtr ptr) : MonoBehaviour(ptr)
1919 public PlayerControl Target { get ; set ; }
2020 public PlayerControl npc ;
2121 public LightSource ownerLight ;
22- public bool isActive = false ;
22+ public bool isActive ;
2323
2424 [ HideFromIl2Cpp ]
25-
2625 // Inspired by: https://github.com/NuclearPowered/Reactor/blob/e27a79249ea706318f3c06f3dc56a5c42d65b1cf/Reactor.Debugger/Window/Tabs/GameTab.cs#L70
27- public void Initialize ( PlayerControl wraith , PlayerControl target )
26+ public void Initialize ( PlayerControl wraith , PlayerControl target , PlayerControl spawned )
2827 {
2928 Owner = wraith ;
3029 Target = target ;
30+ npc = spawned ;
3131
32- var prefab = AmongUsClient . Instance . PlayerPrefab ;
33- npc = Instantiate ( prefab ) ;
34- npc . PlayerId = ( byte ) GameData . Instance . GetAvailableId ( ) ;
35-
36- var npcData = GameData . Instance . AddDummy ( npc ) ;
37- AmongUsClient . Instance . Spawn ( npcData ) ;
38- AmongUsClient . Instance . Spawn ( npc ) ;
32+ isActive = true ;
3933
40- npc . isDummy = false ;
41- npc . notRealPlayer = true ;
4234 KillAnimation . SetMovement ( npc , true ) ;
43- npc . NetTransform . RpcSnapTo ( Owner . transform . position ) ;
44- npc . MyPhysics . Speed = OptionGroupSingleton < WraithCallerOptions > . Instance . NPCSpeed ;
45-
46- var color = ( byte ) ( npc . PlayerId % Palette . PlayerColors . Length ) ;
47- npc . RpcSetName ( "Wraith NPC" ) ;
48- npc . RpcSetColor ( color ) ;
49- npc . RpcSetHat ( "" ) ;
50- npc . RpcSetSkin ( "" ) ;
51- npc . RpcSetPet ( "" ) ;
52- npc . RpcSetVisor ( "" ) ;
5335
5436 npc . Collider . enabled = false ;
37+ npc . MyPhysics . Speed = OptionGroupSingleton < WraithCallerOptions > . Instance . NPCSpeed ;
5538
56- var noShadow = npc . gameObject . AddComponent < NoShadowBehaviour > ( ) ;
57- if ( noShadow != null )
58- {
59- noShadow . rend = npc . cosmetics . currentBodySprite . BodySprite ;
60- noShadow . hitOverride = npc . Collider ;
61- }
39+ if ( ! npc . TryGetComponent < ModifierComponent > ( out _ ) )
40+ npc . gameObject . AddComponent < ModifierComponent > ( ) ;
6241
63- if ( ! npc . TryGetComponent < ModifierComponent > ( out var mc ) )
42+ if ( AmongUsClient . Instance . AmHost )
6443 {
65- mc = npc . gameObject . AddComponent < ModifierComponent > ( ) ;
44+ NewMod . Instance . Log . LogMessage ( $ "Host is setting cosmetics for NPC (ID: { npc . PlayerId } ") ;
45+ npc . NetTransform . RpcSnapTo ( Owner . transform . position ) ;
46+
47+ var color = ( byte ) ( npc . PlayerId % Palette . PlayerColors . Length ) ;
48+ npc . RpcSetName ( "Wraith NPC" ) ;
49+ npc . RpcSetColor ( color ) ;
50+
51+ var noShadow = npc . gameObject . AddComponent < NoShadowBehaviour > ( ) ;
52+ if ( noShadow != null )
53+ {
54+ noShadow . rend = npc . cosmetics . currentBodySprite . BodySprite ;
55+ noShadow . hitOverride = npc . Collider ;
56+ }
6657 }
67-
58+
59+ Coroutines . Start ( WalkToTarget ( ) ) ;
60+
6861 if ( OptionGroupSingleton < WraithCallerOptions > . Instance . ShouldSwitchCamToNPC )
6962 {
7063 Camera . main . GetComponent < FollowerCamera > ( ) . SetTarget ( npc ) ;
@@ -73,52 +66,46 @@ public void Initialize(PlayerControl wraith, PlayerControl target)
7366 ownerLight . transform . localPosition = npc . Collider . offset ;
7467 }
7568
76- npc . cosmetics . enabled = false ;
69+ npc . cosmetics . enabled = true ;
7770 npc . enabled = false ;
7871
79- isActive = true ;
80-
81- Coroutines . Start ( WalkToTarget ( ) ) ;
82-
8372 if ( Target . AmOwner )
84- {
8573 SoundManager . Instance . PlaySound ( NewModAsset . HeartbeatSound . LoadAsset ( ) , false , 1f ) ;
86- }
8774 }
75+
8876 [ HideFromIl2Cpp ]
89- public System . Collections . IEnumerator WalkToTarget ( )
77+ private System . Collections . IEnumerator WalkToTarget ( )
9078 {
91- if ( Target . Data . IsDead || Target . Data . Disconnected )
92- {
93- Dispose ( ) ;
94- }
79+ //yield return null;
80+
81+ if ( ! AmongUsClient . Instance . AmHost ) yield break ;
82+
9583 while ( isActive && ! MeetingHud . Instance )
9684 {
85+ if ( ! Target || ! Target . Data || Target . Data . IsDead )
86+ break ;
87+
9788 Vector2 npcPos = npc . GetTruePosition ( ) ;
9889 Vector2 targetPos = Target . GetTruePosition ( ) ;
9990 Vector2 dir = ( targetPos - npcPos ) . normalized ;
10091
10192 npc . MyPhysics . SetNormalizedVelocity ( dir ) ;
10293
103- float distance = Vector2 . Distance ( npcPos , targetPos ) ;
104-
105- if ( distance <= 0.1f )
94+ if ( Vector2 . Distance ( npcPos , targetPos ) <= 0.1f )
10695 {
10796 npc . MyPhysics . SetNormalizedVelocity ( Vector2 . zero ) ;
10897
10998 Owner . RpcCustomMurder ( Target , true , teleportMurderer : false ) ;
11099
111100 if ( Target . AmOwner )
112- {
113101 CoroutinesHelper . CoNotify ( "<color=#FF4D4D><b>Oops!</b> The <i>Wraith NPC</i> got you..." ) ;
114- }
115- WraithCallerUtilities . AddKillNPC ( Owner . PlayerId ) ;
116102
117- Dispose ( ) ;
118- yield break ;
103+ WraithCallerUtilities . AddKillNPC ( Owner . PlayerId ) ;
104+ break ;
119105 }
120106 yield return new WaitForFixedUpdate ( ) ;
121107 }
108+
122109 npc . MyPhysics . SetNormalizedVelocity ( Vector2 . zero ) ;
123110 Dispose ( ) ;
124111 }
@@ -127,25 +114,26 @@ public System.Collections.IEnumerator WalkToTarget()
127114 public void Dispose ( )
128115 {
129116 if ( ! isActive ) return ;
130-
131117 isActive = false ;
132118
133- if ( npc != null )
119+ if ( OptionGroupSingleton < WraithCallerOptions > . Instance . ShouldSwitchCamToNPC )
120+ {
121+ Camera . main . GetComponent < FollowerCamera > ( ) . SetTarget ( Owner ) ;
122+ ownerLight . transform . SetParent ( Owner . transform , false ) ;
123+ ownerLight . transform . localPosition = Owner . Collider . offset ;
124+ }
125+
126+ if ( AmongUsClient . Instance . AmHost )
134127 {
135- if ( OptionGroupSingleton < WraithCallerOptions > . Instance . ShouldSwitchCamToNPC )
136- {
137- var cam = Camera . main . GetComponent < FollowerCamera > ( ) ;
138- cam . SetTarget ( Owner ) ;
139- ownerLight . transform . SetParent ( Owner . transform , false ) ;
140- ownerLight . transform . localPosition = Owner . Collider . offset ;
141- }
142128 var info = GameData . Instance . AllPlayers . ToArray ( ) . FirstOrDefault ( d => d . PlayerId == npc . PlayerId ) ;
143129 GameData . Instance . RemovePlayer ( info . PlayerId ) ;
144130 PlayerControl . AllPlayerControls . Remove ( npc ) ;
145131
132+ npc . Despawn ( ) ;
146133 Destroy ( npc . gameObject ) ;
147134 npc = null ;
148135 }
136+
149137 Destroy ( gameObject ) ;
150138 }
151139 }
0 commit comments