public void AddItem(ItemData itemData) { Optional <GameObject> owner = GuidHelper.GetObjectFrom(itemData.ContainerGuid); if (owner.IsEmpty()) { Log.Info("Unable to find inventory container with id: " + itemData.ContainerGuid); return; } Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Get()); if (opContainer.IsPresent()) { ItemsContainer container = opContainer.Get(); GameObject item = SerializationHelper.GetGameObject(itemData.SerializedData); Pickupable pickupable = item.RequireComponent <Pickupable>(); using (packetSender.Suppress <ItemContainerAdd>()) { container.UnsafeAdd(new InventoryItem(pickupable)); } } else { Log.Error("Could not find container field on object " + owner.Get().name); } }
public void AddItem(GameObject item, NitroxId containerId) { Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId); if (!owner.HasValue) { Log.Info("Unable to find inventory container with id: " + containerId); return; } Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner.Value); if (!opContainer.HasValue) { Log.Error("Could not find container field on object " + owner.Value.name); return; } ItemsContainer container = opContainer.Value; Pickupable pickupable = item.RequireComponent <Pickupable>(); using (packetSender.Suppress <ItemContainerAdd>()) { container.UnsafeAdd(new InventoryItem(pickupable)); } }
public void RemoveItem(NitroxId ownerId, NitroxId itemId) { GameObject owner = NitroxEntity.RequireObjectFrom(ownerId); GameObject item = NitroxEntity.RequireObjectFrom(itemId); Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner); if (!opContainer.HasValue) { Log.Error("Could not find container field on object " + owner.name); return; } ItemsContainer container = opContainer.Value; Pickupable pickupable = item.RequireComponent <Pickupable>(); using (packetSender.Suppress <ItemContainerRemove>()) { container.RemoveItem(pickupable, true); } }
public void RemoveItem(string ownerGuid, string itemGuid) { GameObject owner = GuidHelper.RequireObjectFrom(ownerGuid); GameObject item = GuidHelper.RequireObjectFrom(itemGuid); Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner); if (opContainer.IsPresent()) { ItemsContainer container = opContainer.Get(); Pickupable pickupable = item.RequireComponent <Pickupable>(); using (packetSender.Suppress <ItemContainerRemove>()) { container.RemoveItem(pickupable, true); } } else { Log.Error("Could not find container field on object " + owner.name); } }
public override void Process(ItemContainerAdd packet) { GameObject owner = GuidHelper.RequireObjectFrom(packet.OwnerGuid); Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner); if (opContainer.IsPresent()) { ItemsContainer container = opContainer.Get(); GameObject item = SerializationHelper.GetGameObject(packet.ItemData); Pickupable pickupable = item.RequireComponent <Pickupable>(); using (packetSender.Suppress <ItemContainerAdd>()) { container.UnsafeAdd(new InventoryItem(pickupable)); } } else { Log.Error("Could not find container field on object " + owner.name); } }
public override void Process(ItemContainerRemove packet) { Optional <GameObject> opOwner = GuidHelper.GetObjectFrom(packet.OwnerGuid); Optional <GameObject> opItem = GuidHelper.GetObjectFrom(packet.ItemGuid); if (opOwner.IsPresent() && opItem.IsPresent()) { GameObject owner = opOwner.Get(); GameObject item = opItem.Get(); Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner); if (opContainer.IsPresent()) { ItemsContainer container = opContainer.Get(); Pickupable pickupable = item.GetComponent <Pickupable>(); if (pickupable != null) { using (packetSender.Suppress <ItemContainerRemove>()) { container.RemoveItem(pickupable, true); } } else { Console.WriteLine(item.name + " did not have a corresponding pickupable script!"); } } else { Console.WriteLine("Could not find container field on object " + owner.name); } } else { Console.WriteLine("Owner or item was not found: " + opOwner + " " + opItem + " " + packet.OwnerGuid + " " + packet.ItemGuid); } }
public override void Process(ItemContainerAdd packet) { Optional <GameObject> opOwner = GuidHelper.GetObjectFrom(packet.OwnerGuid); if (opOwner.IsPresent()) { GameObject owner = opOwner.Get(); Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner); if (opContainer.IsPresent()) { ItemsContainer container = opContainer.Get(); GameObject item = SerializationHelper.GetGameObject(packet.ItemData); Pickupable pickupable = item.GetComponent <Pickupable>(); if (pickupable != null) { using (packetSender.Suppress <ItemContainerAdd>()) { container.UnsafeAdd(new InventoryItem(pickupable)); } } else { Console.WriteLine(item.name + " did not have a corresponding pickupable script!"); } } else { Console.WriteLine("Could not find container field on object " + owner.name); } } else { Console.WriteLine("Could not find owner with guid: " + packet.OwnerGuid); } }