1010using YamlDotNet . Serialization ;
1111using Random = System . Random ;
1212using ServerEvents = Exiled . Events . Handlers . Server ;
13+ using PlayerEvent = Exiled . Events . Handlers . Player ;
14+ using E = ExtendedItems . Utils ;
1315
1416namespace ExtendedItems . Items
1517{
@@ -56,13 +58,14 @@ public class Scp1162 : CustomItem
5658 ItemType . Coin ,
5759 ItemType . Flashlight ,
5860 ItemType . Radio ,
61+ ItemType . None ,
5962
6063 ] ;
6164
6265 private void OnRoundStarted ( )
6366 {
6467 Room room = Room . Get ( Plugin . Instance . Config . Scp1162Room ) ;
65- Vector3 globalPos = Utils . GetGlobalCords ( Plugin . Instance . Config . Scp1162Room , new Vector3 ( 16.68f , 11.6f , 8.11f ) ) ;
68+ Vector3 globalPos = E . GetGlobalCords ( Plugin . Instance . Config . Scp1162Room , new Vector3 ( 16.68f , 11.6f , 8.11f ) ) ;
6669
6770 Quaternion rotation = room . Rotation ;
6871 Vector3 rot = new ( 0f , 1f , 0.0f ) ;
@@ -78,23 +81,28 @@ private void OnRoundStarted()
7881 protected override void SubscribeEvents ( )
7982 {
8083 ServerEvents . RoundStarted += OnRoundStarted ;
84+ PlayerEvent . PickingUpItem += OnPickingUp ;
85+ PlayerEvent . DroppingItem += OnDroppingItem ;
8186
8287 base . SubscribeEvents ( ) ;
8388 }
8489
8590 protected override void UnsubscribeEvents ( )
8691 {
8792 ServerEvents . RoundStarted -= OnRoundStarted ;
93+ PlayerEvent . PickingUpItem -= OnPickingUp ;
94+ PlayerEvent . DroppingItem -= OnDroppingItem ;
8895
8996 base . UnsubscribeEvents ( ) ;
9097 }
9198
9299 protected override void OnDroppingItem ( DroppingItemEventArgs ev )
93100 {
101+ if ( ! Check ( ev . Item ) )
94102 ev . Item . Destroy ( ) ;
95103
96104 Room room = Room . Get ( Plugin . Instance . Config . Scp1162Room ) ;
97- Vector3 globalPos = Utils . GetGlobalCords ( Plugin . Instance . Config . Scp1162Room , new Vector3 ( 16.68f , 11.6f , 8.11f ) ) ;
105+ Vector3 globalPos = E . GetGlobalCords ( Plugin . Instance . Config . Scp1162Room , new Vector3 ( 16.68f , 11.6f , 8.11f ) ) ;
98106
99107 Quaternion rotation = room . Rotation ;
100108 Vector3 rot = new ( 0f , 1f , 0.0f ) ;
@@ -111,11 +119,13 @@ protected override void OnDroppingItem(DroppingItemEventArgs ev)
111119
112120 protected override void OnPickingUp ( PickingUpItemEventArgs ev )
113121 {
114- ev . IsAllowed = false ;
122+ if ( ! Check ( ev . Pickup ) ) return ;
123+ ev . IsAllowed = false ;
115124
116125 try
117126 {
118127 Item item = ev . Player . CurrentItem ;
128+ int rnad ;
119129 if ( item == null )
120130 {
121131 ev . Player . EnableEffect ( EffectType . SeveredHands , byte . MaxValue ) ;
@@ -130,18 +140,21 @@ protected override void OnPickingUp(PickingUpItemEventArgs ev)
130140 }
131141 ev . Player . RemoveItem ( item ) ;
132142 if ( _rng . NextDouble ( ) < LoseChance ) return ;
143+ rnad = _rng . Next ( 0 , ItemTypes . Length ) ;
144+ if ( ItemTypes [ rnad ] == ItemType . None )
145+ {
146+ ev . Player . TryAddCandy ( E . AddCandy ( _rng . Next ( 0 , 6 ) ) ) ;
147+ }
133148 item = ev . Player . AddItem ( ItemTypes [ _rng . Next ( 0 , ItemTypes . Length ) ] ) ;
134149
135-
136-
137150 ev . Player . CurrentItem = item ;
138-
139151 }
140152 return ;
141153 }
142- catch
154+ catch ( Exception ex )
143155 {
144- // ignored
156+ Log . Warn ( $ "Error: { ex } ") ;
157+ ev . Player . ShowHint ( "Something went wrong" , 5 ) ;
145158 }
146159
147160 base . OnPickingUp ( ev ) ;
0 commit comments