Esempio n. 1
0
    void InitBoard()
    {
        grid                 = boardRect.GetComponent <GridLayoutGroup>();
        grid.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
        grid.constraintCount = boardColumnCount;

        boardWidth  = boardRect.sizeDelta.x;
        boardHeight = boardRect.sizeDelta.y;

        int numCells = boardColumnCount * boardRowCount;

        for (int i = 0; i < numCells; i++)
        {
            CellSlot cellSlot = Instantiate(cellSlotPrefab, boardRect);
            slotList.Add(cellSlot);
        }

        BoardEditor be = FindObjectOfType <BoardEditor>();

        if (be != null)
        {
            be.LoadSlots();
        }

        BoardGenerator bg = GetComponent <BoardGenerator>();

        if (bg != null)
        {
            bg.GenerateBoard();
        }
    }
Esempio n. 2
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);
    }
Esempio n. 3
0
 void Start()
 {
     cellAttack = GetComponentInChildren <CellAttack>();
     mySlot     = transform.GetComponentInParent <CellSlot>();
     battleUI   = FindObjectOfType <BattleUI>();
     battle     = FindObjectOfType <Battle>();
 }
    /// 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);
    }
Esempio n. 5
0
    public static CellSlot Rotate(this CellSlot slot, int rotation)
    {
        CellSlot result = CellSlot.None;

        if (slot.HasFlag(CellSlot.Floor))
        {
            result |= CellSlot.Floor;
        }
        if (slot.HasFlag(CellSlot.Ceiling))
        {
            result |= CellSlot.Ceiling;
        }
        if (slot.HasFlag(CellSlot.Wall0))
        {
            result |= RotateWall(CellSlot.Wall0, rotation);
        }
        if (slot.HasFlag(CellSlot.Wall1))
        {
            result |= RotateWall(CellSlot.Wall1, rotation);
        }
        if (slot.HasFlag(CellSlot.Wall2))
        {
            result |= RotateWall(CellSlot.Wall2, rotation);
        }
        if (slot.HasFlag(CellSlot.Wall3))
        {
            result |= RotateWall(CellSlot.Wall3, rotation);
        }
        return(result);
    }
Esempio n. 6
0
    public CombatantCell SpawnCombatCell(CellData cellData, CellSlot parentSlot)
    {
        CombatantCell cc = Instantiate(combatCellPrefab, parentSlot.transform);

        combatCellList.Add(cc);
        parentSlot.LoadCell(cc, cellData, false);
        return(cc);
    }
Esempio n. 7
0
 public void SwapCard(CellSlot slot)
 {
     slot.cardGO        = this.gameObject;
     transform.position = slot.transform.position;
     transform.SetParent(slot.transform);
     cellSlot = slot;
     IsInCell = true;
 }
Esempio n. 8
0
 void Awake()
 {
     cellImage   = GetComponent <Image>();
     health      = GetComponent <Health>();
     canvasGroup = GetComponent <CanvasGroup>();
     arsenal     = GetComponent <CellArsenal>();
     ShowCanvasGroup(false);
     mySlot = transform.parent.GetComponent <CellSlot>();
 }
Esempio n. 9
0
    public override void StartAttack(Transform attacker, Transform defender)
    {
        base.StartAttack(attacker, defender);

        mySlot       = attacker.GetComponent <CellSlot>();
        opponentSlot = defender.GetComponent <CellSlot>();

        StartLineAttack();
    }
Esempio n. 10
0
 public void UpdateRemovingSlot(CellSlot value)
 {
     removingSlot = value;
     removeCellPanel.transform.position = value.transform.position;
     if ((value != null) && (hotCellData == null))
     {
         EnableRemovePanel(true);
     }
 }
Esempio n. 11
0
    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);
            }
        }
    }
Esempio n. 12
0
 void Start()
 {
     myRectTransform     = GetComponent <RectTransform>();
     parentRectTransform = transform.parent.GetComponent <RectTransform>();
     if (FindObjectOfType <MoveField>() != null)
     {
         moveFieldTransform = FindObjectOfType <MoveField>().GetComponent <RectTransform>();
     }
     cameraMain = Camera.main;
     cellSlot   = transform.GetComponentInParent <CellSlot>();
     combatCell = GetComponent <CombatantCell>();
 }
Esempio n. 13
0
    public void RemoveCell()
    {
        if (removingSlot != null)
        {
            removingSlot.ClearCell(true);
            removingSlot = null;
            hotCellData  = null;

            UpdateBoardValue();
            game.SaveGame();
            EnableRemovePanel(false);
        }
    }
Esempio n. 14
0
 private void ClearNeighbourWallSlots(int x, int z, CellSlot slot)
 {
     for (int i = 0; i < 4; i++)
     {
         var wallSlot = CellSlotExtensions.ToWallSlot(i);
         if (slot.HasFlag(wallSlot))
         {
             var oppositeWallSlot = CellSlotExtensions.RotateWall(wallSlot, 2);
             var(dx, dz) = wallSlot.ToDirectionVector();
             ClearCellSlot(x + dx, z + dz, oppositeWallSlot);
         }
     }
 }
Esempio n. 15
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);
            }
        }
    }
    /// 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);
            }
        }
    }
Esempio n. 17
0
    public bool IsSingleWallEmpty(CellSlot slot)
    {
        switch (slot)
        {
        case CellSlot.Wall0: return(Wall0 == null);

        case CellSlot.Wall1: return(Wall1 == null);

        case CellSlot.Wall2: return(Wall2 == null);

        case CellSlot.Wall3: return(Wall3 == null);

        default: throw new InvalidOperationException();
        }
    }
Esempio n. 18
0
 public void ReturnCardToHand()
 {
     if (IsInCell)
     {
         IsInCell = false;
         //cellSlot.cardGO.Remove(gameObject);
         cellSlot.RemoveCard();
         cellSlot = null;
         CellSlot.OnCardDropFunc();
     }
     //transform.position = _startPosition;
     transform.SetParent(null);
     transform.SetParent(_startParent.transform);
     //transform.localPosition = new Vector3(0, 0, 0);
 }
Esempio n. 19
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();
        }
    }
Esempio n. 20
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);
    }
Esempio n. 21
0
 public void PutCardOnSlot(CellSlot slot)
 {
     if (cellSlot != null && cellSlot != slot) // Попали в другой слот
     {
         slot.cardGO.GetComponent <DragAndDrop>().SwapCard(cellSlot);
     }
     if (cellSlot == null && slot.cardGO != null)
     {
         slot.cardData.DragController.ReturnCardToHand();
         slot.cardGO = gameObject;
     }
     transform.position = slot.transform.position;
     transform.SetParent(slot.transform);
     cellSlot = slot;
     IsInCell = true;
 }
Esempio n. 22
0
    public static int ToDirection(this CellSlot wallSlot)
    {
        switch (wallSlot)
        {
        case CellSlot.Wall0: return(0);

        case CellSlot.Wall1: return(1);

        case CellSlot.Wall2: return(2);

        case CellSlot.Wall3: return(3);

        default:
            throw new InvalidOperationException();
        }
    }
Esempio n. 23
0
    public static (int, int) ToDirectionVector(this CellSlot slot)
    {
        switch (slot)
        {
        case CellSlot.Wall0: return(0, -1);

        case CellSlot.Wall1: return(-1, 0);

        case CellSlot.Wall2: return(0, +1);

        case CellSlot.Wall3: return(+1, 0);

        default:
            throw new InvalidOperationException();
        }
    }
Esempio n. 24
0
    public void PutDecorator(CellSlot slot, GameObject prefab, int rotation)
    {
        var deco = prefab == null ? null : new CellDecorator
        {
            prefab   = prefab,
            rotation = rotation
        };

        if (slot.HasFlag(CellSlot.Floor))
        {
            DisposeDeco(Floor);
            Floor = deco;
        }

        if (slot.HasFlag(CellSlot.Ceiling))
        {
            DisposeDeco(Ceiling);
            Ceiling = deco;
        }

        if (slot.HasFlag(CellSlot.Wall0))
        {
            DisposeDeco(Wall0);
            Wall0 = deco;
        }

        if (slot.HasFlag(CellSlot.Wall1))
        {
            DisposeDeco(Wall1);
            Wall1 = deco;
        }

        if (slot.HasFlag(CellSlot.Wall2))
        {
            DisposeDeco(Wall2);
            Wall2 = deco;
        }

        if (slot.HasFlag(CellSlot.Wall3))
        {
            DisposeDeco(Wall3);
            Wall3 = deco;
        }

        UpdateView();
    }
Esempio n. 25
0
    private IEnumerator Merge(DragAndDrop droppedObject, DragAndDrop otherCard, CellSlot cellSlot)
    {
        battle.MoveCard(otherCard.gameObject, droppedObject.gameObject);
        yield return(new WaitForSeconds(2.2f));

        battle.StopAllCoroutines();
        if (droppedObject != null)
        {
            droppedObject.gameObject.GetComponent <Image>().color = new Color(0.77f, 1f, 0.75f);
            droppedObject.probability += otherCard.probability;
            droppedObject.probability /= 2;
            cellSlot.ClearCards();
        }
        battle.CheckEndOfTurns();
        if (droppedObject.handler == "player")
        {
            BattleBot.singleton.BotTurn();
        }
    }
Esempio n. 26
0
    private void HitCell(Transform attackerTransform, Transform targetTransform, int damage)
    {
        attackParticles.transform.SetParent(targetTransform);
        attackParticles.transform.localPosition = Vector3.zero;
        int particleDamageScale = Mathf.Clamp(damage, 1, 20);

        attackParticles.transform.localScale = Vector3.one * particleDamageScale;
        attackParticles.Play();

        bool bAttackThrough = true;

        CombatantCell targetCell = targetTransform.GetComponent <CombatantCell>();

        if (!targetCell)
        {
            targetCell = targetTransform.GetComponentInChildren <CombatantCell>();
        }
        if (targetCell != null)
        {
            if (targetCell != null)
            {
                CellData targetCellData = targetCell.GetCellData();
                if ((targetCellData != null) && targetCellData.bOnAttackedAbility)
                {
                    CellSlot slotA = attackerTransform.GetComponent <CellSlot>();
                    CellSlot slotB = targetTransform.GetComponent <CellSlot>();
                    bAttackThrough = targetCellData.OnAttackedAbility(slotB, slotA);
                }
            }

            if (bAttackThrough)
            {
                targetCell.TakeDamage(damage);
                battleUI.ToastInteraction(targetCell.transform.position, damage, 0, "--");
                battle.TestBattleOver();
            }
        }
        else
        {
            battleUI.ToastInteraction(targetTransform.position, damage, 0, "--");
            battle.TestBattleOver();
        }
    }
Esempio n. 27
0
    public void SetBoardTeamID(int value)
    {
        if (combatCellList != null)
        {
            for (int i = 0; i < combatCellList.Count; i++)
            {
                CombatantCell cc = combatCellList[i];
                cc.InitCombatantCell(value);
            }
        }

        if (slotList != null)
        {
            for (int j = 0; j < slotList.Count; j++)
            {
                CellSlot cs = slotList[j];
                cs.SetTeamID(value);
            }
        }
    }
Esempio n. 28
0
    void ResolveCellRow(int rowIndex)
    {
        int numColumns = playerBoard.boardColumnCount;
        int startingColumnIndexInBoard = playerBoard.boardRowCount * Mathf.Clamp(rowIndex, 0, numColumns - 1);

        for (int i = 0; i < numColumns; i++)
        {
            int      playerColumnIndex = startingColumnIndexInBoard + i;
            CellSlot playerSlot        = playerBoard.GetSlots()[playerColumnIndex];

            int opponentColumnIndex = 0;
            if (playerColumnIndex != 0)
            {
                opponentColumnIndex = (opponentBoard.GetSlots().Count - playerColumnIndex) - 1;
            }
            Debug.Log("trying opponent slot index " + opponentColumnIndex);
            CellSlot opponentSlot = opponentBoard.GetSlots()[opponentColumnIndex];
            ResolveCellPair(playerSlot, opponentSlot);
        }
    }
Esempio n. 29
0
    IEnumerator CellDeathTimer(float time, CellSlot Cell)
    {
        bool  Dead     = true;
        float timeDead = time;

        while (Dead)
        {
            if (timeDead > 0)
            {
                timeDead -= Time.deltaTime;
                Cell.UpdateTimer(timeDead);
            }
            else
            {
                Cell.UpdateTimer(timeDead);
                Dead = false;
            }
            yield return(null);
        }
    }
Esempio n. 30
0
    public void ClearBoard()
    {
        if (removingSlot != null)
        {
            removingSlot.ClearCell(true);
            removingSlot = null;
        }

        if (hotCellData != null)
        {
            UpdateHotCell(null);
        }

        foreach (CellSlot cs in slotList)
        {
            cs.ClearCell(true);
        }

        UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
        UpdateBoardValue();
        game.SaveGame();
    }