public void StartBattle()
    {
        // Disable player movement
        //GameManager.gm.leader.DisableMovement();

        epm = GameObject.Instantiate(areaEncounters.GetRandomEncounter(GameManager.currAreaName).gameObject)
              .GetComponent <EnemyPartyManager>();

        int heroDisplayCount = allHeroStats.transform.childCount;

        for (int k = 0; k < heroDisplayCount; k++)
        {
            Destroy(allHeroStats.transform.GetChild(0).gameObject);
        }

        // Activate the panels that display HP, MP, etc.
        for (int i = 0; i < hpm.activePartyMembers.Count; i++)
        {
            HeroDisplayPanel heroDispPanel = GameObject.Instantiate(
                defaultHeroDisplay.gameObject, allHeroStats).GetComponent <HeroDisplayPanel>();
            heroDispPanel.InitiatePanel(hpm.activePartyMembers[i]);

            hpm.activePartyMembers[i].GetComponent <GridController>().canMove = false;

            battleMenu.heroDisplayMidHeight = heroDispPanel.transform.position.y;
        }

        heroesAlive = hpm.activePartyMembers.Count;


        // Instantiate the Enemy sprites
        for (int j = 0; j < epm.activePartyMembers.Count; j++)
        {
            GameObject enemyObj = GameObject.Instantiate(epm.activePartyMembers[j].gameObject);
            epm.activePartyMembers[j] = enemyObj.GetComponent <BaseCharacter>();
            Vector3 tempScale = enemyObj.transform.lossyScale;
            enemyObj.transform.SetParent(enviroImg.transform, false);
            tempScale = new Vector3(tempScale.x / enviroImg.transform.localScale.x,
                                    tempScale.y / enviroImg.transform.localScale.y, tempScale.z / enviroImg.transform.localScale.z);
            enemyObj.transform.localScale = tempScale;
            enemyObj.SetActive(false);
        }

        enemiesAlive = epm.activePartyMembers.Count;

        OpenWindow();
    }
Пример #2
0
    public void StartBattle(string[] introMessage            = null,
                            EnemyPartyManager enemyEncounter = null)
    {
        // Disable player movement
        //GameManager.gm.leader.DisableMovement();

        if (enemyEncounter == null)
        {
            Collider2D currentTile = Physics2D.OverlapCircle(GameManager.gm.leader.transform.position, 4, groundLayer);

            GroundTile ground = currentTile.GetComponent <GroundTile>();
            if (ground)
            {
                if (!MazeGenerator.inMaze)
                {
                    RandomEncounterManager.SetCurrArea(ground.tileChar);
                }
            }
            else
            {
                Debug.Log("Invalid Ground");
            }

            epm = GameObject.Instantiate(areaEncounters
                                         .GetRandomEncounter(RandomEncounterManager.currArea).gameObject)
                  .GetComponent <EnemyPartyManager>();
            Debug.Log("encounter at " + RandomEncounterManager.currArea);
        }
        else
        {
            epm = enemyEncounter;
        }

        int heroDisplayCount = allHeroStats.transform.childCount;

        for (int k = 0; k < heroDisplayCount; k++)
        {
            Destroy(allHeroStats.transform.GetChild(0).gameObject);
        }

        // Activate the panels that display HP, MP, etc.
        for (int i = 0; i < hpm.activePartyMembers.Count; i++)
        {
            HeroDisplayPanel heroDispPanel = GameObject.Instantiate(
                defaultHeroDisplay.gameObject, allHeroStats).GetComponent <HeroDisplayPanel>();
            heroDispPanel.InitiatePanel(hpm.activePartyMembers[i]);

            hpm.activePartyMembers[i].GetComponent <GridController>().canMove = false;

            battleMenu.heroDisplayMidHeight = heroDispPanel.transform.position.y;
        }

        heroesAlive = hpm.activePartyMembers.Count;

        totalGoldDrop = 0;

        // Set the background image
        if (epm.background != null)
        {
            enviroImg.sprite = epm.background;
        }

        // The Skeleton King's body parts shouldn't be lined up,
        // so disable the horizontal layout group.
        if (isFightingFinalBoss)
        {
            enviroImg.GetComponent <HorizontalLayoutGroup>().enabled = false;
        }
        else
        {
            enviroImg.GetComponent <HorizontalLayoutGroup>().enabled = true;
            enviroImg.sprite = AreaEncounters.currBackground;
        }

        // Instantiate the Enemy sprites
        for (int j = 0; j < epm.activePartyMembers.Count; j++)
        {
            GameObject enemyObj = GameObject.Instantiate(epm.activePartyMembers[j].gameObject);
            epm.activePartyMembers[j] = enemyObj.GetComponent <BaseCharacter>();
            Vector3 tempScale = enemyObj.transform.lossyScale;
            enemyObj.transform.SetParent(enviroImg.transform, false);
            tempScale = new Vector3(tempScale.x / enviroImg.transform.localScale.x,
                                    tempScale.y / enviroImg.transform.localScale.y, tempScale.z / enviroImg.transform.localScale.z);
            enemyObj.transform.localScale = tempScale;
            enemyObj.SetActive(false);

            if (isFightingFinalBoss)
            {
                enemyObj.GetComponent <RectTransform>().localScale *= 2;
                enemyObj.GetComponent <RectTransform>().position   += new Vector3((enviroImg.rectTransform.rect.width / 2) * 1.5f,
                                                                                  (-enviroImg.rectTransform.rect.height / 2) * 1.3f);
                enemyObj.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2, Screen.height / 2);
            }

            totalGoldDrop += enemyObj.GetComponent <BaseCharacter>().goldDrop;
        }

        enemiesAlive = epm.activePartyMembers.Count;

        OpenWindow(introMessage);
    }