Пример #1
0
        /// <summary>
        /// Builds cache of accessible inventories on this ship.
        /// </summary>
        /// <param name="Force">Forces to build cache even if UseConveyorSystem == false.</param>
        void BuildInventoryCache(bool Force = false)
        {
            if (!Tool.UseConveyorSystem && !Force)
            {
                return;
            }
            List <IMyTerminalBlock> InventoryOwners = new List <IMyTerminalBlock>();

            Term.GetBlocksOfType(InventoryOwners, x => x.HasPlayerAccess(Tool.OwnerId) && x.HasInventory);
            OnboardInventoryOwners.Clear();
            OnboardInventoryOwners.Add(Tool);
            foreach (var InventoryOwner in InventoryOwners)
            {
                if (InventoryOwner == Tool)
                {
                    continue;
                }
                foreach (var Inventory in InventoryOwner.GetInventories())
                {
                    if (Inventory == ToolCargo)
                    {
                        continue;
                    }
                    if (Inventory.IsConnectedTo(ToolCargo))
                    {
                        OnboardInventoryOwners.Add(InventoryOwner);
                    }
                }
            }
        }
Пример #2
0
        public static InventoryOwner CreateInventoryOwner(string dataAreaId, string inventoryOwnerId)
        {
            InventoryOwner inventoryOwner = new InventoryOwner();

            inventoryOwner.dataAreaId       = dataAreaId;
            inventoryOwner.InventoryOwnerId = inventoryOwnerId;
            return(inventoryOwner);
        }
Пример #3
0
        private void EnablePanels(InventoryOwner owner)
        {
            List <PanelManagerLink> toEnable = panelManagerLinkers.FindAll(x => !x.disableOn.Contains(owner));

            foreach (PanelManagerLink item in toEnable)
            {
                item.gameObject.SetActive(true);
            }
        }
Пример #4
0
    public IInventoryManager GetGlobalComponent(InventoryOwner inventoryOwner)
    {
        IInventoryManager result;

        if (components.TryGetValue(inventoryOwner, out result))
        {
            return(result);
        }
        return(null);
    }
Пример #5
0
 void OnDisable()
 {
     UpdateInventories();
     inventoryFrom       = null;
     inventoryTo         = null;
     originSlot          = null;
     targetSlot          = null;
     quantityToSend      = 0;
     inputFieldText.text = "0";
 }
Пример #6
0
 public bool AddGlobalComponent(InventoryOwner inventoryOwner, IInventoryManager inventoryManager)
 {
     if (components.ContainsKey(inventoryOwner))
     {
         Debug.LogWarning("Attempting to add multiple " + inventoryOwner.ToString() + " to the Inventory Toolbox!");
         return(false);
     }
     if (inventoryOwner == InventoryOwner.Default)
     {
         Debug.LogWarning("Attempting to add a default inventory to the Inventory Toolbox!");
         return(false);
     }
     components.Add(inventoryOwner, inventoryManager);
     return(true);
 }
Пример #7
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (GameManager.Instance.CurrentState == GameState.InTuto)
        {
            return;
        }

        if (eventData.pointerEnter == null && startParent.parent.GetComponent <InventoryOwner>() != null && startParent.parent.GetComponent <InventoryOwner>().Owner != null)
        {
            InventoryOwner inventaireDequi = startParent.parent.GetComponent <InventoryOwner>();

            // On ne peut drop que d'un keeper
            if (inventaireDequi.Owner.GetComponent <Behaviour.Keeper>() != null)
            {
                ItemContainer[] inventoryKeeperDequi = inventaireDequi.Owner.GetComponent <Behaviour.Inventory>().Items;


                InventoryManager.RemoveItem(inventoryKeeperDequi, eventData.pointerDrag.gameObject.GetComponent <ItemInstance>().ItemContainer);
                ItemContainer[] loot = new ItemContainer[1];
                loot[0] = eventData.pointerDrag.gameObject.GetComponent <ItemInstance>().ItemContainer;


                Tile t = inventaireDequi.Owner.GetComponent <PawnInstance>().CurrentTile;

                ItemManager.AddItemOnTheGround(t, inventaireDequi.Owner.transform, loot);

                Destroy(eventData.pointerDrag.gameObject);
            }
        }

        if (transform.parent == absoluteParent)
        {
            if (!GameManager.Instance.Ui.itemSplitter.activeSelf)
            {
                transform.position = startPosition;

                // force the item being drag to reset on his starting position
                transform.SetParent(startParent);
            }
        }

        if (GameManager.Instance.Ui.tooltipItem != null)
        {
            GameManager.Instance.Ui.tooltipItem.SetActive(false);
        }

        GetComponent <CanvasGroup>().blocksRaycasts = true;
    }
Пример #8
0
        private IEnumerator WaitForPossibleSecondInventory()
        {
            yield return(StartCoroutine(InventoryEventListener.WaitForPossibleEvent(1)));

            if (receivedInventories[1] == null)
            {
                EnablePanels(receivedInventories[0].owner);
            }
            else
            {
                InventoryOwner nonPlayerOwner = GetNonPlayerOwner();
                EnablePanels(nonPlayerOwner);
            }

            inventoryOpen = true;
        }
Пример #9
0
        public InventoryView(InventoryOwner owner)
        {
            FullInventoryView = DbTransactionHolder.Context.Equipment.Include(x => x.Product).Include(x => x.Product.DisassemblyProducts).Include(x => x.Inventory)
                                .Where(x => x.Inventory.Id == (int)owner).Select(x => new InventoryViewRow()
            {
                ProductId           = x.Product.Id,
                Price               = x.Product.Price,
                Name                = x.Product.Name,
                Quantity            = x.Quantity,
                Description         = x.Product.Description,
                TypeExt             = x.Product.Type,
                DisassemblyProducts = x.Product.DisassemblyProducts
            }).ToList();

            InventoryMoney = DbTransactionHolder.Context.Inventories.Where(x => x.Id == (int)owner).Select(x => x.Money).FirstOrDefault();
            Owner          = owner;
        }
Пример #10
0
        IEnumerator <bool> RefreshInventoryOwners(bool BypassLoadChecks = false)
        {
            int opStart = Ticker;

            bool shouldUseDebug = useDebug && MyKernel.Multigridder.CompleteGrid.Count > 1;

            if (shouldUseDebug)
            {
                WriteToLog(nameof(RefreshInventoryOwners), $"Starting update...");
            }

            Dictionary <long, ILaserToolKernel> subscribedLaserTools = CombineSubscribed();
            Dictionary <ILaserToolKernel, HashSet <IMyTerminalBlock> > inventoriesPerTool = new Dictionary <ILaserToolKernel, HashSet <IMyTerminalBlock> >();

            if (subscribedLaserTools.Count == 0)
            {
                if (shouldUseDebug)
                {
                    WriteToLog(nameof(RefreshInventoryOwners), $"Early exit: no subscribed tools");
                }
                yield return(false);
            }

            List <IMyTerminalBlock> inventoryOwners = new List <IMyTerminalBlock>(80);

            Term.GetBlocksOfType(inventoryOwners, IsValidInventory);

            if (useDebug)
            {
                WriteToLog(nameof(RefreshInventoryOwners), $"Combined subscribed tools: {subscribedLaserTools.Count}");
                WriteToLog(nameof(RefreshInventoryOwners), $"Combined valid inventories: {inventoryOwners.Count}");
            }

            int capacity = subscribedLaserTools.Count + 1;
            Dictionary <long, HashSet <long> > ToolsInterlinks       = new Dictionary <long, HashSet <long> >(capacity);
            Dictionary <long, HashSet <long> > ToolsFailedInterlinks = new Dictionary <long, HashSet <long> >(capacity);

            int opCounter1 = 0;

            foreach (ILaserToolKernel LaserTool in subscribedLaserTools.Values)
            {
                long ToolId = LaserTool.Block.EntityId;
                if (!ToolsInterlinks.ContainsKey(ToolId))
                {
                    ToolsInterlinks.Add(ToolId, new HashSet <long>());
                }
                if (!ToolsFailedInterlinks.ContainsKey(ToolId))
                {
                    ToolsFailedInterlinks.Add(ToolId, new HashSet <long>());
                }
                if (!inventoriesPerTool.ContainsKey(LaserTool))
                {
                    inventoriesPerTool.Add(LaserTool, new HashSet <IMyTerminalBlock>());
                }

                HashSet <long> ToolInterlinks       = ToolsInterlinks[ToolId];
                HashSet <long> ToolFailedInterlinks = ToolsFailedInterlinks[ToolId];
                IMyInventory   ToolCargo            = LaserTool.Inventory.ToolCargo;

                foreach (ILaserToolKernel OtherLaserTool in subscribedLaserTools.Values)
                {
                    long OtherToolId = OtherLaserTool.Block.EntityId;
                    if (ToolId == OtherToolId)
                    {
                        continue;
                    }

                    if (!ToolsInterlinks.ContainsKey(OtherToolId))
                    {
                        ToolsInterlinks.Add(OtherToolId, new HashSet <long>());
                    }
                    if (!ToolsFailedInterlinks.ContainsKey(OtherToolId))
                    {
                        ToolsFailedInterlinks.Add(OtherToolId, new HashSet <long>());
                    }
                    if (!inventoriesPerTool.ContainsKey(OtherLaserTool))
                    {
                        inventoriesPerTool.Add(OtherLaserTool, new HashSet <IMyTerminalBlock>());
                    }

                    IMyInventory   OtherToolCargo            = OtherLaserTool.Inventory.ToolCargo;
                    HashSet <long> OtherToolInterlinks       = ToolsInterlinks[OtherToolId];
                    HashSet <long> OtherToolFailedInterlinks = ToolsFailedInterlinks[OtherToolId];

                    if (!ToolInterlinks.Contains(OtherToolId) && !ToolFailedInterlinks.Contains(OtherToolId))
                    {
                        bool Accessible = OtherLaserTool.Block.HasPlayerAccess(LaserTool.Block.OwnerId);
                        bool Connected  = Accessible && ToolCargo.IsConnectedTo(OtherToolCargo);

                        if (Connected)
                        {
                            ToolInterlinks.Add(OtherToolId);
                            OtherToolInterlinks.Add(ToolId);
                        }
                        else
                        {
                            ToolFailedInterlinks.Add(OtherToolId);
                            OtherToolFailedInterlinks.Add(ToolId);
                        }
                        opCounter1++;
                    }

                    if (opCounter1 % OpLimit == 0 && !BypassLoadChecks)
                    {
                        yield return(true);
                    }
                }
            }
            if (!BypassLoadChecks)
            {
                yield return(true);
            }
            opCounter1 = 0;
            foreach (IMyTerminalBlock InventoryOwner in inventoryOwners)
            {
                IMyInventory Inventory = InventoryOwner.GetInventory(0);
                foreach (ILaserToolKernel LaserTool in subscribedLaserTools.Values)
                {
                    HashSet <IMyTerminalBlock> ToolSupportInventories = inventoriesPerTool[LaserTool];
                    if (ToolSupportInventories.Contains(InventoryOwner))
                    {
                        continue;
                    }
                    long           ToolId         = LaserTool.Block.EntityId;
                    IMyInventory   ToolCargo      = LaserTool.Inventory.ToolCargo;
                    HashSet <long> ToolInterlinks = ToolsInterlinks[ToolId];

                    bool Connected = Inventory.IsConnectedTo(ToolCargo);
                    if (Connected)
                    {
                        inventoriesPerTool[LaserTool].Add(InventoryOwner);

                        foreach (ILaserToolKernel OtherLaserTool in subscribedLaserTools.Values)
                        {
                            if (ToolId == OtherLaserTool.Block.EntityId)
                            {
                                continue;
                            }
                            inventoriesPerTool[OtherLaserTool].Add(InventoryOwner);
                        }
                        opCounter1++;
                    }
                    if (opCounter1 % OpLimit == 0 && !BypassLoadChecks)
                    {
                        yield return(true);
                    }
                }
            }

            _InventoryOwners.Clear();
            InventoriesPerTool.Clear();

            if (_InventoryOwners.Capacity < inventoryOwners.Count + 10)
            {
                _InventoryOwners.Capacity = inventoryOwners.Count + 10;
            }
            _InventoryOwners.AddRange(inventoryOwners);

            foreach (KeyValuePair <ILaserToolKernel, HashSet <IMyTerminalBlock> > kvp in inventoriesPerTool)
            {
                InventoriesPerTool.Add(kvp.Key, kvp.Value);
            }

            int updateTook = Ticker - opStart;

            if (shouldUseDebug)
            {
                WriteToLog(nameof(RefreshInventoryOwners), $"Tool/inventories pairs: {InventoriesPerTool.Count}");

                WriteToLog(nameof(RefreshInventoryOwners), $"Tool/inventories working pairs: {InventoriesPerTool.Count(x => x.Value.Count > 0)}");

                WriteToLog(nameof(RefreshInventoryOwners), $"Update took: {updateTook} ticks");
            }

            DueStartTick = Ticker + updateSkipTicks + (updateTook * 2);
            yield return(false);
        }
Пример #11
0
 internal void Init(Inventory inventory)
 {
     money             = inventory.money;
     quantityText.text = money.ToString();
     thisOwner         = inventory.owner;
 }
Пример #12
0
    public void OnPointerClick(PointerEventData eventData)
    {
        int tap = eventData.clickCount;

        if (tap == 2)
        {
            if (GameManager.Instance.Ui.tooltipItem != null)
            {
                GameManager.Instance.Ui.tooltipItem.SetActive(false);
            }
            // Only keeper can use items
            Behaviour.Keeper owner = eventData.pointerPress.GetComponentInParent <InventoryOwner>().Owner.GetComponent <Behaviour.Keeper>();
            if (owner == null ||
                owner != GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Behaviour.Keeper>())
            {
                GameObject          goOwner = eventData.pointerPress.GetComponentInParent <InventoryOwner>().Owner;
                ItemContainer[]     selectedKeeperInventory = GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Behaviour.Inventory>().Items;
                Behaviour.Inventory ownerInventory          = goOwner.GetComponent <Behaviour.Inventory>();

                ItemContainer itemDragged = eventData.pointerPress.GetComponent <ItemInstance>().ItemContainer;

                if (InventoryManager.AddItemToInventory(selectedKeeperInventory, itemDragged))
                {
                    InventoryManager.RemoveItem(ownerInventory.Items, itemDragged);
                }

                // IF trying to merge 99 with 10 should swap or merge @rémi
                // else
                // foreach item
                //int quantityLeft = InventoryManager.MergeStackables(itemDragged, item);
                //if (quantityLeft <= 0)
                //{
                //    InventoryManager.RemoveItem(ownerInventory.Items, itemDragged);
                //}


                // Destroy inventory if it is empty for loot
                if (goOwner.GetComponent <LootInstance>() != null)
                {
                    bool isEmpty = true;
                    for (int i = 0; i < ownerInventory.Items.Length; i++)
                    {
                        if (ownerInventory.Items[i] != null)
                        {
                            isEmpty = false;
                            break;
                        }
                    }
                    if (isEmpty)
                    {
                        if (goOwner.GetComponentInChildren <Canvas>() != null)
                        {
                            goOwner.GetComponentInChildren <Canvas>().transform.SetParent(null);
                        }
                        Destroy(goOwner.gameObject);

                        // Get the original parent
                        Transform      previous        = eventData.pointerPress.GetComponentInParent <DragHandler>().transform;
                        InventoryOwner inventaireDequi = previous.GetComponentInParent <InventoryOwner>();
                        Destroy(inventaireDequi.GetComponentInParent <DragHandlerInventoryPanel>().gameObject);
                    }
                }

                goOwner.GetComponent <Behaviour.Inventory>().UpdateInventories();
                GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Behaviour.Inventory>().UpdateInventories();
                //}
                return;
            }

            // Check if an inventory is opened
            Behaviour.Inventory openInventory = null;
            for (int i = 0; i < GameManager.Instance.Ui.Panel_Inventories.transform.childCount; i++)
            {
                if (GameManager.Instance.Ui.Panel_Inventories.transform.GetChild(i).gameObject.activeSelf)
                {
                    openInventory = GameManager.Instance.Ui.Panel_Inventories.transform.GetChild(i).GetComponentInChildren <InventoryOwner>().Owner.GetComponent <Behaviour.Inventory>();
                    break;
                }
            }

            // Use the item if no inventory opened
            if (openInventory == null)
            {
                ii.ItemContainer.UseItem(owner.GetComponent <PawnInstance>());

                if (ii.ItemContainer.Quantity <= 0)
                {
                    if (GameManager.Instance.Ui.tooltipItem.activeSelf)
                    {
                        GameManager.Instance.Ui.tooltipItem.SetActive(false);
                    }
                    InventoryManager.RemoveItem(owner.GetComponent <Behaviour.Inventory>().Items, ii.ItemContainer);
                    if (GameManager.Instance.CurrentState == GameState.InTuto)
                    {
                        TutoManager.MouseClicked = true;
                    }
                }
            }
            // Change item owner if an inventory is opened when double clicking
            else
            {
                ItemContainer itemDoubleClicked = eventData.pointerPress.GetComponent <ItemInstance>().ItemContainer;

                if (InventoryManager.AddItemToInventory(openInventory.Items, itemDoubleClicked))
                {
                    InventoryManager.RemoveItem(GameManager.Instance.GetFirstSelectedKeeper().GetComponent <Behaviour.Inventory>().Items, itemDoubleClicked);
                }

                openInventory.UpdateInventories();
            }

            owner.GetComponent <Behaviour.Inventory>().UpdateInventories();
        }
    }
Пример #13
0
    public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag.GetComponent<DragHandler>() != null 
            && (!hasAlreadyAnItem || (currentItem != null && currentItem.GetComponent<DragHandler>() != null)))
        {
            // Get the original parent
            Transform previous = eventData.pointerDrag.GetComponent<DragHandler>().startParent;
            if (previous.GetComponentInParent<InventoryOwner>() != null && transform.GetComponentInParent<InventoryOwner>() != null)
            {
                //Ou on est ?
                InventoryOwner inventaireDequi = previous.GetComponentInParent<InventoryOwner>();
                InventoryOwner inventaireversqui = transform.GetComponentInParent<InventoryOwner>();

                ItemContainer[] inventoryKeeperDequi = inventaireDequi.Owner.GetComponent<Behaviour.Inventory>().Items;
                ItemContainer[] inventoryKeeperVersqui = inventaireversqui.Owner.GetComponent<Behaviour.Inventory>().Items;

                //Si les inventaires sont differents
                if (inventaireDequi != inventaireversqui)
                {
                    ItemSplitter itemSplitter = GameManager.Instance.Ui.itemSplitter.GetComponent<ItemSplitter>();
                    itemSplitter.inventoryFrom = inventaireDequi;
                    itemSplitter.inventoryTo = inventaireversqui;
                    itemSplitter.originSlot = previous;
                    itemSplitter.targetSlot = transform;
                    itemSplitter.selectedItem = eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer;
                    itemSplitter.uiItem = eventData.pointerDrag.gameObject;

                    ItemContainer itemDragged = eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer;

                    // Split items only if on the same item
                    if (hasAlreadyAnItem)
                    {
                        ItemContainer itemOn = currentItem.GetComponent<ItemInstance>().ItemContainer;

                        if (itemOn.Item.Id == itemDragged.Item.Id)
                        {
                            if (itemDragged.Quantity > 1)
                                itemSplitter.gameObject.SetActive(true);
                            else
                            {
                                InventoryManager.MergeStackables(currentItem.GetComponent<ItemInstance>().ItemContainer, eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer);
                                InventoryManager.RemoveItem(inventoryKeeperDequi, eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer);
                            }
                        }
                        else
                        {
                            // Auto swap
                            InventoryManager.SwapItemBeetweenInventories(inventoryKeeperDequi, previous.GetSiblingIndex(), inventoryKeeperVersqui, transform.GetSiblingIndex());
                        }
                    }
                    else
                    {
                        //Move the item to the slot
                        //eventData.pointerDrag.transform.SetParent(transform);
                        if (itemDragged.Quantity > 1)
                        {
                            itemSplitter.gameObject.SetActive(true);
                        }
                        else
                        {
                            InventoryManager.SwapItemBeetweenInventories(inventoryKeeperDequi, previous.GetSiblingIndex(), inventoryKeeperVersqui, transform.GetSiblingIndex());
                        }
                    }

                    // Destroy inventory if it is empty for loot
                    if (inventaireDequi.Owner.GetComponent<LootInstance>() != null)
                    {
                        bool isEmpty = true;
                        for (int i = 0; i < inventaireDequi.Owner.GetComponent<Behaviour.Inventory>().Items.Length; i++)
                        {
                            if (inventaireDequi.Owner.GetComponent<Behaviour.Inventory>().Items[i] != null)
                            {
                                isEmpty = false;
                                break;
                            }
                        }
                        if (isEmpty)
                        {
                            if (inventaireDequi.Owner.gameObject.GetComponentInChildren<Canvas>() != null)
                            {
                                inventaireDequi.Owner.gameObject.GetComponentInChildren<Canvas>().transform.SetParent(null);
                            }
                            Destroy(inventaireDequi.Owner.gameObject);
                            Destroy(inventaireDequi.GetComponentInParent<DragHandlerInventoryPanel>().gameObject);
                        }
                    }
                }
                // Si l'inventaire est le meme
                else
                {
                    if (hasAlreadyAnItem)
                    {
              
                        ItemContainer itemDragged = eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer;
                        ItemContainer itemOn = currentItem.GetComponent<ItemInstance>().ItemContainer;

                        if (itemOn.Item.Id == itemDragged.Item.Id)
                        {

                            int quantityLeft = InventoryManager.MergeStackables(currentItem.GetComponent<ItemInstance>().ItemContainer, eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer);
                            if (quantityLeft <= 0)
                            {
                                InventoryManager.RemoveItem(inventoryKeeperDequi, eventData.pointerDrag.GetComponent<ItemInstance>().ItemContainer);
                            }
                        }
                        else
                        {
                            // swap dequi = versqui
                            InventoryManager.SwapItemInSameInventory(inventoryKeeperDequi, previous.GetSiblingIndex(), transform.GetSiblingIndex());
                        }
                    }
                    else
                    {
                        InventoryManager.SwapItemInSameInventory(inventoryKeeperDequi, previous.GetSiblingIndex(), transform.GetSiblingIndex());

                    }
                }

                if (!GameManager.Instance.Ui.itemSplitter.activeSelf)
                {
                    Destroy(eventData.pointerDrag.gameObject);

                    inventaireDequi.Owner.GetComponent<Behaviour.Inventory>().UpdateInventories();
                    inventaireversqui.Owner.GetComponent<Behaviour.Inventory>().UpdateInventories();
                }
            }
            // Drag Characters in battle scene
            else
            {
                // Si ce n'est pas un objet qui est drag ( selection de perso pour le combat)
                if (eventData.pointerDrag.GetComponent<ItemInstance>() == null && transform.parent.GetComponent<InventoryOwner>() == null)
                {
                    // Swap image perso
                    if (hasAlreadyAnItem)
                    {
                        currentItem.transform.SetParent(previous);
                    }
                    eventData.pointerDrag.transform.SetParent(transform);
                }
            }
        }
        else if (eventData.pointerDrag.GetComponent<DragHandlerInventoryPanel>() != null)
        {
            Debug.Log("A panel was drop in a slot");
        }
    }