Пример #1
0
        // Use this for initialization
        void Start()
        {
            //turn on feedback scripts
            FloatingTextController.DamageEnemy();
            FloatingTextController.DamageAlly();
            FloatingTextController.Miss();
            FloatingTextController.HealEnemy();
            FloatingTextController.HealAlly();

            RPG.BattleManager battleManager = RPG.BattleManager.Instance;
            battleManager.stateManager = this;
            turnBehaviour = GetComponent <TurnBehaviour>();
            decalUI       = GetComponent <DecalUI>();
            confirmMenu   = GetComponent <MoveConfirmMenu>();

            camMovement  = GetComponent <CameraMovement>();
            storeTargets = new List <Character>();

            if (camera == null)
            {
                camera = Camera.main;
            }


            characters           = new List <Character>();
            enemies              = new List <Character>();
            deadCharactersREVIVE = new List <Character>();

            // Activate own and enemy team from battleManager, and move enemy team into this scene
            battleManager.playerTeam.gameObject.SetActive(true);
            battleManager.enemyTeam.gameObject.SetActive(true);
            SceneManager.MoveGameObjectToScene(battleManager.enemyTeam.gameObject, gameObject.scene);

            enemyBehav = battleManager.enemyTeam.GetComponentsInChildren <EnemyBehaviour>(true);

            GameObject go = Instantiate(selector);

            selector = go;
            selector.SetActive(false);

            // move Selector into this scene
            SceneManager.MoveGameObjectToScene(selector, this.gameObject.scene);


            //game over menu stuff
            GameOverUI = GameObject.Find("GameOverMenu");

            GameOverTextLose = GameObject.Find("LoseText");
            GameOverTextWin  = GameObject.Find("WinText");

            GameOverUI.SetActive(false);
            GameOverNext.gameObject.SetActive(false);
            GameOverInfo.gameObject.SetActive(false);
            GameOverTextLose.SetActive(false);
            GameOverTextWin.SetActive(false);
            descriptionUI.gameObject.SetActive(false);

            //grabbing players/enemies from the scene to fill lists
            characters.AddRange(battleManager.playerTeam.GetComponentsInChildren <Character>(true));


            //sort player list based on their choiceOrder number(so you can make it that the closest one to the screen picks first ect)
            List <Character> sortedList = characters.OrderBy(o => o.ChoiceOrder).ToList();

            characters         = sortedList;
            battleUIController = GetComponent <BattleUIController>();
            battleUIController.UISetup(characters);

            //setting all characters to be inactive
            foreach (Character chara in characters)
            {
                chara.ActivePlayer = false;
            }

            //TODO place characters in scene positions based on this order (ie List<Transform> playerPositions and List<Transform> enemyPositions)

            enemies.AddRange(battleManager.enemyTeam.GetComponentsInChildren <Character>(true));

            //////PLACES CHARACTERS TO PRE-SET LOCATIONS
            foreach (Character chara in characters)
            {
                //chara.GetComponent<ButtonBehaviour>().Setup(buttonBehaviourObjects);
                chara.GetComponent <TargetSelection>().Init(this.gameObject, camera);
            }

            // place player team in set positions
            for (int i = 0; i < playerPositions.Count && i < characters.Count; ++i)
            {
                characters[i].transform.position = playerPositions[i].position;
                characters[i].transform.rotation = playerPositions[i].rotation;
            }
            //////

            List <Character> tmp = new List <Character>();

            //when battle reentered, forces any dead characters to act like it
            foreach (Character chara in characters)
            {
                if (chara.Hp <= 0)
                {
                    tmp.Add(chara);
                    Death(chara, tmp);
                }
            }

            //moving enemies into position
            for (int i = 0; i < enemyPositions.Count && i < enemies.Count; ++i)
            {
                enemies[i].transform.position = enemyPositions[i].position;
                enemies[i].transform.rotation = enemyPositions[i].rotation;
            }

            //shows enemy ui
            foreach (Character enemy in enemies)
            {
                enemy.GetComponent <EnemyUI>().enemyUISetup(uiCanvas);
            }
            foreach (Character enemy in enemies)
            {
                enemy.GetComponent <EnemyUI>().ShowUI();
            }

            turnBehaviour.Setup(characters, enemies);

            result = EBattleResult.Flee;

            // initialize XP to 0
            xpEarned = 0;

            //starting game loops
            StartCoroutine(GameLoop());
        }
Пример #2
0
        //loop through moves on a delay, apply to targets
        public IEnumerator ApplyMoves()
        {
            PlayerTurnOver = false;
            turnBehaviour.contUi.Active(false);

            //sort move list by speed
            List <TurnBehaviour.TurnInfo> sortedList = turnBehaviour.MovesThisRound.OrderByDescending(o => o.player.Speed).ToList();

            turnBehaviour.MovesThisRound = sortedList;

            //destroying all the projector objects in the lists and then clearing lists
            decalUI.ClearAll();

            //each loop is a players turn
            foreach (TurnBehaviour.TurnInfo info in turnBehaviour.MovesThisRound)
            {
                originalRotation = info.player.transform.rotation;


                info.player.Timer();
                //died due to effect SET UP BETTER DEATH CHECK SYSTEM THIS IS GETTING SILLY
                if (info.player.IsDead)
                {
                    List <Character> tmp = new List <Character>();
                    tmp.Add(info.player);
                    Death(info.player, tmp);
                }
                // HACK maybe just use else? Does the previous block change info or player?
                if (!info.player.IsDead)
                {
                    RandomTargetSelect(info);

                    if (info.player.target != null)
                    {
                        //turn player towards target

                        //check to see if self targeting powers are targeting self, if not set it to be so
                        if (info.ability.areaOfEffect == Powers.AreaOfEffect.Self)
                        {
                            info.player.target = info.player.gameObject;
                        }

                        info.player.transform.LookAt(info.player.target.transform);
                        camMovement.LookAtAttacker(info.player);
                        descriptionUI.gameObject.SetActive(true);
                        descriptionUI.Display(info);
                        yield return(new WaitForSeconds(0.5f));


                        //does damage/animations
                        if (info.ability.areaOfEffect == Powers.AreaOfEffect.Group)
                        {
                            if (info.player.target.tag == "Player")
                            {
                                AddToStoredList(characters);
                            }
                            else
                            {
                                AddToStoredList(enemies);
                            }
                            camMovement.LookAtGroup(storeTargets);

                            if (info.player.target.tag == "Player")
                            {
                                GroupAttack(info, characters, storeTargets);
                            }
                            else
                            {
                                GroupAttack(info, enemies, storeTargets);
                            }
                        }
                        else if (info.ability.areaOfEffect == Powers.AreaOfEffect.Single || info.ability.areaOfEffect == Powers.AreaOfEffect.Self)
                        {
                            //if same team, use facecam, else single out enemy target
                            if (info.player.tag == info.player.target.tag)
                            {
                                camMovement.LookAtAttacker(info.player.target.GetComponent <Character>());
                            }
                            else
                            {
                                camMovement.LookAtTarget(info.player, info.player.target.GetComponent <Character>());
                            }


                            info.ability.Apply(info.player, info.player.target.GetComponent <Character>());
                            string name = info.ability.anim.ToString();
                            info.player.GetComponent <Animator>().Play(name);


                            if (info.player.target.GetComponent <Character>() != info.player)
                            {
                                info.player.target.GetComponent <Animator>().Play("Hit");
                            }
                            //if player character, will allow them to go back to isle anim
                            if (info.player.tag != "Enemy")
                            {
                                info.player.GetComponent <Animator>().SetBool("IdleTransition", true);
                            }
                            storeTargets.Add(info.player.target.GetComponent <Character>());
                        }
                        else
                        {
                            storeTargets = null;
                        }

                        //foreach(Character chara in characters) {
                        //	if(chara != info.player && chara != info.player.target.GetComponent) {
                        //		chara.gameObject.SetActive(false);
                        //	}
                        //}

                        //foreach(Character enem in enemies) {
                        //	if(enem != info.player && enem != info.player.target) {
                        //		enem.gameObject.SetActive(false);
                        //	}
                        //}

                        yield return(new WaitForSeconds(1.5f));



                        //reset player rotation
                        float step = speed * Time.deltaTime;

                        //waits for attack anim to finish before spinning character back towards front
                        yield return(new WaitForSeconds(info.player.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length - info.player.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime));

                        info.player.transform.rotation = Quaternion.Slerp(info.player.transform.rotation, originalRotation, speed);
                        camMovement.Reset();

                        //foreach(Character chara in characters) {
                        //	if(chara != info.player || chara != info.player.target) {
                        //		chara.gameObject.SetActive(true);
                        //	}
                        //}

                        //foreach(Character enem in enemies) {
                        //	if(enem != info.player || enem != info.player.target) {
                        //		enem.gameObject.SetActive(true);
                        //	}
                        //}
                        descriptionUI.gameObject.SetActive(false);
                    }
                }

                yield return(new WaitForSeconds(info.player.GetComponent <Animator>().GetCurrentAnimatorStateInfo(1).length + 1.5f));

                if (storeTargets != null)
                {
                    Death(info.player.target.GetComponent <Character>(), storeTargets);
                }
                //if either side dead already, end fight
                if (BattleOver() == true)
                {
                    yield return(EndBattle());

                    break;
                }
            }

            //REMOVE ANY INSTANCE OF THIS GARBAGE, REDO DEATH CHECK WITH A BOOL OR SOMETHING
            List <Character> deadCharacters = new List <Character>();

            //if dead, remove from list
            foreach (Character chara in characters)
            {
                if (chara.IsDead)
                {
                    Debug.Log(chara.name + " is dead");
                    chara.Hp = 0;
                    deadCharacters.Add(chara);
                }
            }
            if (deadCharacters.Count > 0)
            {
                foreach (Character dead in deadCharacters)
                {
                    characters.Remove(dead);
                }
            }

            List <Character> deadEnemies = new List <Character>();

            foreach (Character enemy in enemies)
            {
                if (enemy.IsDead)
                {
                    Debug.Log(enemy.name + " is dead");
                    enemy.Hp = 0;
                    deadEnemies.Add(enemy);
                    enemy.GetComponent <EnemyUI>().HideUI();
                }
            }
            if (deadEnemies.Count > 0)
            {
                foreach (Character dead in deadEnemies)
                {
                    enemies.Remove(dead);
                    XPSource xp = dead.GetComponent <XPSource>();
                    if (xp != null)
                    {
                        xpEarned += xp.XP;
                    }
                }
            }

            turnBehaviour.MovesThisRound.Clear();
            turnBehaviour.Setup(characters, enemies);
            //turnBehaviour.numOfTurns = turnBehaviour.AvailablePlayers.Count;
            //turnBehaviour.numOfEnemyTurns = turnBehaviour.AvailableEnemies.Count;

            yield return(new WaitForSeconds(0.5f));
        }