コード例 #1
0
 public void LoadContent(BattleItemData itemData, int QTY)
 {
     //Loads from a BattleItemData object.
     itemID = itemData.itemID;
     itemDescription = itemData.itemDescription;
     qty = QTY;
     battleEffectTargeting = itemData.itemBattleEffectTargeting;
     battleEffect = new BattleTechniqueEffect();
     battleEffect.LoadContent(itemData.itemBattleEffect);
 }
コード例 #2
0
        public override void Update(GameTime gameTime)
        {
            //Update the controllers.
            controls.Update(gameTime);
            debugControls.Update(gameTime);
            restartScreenControls.Update(gameTime);

            if (ScreenManager.CurrentFadeState == ScreenFadeState.IdleFaded)
            {//If the screen isn't fading in or out...

                //Update all the Menus and the info bar.
                playerTurnMenu.Update(gameTime);
                playerTechniqueMenu.Update(gameTime);
                battleTargetSelector.Update(gameTime);
                battleInventoryMenu.Update(gameTime);
                gameOverMenu.Update(gameTime);
                infoBar.Update(gameTime);

                //Update all the player status boxes.
                foreach (PlayerCharacterStatusBox statusBox in playerStatusBoxes)
                {
                    statusBox.Update(gameTime);
                }
                //Update everyone in the draw list.
                foreach (BattleCharacter character in drawList)
                {
                    character.Update(gameTime);
                }

                switch (battleState)
                {//At what stage is this turn...?
                    #region Start of Battle
                      //The battle is only starting. All characters if introductory animations perform them, and then the first turn starts.
                    case BattleState.AwaitingBattleStart:
                        bool battleShouldStart = true;
                        foreach (BattleCharacter character in activeCharacters)
                        {
                            if (character.CurrentAction == "BattleStart")
                            {
                                battleShouldStart = false;
                            }
                        }

                        if (battleShouldStart == true)
                        {
                            battleState = BattleState.GeneralTechniqueChoice;
                        }
                        break;
                    #endregion
                    #region Beginning of Turn; Technique Selection
                    case BattleState.GeneralTechniqueChoice:

                        if (TurnCharacter.CurrentAction != "Defend")
                        {//If this turns character wasn't defending from last turn....

                            if (characterOriginalPosition != TurnCharacter.Position)
                            {//If there is a discrepency between the characters current position and where it should be, correct it.
                                characterOriginalPosition = TurnCharacter.Position;
                            }

                            if (TurnCharacter is PlayerBattleCharacter)
                            {//If it is a player characters turn...

                                switch (playerTurnMenu.MenuState)
                                {//What state is the general menu in?
                                    case MenuState.IdleFaded:
                                        //Its hidden; Show it and the info bar.
                                        GameClass.SoundManager.PlaySoundEffect("Audio/menuPopUp");
                                        playerTurnMenu.Show();
                                        infoBar.Show();
                                        infoBar.InfoText = playerTurnMenu.GetSelectionDescription();
                                        break;

                                    case MenuState.IdleAwaitingInput:
                                        //Its waiting for player input; update the info bar to show information for what the player is currently selecting.
                                        infoBar.InfoText = playerTurnMenu.GetSelectionDescription();
                                        break;

                                    case MenuState.IdleValueSelected:
                                        //Its received input from the player to perform a technique.

                                        //get the technique name from the Menu.
                                        selectedTechniqueName = playerTurnMenu.GetSelection();

                                        if (selectedTechniqueName == "Skills")
                                        {//If the player selected 'Skills'...

                                            if (TurnCharacter.Techniques.Count > 2)
                                            {//If this player character has more than 'Attack' and 'Defend' defined for it....

                                                //Deactivate the general menu, load the characters techniques into the technique menu and change the battle state.
                                                playerTurnMenu.HalfHide();
                                                playerTechniqueMenu.LoadTechniques(TurnCharacter);
                                                battleState = BattleState.PlayerTechniqueChoice;
                                            }
                                            else
                                            {//Otherwise this character has no 'Skills'; continue listening for different player input.
                                                playerTurnMenu.ListenForNewSelection();
                                            }
                                        }
                                        else if (selectedTechniqueName == "Items")
                                        {//If the player selected 'Items'...

                                            int items = 0;
                                            foreach (BattleItem item in battleItemInventory)
                                            {

                                                if (item.QTY > 0)
                                                {
                                                    items++;
                                                }
                                            }

                                            if (items > 0)
                                            {//If the player has any items...

                                                //Deactivate the general menu, load the players items into the Battle Inventory menu and change the battle state.
                                                playerTurnMenu.HalfHide();
                                                battleInventoryMenu.LoadBattleItems(battleItemInventory);
                                                battleState = BattleState.PlayerItemChoice;
                                            }
                                            else
                                            {//Otherwise player has no items; continue listening for different player input.
                                                playerTurnMenu.ListenForNewSelection();
                                            }
                                        }
                                        else
                                        {//Otherwise, player selected 'Attack' or 'Defend'; Deactivate general menu; Load the technique data for the selection and advance to target selection.
                                            playerTurnMenu.HalfHide();
                                            selectedTechnique = getTechniqueFromAction(selectedTechniqueName);
                                            battleState = BattleState.TargetChoice;
                                        }
                                        break;
                                }
                            }
                            else if (TurnCharacter is EnemyBattleCharacter)
                            {//Otherwise, character is an enemy; Determine action and targets from AI method and advance to resolving the selection.

                                AIActionSelection();
                                battleState = BattleState.TechniqueResolve;
                            }
                        }
                        else
                        {//Otherwise character was defending last turn; set character back to idle.
                            TurnCharacter.CurrentSprite.AnimationType = SpriteAnimationType.RepeatingReverse;
                            if (TurnCharacter.CurrentSprite.CurrentFrame < 1)
                            {
                                TurnCharacter.CurrentSprite.AnimationType = SpriteAnimationType.AnimateOnceMaintainLast;
                                TurnCharacter.CurrentAction = "Idle";
                            }
                        }
                        break;
                    #endregion
                    #region Player selected 'Skills'; Technique choice
                    case BattleState.PlayerTechniqueChoice:
                        //Player is selecting a skill to use.
                        if (controls.ButtonPressed(Buttons.A, false, false) || debugControls.KeyPressed(Keys.Back, false, false))
                        {//Player chose not to use a skill and cancel; Hide Technique Menu, Show General Menu, Return state to general technique selection.
                            GameClass.SoundManager.PlaySoundEffect("Audio/menuCancel");
                            controls.ControlsActive = false;
                            debugControls.ControlsActive = false;
                            playerTechniqueMenu.Hide();
                            playerTurnMenu.Show();
                            battleState = BattleState.GeneralTechniqueChoice;
                        }

                        switch (playerTechniqueMenu.MenuState)
                        {//What state is the Skills Menu in?
                            case MenuState.IdleFaded:
                                //Its hidden; show it and set the info bar to display info for it.
                                playerTechniqueMenu.Show();
                                infoBar.InfoText = playerTechniqueMenu.GetSelectionDescription();
                                controls.ControlsActive = true;
                                debugControls.ControlsActive = true;
                                break;

                            case MenuState.IdleAwaitingInput:
                                //It's listening for player input; set info bar to display information about players current selection.
                                infoBar.InfoText = playerTechniqueMenu.GetSelectionDescription();
                                break;

                            case MenuState.IdleValueSelected:
                                //Player selected a skill to use; Get the technique name for the skill, identify possible targets.
                                selectedTechniqueName = playerTechniqueMenu.GetSelection();
                                selectedTechnique = getTechniqueFromAction(selectedTechniqueName);
                                int possibleTargetCount = getAvailableTargets(selectedTechnique.techniqueTargeting).Count;

                                if (selectedTechnique.techniqueCost > TurnCharacter.CurrentMP || possibleTargetCount == 0)
                                {//Character hasn't enough MP to perform the skill or theres no-one to target with it; Reset selection and listen for new input.
                                    ResetTurnParameters();
                                    playerTechniqueMenu.ListenForNewSelection();
                                }
                                else
                                {//Otherwise Skill is usable; Deactivate technique Menu and advance to target selection.
                                    playerTechniqueMenu.HalfHide();
                                    battleState = BattleState.TargetChoice;
                                }
                                break;
                        }
                        break;
                    #endregion
                    #region Player selected 'Items'; Item choice
                    case BattleState.PlayerItemChoice:
                    //Player is selected an Item to use.
                        if (controls.ButtonPressed(Buttons.A, false, false) || debugControls.KeyPressed(Keys.Back, false, false))
                        {//Player decided not to use an item and cancel; Hide Item Menu, Show General Menu, and return to general technique selection.
                            GameClass.SoundManager.PlaySoundEffect("Audio/menuCancel");
                            controls.ControlsActive = false;
                            debugControls.ControlsActive = false;
                            battleInventoryMenu.Hide();
                            playerTurnMenu.Show();
                            battleState = BattleState.GeneralTechniqueChoice;
                            selectedTechniqueNameIsItem = false;
                        }

                        switch (battleInventoryMenu.MenuState)
                        {//what state is the Item Menu in?
                            case MenuState.IdleFaded:
                                //Its hidden; Show it and set the info bar to display information about it.
                                battleInventoryMenu.Show();
                                infoBar.InfoText = battleInventoryMenu.GetSelectionDescription();
                                controls.ControlsActive = true;
                                debugControls.ControlsActive = true;
                                break;

                            case MenuState.IdleAwaitingInput:
                                //It's listening for player input; set info bar to display information about players current selection.
                                infoBar.InfoText = battleInventoryMenu.GetSelectionDescription();
                                break;

                            case MenuState.IdleValueSelected:
                                //Player selected an item to use; Get the technique name for the item, identify possible targets.
                                selectedTechniqueName = battleInventoryMenu.GetSelection();
                                selectedTechnique = getTechniqueFromAction(selectedTechniqueName);

                                int possibleTargetCount = getAvailableTargets(selectedTechnique.techniqueTargeting).Count;

                                if (possibleTargetCount == 0)
                                {//Theres no-one to use the item on; Reset selection and listen for new input.
                                    ResetTurnParameters();
                                    battleInventoryMenu.ListenForNewSelection();
                                }
                                else
                                {//Otherwise item is usable; Deactivate item Menu and advance to target selection.
                                    battleInventoryMenu.HalfHide();
                                    battleState = BattleState.TargetChoice;
                                    selectedTechniqueNameIsItem = true;
                                }

                                break;
                        }
                        break;
                    #endregion
                    #region Technique selected; Target for Technique Selection
                    case BattleState.TargetChoice:
                        //Player is selecting targets for their selected technique.
                        switch (battleTargetSelector.CurrentState)
                        {//What state is the battle target selector in?
                            case BattleTargetSelectorState.Inactive:
                                //Its not activated; Load the possible targets into it and activate it.
                                availableTargets = getAvailableTargets(selectedTechnique.techniqueTargeting);
                                battleTargetSelector.BeginTargetSelection(selectedTechnique.techniqueTargeting, availableTargets);
                                controls.ControlsActive = true;
                                debugControls.ControlsActive = true;
                                break;

                            case BattleTargetSelectorState.AwaitingInput:
                            case BattleTargetSelectorState.AllTargetsSelected:
                                //Its listening for the player to make a selection or to confirm their selection...

                                if (controls.ButtonPressed(Buttons.A, false, false) || debugControls.KeyPressed(Keys.Back, false, false))
                                {//Player decided to cancel target selection and head back; Deactivate Target Selector.
                                    GameClass.SoundManager.PlaySoundEffect("Audio/menuCancel");
                                    battleTargetSelector.Reset();
                                    selectedTechniqueNameIsItem = false;

                                    if (selectedTechniqueName == "Attack" || selectedTechniqueName == "Defend")
                                    {//Selected technique was General; show General Menu.
                                        playerTurnMenu.Show();
                                        battleState = BattleState.GeneralTechniqueChoice;
                                    }
                                    else
                                    {//Otherwise selected technique was not General...

                                        if (playerTechniqueMenu.MenuState == MenuState.IdleHalfFaded)
                                        {//Selected technique was a character skill; Show Technique Menu and return to skill selection.
                                            playerTechniqueMenu.Show();
                                            battleState = BattleState.PlayerTechniqueChoice;
                                        }
                                        else if (battleInventoryMenu.MenuState == MenuState.IdleHalfFaded)
                                        {//Selected technique was an item; Show Battle Inventory Menu and return to item selection.
                                            battleInventoryMenu.Show();
                                            battleState = BattleState.PlayerItemChoice;
                                        }
                                    }
                                }

                                if (battleTargetSelector.CurrentState == BattleTargetSelectorState.AllTargetsSelected)
                                {//Player made a target selection...

                                    if (!inputDelay)
                                    {//Player input was not carried over from last menu(i.e. Button was pressed again rather than held.)

                                        if (controls.ButtonPressed(Buttons.B, false, false) || debugControls.KeyPressed(Keys.Space, false, false))
                                        {//Player confirmed target selection; Hide all menus and info bar, advance to technique resolution.
                                            selectedTargets = battleTargetSelector.GetSelections();
                                            battleTargetSelector.Reset();
                                            playerTurnMenu.Hide();
                                            infoBar.Hide();
                                            playerTechniqueMenu.Hide();
                                            battleInventoryMenu.Hide();
                                            battleState = BattleState.TechniqueResolve;

                                            //Take characters MP away equal to the selected techniques cost.
                                            TurnCharacter.ChangeMP(selectedTechnique.techniqueCost, BattleTechniqueActionType.Damage);
                                        }
                                    }
                                    else if (inputDelay)
                                    {//Button is being held down.
                                        if (controls.ButtonReleased(Buttons.B) || debugControls.KeyReleased(Keys.Space))
                                        {//Player released button.
                                            inputDelay = false;
                                        }
                                    }
                                }
                                break;
                        }
                        break;
                    #endregion
                    #region Target and Technique Confirmed; Technique Resolution
                    case BattleState.TechniqueResolve:
                        //Technique and targets are selected; selected technique is being resolved.
                        switch (actionResolveState)
                        {//What state of resolution is the selected technique?
                            #region Determine Target position
                            case ActionResolveState.DetermineTarget:
                                //It is being determined whether and where to move the character.
                                switch (selectedTechnique.techniqueRange)
                                {//What is the selected techniques range?

                                    case BattleTechniqueRange.Direct:
                                        //It is a Direct technique.

                                        switch (selectedTechnique.techniqueTargeting)
                                        {//What form of targeting does the selected technique have?

                                            case BattleTechniqueTargetType.SingleEnemy:
                                                //It targets a single enemy; calculate movement target as position 40 pixels in front of enemy and advance to character movement resolution.
                                                if (TurnCharacter is PlayerBattleCharacter)
                                                {
                                                    techniqueMoveTarget = new Vector2(selectedTargets[0].Position.X - 40, selectedTargets[0].Position.Y + selectedTargets[0].YDrawOffset - TurnCharacter.YDrawOffset);
                                                }
                                                else if (TurnCharacter is EnemyBattleCharacter)
                                                {
                                                    techniqueMoveTarget = new Vector2(selectedTargets[0].Position.X + 40, selectedTargets[0].Position.Y + selectedTargets[0].YDrawOffset - TurnCharacter.YDrawOffset);
                                                }
                                                actionResolveState = ActionResolveState.MoveToTarget;
                                                break;

                                            case BattleTechniqueTargetType.Self:
                                            case BattleTechniqueTargetType.SingleActiveAlly:
                                            case BattleTechniqueTargetType.SingleKOdAlly:
                                                //It targets an ally; skip movement resolution and go straight to performing the technique.
                                                actionResolveState = ActionResolveState.PerformTechnique;
                                                break;

                                            case BattleTechniqueTargetType.Everyone:
                                            case BattleTechniqueTargetType.AllActiveAllies:
                                            case BattleTechniqueTargetType.AllEnemies:
                                                //It targets more than one target; set movement target to he centre of the battlefield and advance to character movement resolution.
                                                techniqueMoveTarget = CentrePosition;
                                                actionResolveState = ActionResolveState.MoveToTarget;
                                                break;
                                        }
                                        break;

                                    case BattleTechniqueRange.Ranged:
                                        //It is a Ranged technique; skip movement resolution and go straight to performing the technique.
                                        actionResolveState = ActionResolveState.PerformTechnique;
                                        break;
                                }
                                break;
                            #endregion
                            #region Resolution of movement to target
                                //Character is moving before performing the selected technique.
                            case ActionResolveState.MoveToTarget:

                                if (dashSoundPlayed == false)
                                {//The dash sound hasn't played; play the dash sound.
                                    GameClass.SoundManager.PlaySoundEffect("Audio/dash");
                                    dashSoundPlayed = true;
                                }

                                if (TurnCharacter.CurrentAction != "Run")
                                {//The character isn't running; make it start running.
                                    TurnCharacter.CurrentAction = "Run";
                                }
                                //set the velocity to the appropriate direction and magnitude, and apply it to the character while they are not at the target position.
                                Vector2 velocity = techniqueMoveTarget - TurnCharacter.Position;
                                velocity.Normalize();

                                if (velocity.X > 0)
                                {
                                    if (TurnCharacter.Position.X < techniqueMoveTarget.X)
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X + (velocity.X * TurnCharacter.RunSpeed), TurnCharacter.Position.Y);
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = new Vector2(techniqueMoveTarget.X, TurnCharacter.Position.Y);
                                    }
                                }
                                else if (velocity.X < 0)
                                {
                                    if (TurnCharacter.Position.X > techniqueMoveTarget.X)
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X + (velocity.X * TurnCharacter.RunSpeed), TurnCharacter.Position.Y);
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = new Vector2(techniqueMoveTarget.X, TurnCharacter.Position.Y);
                                    }
                                }

                                if (velocity.Y > 0)
                                {
                                    if (TurnCharacter.Position.Y < techniqueMoveTarget.Y)
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X, TurnCharacter.Position.Y + (velocity.Y * TurnCharacter.RunSpeed));
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X, techniqueMoveTarget.Y);
                                    }
                                }
                                else if (velocity.Y < 0)
                                {
                                    if (TurnCharacter.Position.Y > techniqueMoveTarget.Y)
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X, TurnCharacter.Position.Y + (velocity.Y * TurnCharacter.RunSpeed));
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = new Vector2(TurnCharacter.Position.X, techniqueMoveTarget.Y);
                                    }
                                }

                                if (Math.Abs(TurnCharacter.Position.X - techniqueMoveTarget.X) < 5.0f && Math.Abs(TurnCharacter.Position.Y - techniqueMoveTarget.Y) < 5.0f)
                                {//character is close enough to the target position; advance to performing the technique.
                                    actionResolveState = ActionResolveState.PerformTechnique;
                                }
                                break;
                            #endregion
                            #region Character at Target Location; Performing of Technique and Resolution of Actions and Effects
                            case ActionResolveState.PerformTechnique:

                                if (selectedTechniqueNameIsItem)
                                {//Selected technique is an item....

                                    if (TurnCharacter.CurrentAction != "Item")
                                    {//character isn't performing its 'Item' animation; make it perform its 'Item' animation.
                                        TurnCharacter.CurrentAction = "Item";
                                    }
                                }
                                else
                                {//Otherwise, seelcted technique isn't an item...
                                    if (TurnCharacter.CurrentAction != selectedTechniqueName)
                                    {//character isn't performing the animation for the selected technique; make it perform the technique animation.
                                        TurnCharacter.CurrentAction = selectedTechniqueName;
                                    }
                                }

                                if (selectedTechniqueName != "Defend")
                                {//selected technique is 'Defend'...

                                    foreach (BattleTechniqueBuffData buffData in selectedTechnique.buffs)
                                    {//For every stat buff in the selected tedhnique's data...
                                        if (TurnCharacter.CurrentSprite.CurrentFrame == buffData.buffTime || TurnCharacter.CurrentSprite.CurrentFrame > buffData.buffTime)
                                        {//if it's time to resolve the stat buff...

                                            if(resolvedBuffs.IndexOf(buffData) == -1)
                                            {//if it hasn't already been resolved...

                                                foreach (BattleCharacter target in selectedTargets)
                                                {//for every chosen target...

                                                    //Assume the target isn't already buffed in the same way.
                                                    bool matchingBuffExists = false;
                                                    foreach (BattleTechniqueBuff buff in activeBuffs)
                                                    {//for every stat buff thats active...

                                                        if (buff.Target == target && buff.BuffType == buffData.buffType)
                                                        {//if the active buff has the same target and type as the one we're resolving...

                                                            //The target is already buffed in the same way.
                                                            matchingBuffExists = true;

                                                            //Remove the active buff from the target and apply the new one.
                                                            buff.RemoveStatChange();
                                                            buff.LoadContent(target, buffData);
                                                            buff.ApplyStatChange();

                                                            //mark the new buff as resolved.
                                                            resolvedBuffs.Add(buffData);
                                                        }
                                                    }

                                                    if (matchingBuffExists == false)
                                                    {//if the target isn't already buffed in the same way, apply the new buff and amark it as resolved.
                                                        BattleTechniqueBuff newBuff = new BattleTechniqueBuff();
                                                        newBuff.LoadContent(target, buffData);
                                                        newBuff.ApplyStatChange();
                                                        activeBuffs.Add(newBuff);
                                                        resolvedBuffs.Add(buffData);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    foreach (BattleTechniqueAction action in selectedTechnique.actions)
                                    {//for every damage action in the selected technique's data...
                                        if (TurnCharacter.CurrentSprite.CurrentFrame == action.ActionTime || TurnCharacter.CurrentSprite.CurrentFrame > action.ActionTime)
                                        {//if its time to resolve the action...
                                            if (resolvedActions.IndexOf(action) == -1)
                                            {//if it hasn't already been resolved, resolve it and mark it as resolved.
                                                ResolveDamageAction(action);
                                                resolvedActions.Add(action);
                                            }
                                        }
                                    }

                                    foreach (BattleTechniqueSoundData sound in selectedTechnique.sounds)
                                    {//for every sound effect in the selected technique's data...
                                        if (TurnCharacter.CurrentSprite.CurrentFrame == sound.soundTime || TurnCharacter.CurrentSprite.CurrentFrame > sound.soundTime)
                                        {//if its time to resolve the sound...
                                            if (resolvedSounds.IndexOf(sound) == -1)
                                            {//if it hasn't already been resolved, play it and mark it as resolved.
                                                GameClass.SoundManager.PlaySoundEffect(sound.soundFileName);
                                                resolvedSounds.Add(sound);
                                            }
                                        }
                                    }

                                    foreach (BattleTechniqueEffect activeEffect in activeEffects)
                                    {//For every effect animation object that is active...

                                        //Resolution code for Damage Actions, Stat Buffs and Sound Effect for this effect(Identical in structure to previous technique resolution code)
                                        foreach (BattleTechniqueAction effectAction in activeEffect.EffectActions)
                                        {

                                            if (activeEffect.CurrentTimer == effectAction.ActionTime || activeEffect.CurrentTimer > effectAction.ActionTime)
                                            {
                                                if (resolvedActions.IndexOf(effectAction) == -1)
                                                {
                                                    ResolveDamageAction(effectAction);
                                                    resolvedActions.Add(effectAction);
                                                }
                                            }
                                        }

                                        foreach (BattleTechniqueBuffData effectbuffData in activeEffect.EffectBuffs)
                                        {
                                            if (activeEffect.CurrentTimer == effectbuffData.buffTime || activeEffect.CurrentTimer > effectbuffData.buffTime)
                                            {
                                                if (resolvedBuffs.IndexOf(effectbuffData) == -1)
                                                {
                                                    foreach (BattleCharacter target in selectedTargets)
                                                    {
                                                        bool matchingBuffExists = false;
                                                        foreach (BattleTechniqueBuff buff in activeBuffs)
                                                        {
                                                            if (buff.Target == target && buff.BuffType == effectbuffData.buffType)
                                                            {
                                                                matchingBuffExists = true;
                                                                buff.RemoveStatChange();
                                                                buff.LoadContent(target, effectbuffData);
                                                                buff.ApplyStatChange();
                                                                resolvedBuffs.Add(effectbuffData);
                                                            }
                                                        }

                                                        if (matchingBuffExists == false)
                                                        {
                                                            BattleTechniqueBuff newBuff = new BattleTechniqueBuff();
                                                            newBuff.LoadContent(target, effectbuffData);
                                                            newBuff.ApplyStatChange();
                                                            activeBuffs.Add(newBuff);
                                                            resolvedBuffs.Add(effectbuffData);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        foreach (BattleTechniqueSoundData sound in activeEffect.EffectSounds)
                                        {
                                            if (activeEffect.CurrentTimer == sound.soundTime || activeEffect.CurrentTimer > sound.soundTime)
                                            {
                                                if (resolvedSounds.IndexOf(sound) == -1)
                                                {
                                                    GameClass.SoundManager.PlaySoundEffect(sound.soundFileName);
                                                    resolvedSounds.Add(sound);
                                                }
                                            }
                                        }

                                        //end of identical resolution code.
                                    }

                                    if (TurnCharacter.CurrentSprite.CurrentFrame > TurnCharacter.CurrentSprite.TotalFrames - 2)
                                    {//if the character has finished the technique animation...

                                        if (TurnCharacter.Position != characterOriginalPosition)
                                        {//if the character had to move to perform the technique, change the state to return movement resolution.
                                            actionResolveState = ActionResolveState.ReturnToOriginalPosition;
                                        }
                                        else
                                        {//otherwise, the character didn't have to move...
                                            if (activeEffects.Count == 0)
                                            {//All active effects have been resolved, return character to idle animation, change the state to damage effect resolution.
                                                TurnCharacter.CurrentAction = "Idle";
                                                battleState = BattleState.DamageResolve;
                                            }
                                        }
                                    }

                                    foreach (BattleTechniqueEffect effect in selectedTechnique.effects)
                                    {//for every effect animation object in selected technique data...

                                        if (resolvedEffects.IndexOf(effect) == -1)
                                        {//if the effect hasn't been resolved.

                                            if (TurnCharacter.CurrentSprite.CurrentFrame == effect.StartTime || TurnCharacter.CurrentSprite.CurrentFrame > effect.StartTime)
                                            {//if it's time to resolve the effect...

                                                //initialise and activate the effect.
                                                effect.Initialise(TurnCharacter.Position);
                                                effect.EffectState = BattleEffectState.Active;
                                                if (effect.EffectType == EffectType.ProjectileTargeted)
                                                {//if the effect is a targeted projectile...

                                                        //Set the direction and magnitude of the velocity of the projectile effect.
                                                        Vector2 targetVelocity = new Vector2(selectedTargets[0].Position.X - TurnCharacter.Position.X, selectedTargets[0].Position.Y - TurnCharacter.Position.Y);
                                                        targetVelocity.Normalize();
                                                        effect.Velocity = targetVelocity;
                                                        effect.Velocity *= effect.Speed;

                                                        if (selectedTargets.Count > 1)
                                                        {//if the projectile effect is supposed to hit multiple targets...
                                                            for (int count = 1; count < selectedTargets.Count; count++)
                                                            {//for every extra target, create a copy of the projectile effect  and set it in the same way as if they were the lone target.
                                                                BattleTechniqueEffect effectCopy = new BattleTechniqueEffect();
                                                                effectCopy.LoadContent(effect);
                                                                Vector2 copyVelocity = new Vector2(selectedTargets[count].Position.X - TurnCharacter.Position.X, selectedTargets[count].Position.Y - TurnCharacter.Position.Y);
                                                                copyVelocity.Normalize();
                                                                effectCopy.Velocity = copyVelocity;
                                                                effectCopy.Velocity *= effectCopy.Speed;
                                                                activeEffects.Add(effectCopy);
                                                            }
                                                        }
                                                }
                                                else if (effect.EffectType == EffectType.ProjectileIndirect)
                                                {//effect is an indirect projectile, set it to fire forward into the enemy.
                                                    if (TurnCharacter is PlayerBattleCharacter)
                                                    {
                                                        effect.Velocity = new Vector2(effect.Speed, 0);
                                                    }
                                                    else if (TurnCharacter is EnemyBattleCharacter)
                                                    {
                                                        effect.Velocity = new Vector2(-effect.Speed, 0);
                                                    }
                                                }
                                                else if (effect.EffectType == EffectType.SpellTargeted)
                                                {//effect is a targeted spell effect...

                                                        //set the effect to appear on the target.
                                                        effect.Position = new Vector2(selectedTargets[0].Position.X + effect.RelativePosition.X, selectedTargets[0].Position.Y + effect.RelativePosition.Y);

                                                        if (selectedTargets.Count > 1)
                                                        {//if the spell is supposed to affect multiple targets...
                                                            for (int count = 1; count < selectedTargets.Count; count++)
                                                            {//for every extra target, create a copy of the spell effect ands set as if they were the lone target.
                                                                BattleTechniqueEffect effectCopy = new BattleTechniqueEffect();
                                                                effectCopy.LoadContent(effect);
                                                                effect.Position = new Vector2(selectedTargets[count].Position.X + effect.RelativePosition.X, selectedTargets[count].Position.Y + effect.RelativePosition.Y);
                                                                activeEffects.Add(effectCopy);
                                                            }
                                                        }
                                                }

                                                //activate the effect and mark it as resolved.
                                                activeEffects.Add(effect);
                                                resolvedEffects.Add(effect);
                                            }
                                        }
                                    }
                                }
                                else
                                {//Otherwise, character is defending, ensure they stop animating at the last frame of the animtion and advance straight to resolving the turn.
                                    TurnCharacter.CurrentSprite.AnimationType = SpriteAnimationType.AnimateOnceMaintainLast;
                                    battleState = BattleState.TurnResolve;
                                }
                                break;
                            #endregion
                            #region Technique completed; Resolution of movement back to characters original position
                                //selected Direct technique is completely resolved; character must return to their original position.
                            case ActionResolveState.ReturnToOriginalPosition:
                                if (TurnCharacter is PlayerBattleCharacter)
                                {
                                    if (TurnCharacter.CurrentAction != "Run")
                                    {
                                        TurnCharacter.CurrentAction = "Run";
                                        TurnCharacter.Facing = CharacterFacing.Left;
                                    }

                                    if (TurnCharacter.Position.X > characterOriginalPosition.X || TurnCharacter.Position.Y > characterOriginalPosition.Y)
                                    {
                                        Vector2 velocity2 = characterOriginalPosition - TurnCharacter.Position;
                                        velocity2.Normalize();
                                        TurnCharacter.Position += velocity2 * TurnCharacter.RunSpeed;
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = characterOriginalPosition;
                                        TurnCharacter.CurrentAction = "Idle";
                                        TurnCharacter.Facing = CharacterFacing.Right;
                                        battleState = BattleState.DamageResolve;
                                    }
                                }
                                else if (TurnCharacter is EnemyBattleCharacter)
                                {
                                    if (TurnCharacter.CurrentAction != "Run")
                                    {
                                        TurnCharacter.CurrentAction = "Run";
                                        TurnCharacter.Facing = CharacterFacing.Right;
                                    }

                                    if (TurnCharacter.Position.X < characterOriginalPosition.X || TurnCharacter.Position.Y < characterOriginalPosition.Y)
                                    {
                                        Vector2 velocity2 = characterOriginalPosition - TurnCharacter.Position;
                                        velocity2.Normalize();
                                        TurnCharacter.Position += velocity2 * TurnCharacter.RunSpeed;
                                    }
                                    else
                                    {
                                        TurnCharacter.Position = characterOriginalPosition;
                                        TurnCharacter.CurrentAction = "Idle";
                                        TurnCharacter.Facing = CharacterFacing.Left;
                                        battleState = BattleState.DamageResolve;
                                    }
                                }
                                break;
                        }
                        break;
                            #endregion
                    #endregion
                    #region Technique resolution completed; Resolution of KOd characters etc
                        //technique is resolved completely; characters are in correct positions; resolve damage effects...
                    case BattleState.DamageResolve:

                        int deathsToResolve = 0;
                        foreach (BattleCharacter character in activeCharacters)
                        {//for every active character...
                            if (character.CurrentAction == "Death")
                            {//if they died, add one to the death resolve count.
                                deathsToResolve++;
                            }
                        }

                        for (int count = 0; count < activeCharacters.Count; count++)
                        {//for every active character...

                            if (activeCharacters[count].CurrentAction == "Death" && activeCharacters[count].CurrentSprite.CurrentFrame > activeCharacters[count].CurrentSprite.TotalFrames - 2)
                            {//if they died and their animation is complete...

                                //add them to the inactive characters list and shift the turn chart if hadn't had their turn yet.
                                inactiveCharacters.Add(activeCharacters[count]);
                                if (activeCharacters.IndexOf(activeCharacters[count]) < currentTurnIndex)
                                {
                                    currentTurnIndex--;
                                }

                                //remove all the buffs they had on them.
                                for (int count2 = 0; count2 < activeBuffs.Count; count2++)
                                {
                                    if (activeBuffs[count2].Target == activeCharacters[count])
                                    {
                                        activeBuffs[count2].RemoveStatChange();
                                        activeBuffs.Remove(activeBuffs[count2]);
                                    }
                                }

                                //remove them from the active characters list.
                                activeCharacters.Remove(activeCharacters[count]);
                                deathResolveCount++;
                            }
                        }

                        if (deathResolveCount == deathsToResolve && TurnCharacter.CurrentAction == "Idle" && activeEffects.Count == 0)
                        {//if everything is resolved this far...

                            for (int count = 0; count < battleItemInventory.Count; count++)
                            {//for every item the player has...
                                if (battleItemInventory[count].ItemID.ToString() == selectedTechniqueName)
                                {//if the technique that was used was that item, remove one from its QTY.
                                    battleItemInventory[count].QTY--;
                                    break;
                                }
                            }
                            //advance to resolving the turn.
                            battleState = BattleState.TurnResolve;
                        }

                        break;
                    #endregion
                    #region Resolution of next turn
                    case BattleState.TurnResolve:
                    //everything else is resolved; the next turn must be resolved.

                        //determine if a victory or loss was achieved as a result of this turn.
                        bool triggerVictory = true;
                        bool triggerLoss = true;
                        foreach (BattleCharacter character in activeCharacters)
                        {
                            if (character is PlayerBattleCharacter)
                            {
                                triggerLoss = false;
                            }
                            if (character is EnemyBattleCharacter)
                            {
                                triggerVictory = false;
                            }
                        }

                        if (triggerVictory == true && triggerLoss == true)
                        {//int the case of a draw; the player loses by default.
                            triggerVictory = false;
                        }

                        if (triggerVictory == true)
                        {//if victory was achieved...

                            //play the victory jingle.
                            GameClass.SoundManager.StopBackgroundMusic();
                            GameClass.SoundManager.SetBackgroundMusic("Audio/victory", false);
                            GameClass.SoundManager.PlayBackgroundMusic();

                            //determine and add EXP to character statuses.
                            int EXPEarned = 0;
                            foreach(BattleCharacter character in inactiveCharacters)
                            {
                                if(character is EnemyBattleCharacter)
                                {
                                    EnemyBattleCharacter enemy = (EnemyBattleCharacter)character;
                                    EXPEarned += enemy.EXPWorth;
                                }
                            }
                            //show character statuses.
                            foreach (PlayerCharacterStatusBox statusBox in playerStatusBoxes)
                            {
                                statusBox.Show();
                                statusBox.AddEXP(EXPEarned);
                            }
                            //advance to victory state.
                            battleState = BattleState.Victory;

                        }
                        else if (triggerLoss == true)
                        {//if loss was achieved...
                            //play loss jingle.
                            GameClass.SoundManager.StopBackgroundMusic();
                            GameClass.SoundManager.SetBackgroundMusic("Audio/loss", false);
                            GameClass.SoundManager.PlayBackgroundMusic();

                            //advance to loss state.
                            battleState = BattleState.Loss;
                        }
                        else
                        {//if neither victory or loss was achieved...

                            if (currentTurnIndex < activeCharacters.Count - 1)
                            {//if there are still character turns in this battle turn to go, move onto the next character.
                                currentTurnIndex++;
                            }
                            else
                            {//Otherwise, this battle turn is over...

                                //resolve if buffs should run out and be removed, recalculate the turn order, and start a new battle turn.
                                currentTurnIndex = 0;
                                currentTurnCount += 1;
                                for (int count = 0; count < activeBuffs.Count; count++)
                                {
                                    activeBuffs[count].Duration--;
                                    if (activeBuffs[count].Duration == 0)
                                    {
                                        activeBuffs[count].RemoveStatChange();
                                        activeBuffs.Remove(activeBuffs[count]);
                                    }
                                }
                                CalculateTurnOrder();
                            }

                            //reset the turn, and begin another one.
                            ResetTurnParameters();
                            battleState = BattleState.GeneralTechniqueChoice;

                        }
                        break;
                    #endregion
                    #region Victory
                    case BattleState.Victory:
                        //player has won.

                        //set all character to perform their victory animations.
                        foreach (BattleCharacter character in activeCharacters)
                        {
                            if (character is PlayerBattleCharacter)
                            {
                                if (character.CurrentAction != "Victory")
                                {
                                    character.CurrentAction = "Victory";
                                }
                            }
                        }

                        //determine if EXP has all been added.
                        int statusBoxesFinishedAddingEXP = 0;
                        foreach (PlayerCharacterStatusBox statusBox in playerStatusBoxes)
                        {
                            if (statusBox.State == PlayerCharacterStatusBoxState.AwaitingInput)
                            {
                                statusBoxesFinishedAddingEXP += 1;
                            }
                        }

                        //if EXP has all been added and player hits confirm button, refresh inventory, and return to the map screen.
                        if (statusBoxesFinishedAddingEXP == playerStatusBoxes.Count)
                        {
                            if (controls.ButtonPressed(Buttons.B, false, false) || debugControls.KeyPressed(Keys.Space, false, false))
                            {
                                    foreach(BattleItem item in battleItemInventory)
                                    {
                                        if (item.QTY > 0)
                                        {
                                            GlobalGameInfo.Inventory[item.ItemID] = item.QTY;
                                        }
                                        else
                                        {
                                            GlobalGameInfo.Inventory.Remove(item.ItemID);
                                        }
                                    }

                                GameClass.ScreenManager.ScreenTransition(ScreenIdentity.Map);
                            }
                        }
                        break;
                    #endregion
                    #region Loss
                    case BattleState.Loss:
                        switch (gameOverMenu.MenuState)
                        {
                            case MenuState.IdleFaded:
                                gameOverMenu.Show();
                                infoBar.Show();
                                infoBar.InfoText = gameOverMenu.GetSelectionDescription();
                                break;

                            case MenuState.IdleAwaitingInput:
                                infoBar.InfoText = gameOverMenu.GetSelectionDescription();
                                break;

                            case MenuState.IdleValueSelected:
                                string selectedGameOverAction = gameOverMenu.GetSelection();
                                if (selectedGameOverAction == "Retry")
                                {
                                    gameOverMenu.Hide();
                                    GameClass.SoundManager.StopBackgroundMusic();
                                    GameClass.SoundManager.SetBackgroundMusic("Audio/battle", true);
                                    GameClass.SoundManager.PlayBackgroundMusic();
                                    retryingBattle = true;
                                    activeCharacters.Clear();
                                    GameClass.ScreenManager.ScreenTransition(ScreenIdentity.Battle);
                                }
                                else if (selectedGameOverAction == "Quit")
                                {
                                    GameClass.StartExit();
                                }
                                break;
                        }
                        break;
                    #endregion
                }

                #region Alternate flashing turn chart selection
                //set the alpha of the turn chart selection indicator to alternate between 0 and 1 linearly.
                switch (turnChartSelectorFadeState)
                {
                    case AlternatingFadeState.FadingIn:
                        if (turnChartSelectionAlpha > 0.0f)
                        {
                            turnChartSelectionAlpha -= 0.1f;
                        }
                        else
                        {
                            turnChartSelectionAlpha = 0.0f;
                            turnChartSelectorFadeState = AlternatingFadeState.FadingOut;
                        }
                        break;

                    case AlternatingFadeState.FadingOut:
                        if (turnChartSelectionAlpha < 1.0f)
                        {
                            turnChartSelectionAlpha += 0.1f;
                        }
                        else
                        {
                            turnChartSelectionAlpha = 1.0f;
                            turnChartSelectorFadeState = AlternatingFadeState.FadingIn;
                        }
                        break;
                #endregion
                }

                #region Resolve Technique Effect Animations
                for (int count = 0; count < activeEffects.Count; count++)
                {
                    if (activeEffects[count].EffectState == BattleEffectState.Inactive)
                    {
                        activeEffects.Remove(activeEffects[count]);
                    }
                    else
                    {
                        activeEffects[count].Update(gameTime);
                    }
                }
                #endregion
                foreach (BattleTechniqueBuff buff in activeBuffs)
                {
                    buff.Update(gameTime);
                }

                if (restartScreenControls.KeyPressed(Keys.A, false, false))
                {
                    GameClass.SoundManager.StopBackgroundMusic();
                    GameClass.SoundManager.SetBackgroundMusic("Audio/battle", true);
                    GameClass.SoundManager.PlayBackgroundMusic();
                    GameClass.ScreenManager.ScreenTransition(ScreenIdentity.Battle);
                }
                if (restartScreenControls.KeyPressed(Keys.V, false, false))
                {
                    GameClass.SoundManager.StopBackgroundMusic();
                    GameClass.SoundManager.SetBackgroundMusic("Audio/victory", false);
                    GameClass.SoundManager.PlayBackgroundMusic();

                    foreach (PlayerCharacterStatusBox statusBox in playerStatusBoxes)
                    {
                        statusBox.Show();
                    }
                    battleState = BattleState.Victory;
                }
            }
            base.Update(gameTime);
        }