6
6
using NitroxClient . GameLogic . InitialSync . Abstract ;
7
7
using NitroxClient . MonoBehaviours ;
8
8
using NitroxClient . Unity . Helper ;
9
- using NitroxModel . DataStructures . GameLogic ;
9
+ using NitroxModel . DataStructures ;
10
10
using NitroxModel . DataStructures . Util ;
11
11
using NitroxModel . Packets ;
12
12
using UnityEngine ;
@@ -16,10 +16,12 @@ namespace NitroxClient.GameLogic.InitialSync;
16
16
public class EquippedItemInitialSyncProcessor : InitialSyncProcessor
17
17
{
18
18
private readonly IPacketSender packetSender ;
19
+ private readonly Entities entities ;
19
20
20
- public EquippedItemInitialSyncProcessor ( IPacketSender packetSender )
21
+ public EquippedItemInitialSyncProcessor ( IPacketSender packetSender , Entities entities )
21
22
{
22
23
this . packetSender = packetSender ;
24
+ this . entities = entities ;
23
25
24
26
AddDependency < PlayerInitialSyncProcessor > ( ) ;
25
27
AddDependency < RemotePlayerInitialSyncProcessor > ( ) ;
@@ -32,44 +34,36 @@ public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualW
32
34
33
35
using ( PacketSuppressor < EntitySpawnedByClient > . Suppress ( ) )
34
36
{
35
- foreach ( EquippedItemData equippedItem in packet . EquippedItems )
37
+ foreach ( KeyValuePair < string , NitroxId > equippedItem in packet . EquippedItems )
36
38
{
37
- waitScreenItem . SetProgress ( totalEquippedItemsDone , packet . EquippedItems . Count ) ;
39
+ string slot = equippedItem . Key ;
40
+ NitroxId id = equippedItem . Value ;
38
41
39
- GameObject gameObject = SerializationHelper . GetGameObject ( equippedItem . SerializedData ) ;
40
- NitroxEntity . SetNewId ( gameObject , equippedItem . ItemId ) ;
42
+ waitScreenItem . SetProgress ( totalEquippedItemsDone , packet . EquippedItems . Count ) ;
41
43
44
+ GameObject gameObject = NitroxEntity . RequireObjectFrom ( id ) ;
42
45
Pickupable pickupable = gameObject . RequireComponent < Pickupable > ( ) ;
43
- Optional < GameObject > opGameObject = NitroxEntity . GetObjectFrom ( equippedItem . ContainerId ) ;
44
46
45
- if ( opGameObject . HasValue )
46
- {
47
- GameObject owner = opGameObject . Value ;
47
+ GameObject player = Player . mainObject ;
48
+ Optional < Equipment > opEquipment = EquipmentHelper . FindEquipmentComponent ( player ) ;
48
49
49
- Optional < Equipment > opEquipment = EquipmentHelper . FindEquipmentComponent ( owner ) ;
50
-
51
- if ( opEquipment . HasValue )
52
- {
53
- Equipment equipment = opEquipment . Value ;
54
- InventoryItem inventoryItem = new ( pickupable ) ;
55
- inventoryItem . container = equipment ;
56
- inventoryItem . item . Reparent ( equipment . tr ) ;
50
+ if ( opEquipment . HasValue )
51
+ {
52
+ Equipment equipment = opEquipment . Value ;
53
+ InventoryItem inventoryItem = new ( pickupable ) ;
54
+ inventoryItem . container = equipment ;
55
+ inventoryItem . item . Reparent ( equipment . tr ) ;
57
56
58
- Dictionary < string , InventoryItem > itemsBySlot = equipment . equipment ;
59
- itemsBySlot [ equippedItem . Slot ] = inventoryItem ;
57
+ Dictionary < string , InventoryItem > itemsBySlot = equipment . equipment ;
58
+ itemsBySlot [ slot ] = inventoryItem ;
60
59
61
- equipment . UpdateCount ( pickupable . GetTechType ( ) , true ) ;
62
- Equipment . SendEquipmentEvent ( pickupable , 0 , owner , equippedItem . Slot ) ;
63
- equipment . NotifyEquip ( equippedItem . Slot , inventoryItem ) ;
64
- }
65
- else
66
- {
67
- Log . Info ( $ "Could not find equipment type for { gameObject . name } ") ;
68
- }
60
+ equipment . UpdateCount ( pickupable . GetTechType ( ) , true ) ;
61
+ Equipment . SendEquipmentEvent ( pickupable , 0 , player , slot ) ;
62
+ equipment . NotifyEquip ( slot , inventoryItem ) ;
69
63
}
70
64
else
71
65
{
72
- Log . Info ( $ "Could not find Container for { gameObject . name } ") ;
66
+ Log . Info ( $ "Could not find equipment type for { gameObject . name } ") ;
73
67
}
74
68
75
69
totalEquippedItemsDone ++ ;
0 commit comments