public void UIAttemptEquip(OnUIItemAttemptEquipEventData e)
    {
        EquipmentCollection equipment = e.Equipper.GetComponentInChildren <EquipmentCollection>();

        e.Item.UIEmitter.Emit(
            new OnUIItemEquipEventData(
                e.Equipper,
                e.EquipmentPanel.GetSelectedSlot()
                )
            );
        if (equipment.IsItemInSlot(e.EquipmentSlot))
        {
            Item SelectedSlotItem = equipment.GetItemInSlot(e.EquipmentSlot);
            e.EquipmentPanel.SetCurrentItem(SelectedSlotItem);
        }
    }
Beispiel #2
0
    public void UICompareTo(OnUIItemEquipmentCompareEventData e)
    {
        e.StatChangesCollection.ClearAll();
        StatCollection playerStats = e.Player.GetComponentInChildren <StatCollection>();
        List <PlayerUIStatModifier> playerUIStats =
            new List <PlayerUIStatModifier>(playerStats.GetComponentsInChildren <PlayerUIStatModifier>());
        Dictionary <string, float> originalStatValues         = new Dictionary <string, float>();
        Dictionary <string, float> bonusStatValues            = new Dictionary <string, float>();
        Dictionary <string, PlayerUIStatModifier> renderables = new Dictionary <string, PlayerUIStatModifier>();

        foreach (PlayerUIStatModifier UIStat in playerUIStats)
        {
            foreach (KeyValuePair <string, float> stat in UIStat.BasedOnStats.GetAllStats())
            {
                if (!originalStatValues.ContainsKey(stat.Key))
                {
                    originalStatValues[stat.Key] = stat.Value;
                }
                else
                {
                    originalStatValues[stat.Key] += stat.Value;
                }
                if (!renderables.ContainsKey(stat.Key))
                {
                    renderables[stat.Key] = UIStat;
                }
            }
        }
        foreach (PlayerUIStatModifier UIStat in StatBonuses)
        {
            foreach (KeyValuePair <string, float> stat in UIStat.BasedOnStats.GetAllStats())
            {
                if (!bonusStatValues.ContainsKey(stat.Key))
                {
                    bonusStatValues[stat.Key] = stat.Value;
                }
                else
                {
                    bonusStatValues[stat.Key] += stat.Value;
                }
                if (!renderables.ContainsKey(stat.Key))
                {
                    renderables[stat.Key] = UIStat;
                }
            }
        }
        EquipmentCollection playerEquipment = e.Player.GetComponentInChildren <EquipmentCollection>();
        Item thisItem = GetComponent <Item>();

        //remove bonus values based on currently equipped item
        if (playerEquipment.IsItemInSlot(e.ForSlot))
        {
            Item i = playerEquipment.GetItemInSlot(e.ForSlot);
            PlayerUIStatModifier[] UIStats = i.GetComponentsInChildren <PlayerUIStatModifier>();
            if (!playerEquipment.IsEquipped(thisItem))
            {
                foreach (PlayerUIStatModifier UIStat in UIStats)
                {
                    foreach (KeyValuePair <string, float> stat in UIStat.BasedOnStats.GetAllStats())
                    {
                        if (!bonusStatValues.ContainsKey(stat.Key))
                        {
                            bonusStatValues[stat.Key] = -stat.Value;
                        }
                        else
                        {
                            bonusStatValues[stat.Key] -= stat.Value;
                        }
                        if (!renderables.ContainsKey(stat.Key))
                        {
                            renderables[stat.Key] = UIStat;
                        }
                    }
                }
            }
        }
        //remove bonus values based on if item is being re-equiped to another slot
        if (playerEquipment.IsEquipped(thisItem))
        {
            PlayerUIStatModifier[] UIStats =
                thisItem.GetComponentsInChildren <PlayerUIStatModifier>();
            foreach (PlayerUIStatModifier UIStat in UIStats)
            {
                foreach (KeyValuePair <string, float> stat in UIStat.BasedOnStats.GetAllStats())
                {
                    if (!bonusStatValues.ContainsKey(stat.Key))
                    {
                        bonusStatValues[stat.Key] = -stat.Value;
                    }
                    else
                    {
                        bonusStatValues[stat.Key] -= stat.Value;
                    }
                    if (!renderables.ContainsKey(stat.Key))
                    {
                        renderables[stat.Key] = UIStat;
                    }
                }
            }
        }
        foreach (KeyValuePair <string, PlayerUIStatModifier> UIStat in renderables)
        {
            if (originalStatValues.ContainsKey(UIStat.Key) &&
                bonusStatValues.ContainsKey(UIStat.Key) &&
                EquippableTo.ContainsSlot(e.ForSlot)
                )
            {
                e.StatChangesCollection.AddStatChange(
                    originalStatValues[UIStat.Key],
                    bonusStatValues[UIStat.Key],
                    UIStat.Value.Icon
                    );
            }
            else if (originalStatValues.ContainsKey(UIStat.Key) && EquippableTo.ContainsSlot(e.ForSlot))
            {
                e.StatChangesCollection.AddStatChange(
                    originalStatValues[UIStat.Key],
                    0,
                    UIStat.Value.Icon
                    );
            }
            else if (bonusStatValues.ContainsKey(UIStat.Key) && EquippableTo.ContainsSlot(e.ForSlot))
            {
                e.StatChangesCollection.AddStatChange(
                    0,
                    bonusStatValues[UIStat.Key],
                    UIStat.Value.Icon
                    );
            }
        }
    }
    public void UseItemOnKey(OnKeyDownEventData e)
    {
        if (isMoving)
        {
            return;
        }
        switch (e.Key)
        {
        case KeyCode.L:
            if (CurrentPanel == Panels.Category)
            {
                if (VerticalIndex < 0 || VerticalIndex > CategryUIControl.Lines.GetSize() - 1)
                {
                    return;
                }
                VerticalIndexStack.Push(VerticalIndex);
                CategryUIControl.Lines.Get(VerticalIndex).GetComponent <Animator>().enabled = false;
                VerticalIndex = 0;
                CurrentPanel  = Panels.Item;
                StartCoroutine(Move(new Vector3(-183.1666f, 0f, 0f), 0.5f));
            }
            else if (CurrentPanel == Panels.Item)
            {
                if (VerticalIndex < 0 || VerticalIndex > ItemUIControl.Lines.GetSize() - 1)
                {
                    return;
                }
                Item i = PlayerInventory.GetItemAtIndexAndCategory(VerticalIndex, CurrentCategory);
                i.Emitter.Emit(
                    new OnItemUseEventData(Owner)
                    );
                if (CurrentCategory == Item.ItemTag.Armour ||
                    CurrentCategory == Item.ItemTag.Weapon
                    )
                {
                    CurrentPanelStack.Push(CurrentPanel);
                    VerticalIndexStack.Push(VerticalIndex);
                    EquipmentPanel.gameObject.SetActive(true);
                    EquipmentPanel.Show();
                    EquipmentPanel.SetNewItem(i);
                    foreach (PlayerEquipmentPanelSlot slot in EquipmentPanel.GetAllSlots())
                    {
                        if (PlayerEquipment.IsItemInSlot(slot.EquipmentSlot))
                        {
                            Item uii = PlayerEquipment.GetItemInSlot(slot.EquipmentSlot);
                            uii.UIEmitter.Emit(new OnUIItemEquipEventData(
                                                   Owner,
                                                   slot
                                                   ));
                            EquipmentPanel.SetCurrentItem(uii);
                        }
                    }
                    CurrentPanel = Panels.Equipment;
                    RefreshComparedItems();
                }
            }
            else if (CurrentPanel == Panels.Equipment)
            {
                Item i = EquipmentPanel.GetNewItem();
                i.Emitter.Emit(new OnItemAttemptEquipEventData(
                                   Owner,
                                   i,
                                   EquipmentPanel.GetSelectedSlot().EquipmentSlot
                                   ));
                i.UIEmitter.Emit(new OnUIItemAttemptEquipEventData(
                                     Owner,
                                     i,
                                     EquipmentPanel,
                                     EquipmentPanel.GetSelectedSlot().EquipmentSlot
                                     ));
                RefreshComparedItems();
            }
            RefreshRenderedItems();
            break;

        case KeyCode.H:
            if (CurrentPanel == Panels.Item)
            {
                if (VerticalIndex >= 0 && VerticalIndex < ItemUIControl.Lines.GetSize())
                {
                    ItemUIControl.Lines.Get(VerticalIndex).Selector.GetComponent <Image>().enabled = false;
                }
                VerticalIndex = VerticalIndexStack.Pop();
                CategryUIControl.Lines.Get(VerticalIndex).GetComponent <Animator>().enabled = true;
                CurrentPanel = Panels.Category;
                StartCoroutine(Move(new Vector3(183.1666f, 0f, 0f), 0.5f));
            }
            else if (CurrentPanel == Panels.Equipment)
            {
                EquipmentPanel.Close();
                CurrentPanel  = CurrentPanelStack.Pop();
                VerticalIndex = VerticalIndexStack.Pop();
            }
            break;

        case KeyCode.X:
            if (CurrentPanel == Panels.Equipment &&
                PlayerEquipment.IsItemInSlot(EquipmentPanel.GetSelectedSlot().EquipmentSlot)
                )
            {
                Item uii = PlayerEquipment.GetItemInSlot(EquipmentPanel.GetSelectedSlot().EquipmentSlot);
                uii.Emitter.Emit(new OnItemUnequipEventData(
                                     Owner,
                                     uii,
                                     EquipmentPanel.GetSelectedSlot().EquipmentSlot
                                     ));
                uii.UIEmitter.Emit(new OnUIItemUnequipEventData(Owner, EquipmentPanel.GetSelectedSlot()));
                RefreshComparedItems();
            }
            break;
        }
    }