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();
        }
    }
    public CombatantCell SpawnCombatCell(CellData cellData, CellSlot parentSlot)
    {
        CombatantCell cc = Instantiate(combatCellPrefab, parentSlot.transform);

        combatCellList.Add(cc);
        parentSlot.LoadCell(cc, cellData, false);
        return(cc);
    }
    public void FinishMoveToSlot()
    {
        CombatantBoard myBoard = parentRectTransform.parent.GetComponentInParent <CombatantBoard>();

        if (myBoard != null)
        {
            bool      bGoodMove        = false;
            Transform closestTransform = myBoard.GetClosestSlotTo(transform.position);
            if (closestTransform != null)
            {
                CellSlot closestSlot = closestTransform.GetComponent <CellSlot>();
                if (closestSlot != cellSlot)
                {
                    transform.SetParent(closestTransform);
                    transform.localPosition = Vector3.zero;
                    transform.localScale    = Vector3.one;

                    //if ((moveOriginSlot != null) && (moveOriginSlot.GetCell() != null))
                    //{
                    //	CellData cellData = moveOriginSlot.GetCell().GetCellData();
                    //	if (cellData != null)
                    //		combatCell.LoadCellData(cellData);
                    //}

                    bGoodMove = true;
                    cellSlot  = closestSlot;
                    cellSlot.LoadCell(combatCell, movingCellData, false);
                    combatCell.SetSlot(cellSlot);

                    /// On Move Ability
                    if ((combatCell != null) && (combatCell.GetCellData() != null) &&
                        (combatCell.GetCellData().bOnMoveAbility))
                    {
                        combatCell.GetCellData().OnMoveAbility(cellSlot);
                    }
                }
                else
                {
                    /// move ended up at origin
                    transform.SetParent(cellSlot.transform);
                    transform.localPosition = Vector3.zero;
                    transform.localScale    = Vector3.one;
                }
            }

            if (bGoodMove)
            {
                if (moveCounter != null)
                {
                    moveCounter.SpendMoveToken(1);
                }

                moveOriginSlot.ClearCell(false);
            }
        }
    }
    /// HeavyWater 'decays' into regular Water when eliminated
    public override void OnCellDiedAbility(CombatantCell myCell)
    {
        base.OnCellDiedAbility(myCell);

        myCombatCell = myCell;
        if (myCombatCell != null)
        {
            CellSlot mySlot = myCombatCell.GetSlot();
            if (mySlot != null)
            {
                mySlot.LoadCell(myCombatCell, waterCellData, false);
            }
        }
    }
    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);
            }
        }
    }