public override void Process(ModuleRemoved packet) { GameObject owner = NitroxEntity.RequireObjectFrom(packet.OwnerId); Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner); if (!opEquipment.HasValue) { Log.Error("Could not find equipment type for " + owner.name); return; } GameObject item = NitroxEntity.RequireObjectFrom(packet.ItemId); Pickupable pickupable = item.RequireComponent <Pickupable>(); Equipment equipment = opEquipment.Value; Dictionary <string, InventoryItem> itemsBySlot = equipment.equipment; InventoryItem inventoryItem = itemsBySlot[packet.Slot]; itemsBySlot[packet.Slot] = null; equipment.UpdateCount(pickupable.GetTechType(), false); Equipment.SendEquipmentEvent(pickupable, UNEQUIP_EVENT_TYPE_ID, owner, packet.Slot); equipment.NotifyUnequip(packet.Slot, inventoryItem); UnityEngine.Object.Destroy(item); }
public override void Process(ModuleAdded packet) { EquippedItemData equippedItemData = packet.EquippedItemData; GameObject gameObject = SerializationHelper.GetGameObject(equippedItemData.SerializedData); Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(equippedItemData.ContainerId); if (!opGameObject.HasValue) { throw new Exception("Could not find equipment container for " + gameObject.name); } Pickupable pickupable = gameObject.RequireComponent <Pickupable>(); GameObject owner = opGameObject.Value; Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner); if (!opEquipment.HasValue) { throw new Exception("Could not find equipment type for " + gameObject.name); } Equipment equipment = opEquipment.Value; InventoryItem inventoryItem = new(pickupable); inventoryItem.container = equipment; inventoryItem.item.Reparent(equipment.tr); Dictionary <string, InventoryItem> itemsBySlot = equipment.equipment; itemsBySlot[equippedItemData.Slot] = inventoryItem; equipment.UpdateCount(pickupable.GetTechType(), true); Equipment.SendEquipmentEvent(pickupable, EQUIP_EVENT_TYPE_ID, owner, equippedItemData.Slot); equipment.NotifyEquip(equippedItemData.Slot, inventoryItem); }
public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem) { int totalEquippedItemsDone = 0; using (packetSender.Suppress <ItemContainerAdd>()) { foreach (EquippedItemData equippedItem in packet.EquippedItems) { waitScreenItem.SetProgress(totalEquippedItemsDone, packet.EquippedItems.Count); GameObject gameObject = SerializationHelper.GetGameObject(equippedItem.SerializedData); NitroxEntity.SetNewId(gameObject, equippedItem.ItemId); Pickupable pickupable = gameObject.RequireComponent <Pickupable>(); Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(equippedItem.ContainerId); if (opGameObject.HasValue) { GameObject owner = opGameObject.Value; Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner); if (opEquipment.HasValue) { Equipment equipment = opEquipment.Value; InventoryItem inventoryItem = new(pickupable); inventoryItem.container = equipment; inventoryItem.item.Reparent(equipment.tr); Dictionary <string, InventoryItem> itemsBySlot = equipment.equipment; itemsBySlot[equippedItem.Slot] = inventoryItem; equipment.UpdateCount(pickupable.GetTechType(), true); Equipment.SendEquipmentEvent(pickupable, 0, owner, equippedItem.Slot); equipment.NotifyEquip(equippedItem.Slot, inventoryItem); } else { Log.Info("Could not find equipment type for " + gameObject.name); } } else { Log.Info("Could not find Container for " + gameObject.name); } totalEquippedItemsDone++; yield return(null); } } Log.Info("Recieved initial sync with " + totalEquippedItemsDone + " pieces of equipped items"); }
public void AddItems(List <EquippedItemData> equippedItems) { ItemsContainer container = Inventory.Get().container; foreach (EquippedItemData equippedItem in equippedItems) { GameObject gameObject = SerializationHelper.GetGameObject(equippedItem.SerializedData); NitroxEntity.SetNewId(gameObject, equippedItem.ItemId); Log.Info("EquipmentSlots/Modules: Received item add request " + gameObject.name + " for container " + equippedItem.ContainerId); Pickupable pickupable = gameObject.RequireComponent <Pickupable>(); Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(equippedItem.ContainerId); if (opGameObject.HasValue) { GameObject owner = opGameObject.Value; Optional <Equipment> opEquipment = EquipmentHelper.FindEquipmentComponent(owner); if (opEquipment.HasValue) { Equipment equipment = opEquipment.Value; InventoryItem inventoryItem = new InventoryItem(pickupable); inventoryItem.container = equipment; inventoryItem.item.Reparent(equipment.tr); Dictionary <string, InventoryItem> itemsBySlot = (Dictionary <string, InventoryItem>)equipment.ReflectionGet("equipment"); itemsBySlot[equippedItem.Slot] = inventoryItem; equipment.ReflectionCall("UpdateCount", false, false, new object[] { pickupable.GetTechType(), true }); Equipment.SendEquipmentEvent(pickupable, 0, owner, equippedItem.Slot); equipment.ReflectionCall("NotifyEquip", false, false, new object[] { equippedItem.Slot, inventoryItem }); } else { Log.Info("Could not find equipment type for " + gameObject.name); } } else { Log.Info("Could not find Container for " + gameObject.name); } } }