Ejemplo n.º 1
0
    void ResolveCellPair(CellSlot cellSlotA, CellSlot cellSlotB)
    {
        cellSlotA.HighlightForDuration(0.5f);
        cellSlotB.HighlightForDuration(0.5f);

        CellData      cellA       = null;
        CombatantCell combatCellA = null;

        if (cellSlotA.GetCell() != null)
        {
            combatCellA = cellSlotA.GetCell();
            cellA       = combatCellA.GetCellData();
        }
        CellData      cellB       = null;
        CombatantCell combatCellB = null;

        if (cellSlotB.GetCell() != null)
        {
            combatCellB = cellSlotB.GetCell();
            cellB       = combatCellB.GetCellData();
        }

        if (cellA != null)
        {
            if (cellA.bAttackAbility)
            {
                cellA.AttackAbility(cellSlotA, cellSlotB);
            }

            int cellADamage = combatCellA.GetDamage();
            if (cellADamage > 0)
            {
                combatCellA.GetComponent <CellArsenal>().StartHitAfterDelay(cellSlotA.transform, cellSlotB.transform, cellADamage);
            }
        }

        if (cellB != null)
        {
            if (cellB.bAttackAbility)
            {
                cellB.AttackAbility(cellSlotB, cellSlotA);
            }

            int cellBDamage = combatCellB.GetDamage();
            if (cellBDamage > 0)
            {
                combatCellB.GetComponent <CellArsenal>().StartHitAfterDelay(cellSlotB.transform, cellSlotA.transform, cellBDamage);
            }
        }
    }
Ejemplo n.º 2
0
    public void GenerateBoard()
    {
        if (cellLibrary == null)
        {
            cellLibrary = FindObjectOfType <CellLibrary>();
        }
        if (board == null)
        {
            board = GetComponent <CombatantBoard>();
        }

        boardSlotList = board.GetSlots();
        numCellTypes  = cellLibrary.allCells.Length;
        numBoardSlots = boardSlotList.Count;

        while ((cells < cellCount) && (cellValue < numBoardSlots) && (tries < 100))
        {
            /// first row guaranteed
            for (int i = 0; i < board.boardColumnCount; i++)
            {
                CellSlot cs = boardSlotList[i];
                NewCell();
            }

            /// remaining cells randomly
            foreach (CellSlot cs in boardSlotList)
            {
                if ((cs.GetCell() == null) ||
                    ((cs.GetCell() != null) && (cs.GetCell().GetCellData() != null)))
                {
                    if ((Random.Range(0f, 1f) > 0.3f) && (cells < cellCount))
                    {
                        NewCell();
                    }
                    else
                    {
                        if (cells < cellCount)
                        {
                            cellList.Add(null);
                        }
                    }
                }
            }
            tries++;
        }

        board.LoadBoard(cellList);
    }
Ejemplo n.º 3
0
    public void PlaceCell(CellSlot intoSlot)
    {
        if (bEditing && (hotCellData != null))
        {
            int placingSlotIndex = intoSlot.transform.GetSiblingIndex();

            /// placed to empty slot...
            if (((intoSlot.GetCell() == null) || ((intoSlot.GetCell() != null) && (intoSlot.GetCell().GetCellData() == null))) &&
                ((boardValue + hotCellData.cellValue) <= maxBoardValue))
            {
                CombatantCell combatCell = playerBoard.SpawnCombatCell(hotCellData, intoSlot);
                intoSlot.LoadCell(combatCell, hotCellData, false);
                if (boardCellDataList.Count > placingSlotIndex)
                {
                    boardCellDataList[placingSlotIndex] = hotCellData;
                }
                else
                {
                    int difference = (placingSlotIndex - boardCellDataList.Count) + 1;
                    for (int i = 0; i < difference; i++)
                    {
                        boardCellDataList.Add(null);
                    }
                    boardCellDataList[placingSlotIndex] = hotCellData;
                }
            }
            else if (intoSlot.GetCell() != null)
            {
                /// or overwrite existing cell
                CombatantCell existingCell = intoSlot.GetCell();
                existingCell.LoadCellData(hotCellData);
                intoSlot.LoadCell(existingCell, hotCellData, false);
                if (boardCellDataList.Count > placingSlotIndex)
                {
                    boardCellDataList[placingSlotIndex] = hotCellData;
                }
                else
                {
                    boardCellDataList.Add(hotCellData);
                }
            }

            hotCellData = null;
            bEditing    = false;
            UpdateBoardValue();
            game.SaveGame();
        }
    }
Ejemplo n.º 4
0
    /// Francium absorbs health from damage
    public override bool OnAttackedAbility(CellSlot mySlot, CellSlot targetSlot)
    {
        base.OnAttackedAbility(mySlot, targetSlot);

        bool bAttackThrough = true;

        CombatantCell targetCell = targetSlot.GetComponentInChildren <CombatantCell>();

        if (targetCell != null)
        {
            int targetCellDamage = targetCell.GetDamage();

            CombatantCell myCell = mySlot.GetCell();
            if (myCell != null)
            {
                if (!battleUI)
                {
                    battleUI = FindObjectOfType <BattleUI>();
                }
                battleUI.ToastInteraction(myCell.transform.position, targetCellDamage, 3, "hp +");

                myCell.ModifyHealth(targetCellDamage);

                bAttackThrough = false;
            }
        }

        return(bAttackThrough);
    }
Ejemplo n.º 5
0
    /// Caesium returns attacks back to the opponent
    public override bool OnAttackedAbility(CellSlot mySlot, CellSlot targetSlot)
    {
        base.OnAttackedAbility(mySlot, targetSlot);

        bool bAttackThrough = true;

        CombatantCell targetCell = targetSlot.GetComponentInChildren <CombatantCell>();

        if (targetCell != null)
        {
            int targetCellDamage = targetCell.GetDamage();

            CombatantCell myCell = mySlot.GetCell();
            if (myCell != null)
            {
                if (!battleUI)
                {
                    battleUI = FindObjectOfType <BattleUI>();
                }
                battleUI.ToastInteraction(myCell.transform.position, targetCellDamage, 2, "reflect ");
                bAttackThrough = false;
                myCell.SetDamage(targetCellDamage);
                myCell.GetComponent <CellArsenal>().StartHitAfterDelay(mySlot.transform, targetSlot.transform, myCell.GetDamage());
                myCell.SetDamage(0);
            }
        }

        return(bAttackThrough);
    }
Ejemplo n.º 6
0
    public bool SetMoving(bool value, CellSlot originSlot)
    {
        bool bMoveStarted = false;

        if (bMoveable)
        {
            if (value)
            {
                bMoving = true;
                transform.SetParent(moveFieldTransform);
                transform.localScale = Vector3.one;
                bMoveStarted         = true;
                moveOriginSlot       = originSlot;
                movingCellData       = originSlot.GetCell().GetCellData();
            }
            else
            {
                bMoving = false;
                transform.SetParent(parentRectTransform);
                transform.localScale = Vector3.one;
            }
        }
        return(bMoveStarted);
    }
Ejemplo n.º 7
0
    public void MirrorBoard()
    {
        // 1 - store & clear the top and bottom rows
        /// top
        List <CombatantCell> topRowCells = new List <CombatantCell>();

        for (int i = 0; i < boardColumnCount; i++)
        {
            CellSlot slot = slotList[i];
            if (slot != null)
            {
                CombatantCell cell = slot.GetCell();
                if ((cell != null) && (cell.GetCellData() != null))
                {
                    topRowCells.Add(cell);
                }
            }
        }
        /// bottom
        List <CombatantCell> bottomRowCells = new List <CombatantCell>();

        for (int i = 0; i < boardColumnCount; i++)
        {
            int      mirrorIndex = i + (boardColumnCount * 2);
            CellSlot slot        = slotList[mirrorIndex];
            if (slot != null)
            {
                CombatantCell cell = slot.GetCell();
                if ((cell != null) && (cell.GetCellData() != null))
                {
                    bottomRowCells.Add(cell);
                }
            }
        }

        // 2 - load exchanged rows
        /// top
        for (int i = 0; i < boardColumnCount; i++)
        {
            if ((i < bottomRowCells.Count) && (bottomRowCells[i] != null))
            {
                CellSlot      slot = slotList[i];
                CombatantCell cell = bottomRowCells[i];
                CellData      data = cell.GetCellData();

                slot.LoadCell(cell, data, false);
                cell.LoadCellData(data);
                cell.transform.SetParent(slot.transform);
                cell.transform.localPosition = Vector3.zero;
                transform.localScale         = Vector3.one;
                cell.SetSlot(slot);
            }
        }
        /// bottom
        for (int i = 0; i < boardColumnCount; i++)
        {
            if ((i < topRowCells.Count) && (topRowCells[i] != null))
            {
                int           mirrorIndex = i + (boardColumnCount * 2);
                CellSlot      slot        = slotList[mirrorIndex];
                CombatantCell cell        = topRowCells[i];
                CellData      data        = cell.GetCellData();

                slot.LoadCell(cell, data, false);
                cell.LoadCellData(data);
                cell.transform.SetParent(slot.transform);
                cell.transform.localPosition = Vector3.zero;
                transform.localScale         = Vector3.one;
                cell.SetSlot(slot);
            }
        }
    }