@@ -27,7 +27,8 @@ public static Sprite getTrapSprite() {
2727 return trapSprite ;
2828 }
2929
30- public Trap ( Vector2 p ) {
30+ public Trap ( Vector2 p )
31+ {
3132 trap = new GameObject ( "Trap" ) { layer = 11 } ;
3233 trap . AddSubmergedComponent ( SubmergedCompatibility . Classes . ElevatorMover ) ;
3334 Vector3 position = new Vector3 ( p . x , p . y , p . y / 1000 + 0.001f ) ; // just behind player
@@ -44,68 +45,77 @@ public Trap(Vector2 p) {
4445 arrow . Update ( position ) ;
4546 arrow . arrow . SetActive ( false ) ;
4647 FastDestroyableSingleton < HudManager > . Instance . StartCoroutine ( Effects . Lerp ( 5 , new Action < float > ( ( x ) => {
47- if ( x == 1f ) {
48+ if ( x == 1f )
49+ {
4850 this . triggerable = true ;
4951 trapRenderer . color = Color . white ;
5052 }
5153 } ) ) ) ;
5254 }
5355
54- public static void clearTraps ( ) {
55- foreach ( Trap t in traps ) {
56+ public static void clearTraps ( )
57+ {
58+ foreach ( Trap t in traps )
59+ {
5660 UnityEngine . Object . Destroy ( t . arrow . arrow ) ;
57- UnityEngine . Object . Destroy ( t . trap ) ;
61+ UnityEngine . Object . Destroy ( t . trap ) ;
5862 }
5963 traps = new List < Trap > ( ) ;
6064 trapPlayerIdMap = new Dictionary < byte , Trap > ( ) ;
6165 instanceCounter = 0 ;
6266 }
6367
64- public static void clearRevealedTraps ( ) {
68+ public static void clearRevealedTraps ( )
69+ {
6570 var trapsToClear = traps . FindAll ( x => x . revealed ) ;
6671
67- foreach ( Trap t in trapsToClear ) {
72+ foreach ( Trap t in trapsToClear )
73+ {
6874 traps . Remove ( t ) ;
6975 UnityEngine . Object . Destroy ( t . trap ) ;
7076 }
7177 }
7278
73- public static void triggerTrap ( byte playerId , byte trapId ) {
79+ public static void triggerTrap ( byte playerId , byte trapId )
80+ {
7481 Trap t = traps . FirstOrDefault ( x => x . instanceId == ( int ) trapId ) ;
7582 PlayerControl player = Helpers . playerById ( playerId ) ;
7683 if ( Trapper . trapper == null || t == null || player == null ) return ;
7784 bool localIsTrapper = PlayerControl . LocalPlayer . PlayerId == Trapper . trapper . PlayerId ;
7885 if ( ! trapPlayerIdMap . ContainsKey ( playerId ) ) trapPlayerIdMap . Add ( playerId , t ) ;
79- t . usedCount ++ ;
86+ t . usedCount ++ ;
8087 t . triggerable = false ;
81- if ( playerId == PlayerControl . LocalPlayer . PlayerId || playerId == Trapper . trapper . PlayerId ) {
88+ if ( playerId == PlayerControl . LocalPlayer . PlayerId || playerId == Trapper . trapper . PlayerId )
89+ {
8290 t . trap . SetActive ( true ) ;
8391 SoundEffectsManager . play ( "trapperTrap" ) ;
8492 }
8593 player . moveable = false ;
8694 player . NetTransform . Halt ( ) ;
87- Trapper . playersOnMap . Add ( player ) ;
95+ Trapper . playersOnMap . Add ( player . PlayerId ) ;
8896 if ( localIsTrapper ) t . arrow . arrow . SetActive ( true ) ;
8997
90- FastDestroyableSingleton < HudManager > . Instance . StartCoroutine ( Effects . Lerp ( Trapper . trapDuration , new Action < float > ( ( p ) => {
91- if ( p == 1f ) {
98+ FastDestroyableSingleton < HudManager > . Instance . StartCoroutine ( Effects . Lerp ( Trapper . trapDuration , new Action < float > ( ( p ) => {
99+ if ( p == 1f )
100+ {
92101 player . moveable = true ;
93- Trapper . playersOnMap . RemoveAll ( x => x == player ) ;
102+ Trapper . playersOnMap . RemoveAll ( x => x == player . PlayerId ) ;
94103 if ( trapPlayerIdMap . ContainsKey ( playerId ) ) trapPlayerIdMap . Remove ( playerId ) ;
95104 t . arrow . arrow . SetActive ( false ) ;
96105 }
97106 } ) ) ) ;
98107
99- if ( t . usedCount == t . neededCount ) {
108+ if ( t . usedCount == t . neededCount )
109+ {
100110 t . revealed = true ;
101111 }
102112
103- t . trappedPlayer . Add ( player ) ;
113+ t . trappedPlayer . Add ( ( PlayerControl ) player . PlayerId ) ;
104114 t . triggerable = true ;
105-
106115 }
107116
108- public static void Update ( ) {
117+ public static void Update ( )
118+ {
109119 if ( Trapper . trapper == null ) return ;
110120 var player = PlayerControl . LocalPlayer ;
111121 Vent vent = MapUtilities . CachedShipStatus . AllVents [ 0 ] ;
@@ -114,27 +124,31 @@ public static void Update() {
114124 if ( vent == null || player == null ) return ;
115125 float ud = vent . UsableDistance / 2 ;
116126 Trap target = null ;
117- foreach ( Trap trap in traps ) {
127+ foreach ( Trap trap in traps )
128+ {
118129 if ( trap . arrow . arrow . active ) trap . arrow . Update ( ) ;
119- if ( trap . revealed || ! trap . triggerable || trap . trappedPlayer . Contains ( player ) ) continue ;
130+ if ( trap . revealed || ! trap . triggerable || trap . trappedPlayer . Contains ( ( PlayerControl ) player . PlayerId ) ) continue ;
120131 if ( player . inVent || ! player . CanMove ) continue ;
121132 float distance = Vector2 . Distance ( trap . trap . transform . position , player . GetTruePosition ( ) ) ;
122- if ( distance <= ud && distance < closestDistance ) {
133+ if ( distance <= ud && distance < closestDistance )
134+ {
123135 closestDistance = distance ;
124136 target = trap ;
125137 }
126138 }
127- if ( target != null && player . PlayerId != Trapper . trapper . PlayerId && ! player . Data . IsDead ) {
139+ if ( target != null && player . PlayerId != Trapper . trapper . PlayerId && ! player . Data . IsDead )
140+ {
128141 MessageWriter writer = AmongUsClient . Instance . StartRpcImmediately ( PlayerControl . LocalPlayer . NetId , ( byte ) CustomRPC . TriggerTrap , Hazel . SendOption . Reliable , - 1 ) ;
129142 writer . Write ( player . PlayerId ) ;
130143 writer . Write ( target . instanceId ) ;
131144 AmongUsClient . Instance . FinishRpcImmediately ( writer ) ;
132- RPCProcedure . triggerTrap ( player . PlayerId , ( byte ) target . instanceId ) ;
145+ RPCProcedure . triggerTrap ( player . PlayerId , ( byte ) target . instanceId ) ;
133146 }
134147
135148
136149 if ( ! player . Data . IsDead || player . PlayerId == Trapper . trapper . PlayerId ) return ;
137- foreach ( Trap trap in traps ) {
150+ foreach ( Trap trap in traps )
151+ {
138152 if ( ! trap . trap . active ) trap . trap . SetActive ( true ) ;
139153 }
140154 }
0 commit comments