Пример #1
0
    void Update()
    {
        Player player = Player.localPlayer;

        // use collider point(s) to also work with big entities
        if (player != null &&
            panel.activeSelf &&
            player.target != null &&
            player.target.health == 0 &&
            Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange &&
            player.target is Monster &&
            ((Monster)player.target).HasLoot())
        {
            // gold slot
            if (player.target.gold > 0)
            {
                goldSlot.SetActive(true);
                goldSlot.GetComponentInChildren <Button>().onClick.SetListener(() => {
                    player.CmdTakeLootGold();
                });
                goldText.text = player.target.gold.ToString();
            }
            else
            {
                goldSlot.SetActive(false);
            }

            // instantiate/destroy enough slots
            // (we only want to show the non-empty slots)
            List <ItemSlot> items = player.target.inventory.Where(slot => slot.amount > 0).ToList();
            UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Count, content);

            // refresh all valid items
            for (int i = 0; i < items.Count; ++i)
            {
                UILootSlot slot = content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int itemIndex = player.target.inventory.FindIndex(
                    // note: .Equals because name AND dynamic variables matter (petLevel etc.)
                    itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item)
                    );

                // refresh
                slot.button.interactable = player.InventoryCanAdd(items[i].item, items[i].amount);
                slot.button.onClick.SetListener(() => {
                    player.CmdTakeLootItem(itemIndex);
                });
                slot.tooltip.text  = items[i].ToolTip();
                slot.image.color   = Color.white;
                slot.image.sprite  = items[i].item.image;
                slot.nameText.text = items[i].item.name;
                slot.amountOverlay.SetActive(items[i].amount > 1);
                slot.amountText.text = items[i].amount.ToString();
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (panel.activeSelf &&
            player.UCE_ResourceNodeValidation()
            )
        {
            if (player.UCE_selectedResourceNode == null || !player.UCE_ResourceNodeValidation() || !player.UCE_selectedResourceNode.HasResources())
            {
                Hide();
                return;
            }

            List <ItemSlot> items = player.UCE_selectedResourceNode.inventory.Where(slot => slot.amount > 0).ToList();
            UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Count, content);

            for (int i = 0; i < items.Count; ++i)
            {
                UILootSlot slot = content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int itemIndex = player.UCE_selectedResourceNode.inventory.FindIndex(
                    itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item)
                    );

                slot.button.interactable = player.InventoryCanAdd(items[i].item, items[i].amount);
                slot.button.onClick.SetListener(() =>
                {
                    player.Cmd_UCE_TakeHarvestingResources(itemIndex);
                });
                slot.tooltip.text  = items[i].ToolTip();
                slot.image.color   = Color.white;
                slot.image.sprite  = items[i].item.image;
                slot.nameText.text = items[i].item.name;
                slot.amountOverlay.SetActive(items[i].amount > 1);
                slot.amountText.text = items[i].amount.ToString();
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
    public void LootAll()
    {
        Player player = Player.localPlayer;

        var items = player.target.inventory.Where(item => item.amount > 0).ToList();

        invFull = 0;
        // refresh all valid items
        for (int i = 0; i < items.Count; ++i)
        {
            if (loot.content.childCount > 0)
            {
                UILootSlot slot = loot.content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                                                          // int itemIndex = player.target.inventory.FindIndex(item => item.amount > 0 && item.item.name == items[i].item.name);
                                                          // add a check for each item (we cannot loot all if we dont have enough space in our inventory
                if (player.InventoryCanAdd(items[i].item, items[i].amount))
                {
                    invFull++;
                }
                else
                {
                    invFull--;
                }

                if (invFull == items.Count)
                {
                    lootAllBtn.interactable = true;
                }
                else
                {
                    lootAllBtn.interactable = false;
                }

                lootAllBtn.onClick.RemoveAllListeners();
                lootAllBtn.onClick.SetListener(() => { player.TakeAllLootItem(); });
            }
        }
    }
    // Assign our componenet based on the slot type.
    private void LateUpdate()
    {
        player = Player.localPlayer;

        if (player != null)
        {
            switch (slotType)
            {
            case SlotType.Equipment:
                // refresh all
                int lastECount = 0;
                if (lastECount != player.equipment.Count)
                {
                    for (int i = 0; i < player.equipment.Count; ++i)
                    {
                        lastECount = player.equipment.Count;
                        if (player.equipment[i].amount > 0)
                        {
                            UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>();
                            UIUtils.BalancePrefabs(equipmentContents.slotPrefab.gameObject, player.equipment.Count, equipmentContents.content);
                            if (equipmentContents.panel.activeSelf)
                            {
                                UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                itemSlot = player.equipment[i];
                                SetRarityColor(itemSlot.item.data);
                            }
                        }
                        else
                        {
                            UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>();
                            if (equipmentContents.panel.activeSelf)
                            {
                                UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;

            case SlotType.Inventory:
                // refresh all
                int lastICount = 0;
                if (lastICount != player.inventory.Count)
                {
                    for (int i = 0; i < player.inventory.Count; ++i)
                    {
                        lastICount = player.inventory.Count;
                        if (player.inventory[i].amount > 0)
                        {
                            UIInventory inventoryContents = GetComponent <UIInventory>();
                            UIUtils.BalancePrefabs(inventoryContents.slotPrefab.gameObject, player.inventory.Count, inventoryContents.content);
                            if (inventoryContents.panel.activeSelf)
                            {
                                UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                itemSlot = player.inventory[i];
                                SetRarityColor(itemSlot.item.data);
                            }
                        }
                        else
                        {
                            UIInventory inventoryContents = gameObject.GetComponent <UIInventory>();
                            if (inventoryContents.panel.activeSelf)
                            {
                                UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;

            case SlotType.Loot:
                if (player.target != null && player.target.health <= 0)
                {
                    UILoot          lootContent = GetComponent <UILoot>();
                    List <ItemSlot> items       = player.target.inventory.Where(slot => slot.amount > 0).ToList();
                    UIUtils.BalancePrefabs(lootContent.itemSlotPrefab.gameObject, items.Count, lootContent.content);

                    // refresh all valid items
                    for (int i = 0; i < items.Count; ++i)
                    {
                        UILootSlot slot = lootContent.content.GetChild(i).GetComponent <UILootSlot>();
                        slot.dragAndDropable.name = i.ToString();     // drag and drop index
                        int itemIndex = player.target.inventory.FindIndex(
                            // note: .Equals because name AND dynamic variables matter (petLevel etc.)
                            itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item)
                            );

                        // refresh
                        raritySlot = slot.GetComponent <UCE_RaritySlot>();
                        tooltip    = slot.tooltip;
                        slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                        itemSlot = items[i];
                        SetRarityColor(itemSlot.item.data);
                    }
                }
                break;

            case SlotType.PlayerTrade:
                if (player.state == "TRADING")
                {
                    Player other        = (Player)player.target;
                    int    lastPTYCount = 0;
                    if (lastPTYCount != player.tradeOfferItems.Count)
                    {
                        for (int i = 0; i < player.tradeOfferItems.Count; ++i)
                        {
                            lastPTYCount = player.tradeOfferItems.Count;
                            UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>();
                            UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, player.tradeOfferItems.Count, tradeContents.myContent);
                            if (tradeContents.panel.activeSelf)
                            {
                                UIPlayerTradingSlot slot = tradeContents.myContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                                if (slot.amountText.text != "0")
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    tooltip    = slot.tooltip;
                                    slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                    int inventoryIndex = player.tradeOfferItems[i];
                                    itemSlot = player.inventory[inventoryIndex];
                                    SetRarityColor(itemSlot.item.data);
                                }
                                else
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    raritySlot.rarityOutline.color = Color.clear;
                                }
                            }
                        }
                    }

                    int lastPTOCount = 0;
                    if (lastPTOCount != other.tradeOfferItems.Count)
                    {
                        for (int i = 0; i < other.tradeOfferItems.Count; ++i)
                        {
                            lastPTOCount = other.tradeOfferItems.Count;
                            UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>();
                            UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, other.tradeOfferItems.Count, tradeContents.otherContent);
                            if (tradeContents.panel.activeSelf)
                            {
                                UIPlayerTradingSlot slot = tradeContents.otherContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                                if (slot.amountText.text != "0")
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    tooltip    = slot.tooltip;
                                    slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                    int inventoryIndex = other.tradeOfferItems[i];
                                    itemSlot = other.inventory[inventoryIndex];
                                    SetRarityColor(itemSlot.item.data);
                                }
                                else
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    raritySlot.rarityOutline.color = Color.clear;
                                }
                            }
                        }
                    }
                }
                break;

            case SlotType.NpcTrade:
                if (player.target is Npc)
                {
                    Npc npc = (Npc)player.target;
#if _iMMONPCSHOP
                    UCE_UI_NpcShop shopContents = GetComponent <UCE_UI_NpcShop>();
                    if (shopContents.panel.activeSelf)
                    {
                        ScriptableItem[] items = npc.saleItems.Where(x => x.itemCategory == shopContents.currentCategory || shopContents.currentCategory == "").ToArray();
                        UIUtils.BalancePrefabs(shopContents.itemSlotPrefab.gameObject, items.Length, shopContents.itemContent);

                        int    lastIMCount = 0;
                        string currentPage = "";
                        if (lastIMCount != items.Length || currentPage != shopContents.currentCategory)
                        {
                            for (int i = 0; i < items.Length; ++i)
                            {
                                lastIMCount = items.Length;
                                currentPage = shopContents.currentCategory;

                                UCE_UI_NpcShopSlot slot = shopContents.itemContent.GetChild(i).GetComponent <UCE_UI_NpcShopSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                scriptItem = items[i];
                                SetRarityColor(scriptItem);
                            }
                        }
                    }
#else
                    int lastNTCount = 0;
                    if (lastNTCount != npc.saleItems.Length)
                    {
                        for (int i = 0; i < npc.saleItems.Length; ++i)
                        {
                            lastNTCount = npc.saleItems.Length;
                            UINpcTrading npcContents = GetComponent <UINpcTrading>();
                            UIUtils.BalancePrefabs(npcContents.slotPrefab.gameObject, npc.saleItems.Length, npcContents.content);
                            if (npcContents.panel.activeSelf)
                            {
                                UINpcTradingSlot slot = npcContents.content.transform.GetChild(i).GetComponent <UINpcTradingSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                scriptItem = npc.saleItems[i];
                                SetRarityColor(scriptItem);
                            }
                        }
                    }
#endif
                }
                break;

            case SlotType.ItemMall:
                UIItemMall mallContents = GetComponent <UIItemMall>();
                if (mallContents.panel.activeSelf)
                {
                    ScriptableItem[] items = player.itemMallCategories[mallContents.currentCategory].items;
                    UIUtils.BalancePrefabs(mallContents.itemSlotPrefab.gameObject, items.Length, mallContents.itemContent);

                    int lastIMCount = 0;
                    int currentPage = 0;
                    if (lastIMCount != items.Length || currentPage != mallContents.currentCategory)
                    {
                        for (int i = 0; i < items.Length; ++i)
                        {
                            lastIMCount = items.Length;
                            currentPage = mallContents.currentCategory;
                            UIItemMallSlot slot = mallContents.itemContent.GetChild(i).GetComponent <UIItemMallSlot>();
                            raritySlot = slot.GetComponent <UCE_RaritySlot>();
                            tooltip    = slot.tooltip;
                            scriptItem = items[i];
                            SetRarityColor(scriptItem);
                        }
                    }
                }
                break;

            case SlotType.Crafting:
                UICrafting craftContents = GetComponent <UICrafting>();
                UIUtils.BalancePrefabs(craftContents.ingredientSlotPrefab.gameObject, player.craftingIndices.Count, craftContents.ingredientContent);
                if (craftContents.panel.activeSelf)
                {
                    int lastCCount = 0;
                    if (lastCCount != player.craftingIndices.Count)
                    {
                        for (int i = 0; i < player.craftingIndices.Count; ++i)
                        {
                            lastCCount = player.craftingIndices.Count;
                            UICraftingIngredientSlot slot = craftContents.ingredientContent.GetChild(i).GetComponent <UICraftingIngredientSlot>();
                            if (player.craftingIndices[i] != -1)
                            {
                                int itemIndex = player.craftingIndices[i];
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                itemSlot   = player.inventory[itemIndex];
                                SetRarityColor(itemSlot.item.data);
                            }
                            else
                            {
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;
            }
        }
    }
Пример #5
0
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (panel.activeSelf &&
            player.UCE_LootcrateValidation()
            )
        {
            if (!player.UCE_selectedLootcrate.HasLoot())
            {
                Hide();
                return;
            }

            // -- gold slot
            if (player.UCE_selectedLootcrate.gold > 0)
            {
                goldSlot.SetActive(true);
                goldSlot.GetComponentInChildren <Button>().onClick.SetListener(() =>
                {
                    player.Cmd_UCE_TakeLootcrateGold();
                });
                goldText.text = player.UCE_selectedLootcrate.gold.ToString();
            }
            else
            {
                goldSlot.SetActive(false);
            }

            // -- coin slot
            if (player.UCE_selectedLootcrate.coins > 0)
            {
                coinSlot.SetActive(true);
                coinSlot.GetComponentInChildren <Button>().onClick.SetListener(() =>
                {
                    player.Cmd_UCE_TakeLootcrateCoins();
                });
                coinText.text = player.UCE_selectedLootcrate.coins.ToString();
            }
            else
            {
                coinSlot.SetActive(false);
            }

            // instantiate/destroy enough slots
            // (we only want to show the non-empty slots)
            List <ItemSlot> items = player.UCE_selectedLootcrate.inventory.Where(slot => slot.amount > 0).ToList();
            UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Count, content);

            // refresh all valid items
            for (int i = 0; i < items.Count; ++i)
            {
                UILootSlot slot = content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int itemIndex = player.UCE_selectedLootcrate.inventory.FindIndex(
                    // note: .Equals because name AND dynamic variables matter (petLevel etc.)
                    itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item)
                    );

                // refresh
                slot.button.interactable = player.InventoryCanAdd(items[i].item, items[i].amount);
                slot.button.onClick.SetListener(() =>
                {
                    player.Cmd_UCE_TakeLootcrateItem(itemIndex);
                });
                slot.tooltip.text  = items[i].ToolTip();
                slot.image.color   = Color.white;
                slot.image.sprite  = items[i].item.image;
                slot.nameText.text = items[i].item.name;
                slot.amountOverlay.SetActive(items[i].amount > 1);
                slot.amountText.text = items[i].amount.ToString();
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Пример #6
0
    void Update()
    {
        Player player = Player.localPlayer;

        // use collider point(s) to also work with big entities
        if (player != null &&
            panel.activeSelf &&
            player.target != null &&
            player.target.health.current == 0 &&
            Utils.ClosestDistance(player, player.target) <= player.interactionRange &&
            player.target is Monster &&
            ((Monster)player.target).inventory.HasLoot())
        {
            // gold slot
            if (player.target.gold > 0)
            {
                goldSlot.SetActive(true);
                goldSlot.GetComponentInChildren <Button>().onClick.SetListener(() => {
                    player.looting.CmdTakeGold();
                });
                goldText.text = player.target.gold.ToString();
            }
            else
            {
                goldSlot.SetActive(false);
            }

            // IMPORTANT: when showing slots, we never filter out the empty ones.
            // the slot position should never change, otherwise party members
            // might accidentally click on the same slot at the same time, and
            // then the first person gets the item, the second person gets the
            // other item that he didn't click on because it was moved up.
            // => simply don't ever modify slot positions / indices!

            // instantiate/destroy enough slots
            // (we only want to show the non-empty slots)
            UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, ((Monster)player.target).inventory.slots.Count, content);

            // refresh all valid items
            for (int i = 0; i < ((Monster)player.target).inventory.slots.Count; ++i)
            {
                ItemSlot itemSlot = ((Monster)player.target).inventory.slots[i];

                UILootSlot slot = content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index

                if (itemSlot.amount > 0)
                {
                    // refresh valid item
                    slot.button.interactable = player.inventory.CanAdd(itemSlot.item, itemSlot.amount);
                    int icopy = i;
                    slot.button.onClick.SetListener(() => {
                        player.looting.CmdTakeItem(icopy);
                    });
                    // only build tooltip while it's actually shown. this
                    // avoids MASSIVE amounts of StringBuilder allocations.
                    slot.tooltip.enabled = true;
                    if (slot.tooltip.IsVisible())
                    {
                        slot.tooltip.text = itemSlot.ToolTip();
                    }
                    slot.image.color   = Color.white;
                    slot.image.sprite  = itemSlot.item.image;
                    slot.nameText.text = itemSlot.item.name;
                    slot.amountOverlay.SetActive(itemSlot.amount > 1);
                    slot.amountText.text = itemSlot.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.button.interactable = false;
                    slot.button.onClick.RemoveAllListeners();
                    slot.tooltip.enabled = false;
                    slot.tooltip.text    = "";
                    slot.image.color     = Color.clear;
                    slot.image.sprite    = null;
                    slot.nameText.text   = "";
                    slot.amountOverlay.SetActive(false);
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }