Ejemplo n.º 1
0
    public void DiactivateBuff(Item item)
    {
        if (item.itemBuff.buff != null)
        {
            BuffCell buffCell = TryGetBuffCell(item);

            if (buffCell != null)
            {
                buffCell.SetBuffActive(false);
            }

            item.itemBuff.buff.BuffDiactivate();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Возврощает ячейку или null
    /// </summary>
    public BuffCell TryGetBuffCell(Item item)
    {
        foreach (var cell in buffCells)
        {
            BuffCell currentCell = cell.GetComponent <BuffCell>();

            if (currentCell.buffType == item.itemBuff.buff.buffType)
            {
                return(currentCell);
            }
        }

        return(null);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Проверяет если баф существует
    /// </summary>
    public bool IsBuffExist(Item item)
    {
        foreach (var cell in buffCells)
        {
            BuffCell activeBuffCell = cell.GetComponent <BuffCell>();

            if (activeBuffCell.buffType == item.itemBuff.buff.buffType)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Проверяет если бафф существует по типу бафа в ячейках баффов или дебаффов
    /// <br>isBuff = true - поиск в листе бафов </br>
    /// <br>false - дебафов</br>
    /// </summary>
    public bool IsBuffExistByTypeName(BuffType buffType, bool isBuff = true)
    {
        List <GameObject> buffs = (isBuff == true) ? buffCells : debuffCells;

        foreach (var cell in buffs)
        {
            BuffCell bcell = cell.GetComponent <BuffCell>();

            if (bcell.buffType == buffType)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 5
0
 public void SetParam(BuffCell buffCell, BasePanel rootPanel)
 {
     base.SetParam(buffCell, rootPanel);
 }
Ejemplo n.º 6
0
    void AddBuff(Item item)
    {
        List <GameObject> buffs = (item.itemBuff.buff.buffMode == Buff.BuffMode.BUFF) ? buffCells : debuffCells;

        // remove debuff if  buff contains list
        if (item.itemBuff.buff.buffMode == Buff.BuffMode.BUFF)
        {
            Buff debuffToRemove = item.itemBuff.buff.debuffToRemove;

            if (debuffToRemove != null)
            {
                foreach (var cell in debuffCells)
                {
                    BuffCell activeBuffCell = cell.GetComponent <BuffCell>();

                    if (activeBuffCell.buffType == debuffToRemove.buffType)
                    {
                        if (IsBuffExist(item) == false)
                        {
                            if (item.itemBuff.buffTime > Global.Buff.CONSTANT_BUFF_TIME)
                            {
                                RemoveBuff(cell, debuffToRemove);
                                return;
                            }
                            else // если шмотка
                            {
                                if (IsBuffExistByTypeName(debuffToRemove.buffType, false))
                                {
                                    RollBackBuff(debuffToRemove);
                                }
                            }
                        }
                        else
                        {
                            if (item.itemBuff.buffTime > Global.Buff.CONSTANT_BUFF_TIME)
                            {
                                RemoveBuff(cell, debuffToRemove);
                                item.itemBuff.buff.BuffDirty();
                            }
                        }
                    }
                }
            }
        }
        else if (item.itemBuff.buff.buffMode == Buff.BuffMode.DEBUFF)
        {
            Buff buffToRemove = item.itemBuff.buff.debuffToRemove;

            if (buffToRemove != null)
            {
                foreach (var cell in buffCells)
                {
                    BuffCell activeBuffCell = cell.GetComponent <BuffCell>();

                    if (activeBuffCell.buffType == buffToRemove.buffType)
                    {
                        if (activeBuffCell.GetBuffTimeLeft() != float.MaxValue)
                        {
                            RemoveBuff(cell, buffToRemove);
                            return;
                        }
                        else
                        {
                            RollBackBuff(item);
                        }
                    }
                }
            }
        }

        //find if buff exist
        foreach (var cell in buffs)
        {
            BuffCell activeBuffCell = cell.GetComponent <BuffCell>();

            if (activeBuffCell.buffType == item.itemBuff.buff.buffType)
            {
                if (activeBuffCell.GetBuffTimeLeft() < item.itemBuff.buffTime ||
                    item.itemBuff.buffTime <= Global.Buff.CONSTANT_BUFF_TIME)
                {
                    activeBuffCell.RefreshBuff(cell, item);
                }

                return;
            }
        }

        //if not exist
        GameObject freeCell = FindFreeBuffCell(buffs);
        BuffCell   buffCell = null;

        // когда все ячейки для баффа заняты
        if (freeCell == null)
        {
            return;
        }

        buffCell = freeCell.GetComponent <BuffCell>();

        freeCell.SetActive(true);
        freeCell.GetComponent <Image>().sprite = item.itemBuff.buff.buffSprite;
        freeCell.transform.GetChild(0).GetComponent <Text>().text = item.itemBuff.buff.buffDescription;
        buffCell.buffType = item.itemBuff.buff.buffType;

        buffCell.InitBuff(freeCell, item);
    }