Exemplo n.º 1
0
    public void ShowSpaceAvailable(Vector2 pos, Skill skill)
    {
        BattleSpace space = battleSpaces[(int)pos.x, (int)pos.y];

        space.loadedSkill = skill;

        space.SetToActive(true);
    }
Exemplo n.º 2
0
 public void FinishGeneratingBattleSpaces()
 {
     for (int y = 0; y < dimensionY; y++)
     {
         for (int x = 0; x < dimensionX; x++)
         {
             BattleSpace space = new BattleSpace(Instantiate(battleSpacePrefab), x, y);
             space.objectRef.name = space.objectRef.name.Replace("(Clone)", " ") + "(" + x + ", " + y + ")";
             space.objectRef.transform.SetParent(gameObject.transform, false);
             battleSpaces[x, y] = space;
         }
     }
     tokenPositions = new BodToken[dimensionX, dimensionY];
 }
Exemplo n.º 3
0
    public void SelectTokenButtonPress(BodToken token)
    {
        BattleSpace space = battleBoard.battleSpaces[token.posX, token.posY];

        if (space.loadedSkill != null)
        {
            space.PerformLoadedSkill();
        }
        else
        {
            battleBoard.ResetSpaces();
            token.ToggleBodMenu();
        }
    }
Exemplo n.º 4
0
    //Function to start the fight after the Game Manager has set up the players and enemies
    public void StartBattle()
    {
        //sets the first flag for the victory screen
        m_victoryState = VictoryState.VICTORYSTATE_START;

        m_SelectableSpaces = new List <BattleSpace>();
        m_battleSpaces     = new BattleSpace[8, 4];
        int spaceNum = 0;

        //set up battle spaces
        for (int x = 0; x < 8; x++)
        {
            for (int y = 0; y < 4; y++)
            {
                m_battleSpaces[x, y]        = new BattleSpace();
                m_battleSpaces[x, y].m_cube = r_spaces[spaceNum];
                m_battleSpaces[x, y].x      = x;
                m_battleSpaces[x, y].y      = y;
                spaceNum++;
            }
        }

        m_battleState     = BattleState.BATTLESTATE_START;
        m_selectedCommand = Command.COMMAND_NONE;



        foreach (BattlePawn pawn in m_charactersInBattle)
        {
            m_battleSpaces[pawn.m_x, pawn.m_y].m_pawn = pawn;
            if (pawn.gameObject.tag == "Player")
            {
                m_partyMembers.Add(pawn);
                m_StatusBoxes[m_partyMembers.Count - 1].r_character = pawn;
            }

            pawn.StartBattle();
        }



        TurnOrder();
        EventSystem.current.SetSelectedGameObject(null);
        r_attackButton.Select();

        if (m_charactersInBattle[0].gameObject.tag == "Player")
        {
            m_battleState = BattleState.BATTLESTATE_PLAYER_TURN;
            r_characterActionButtons.SetActive(true);
            EventSystem.current.SetSelectedGameObject(null);
            r_attackButton.Select();
        }
        else if (m_charactersInBattle[0].gameObject.tag == "Enemy")
        {
            m_battleState = BattleState.BATTLESTATE_ENEMY_TURN;
            r_characterActionButtons.SetActive(false);
        }

        m_currentTurnPawn = m_charactersInBattle[0];
        m_charactersInBattle[0].TakeTurn();
    }
Exemplo n.º 5
0
    void calcLandingSquare()
    {
        int throwMax;
        int range;
        int i = 0;

        switch (m_throwDirection)
        {
        case Direction.DIRECTION_NONE:
            break;

        case Direction.DIRECTION_UP:
            //calculate the throw  range so it cant go out of bounds
            throwMax = 3 - m_target.m_y;
            if (throwMax < THROWRANGE)
            {
                range = throwMax;
            }
            else
            {
                range = THROWRANGE;
            }

            if (m_target.m_y == 3)
            {
                m_hitPawn       = null;
                m_hasCollided   = false;
                m_landingDist   = 1;
                m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y];
                break;
            }

            //loop through all squares in the throw path
            for (i = 1; i <= range; i++)
            {
                //if there is an enemy in one, set it so thay will be hit and stop one tile short
                if (m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y + i].m_occupied == true)
                {
                    m_hitPawn       = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y + i].m_pawn;
                    m_hasCollided   = true;
                    m_landingDist   = i - 1;
                    m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y + i - 1];
                    return;
                }
            }
            //if an enemy won't be hit, stop at the end of the range
            m_hitPawn       = null;
            m_hasCollided   = false;
            m_landingDist   = range;
            m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y + i - 1];
            break;

        case Direction.DIRECTION_DOWN:
            //calculate the throw  range so it cant go out of bounds
            throwMax = 0 + m_target.m_y;
            if (throwMax < THROWRANGE)
            {
                range = throwMax;
            }
            else
            {
                range = THROWRANGE;
            }

            if (m_target.m_y == 0)
            {
                m_hitPawn       = null;
                m_hasCollided   = false;
                m_landingDist   = 1;
                m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y];
                break;
            }

            //loop through all squares in the throw path
            for (i = 1; i <= range; i++)
            {
                //if there is an enemy in one, set it so thay will be hit and stop one time short
                if (m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y - i].m_occupied == true)
                {
                    m_hitPawn       = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y - i].m_pawn;
                    m_hasCollided   = true;
                    m_landingDist   = i - 1;
                    m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y - i + 1];
                    return;
                }
            }
            //if an enemy won't be hit, stop at the end of the range
            m_hitPawn       = null;
            m_hasCollided   = false;
            m_landingDist   = range;
            m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y - i + 1];
            break;

        case Direction.DIRECTION_RIGHT:
            //calculate the throw  range so it cant go out of bounds
            throwMax = 7 - m_target.m_x;
            if (throwMax < THROWRANGE)
            {
                range = throwMax;
            }
            else
            {
                range = THROWRANGE;
            }

            m_user.GetComponent <SpriteRenderer>().sprite = m_user.m_spriteR;
            if (m_target.m_x == 7)
            {
                m_hitPawn       = null;
                m_hasCollided   = false;
                m_landingDist   = 1;
                m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y];
                break;
            }

            //loop through all squares in the throw path
            for (i = 1; i <= range; i++)
            {
                //if there is an enemy in one, set it so thay will be hit and stop one time short
                if (m_user.m_battleSystem.m_battleSpaces[m_target.m_x + 1, m_target.m_y].m_occupied == true)
                {
                    m_hitPawn       = m_user.m_battleSystem.m_battleSpaces[m_target.m_x + i, m_target.m_y].m_pawn;
                    m_hasCollided   = true;
                    m_landingDist   = i - 1;
                    m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x + i - 1, m_target.m_y];
                    return;
                }
            }
            //if an enemy won't be hit, stop at the end of the range
            m_hitPawn       = null;
            m_hasCollided   = false;
            m_landingDist   = range;
            m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x + i - 1, m_target.m_y];
            break;

        case Direction.DIRECTION_LEFT:
            //calculate the throw  range so it cant go out of bounds
            throwMax = 0 + m_target.m_x;
            if (throwMax < THROWRANGE)
            {
                range = throwMax;
            }
            else
            {
                range = THROWRANGE;
            }

            m_user.GetComponent <SpriteRenderer>().sprite = m_user.m_spriteL;

            if (m_target.m_x == 0)
            {
                m_hitPawn       = null;
                m_hasCollided   = false;
                m_landingDist   = 1;
                m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x, m_target.m_y];
                break;
            }

            //loop through all squares in the throw path
            for (i = 1; i <= range; i++)
            {
                //if there is an enemy in one, set it so thay will be hit and stop one time short
                if (m_user.m_battleSystem.m_battleSpaces[m_target.m_x - i, m_target.m_y].m_occupied == true)
                {
                    m_hitPawn       = m_user.m_battleSystem.m_battleSpaces[m_target.m_x - i, m_target.m_y].m_pawn;
                    m_hasCollided   = true;
                    m_landingDist   = i - 1;
                    m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x - i + 1, m_target.m_y];
                    return;
                }
            }
            //if an enemy won't be hit, stop at the end of the range
            m_hitPawn       = null;
            m_hasCollided   = false;
            m_landingDist   = range;
            m_landingSquare = m_user.m_battleSystem.m_battleSpaces[m_target.m_x - i + 1, m_target.m_y];
            break;

        default:
            break;
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (m_isDead && m_myTurn)
        {
            m_battleSystem.EndTurn();
            return;
        }

        if (m_playingSkillAnimation || m_playingItemAnimation)
        {
            return;
        }

        //move animation
        if (moveTimer > 0)
        {
            r_myTurnMarker.SetActive(false);
            moveTimer -= Time.deltaTime * 2;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(newPos, oldPos, moveTimer), gameObject.transform.rotation);
        }
        else if (moveTimer < 0)
        {
            r_myTurnMarker.SetActive(true);
            moveTimer = 0;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(newPos, oldPos, moveTimer), gameObject.transform.rotation);
        }

        //attackAnimation
        if (attackTimer > 0 && m_attackHasHit == false)
        {
            r_myTurnMarker.SetActive(false);
            attackTimer -= Time.deltaTime * 4;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }
        else if (attackTimer < 0 && m_attackHasHit == false)
        {
            r_myTurnMarker.SetActive(false);
            m_attackHasHit = true;
            //deal Damage
            m_battleSystem.m_battleSpaces[m_targetX, m_targetY].m_pawn.TakeDamage(this, DamageType.DAMAGETYPE_PHYSICAL, 1.0f);
            if (gameObject.tag == "Player")
            {
                m_battleSystem.AttackEnd(false);
            }
        }
        else if (attackTimer > 1 && m_attackHasHit == true)
        {
            r_myTurnMarker.SetActive(true);
            attackTimer = 1;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }
        else if (attackTimer < 1 && m_attackHasHit == true)
        {
            r_myTurnMarker.SetActive(false);
            attackTimer += Time.deltaTime * 3;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }



        if (m_HP <= 0)
        {
            Death();
            return;
        }

        if (!m_myTurn)
        {
            r_myTurnMarker.SetActive(false);
            return;
        }

        if (m_AP == 0 && m_myTurn)
        {
            EndTurn();
            return;
        }

        if (gameObject.tag == "Enemy" && m_myTurn)
        {
            m_enemyActionTimer += Time.deltaTime;
            if (m_enemyActionTimer < m_enemyActionDelay)
            {
                return;
            }
            //check if player is in range
            m_enemyActionTimer = 0;
            //attack an adjecent enemy
            {
                //right space
                if (m_x < 7)
                {
                    if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x + 1, m_y, m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
                //up space
                if (m_y < 3)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x, m_y + 1, m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
                //left space
                if (m_x > 0)
                {
                    if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x - 1, m_y, m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }

                //down space
                if (m_y > 0)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x, m_y - 1, m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
            }
            //if no adjecent enemy, move towards target
            List <BattleSpace> targetSpaces = r_targetPlayer.GetAdjacentSpaces();
            List <float>       distences    = new List <float>();

            int i = 0;
            //right space
            if (r_targetPlayer.m_x > 0)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            //up space
            if (r_targetPlayer.m_y < 3)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            //left space
            if (r_targetPlayer.m_x < 7)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }

            //down space
            if (r_targetPlayer.m_y > 0)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            bool found = false;

            float lowestDist = 0;
            int   lowestJ    = 0;

            while (!found && distences.Count >= 0)
            {
                lowestJ    = 0;
                lowestDist = 0;
                for (int j = 0; j < distences.Count; j++)
                {
                    if (distences[j] < lowestDist)
                    {
                        lowestJ    = j;
                        lowestDist = distences[j];
                    }
                }

                if (targetSpaces[lowestJ].m_occupied)
                {
                    targetSpaces.RemoveAt(lowestJ);
                    distences.RemoveAt(lowestJ);
                }
                else
                {
                    found = true;
                }
            }

            if (found)
            {
                BattleSpace targetSpace = targetSpaces[lowestJ];
                //if the target space is to the right move right
                if (targetSpace.x > m_x)
                {
                    //only if right is unocupied
                    if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_occupied == false)
                    {
                        MoveTo(m_x + 1, m_y, new Vector3(m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }

                //if it is left move left
                if (targetSpace.x < m_x)
                {
                    //and if left is unocupied
                    if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_occupied == false)
                    {
                        MoveTo(m_x - 1, m_y, new Vector3(m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }
                // if it is up
                if (targetSpace.y > m_y)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_occupied == false)
                    {
                        MoveTo(m_x, m_y + 1, new Vector3(m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }

                // if it is down
                if (targetSpace.y < m_y)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_occupied == false)
                    {
                        MoveTo(m_x, m_y - 1, new Vector3(m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }
            }



            EndTurn();
        }
    }