Search Unity

Change from 2D sprite to 3D model

Discussion in '2D' started by Karisahaya, Dec 27, 2017.

  1. Karisahaya

    Karisahaya

    Joined:
    May 22, 2013
    Posts:
    3
    So, there is a pokemon essentials for unity, which uses sprites for the battle system, the question is, i dont know anything about programming, im beginning to learn, and i was wondering, is there any way to change the 2D sprites to 3D models? if so, i dont need you to change the code, just tell me how i can change from 2D sprite to a Prefab Game object (which would be the 3d model) because when i see the code, seems like its all handled by sprites, here is the code (Also, i believe the whole battle system is a GUI system, so thats why im unsure if its posible or i will have to make it again from skratch):

    Code (CSharp):
    1. //Original Scripts by IIColour (IIColour_Spectrum)
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6.  
    7. public class BattleHandler : MonoBehaviour
    8. {
    9.     public int victor = -1; //0 = player, 1 = opponent, 2 = tie
    10.     private bool trainerBattle;
    11.  
    12.     private DialogBoxHandlerNew Dialog;
    13.  
    14.     private AudioSource BattleAudio;
    15.     public AudioClip defaultTrainerBGM;
    16.     public int defaultTrainerBGMLoopStart = 577000;
    17.  
    18.     public AudioClip defaultTrainerVictoryBGM;
    19.     public int defaultTrainerVictoryBGMLoopStart = 79000;
    20.  
    21.     public AudioClip defaultWildBGM;
    22.     public int defaultWildBGMLoopStart = 578748;
    23.  
    24.     public AudioClip defaultWildVictoryBGM;
    25.     public int defaultWildVictoryBGMLoopStart = 65000;
    26.  
    27.     public AudioClip
    28.         scrollClip,
    29.         selectClip,
    30.         runClip,
    31.         statUpClip,
    32.         statDownClip,
    33.         healFieldClip,
    34.         fillExpClip,
    35.         expFullClip,
    36.         pokeballOpenClip,
    37.         pokeballBounceClip,
    38.         faintClip,
    39.         hitClip,
    40.         hitSuperClip,
    41.         hitPoorClip;
    42.  
    43.     public Sprite
    44.         partySpaceTex,
    45.         partyBallTex,
    46.         partyStatusTex,
    47.         partyFaintTex,
    48.         buttonFightTex,
    49.         buttonFightSelTex,
    50.         buttonBagTex,
    51.         buttonBagSelTex,
    52.         buttonRunTex,
    53.         buttonRunSelTex,
    54.         buttonPokeTex,
    55.         buttonPokeSelTex,
    56.         buttonMoveBackgroundTex,
    57.         buttonMoveBackgroundSelTex,
    58.         buttonMegaTex,
    59.         buttonMegaActiveTex,
    60.         buttonMegaActiveSelTex,
    61.         buttonReturnTex,
    62.         buttonReturnSelTex,
    63.         buttonBlueTex,
    64.         buttonBlueSelTex,
    65.         buttonBackBagTex,
    66.         buttonBackBagSelTex,
    67.         buttonBagItemCategoryTex,
    68.         buttonBagItemCategorySelTex,
    69.         buttonBagItemListTex,
    70.         buttonBagItemListSelTex,
    71.         buttonBackPokeTex,
    72.         buttonBackPokeSelTex,
    73.         buttonPokemonTex,
    74.         buttonPokemonRoundTex,
    75.         buttonPokemonFntTex,
    76.         buttonPokemonRoundFntTex,
    77.         buttonPokemonSelTex,
    78.         buttonPokemonRoundSelTex,
    79.         buttonPokemonFntSelTex,
    80.         buttonPokemonRoundFntSelTex;
    81.  
    82.     public Texture
    83.         overlayHealTex,
    84.         overlayStatUpTex,
    85.         overlayStatDownTex;
    86.  
    87.  
    88.     //TASK BUTTONS
    89.     private Image
    90.         buttonFight,
    91.         buttonBag,
    92.         buttonRun,
    93.         buttonPoke;
    94.  
    95.     private Image[]
    96.         buttonMoveCover = new Image[4],
    97.         buttonMove = new Image[4];
    98.  
    99.     private Image
    100.         buttonMegaEvolution,
    101.         buttonMoveReturn;
    102.  
    103.     private Image
    104.         buttonBackBag,
    105.         buttonBackPoke;
    106.  
    107.     private Image buttonItemLastUsed;
    108.  
    109.     private Image[]
    110.         buttonItemCategory = new Image[4],
    111.         buttonItemList = new Image[8];
    112.  
    113.     private Image[] buttonPokemonSlot = new Image[6];
    114.  
    115.     private Image
    116.         buttonSwitch,
    117.         buttonCheck;
    118.  
    119.     private Text
    120.         buttonCheckText,
    121.         buttonCheckTextShadow;
    122.  
    123.  
    124.     //MOVE BUTTON DETAILS
    125.     private Image[] buttonMoveType = new Image[4];
    126.  
    127.     private Text[]
    128.         buttonMoveName = new Text[4],
    129.         buttonMoveNameShadow = new Text[4],
    130.         buttonMovePP = new Text[4],
    131.         buttonMovePPShadow = new Text[4];
    132.  
    133.     private GameObject bagObject;
    134.     //ITEM LIST DETAILS
    135.     private GameObject itemList;
    136.  
    137.     private Text
    138.         itemListCategoryText,
    139.         itemListCategoryTextShadow,
    140.         itemListPageNumber,
    141.         itemListPageNumberShadow;
    142.  
    143.     private GameObject
    144.         itemListArrowPrev,
    145.         itemListArrowNext;
    146.  
    147.     private GameObject[] itemListButton = new GameObject[8];
    148.     private Image[] itemListIcon = new Image[8];
    149.  
    150.     private Text[]
    151.         itemListName = new Text[8],
    152.         itemListNameShadow = new Text[8],
    153.         itemListQuantity = new Text[8],
    154.         itemListQuantityShadow = new Text[8];
    155.  
    156.     private Text
    157.         itemListDescription,
    158.         itemListDescriptionShadow;
    159.  
    160.     //POKEMON LIST DETAILS
    161.     private GameObject pokemonPartyObject;
    162.     private Image[] pokemonSlotIcon = new Image[6];
    163.  
    164.     private Text[]
    165.         pokemonSlotName = new Text[6],
    166.         pokemonSlotNameShadow = new Text[6],
    167.         pokemonSlotGender = new Text[6],
    168.         pokemonSlotGenderShadow = new Text[6],
    169.         pokemonSlotLevel = new Text[6],
    170.         pokemonSlotLevelShadow = new Text[6],
    171.         pokemonSlotCurrentHP = new Text[6],
    172.         pokemonSlotCurrentHPShadow = new Text[6],
    173.         pokemonSlotMaxHP = new Text[6],
    174.         pokemonSlotMaxHPShadow = new Text[6];
    175.  
    176.     private Image[]
    177.         pokemonSlotHPBar = new Image[6],
    178.         pokemonSlotStatus = new Image[6],
    179.         pokemonSlotItem = new Image[6];
    180.  
    181.     private Sprite[][] pokemonIconAnim = new Sprite[][]
    182.     {
    183.         new Sprite[2],
    184.         new Sprite[2],
    185.         new Sprite[2],
    186.         new Sprite[2],
    187.         new Sprite[2],
    188.         new Sprite[2]
    189.     };
    190.  
    191.     //POKE SELECTED DETAILS
    192.     private GameObject pokemonSelectedPokemon;
    193.  
    194.     private Image
    195.         pokemonSelectedIcon,
    196.         pokemonSelectedStatus,
    197.         pokemonSelectedType1,
    198.         pokemonSelectedType2;
    199.  
    200.     private Text
    201.         pokemonSelectedName,
    202.         pokemonSelectedNameShadow,
    203.         pokemonSelectedGender,
    204.         pokemonSelectedGenderShadow,
    205.         pokemonSelectedLevel,
    206.         pokemonSelectedLevelShadow;
    207.  
    208.     private GameObject pokeObject;
    209.     //POKE SUMMARY DETAILS
    210.     private GameObject pokemonSummary;
    211.  
    212.     private Text
    213.         pokemonSummaryHP,
    214.         pokemonSummaryHPShadow,
    215.         pokemonSummaryStatsTextShadow,
    216.         pokemonSummaryStats,
    217.         pokemonSummaryStatsShadow,
    218.         pokemonSummaryNextLevelEXP,
    219.         pokemonSummaryNextLevelEXPShadow,
    220.         pokemonSummaryItemName,
    221.         pokemonSummaryItemNameShadow,
    222.         pokemonSummaryAbilityName,
    223.         pokemonSummaryAbilityNameShadow,
    224.         pokemonSummaryAbilityDescription,
    225.         pokemonSummaryAbilityDescriptionShadow;
    226.  
    227.     private Image
    228.         pokemonSummaryHPBar,
    229.         pokemonSummaryEXPBar,
    230.         pokemonSummaryItemIcon;
    231.  
    232.     //POKE MOVES DETAILS
    233.     private GameObject pokemonMoves;
    234.  
    235.     private Text[]
    236.         pokemonMovesName = new Text[4],
    237.         pokemonMovesNameShadow = new Text[4],
    238.         pokemonMovesPPText = new Text[4],
    239.         pokemonMovesPPTextShadow = new Text[4],
    240.         pokemonMovesPP = new Text[4],
    241.         pokemonMovesPPShadow = new Text[4];
    242.  
    243.     private Image[] pokemonMovesType = new Image[4];
    244.  
    245.     private Text
    246.         pokemonMovesSelectedPower,
    247.         pokemonMovesSelectedPowerShadow,
    248.         pokemonMovesSelectedAccuracy,
    249.         pokemonMovesSelectedAccuracyShadow,
    250.         pokemonMovesSelectedDescription,
    251.         pokemonMovesSelectedDescriptionShadow;
    252.  
    253.     private Image
    254.         pokemonMovesSelectedCategory,
    255.         pokemonMovesSelector,
    256.         pokemonMovesSelectedMove;
    257.  
    258.  
    259.     //PARTY DISPLAYS
    260.     private Image
    261.         playerPartyBar,
    262.         opponentPartyBar;
    263.  
    264.     private Image[]
    265.         playerPartyBarSpace = new Image[6],
    266.         opponentPartyBarSpace = new Image[6];
    267.  
    268.     //POKEMON STAT DISPLAYS
    269.     private Text
    270.         pokemon0CurrentHP,
    271.         pokemon0CurrentHPShadow,
    272.         pokemon0MaxHP,
    273.         pokemon0MaxHPShadow;
    274.  
    275.     private Image pokemon0ExpBar;
    276.  
    277.     private Image[]
    278.         pokemonStatsDisplay = new Image[6],
    279.         statsHPBar = new Image[6],
    280.         statsStatus = new Image[6];
    281.  
    282.     private Text[]
    283.         statsName = new Text[6],
    284.         statsNameShadow = new Text[6],
    285.         statsGender = new Text[6],
    286.         statsGenderShadow = new Text[6],
    287.         statsLevel = new Text[6],
    288.         statsLevelShadow = new Text[6];
    289.  
    290.     //BACKGROUNDS
    291.     private Image
    292.         playerBase,
    293.         opponentBase,
    294.         background;
    295.  
    296.     //DEBUG
    297.     public bool canMegaEvolve = false;
    298.  
    299.     private Sprite[] playerTrainer1Animation;
    300.     private Image playerTrainerSprite1;
    301.     private Sprite[] trainer1Animation;
    302.     private Image trainerSprite1;
    303.  
    304.     private Sprite[] player1Animation;
    305.     private Image player1;
    306.     private RawImage player1Overlay;
    307.     private Sprite[] opponent1Animation;
    308.     private Image opponent1;
    309.     private RawImage opponent1Overlay;
    310.  
    311.     private Coroutine animatePlayer1;
    312.     private Coroutine animateOpponent1;
    313.  
    314.     private Coroutine animatingPartyIcons;
    315.  
    316.  
    317.     //POSITIONS
    318.     private int
    319.         currentTask = 0,
    320.         // 0 = task choice, 1 = move choice, 2 = bag choice, 3 = pokemon choice
    321.         //                                4 = item list,              5 = summary, 6 = moves
    322.         taskPosition = 1,
    323.         // 0/3 = bag, 1 = fight, 2/5 = pokemon, 4 = run
    324.         movePosition = 1,
    325.         // 0 = Mega Evolution, 1/2/4/5 = move, 3 = back
    326.         bagCategoryPosition = 0,
    327.         // 0 = HPPP, 1 = Pokeballs, 2 = Status, 3 = Battle, 4 = Back
    328.         pokePartyPosition = 0,
    329.         // 0-5 = pokemon, 6 = Back
    330.         itemListPagePosition = 0,
    331.         //which item list page is currently open (displays +1 of variable)
    332.         itemListPageCount = 0;
    333.  
    334.     private string[] itemListString;
    335.  
    336.  
    337.     private int pokemonPerSide = 1;
    338.  
    339.     //pokemon
    340.     private Pokemon[] pokemon = new Pokemon[6];
    341.     //[pokemonPosition][movePosition]
    342.     private string[][] pokemonMoveset = new string[][]
    343.     {
    344.         new string[4],
    345.         new string[4],
    346.         new string[4],
    347.         new string[4],
    348.         new string[4],
    349.         new string[4]
    350.     };
    351.  
    352.     //Stats can be changed in battle. These changes never persist after swapping out.
    353.     private int[][] pokemonStats = new int[][]
    354.     {
    355.         new int[6], //ATK
    356.         new int[6], //DEF
    357.         new int[6], //SPA
    358.         new int[6], //SPD
    359.         new int[6], //SPE
    360.     };
    361.  
    362.     //Ability can be changed in battle. These changes never persist after swapping out.
    363.     private string[] pokemonAbility = new string[6];
    364.     //Types can be changed in battle. These changes never persist after swapping out.
    365.     private PokemonData.Type[] pokemonType1 = new PokemonData.Type[]
    366.     {
    367.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE,
    368.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE
    369.     };
    370.  
    371.     private PokemonData.Type[] pokemonType2 = new PokemonData.Type[]
    372.     {
    373.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE,
    374.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE
    375.     };
    376.  
    377.     private PokemonData.Type[] pokemonType3 = new PokemonData.Type[]
    378.     {
    379.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE,
    380.         PokemonData.Type.NONE, PokemonData.Type.NONE, PokemonData.Type.NONE
    381.     };
    382.  
    383.     //pokemon stat boost data
    384.     private int[][] pokemonStatsMod = new int[][]
    385.     {
    386.         new int[6], //ATK
    387.         new int[6], //DEF
    388.         new int[6], //SPA
    389.         new int[6], //SPD
    390.         new int[6], //SPE
    391.         new int[6], //ACC
    392.         new int[6], //EVA
    393.     };
    394.  
    395.     //turn task data
    396.     public enum CommandType
    397.     {
    398.         None,
    399.         Move,
    400.         Item,
    401.         Switch,
    402.         Flee
    403.     }
    404.  
    405.     private CommandType[] command = new CommandType[6];
    406.     private int[] commandTarget = new int[6];
    407.     private MoveData[] commandMove = new MoveData[6];
    408.     private ItemData[] commandItem = new ItemData[6];
    409.     private Pokemon[] commandPokemon = new Pokemon[6];
    410.  
    411.  
    412.     //Field effects
    413.     private enum WeatherEffect
    414.     {
    415.         NONE,
    416.         RAIN,
    417.         SUN,
    418.         SAND,
    419.         HAIL,
    420.         HEAVYRAIN,
    421.         HEAVYSUN,
    422.         STRONGWINDS
    423.     }
    424.  
    425.     private enum TerrainEffect
    426.     {
    427.         NONE,
    428.         ELECTRIC,
    429.         GRASSY,
    430.         MISTY
    431.     }
    432.  
    433.     private WeatherEffect weather = WeatherEffect.NONE;
    434.     private int weatherTurns = 0;
    435.     private TerrainEffect terrain = TerrainEffect.NONE;
    436.     private int terrainTurns = 0;
    437.     private int gravityTurns = 0;
    438.     private int[] reflectTurns = new int[2];
    439.     private int[] lightScreenTurns = new int[2];
    440.     private int[] tailwindTurns = new int[2];
    441.     private bool[] stealthRocks = new bool[2];
    442.     private bool[] stickyWeb = new bool[2];
    443.     private int[] spikesLayers = new int[2];
    444.     private int[] toxicSpikesLayers = new int[2];
    445.  
    446.     //Pokemon Effects
    447.     private bool[] confused = new bool[6];
    448.     private int[] infatuatedBy = new int[] {-1, -1, -1, -1, -1, -1};
    449.     private bool[] flinched = new bool[6];
    450.     private int[] statusEffectTurns = new int[6];
    451.     private int[] lockedTurns = new int[6];
    452.     private int[] partTrappedTurns = new int[6];
    453.     private bool[] trapped = new bool[6];
    454.     private bool[] charging = new bool[6];
    455.     private bool[] recharging = new bool[6];
    456.     private bool[] protect = new bool[6];
    457.     //specific moves
    458.     private int[] seededBy = new int[] {-1, -1, -1, -1, -1, -1};
    459.     private bool[] focusEnergy = new bool[6];
    460.     private bool[] destinyBond = new bool[6];
    461.     private bool[] minimized = new bool[6];
    462.     private bool[] defenseCurled = new bool[6];
    463.  
    464.     //Turn Feedback Data
    465.     private bool[] pokemonHasMoved = new bool[6];
    466.     private string[] previousMove = new string[6];
    467.  
    468.     void Awake()
    469.     {
    470.         Dialog = transform.GetComponent<DialogBoxHandlerNew>();
    471.  
    472.         BattleAudio = transform.GetComponent<AudioSource>();
    473.  
    474.         playerBase = transform.Find("player0").GetComponent<Image>();
    475.         opponentBase = transform.Find("opponent0").GetComponent<Image>();
    476.         background = transform.Find("Background").GetComponent<Image>();
    477.  
    478.         trainerSprite1 = opponentBase.transform.Find("Trainer").GetComponent<Image>();
    479.         playerTrainerSprite1 = playerBase.transform.Find("Trainer").GetComponent<Image>();
    480.  
    481.         player1 = playerBase.transform.Find("Pokemon").Find("Mask").Find("Sprite").GetComponent<Image>();
    482.         opponent1 =
    483.             opponentBase.transform.Find("Pokemon").Find("Mask").Find("Sprite").GetComponent<Image>();
    484.         player1Overlay = player1.transform.Find("Overlay").GetComponent<RawImage>();
    485.         opponent1Overlay = opponent1.transform.Find("Overlay").GetComponent<RawImage>();
    486.  
    487.         Transform playerPartyBarTrn = transform.Find("playerParty");
    488.         Transform opponentPartyBarTrn = transform.Find("opponentParty");
    489.         playerPartyBar = playerPartyBarTrn.Find("bar").GetComponent<Image>();
    490.         opponentPartyBar = opponentPartyBarTrn.Find("bar").GetComponent<Image>();
    491.         for (int i = 0; i < 6; i++)
    492.         {
    493.             playerPartyBarSpace[i] = playerPartyBarTrn.Find("space" + i).GetComponent<Image>();
    494.         }
    495.         for (int i = 0; i < 6; i++)
    496.         {
    497.             opponentPartyBarSpace[i] = opponentPartyBarTrn.Find("space" + i).GetComponent<Image>();
    498.         }
    499.  
    500.         pokemonStatsDisplay[0] = transform.Find("playerStats0").GetComponent<Image>();
    501.         statsNameShadow[0] = pokemonStatsDisplay[0].transform.Find("Name").GetComponent<Text>();
    502.         statsName[0] = statsNameShadow[0].transform.Find("Text").GetComponent<Text>();
    503.         statsGenderShadow[0] = pokemonStatsDisplay[0].transform.Find("Gender").GetComponent<Text>();
    504.         statsGender[0] = statsGenderShadow[0].transform.Find("Text").GetComponent<Text>();
    505.         statsLevelShadow[0] = pokemonStatsDisplay[0].transform.Find("Level").GetComponent<Text>();
    506.         statsLevel[0] = statsLevelShadow[0].transform.Find("Text").GetComponent<Text>();
    507.         statsHPBar[0] = pokemonStatsDisplay[0].transform.Find("HPBar").GetComponent<Image>();
    508.         statsStatus[0] = pokemonStatsDisplay[0].transform.Find("Status").GetComponent<Image>();
    509.         pokemon0CurrentHPShadow = pokemonStatsDisplay[0].transform.Find("CurrentHP").GetComponent<Text>();
    510.         pokemon0CurrentHP = pokemon0CurrentHPShadow.transform.Find("Text").GetComponent<Text>();
    511.         pokemon0MaxHPShadow = pokemonStatsDisplay[0].transform.Find("MaxHP").GetComponent<Text>();
    512.         pokemon0MaxHP = pokemon0MaxHPShadow.transform.Find("Text").GetComponent<Text>();
    513.         pokemon0ExpBar = pokemonStatsDisplay[0].transform.Find("ExpBar").GetComponent<Image>();
    514.  
    515.         pokemonStatsDisplay[3] = transform.Find("opponentStats0").GetComponent<Image>();
    516.         statsNameShadow[3] = pokemonStatsDisplay[3].transform.Find("Name").GetComponent<Text>();
    517.         statsName[3] = statsNameShadow[3].transform.Find("Text").GetComponent<Text>();
    518.         statsGenderShadow[3] = pokemonStatsDisplay[3].transform.Find("Gender").GetComponent<Text>();
    519.         statsGender[3] = statsGenderShadow[3].transform.Find("Text").GetComponent<Text>();
    520.         statsLevelShadow[3] = pokemonStatsDisplay[3].transform.Find("Level").GetComponent<Text>();
    521.         statsLevel[3] = statsLevelShadow[3].transform.Find("Text").GetComponent<Text>();
    522.         statsHPBar[3] = pokemonStatsDisplay[3].transform.Find("HPBar").GetComponent<Image>();
    523.         statsStatus[3] = pokemonStatsDisplay[3].transform.Find("Status").GetComponent<Image>();
    524.  
    525.         Transform optionBox = transform.Find("OptionBox");
    526.         buttonFight = optionBox.Find("ButtonFight").GetComponent<Image>();
    527.         buttonBag = optionBox.Find("ButtonBag").GetComponent<Image>();
    528.         buttonPoke = optionBox.Find("ButtonPoke").GetComponent<Image>();
    529.         buttonRun = optionBox.Find("ButtonRun").GetComponent<Image>();
    530.  
    531.         for (int i = 0; i < 4; i++)
    532.         {
    533.             buttonMove[i] = optionBox.Find("Move" + (i + 1)).GetComponent<Image>();
    534.             buttonMoveType[i] = buttonMove[i].transform.Find("Type").GetComponent<Image>();
    535.             buttonMoveNameShadow[i] = buttonMove[i].transform.Find("Name").GetComponent<Text>();
    536.             buttonMoveName[i] = buttonMoveNameShadow[i].transform.Find("Text").GetComponent<Text>();
    537.             buttonMovePPShadow[i] = buttonMove[i].transform.Find("PP").GetComponent<Text>();
    538.             buttonMovePP[i] = buttonMovePPShadow[i].transform.Find("Text").GetComponent<Text>();
    539.             buttonMoveCover[i] = buttonMove[i].transform.Find("Cover").GetComponent<Image>();
    540.         }
    541.         buttonMoveReturn = optionBox.Find("MoveReturn").GetComponent<Image>();
    542.         buttonMegaEvolution = optionBox.Find("MoveMegaEvolution").GetComponent<Image>();
    543.  
    544.         bagObject = optionBox.Find("Bag").gameObject;
    545.         pokeObject = optionBox.Find("Poke").gameObject;
    546.         pokemonPartyObject = optionBox.Find("Party").gameObject;
    547.  
    548.         buttonBackBag = bagObject.transform.Find("ButtonBack").GetComponent<Image>();
    549.         buttonBackPoke = pokeObject.transform.Find("ButtonBack").GetComponent<Image>();
    550.  
    551.         buttonItemCategory[0] = bagObject.transform.Find("ButtonHPPPRestore").GetComponent<Image>();
    552.         buttonItemCategory[1] = bagObject.transform.Find("ButtonPokeBalls").GetComponent<Image>();
    553.         buttonItemCategory[2] = bagObject.transform.Find("ButtonStatusHealers").GetComponent<Image>();
    554.         buttonItemCategory[3] = bagObject.transform.Find("ButtonBattleItems").GetComponent<Image>();
    555.         buttonItemLastUsed = bagObject.transform.Find("ButtonItemUsedLast").GetComponent<Image>();
    556.  
    557.         itemList = bagObject.transform.Find("Items").gameObject;
    558.         for (int i = 0; i < 8; i++)
    559.         {
    560.             buttonItemList[i] = itemList.transform.Find("Item" + i).GetComponent<Image>();
    561.             itemListIcon[i] = buttonItemList[i].transform.Find("Icon").GetComponent<Image>();
    562.             itemListNameShadow[i] = buttonItemList[i].transform.Find("Item").GetComponent<Text>();
    563.             itemListName[i] = itemListNameShadow[i].transform.Find("Text").GetComponent<Text>();
    564.             itemListQuantityShadow[i] = buttonItemList[i].transform.Find("Quantity").GetComponent<Text>();
    565.             itemListQuantity[i] = itemListQuantityShadow[i].transform.Find("Text").GetComponent<Text>();
    566.         }
    567.  
    568.         for (int i = 0; i < 6; i++)
    569.         {
    570.             buttonPokemonSlot[i] = pokemonPartyObject.transform.Find("Slot" + i).GetComponent<Image>();
    571.             pokemonSlotIcon[i] = buttonPokemonSlot[i].transform.Find("Icon").GetComponent<Image>();
    572.             pokemonSlotNameShadow[i] = buttonPokemonSlot[i].transform.Find("Name").GetComponent<Text>();
    573.             pokemonSlotName[i] = pokemonSlotNameShadow[i].transform.Find("Text").GetComponent<Text>();
    574.             pokemonSlotGenderShadow[i] = buttonPokemonSlot[i].transform.Find("Gender").GetComponent<Text>();
    575.             pokemonSlotGender[i] = pokemonSlotGenderShadow[i].transform.Find("Text").GetComponent<Text>();
    576.             pokemonSlotLevelShadow[i] = buttonPokemonSlot[i].transform.Find("Level").GetComponent<Text>();
    577.             pokemonSlotLevel[i] = pokemonSlotLevelShadow[i].transform.Find("Text").GetComponent<Text>();
    578.             pokemonSlotCurrentHPShadow[i] = buttonPokemonSlot[i].transform.Find("CurrentHP").GetComponent<Text>();
    579.             pokemonSlotCurrentHP[i] = pokemonSlotCurrentHPShadow[i].transform.Find("Text").GetComponent<Text>();
    580.             pokemonSlotMaxHPShadow[i] = buttonPokemonSlot[i].transform.Find("MaxHP").GetComponent<Text>();
    581.             pokemonSlotMaxHP[i] = pokemonSlotMaxHPShadow[i].transform.Find("Text").GetComponent<Text>();
    582.             pokemonSlotHPBar[i] = buttonPokemonSlot[i].transform.Find("HPBar").GetComponent<Image>();
    583.             pokemonSlotStatus[i] = buttonPokemonSlot[i].transform.Find("Status").GetComponent<Image>();
    584.             pokemonSlotItem[i] = buttonPokemonSlot[i].transform.Find("Item").GetComponent<Image>();
    585.         }
    586.  
    587.         buttonSwitch = pokeObject.transform.Find("ButtonSwitch").GetComponent<Image>();
    588.         buttonCheck = pokeObject.transform.Find("ButtonCheck").GetComponent<Image>();
    589.         buttonCheckTextShadow = buttonCheck.transform.Find("Text").GetComponent<Text>();
    590.         buttonCheckText = buttonCheckTextShadow.transform.Find("Text").GetComponent<Text>();
    591.  
    592.         //ITEM LIST DETAILS
    593.         itemListCategoryTextShadow = itemList.transform.Find("Category").GetComponent<Text>();
    594.         itemListCategoryText = itemListCategoryTextShadow.transform.Find("Text").GetComponent<Text>();
    595.         itemListPageNumberShadow = itemList.transform.Find("Page").GetComponent<Text>();
    596.         itemListPageNumber = itemListPageNumberShadow.transform.Find("Text").GetComponent<Text>();
    597.         itemListArrowPrev = itemList.transform.Find("PageArrowPrev").gameObject;
    598.         itemListArrowNext = itemList.transform.Find("PageArrowNext").gameObject;
    599.         itemListDescriptionShadow = itemList.transform.Find("ItemDescription").GetComponent<Text>();
    600.         itemListDescription = itemListDescriptionShadow.transform.Find("Text").GetComponent<Text>();
    601.  
    602.         //POKE SELECTED DETAILS
    603.         pokemonSelectedPokemon = pokeObject.transform.Find("SelectedPokemon").gameObject;
    604.         pokemonSelectedIcon = pokemonSelectedPokemon.transform.Find("Icon").GetComponent<Image>();
    605.         pokemonSelectedNameShadow = pokemonSelectedPokemon.transform.Find("Name").GetComponent<Text>();
    606.         pokemonSelectedName = pokemonSelectedNameShadow.transform.Find("Text").GetComponent<Text>();
    607.         pokemonSelectedGenderShadow = pokemonSelectedPokemon.transform.Find("Gender").GetComponent<Text>();
    608.         pokemonSelectedGender = pokemonSelectedGenderShadow.transform.Find("Text").GetComponent<Text>();
    609.         pokemonSelectedLevelShadow = pokemonSelectedPokemon.transform.Find("Level").GetComponent<Text>();
    610.         pokemonSelectedLevel = pokemonSelectedLevelShadow.transform.Find("Text").GetComponent<Text>();
    611.         pokemonSelectedStatus = pokemonSelectedPokemon.transform.Find("Status").GetComponent<Image>();
    612.         pokemonSelectedType1 = pokemonSelectedPokemon.transform.Find("Type1").GetComponent<Image>();
    613.         pokemonSelectedType2 = pokemonSelectedPokemon.transform.Find("Type2").GetComponent<Image>();
    614.  
    615.         //POKE SUMMARY DETAILS
    616.         pokemonSummary = pokeObject.transform.Find("Summary").gameObject;
    617.         pokemonSummaryHPShadow = pokemonSummary.transform.Find("HP").GetComponent<Text>();
    618.         pokemonSummaryHP = pokemonSummaryHPShadow.transform.Find("Text").GetComponent<Text>();
    619.         pokemonSummaryHPBar = pokemonSummary.transform.Find("HPBar").GetComponent<Image>();
    620.         pokemonSummaryStatsTextShadow = pokemonSummary.transform.Find("StatsText").GetComponent<Text>();
    621.         pokemonSummaryStatsShadow = pokemonSummary.transform.Find("Stats").GetComponent<Text>();
    622.         pokemonSummaryStats = pokemonSummaryStatsShadow.transform.Find("Text").GetComponent<Text>();
    623.         pokemonSummaryNextLevelEXPShadow = pokemonSummary.transform.Find("ToNextLevel").GetComponent<Text>();
    624.         pokemonSummaryNextLevelEXP = pokemonSummaryNextLevelEXPShadow.transform.Find("Text").GetComponent<Text>();
    625.         pokemonSummaryEXPBar = pokemonSummary.transform.Find("ExpBar").GetComponent<Image>();
    626.         pokemonSummaryItemIcon = pokemonSummary.transform.Find("ItemIcon").GetComponent<Image>();
    627.         pokemonSummaryItemNameShadow = pokemonSummary.transform.Find("Item").GetComponent<Text>();
    628.         pokemonSummaryItemName = pokemonSummaryItemNameShadow.transform.Find("Text").GetComponent<Text>();
    629.         pokemonSummaryAbilityNameShadow = pokemonSummary.transform.Find("Ability").GetComponent<Text>();
    630.         pokemonSummaryAbilityName = pokemonSummaryAbilityNameShadow.transform.Find("Text").GetComponent<Text>();
    631.         pokemonSummaryAbilityDescriptionShadow =
    632.             pokemonSummary.transform.Find("AbilityDescription").GetComponent<Text>();
    633.         pokemonSummaryAbilityDescription =
    634.             pokemonSummaryAbilityDescriptionShadow.transform.Find("Text").GetComponent<Text>();
    635.  
    636.         //POKE MOVES DETAILS
    637.         pokemonMoves = pokeObject.transform.Find("Moves").gameObject;
    638.         for (int i = 0; i < 4; i++)
    639.         {
    640.             pokemonMovesNameShadow[i] = pokemonMoves.transform.Find("Move" + (i + 1)).GetComponent<Text>();
    641.             pokemonMovesName[i] = pokemonMovesNameShadow[i].transform.Find("Text").GetComponent<Text>();
    642.             pokemonMovesType[i] = pokemonMoves.transform.Find("Move" + (i + 1) + "Type").GetComponent<Image>();
    643.             pokemonMovesPPShadow[i] = pokemonMoves.transform.Find("Move" + (i + 1) + "PP").GetComponent<Text>();
    644.             pokemonMovesPP[i] = pokemonMovesPPShadow[i].transform.Find("Text").GetComponent<Text>();
    645.             pokemonMovesPPTextShadow[i] =
    646.                 pokemonMoves.transform.Find("Move" + (i + 1) + "PPText").GetComponent<Text>();
    647.             pokemonMovesPPText[i] = pokemonMovesPPTextShadow[i].transform.Find("Text").GetComponent<Text>();
    648.         }
    649.  
    650.         pokemonMovesSelectedCategory = pokemonMoves.transform.Find("SelectedCategory").GetComponent<Image>();
    651.         pokemonMovesSelectedPowerShadow = pokemonMoves.transform.Find("SelectedPower").GetComponent<Text>();
    652.         pokemonMovesSelectedPower = pokemonMovesSelectedPowerShadow.transform.Find("Text").GetComponent<Text>();
    653.         pokemonMovesSelectedAccuracyShadow = pokemonMoves.transform.Find("SelectedAccuracy").GetComponent<Text>();
    654.         pokemonMovesSelectedAccuracy =
    655.             pokemonMovesSelectedAccuracyShadow.transform.Find("Text").GetComponent<Text>();
    656.         pokemonMovesSelectedDescriptionShadow =
    657.             pokemonMoves.transform.Find("SelectedDescription").GetComponent<Text>();
    658.         pokemonMovesSelectedDescription =
    659.             pokemonMovesSelectedDescriptionShadow.transform.Find("Text").GetComponent<Text>();
    660.         pokemonMovesSelector = pokemonMoves.transform.Find("MoveSelector").GetComponent<Image>();
    661.         pokemonMovesSelectedMove = pokemonMoves.transform.Find("SelectedMove").GetComponent<Image>();
    662.     }
    663.  
    664.     void Start()
    665.     {
    666.         gameObject.SetActive(false);
    667.     }
    668.  
    669.  
    670.     //////////////////////////////////
    671.     /// ANIMATIONS
    672.     //
    673.     private IEnumerator animatePokemon(Image pokemon, Sprite[] animation)
    674.     {
    675.         int frame = 0;
    676.         while (animation != null)
    677.         {
    678.             if (animation.Length > 0)
    679.             {
    680.                 if (frame < animation.Length - 1)
    681.                 {
    682.                     frame += 1;
    683.                 }
    684.                 else
    685.                 {
    686.                     frame = 0;
    687.                 }
    688.                 pokemon.sprite = animation[frame];
    689.             }
    690.             yield return new WaitForSeconds(0.08f);
    691.         }
    692.     }
    693.  
    694.     private IEnumerator animateOverlayer(RawImage overlay, Texture overlayTex, float verMovement, float hozMovement,
    695.         float time, float fadeTime)
    696.     {
    697.         overlay.gameObject.SetActive(true);
    698.         overlay.texture = overlayTex;
    699.         float fadeStartIncrement = (time - fadeTime) / time;
    700.         float initialAlpha = overlay.color.a;
    701.  
    702.         float increment = 0;
    703.         while (increment < 1)
    704.         {
    705.             increment += (1 / time) * Time.deltaTime;
    706.             if (increment > 1)
    707.             {
    708.                 increment = 1;
    709.             }
    710.  
    711.             overlay.uvRect = new Rect(hozMovement * increment, verMovement * increment, 1, 1);
    712.             if (increment > fadeStartIncrement)
    713.             {
    714.                 float increment2 = (increment - fadeStartIncrement) / (1 - fadeStartIncrement);
    715.                 overlay.color = new Color(overlay.color.r, overlay.color.g, overlay.color.b,
    716.                     initialAlpha * (1 - increment2));
    717.             }
    718.             yield return null;
    719.         }
    720.         overlay.color = new Color(overlay.color.r, overlay.color.g, overlay.color.b, initialAlpha);
    721.         overlay.gameObject.SetActive(false);
    722.     }
    723.  
    724.     /// Slides the Pokemon's Platform across the screen. Takes 1.9f seconds.
    725.     private IEnumerator slidePokemon(Image platform, Image pokemon, bool showPokemon, bool fromRight,
    726.         Vector3 destinationPosition)
    727.     {
    728.         Vector3 startPosition = (fromRight)
    729.             ? new Vector3(171 + (platform.rectTransform.sizeDelta.x * platform.rectTransform.localScale.x / 2f),
    730.                 destinationPosition.y, 0)
    731.             : new Vector3(-171 - (platform.rectTransform.sizeDelta.x * platform.rectTransform.localScale.x / 2f),
    732.                 destinationPosition.y, 0);
    733.         Vector3 distance = destinationPosition - startPosition;
    734.  
    735.         pokemon.color = new Color(0.25f, 0.25f, 0.25f, 1);
    736.  
    737.         pokemon.transform.parent.parent.gameObject.SetActive(showPokemon);
    738.  
    739.         float speed = 1.5f;
    740.         float increment = 0f;
    741.         while (increment < 1)
    742.         {
    743.             increment += (1 / speed) * Time.deltaTime;
    744.             if (increment > 1)
    745.             {
    746.                 increment = 1f;
    747.             }
    748.             platform.rectTransform.localPosition = startPosition + (distance * increment);
    749.             yield return null;
    750.         }
    751.  
    752.         speed = 0.4f;
    753.         increment = 0f;
    754.         while (increment < 1)
    755.         {
    756.             increment += (1 / speed) * Time.deltaTime;
    757.             if (increment > 1)
    758.             {
    759.                 increment = 1f;
    760.             }
    761.             pokemon.color = new Color(0.25f + (0.25f * increment), 0.25f + (0.25f * increment),
    762.                 0.25f + (0.25f * increment), 1);
    763.             yield return null;
    764.         }
    765.     }
    766.  
    767.     private IEnumerator slideTrainer(Image platform, Image trainer, bool isOpponent, bool slideOut)
    768.     {
    769.         Vector3 startPosition = trainer.rectTransform.localPosition;
    770.         //assume !slide out for both
    771.         float destinationPositionX = (isOpponent && !slideOut) ? platform.rectTransform.sizeDelta.x * 0.3f : 0;
    772.         //if it actually was slide out, use the formula to find the hidden position
    773.         if (slideOut)
    774.         {
    775.             destinationPositionX = (171 - Mathf.Abs(platform.rectTransform.localPosition.x)) /
    776.                                    platform.rectTransform.localScale.x + trainer.rectTransform.sizeDelta.x / 2f;
    777.         }
    778.         //flip direction if is player
    779.         if (!isOpponent)
    780.         {
    781.             destinationPositionX = -destinationPositionX;
    782.         }
    783.  
    784.         Vector3 distance = new Vector3(destinationPositionX, startPosition.y, 0) - startPosition;
    785.  
    786.         float speed = 128f;
    787.         float time = Mathf.Abs(distance.x) / speed;
    788.  
    789.         float increment = 0f;
    790.         while (increment < 1)
    791.         {
    792.             increment += (1 / time) * Time.deltaTime;
    793.             if (increment > 1)
    794.             {
    795.                 increment = 1f;
    796.             }
    797.             trainer.rectTransform.localPosition = startPosition + (distance * increment);
    798.             yield return null;
    799.         }
    800.     }
    801.  
    802.     private IEnumerator animatePlayerThrow(Image trainer, Sprite[] throwAnim, bool finishThrow)
    803.     {
    804.         trainer.sprite = throwAnim[1];
    805.         yield return new WaitForSeconds(0.4f);
    806.         trainer.sprite = throwAnim[2];
    807.         yield return new WaitForSeconds(0.05f);
    808.         trainer.sprite = throwAnim[3];
    809.         if (finishThrow)
    810.         {
    811.             yield return new WaitForSeconds(0.05f);
    812.             trainer.sprite = throwAnim[4];
    813.         }
    814.     }
    815.  
    816.     private IEnumerator releasePokemon(Image pokemon)
    817.     {
    818.         Vector2 normalSize = pokemon.rectTransform.sizeDelta;
    819.         pokemon.rectTransform.sizeDelta = new Vector2(0, 0);
    820.         pokemon.color = new Color(0.812f, 0.312f, 0.312f, 1);
    821.  
    822.         pokemon.transform.parent.parent.gameObject.SetActive(true);
    823.  
    824.         SfxHandler.Play(pokeballOpenClip);
    825.  
    826.         float speed = 0.3f;
    827.         float increment = 0f;
    828.         while (increment < 1)
    829.         {
    830.             increment += (1 / speed) * Time.deltaTime;
    831.             if (increment > 1)
    832.             {
    833.                 increment = 1f;
    834.             }
    835.             pokemon.rectTransform.sizeDelta = normalSize * increment;
    836.             pokemon.color = new Color(0.812f - (0.312f * increment), 0.312f + (0.188f * increment),
    837.                 0.312f + (0.188f * increment), 1);
    838.             yield return null;
    839.         }
    840.  
    841.         pokemon.rectTransform.sizeDelta = normalSize;
    842.         pokemon.color = new Color(0.5f, 0.5f, 0.5f, 1);
    843.     }
    844.  
    845.     private IEnumerator withdrawPokemon(Image pokemon)
    846.     {
    847.         Vector2 normalSize = pokemon.rectTransform.sizeDelta;
    848.  
    849.         SfxHandler.Play(pokeballOpenClip);
    850.  
    851.         float speed = 0.3f;
    852.         float increment = 0f;
    853.         while (increment < 1)
    854.         {
    855.             increment += (1 / speed) * Time.deltaTime;
    856.             if (increment > 1)
    857.             {
    858.                 increment = 1f;
    859.             }
    860.             pokemon.rectTransform.sizeDelta = normalSize * (1 - increment);
    861.             pokemon.color = new Color(0.5f + (0.312f * increment), 0.5f - (0.188f * increment),
    862.                 0.5f - (0.188f * increment), 1);
    863.             yield return null;
    864.         }
    865.         pokemon.transform.parent.parent.gameObject.SetActive(false);
    866.  
    867.         pokemon.rectTransform.sizeDelta = normalSize;
    868.         pokemon.color = new Color(0.5f, 0.5f, 0.5f, 1);
    869.     }
    870.  
    871.     private IEnumerator faintPokemonAnimation(Image pokemon)
    872.     {
    873.         Vector3 startPosition = pokemon.rectTransform.localPosition;
    874.         Vector3 distance = new Vector3(0, pokemon.rectTransform.sizeDelta.y, 0);
    875.  
    876.         pokemon.transform.parent.parent.gameObject.SetActive(true);
    877.  
    878.         SfxHandler.Play(faintClip);
    879.  
    880.         float speed = 0.5f;
    881.         float increment = 0f;
    882.         while (increment < 1)
    883.         {
    884.             increment += (1 / speed) * Time.deltaTime;
    885.             if (increment > 1)
    886.             {
    887.                 increment = 1f;
    888.             }
    889.  
    890.             //    pokemon.fillAmount = 1-increment;
    891.             pokemon.rectTransform.localPosition = startPosition - (distance * increment);
    892.  
    893.             yield return null;
    894.         }
    895.  
    896.         pokemon.transform.parent.parent.gameObject.SetActive(false);
    897.  
    898.         pokemon.fillAmount = 1f;
    899.         pokemon.rectTransform.localPosition = startPosition;
    900.     }
    901.  
    902.     private IEnumerator slidePokemonStats(int position, bool retract)
    903.     {
    904.         float distanceX = pokemonStatsDisplay[position].rectTransform.sizeDelta.x;
    905.         float startX = (retract) ? 171f - (distanceX / 2) : 171f + (distanceX / 2);
    906.         //flip values if opponent stats
    907.         if (position > 2)
    908.         {
    909.             startX = -startX;
    910.             distanceX = -distanceX;
    911.         }
    912.         //flip movement direction if retracting
    913.         if (retract)
    914.         {
    915.             distanceX = -distanceX;
    916.         }
    917.  
    918.         pokemonStatsDisplay[position].gameObject.SetActive(true);
    919.  
    920.         float speed = 0.3f;
    921.         float increment = 0f;
    922.         while (increment < 1)
    923.         {
    924.             increment += (1 / speed) * Time.deltaTime;
    925.             if (increment > 1)
    926.             {
    927.                 increment = 1f;
    928.             }
    929.  
    930.             pokemonStatsDisplay[position].rectTransform.localPosition = new Vector3(startX - (distanceX * increment),
    931.                 pokemonStatsDisplay[position].rectTransform.localPosition.y, 0);
    932.  
    933.             yield return null;
    934.         }
    935.     }
    936.  
    937.     private void hidePartyBar(bool isOpponent)
    938.     {
    939.         Image bar = (isOpponent) ? opponentPartyBar : playerPartyBar;
    940.         Image[] space = (isOpponent) ? opponentPartyBarSpace : playerPartyBarSpace;
    941.  
    942.         bar.color = new Color(bar.color.r, bar.color.g, bar.color.b, 0);
    943.         bar.rectTransform.sizeDelta = new Vector2(0, bar.rectTransform.sizeDelta.y);
    944.         for (int i = 0; i < 6; i++)
    945.         {
    946.             space[i].color = new Color(space[i].color.r, space[i].color.g, space[i].color.b, 0);
    947.             space[i].rectTransform.localPosition = new Vector3(-96 + (16 * i) + 128,
    948.                 space[i].rectTransform.localPosition.y);
    949.         }
    950.     }
    951.  
    952.     /// <summary> Displays the party length bar. </summary>
    953.     /// <param name="isOpponent">Does this bar belong to the opponent?</param>
    954.     /// <param name="party">The party, used to determine length and if fainted.</param>
    955.     private IEnumerator displayPartyBar(bool isOpponent, Pokemon[] party)
    956.     {
    957.         Image bar = (isOpponent) ? opponentPartyBar : playerPartyBar;
    958.         Image[] space = (isOpponent) ? opponentPartyBarSpace : playerPartyBarSpace;
    959.  
    960.         hidePartyBar(isOpponent); //this line reset the position to hidden, but also sets alpha to 0
    961.         //set alpha to 1
    962.         bar.color = new Color(bar.color.r, bar.color.g, bar.color.b, 1);
    963.         for (int i = 0; i < 6; i++)
    964.         {
    965.             space[i].color = new Color(space[i].color.r, space[i].color.g, space[i].color.b, 1);
    966.         }
    967.  
    968.         StartCoroutine(stretchBar(bar, 128, 320));
    969.         yield return new WaitForSeconds(0.1f);
    970.         for (int i = 0; i < 6; i++)
    971.         {
    972.             //Set space sprite
    973.             space[i].sprite = partySpaceTex;
    974.             if (party.Length > i)
    975.             {
    976.                 if (party[i] != null)
    977.                 {
    978.                     if (party[i].getStatus() == Pokemon.Status.FAINTED)
    979.                     {
    980.                         space[i].sprite = partyFaintTex;
    981.                     }
    982.                     else if (party[i].getStatus() == Pokemon.Status.NONE)
    983.                     {
    984.                         space[i].sprite = partyBallTex;
    985.                     }
    986.                     else
    987.                     {
    988.                         space[i].sprite = partyStatusTex;
    989.                     }
    990.                 }
    991.             }
    992.             //slide down the line
    993.             StartCoroutine(slidePartyBarBall(space[i], -96 + (16 * i) + 128, -99 + (16 * i), 0.35f));
    994.             yield return new WaitForSeconds(0.05f);
    995.         }
    996.         //Wait for last space to stop moving
    997.         yield return new WaitForSeconds(0.3f);
    998.         //Slide all spaces back a tiny bit
    999.         for (int i = 0; i < 6; i++)
    1000.         {
    1001.             StartCoroutine(slidePartyBarBall(space[i], -99 + (16 * i), -96 + (16 * i), 0.1f));
    1002.         }
    1003.         //Wait for last space to stop moving
    1004.         yield return new WaitForSeconds(0.1f);
    1005.     }
    1006.  
    1007.     private IEnumerator dismissPartyBar(bool isOpponent)
    1008.     {
    1009.         Image bar = (isOpponent) ? opponentPartyBar : playerPartyBar;
    1010.         Image[] space = (isOpponent) ? opponentPartyBarSpace : playerPartyBarSpace;
    1011.  
    1012.         //Slide all out and fade
    1013.         Image[] images = new Image[space.Length + 1];
    1014.         images[0] = bar;
    1015.         for (int i = 0; i < space.Length; i++)
    1016.         {
    1017.             images[i + 1] = space[i];
    1018.         }
    1019.         StartCoroutine(fadeImages(images, 0.6f));
    1020.  
    1021.         StartCoroutine(stretchBar(bar, 192, 128));
    1022.         yield return new WaitForSeconds(0.1f);
    1023.         for (int i = 0; i < 6; i++)
    1024.         {
    1025.             //slide down the line
    1026.             StartCoroutine(slidePartyBarBall(space[i], -96 + (16 * i), -96 + (16 * i) - 192, 0.5f));
    1027.             yield return new WaitForSeconds(0.05f + (0.02f * i));
    1028.         }
    1029.         //Wait for last space to stop moving
    1030.         yield return new WaitForSeconds(0.45f);
    1031.         hidePartyBar(isOpponent);
    1032.     }
    1033.  
    1034.     private IEnumerator fadeImages(Image[] images, float time)
    1035.     {
    1036.         float increment = 0f;
    1037.         while (increment < 1)
    1038.         {
    1039.             increment += (1 / time) * Time.deltaTime;
    1040.             if (increment > 1)
    1041.             {
    1042.                 increment = 1f;
    1043.             }
    1044.  
    1045.             for (int i = 0; i < images.Length; i++)
    1046.             {
    1047.                 images[i].color = new Color(images[i].color.r, images[i].color.g, images[i].color.b, 1 - increment);
    1048.             }
    1049.             yield return null;
    1050.         }
    1051.     }
    1052.  
    1053.     private IEnumerator slidePartyBarBall(Image ball, float startX, float destinationX, float speed)
    1054.     {
    1055.         ball.rectTransform.localPosition = new Vector3(startX, ball.rectTransform.localPosition.y, 0);
    1056.  
    1057.         float distanceX = destinationX - startX;
    1058.  
    1059.         float increment = 0;
    1060.         while (increment < 1)
    1061.         {
    1062.             increment += (1 / speed) * Time.deltaTime;
    1063.             if (increment > 1)
    1064.             {
    1065.                 increment = 1;
    1066.             }
    1067.  
    1068.             ball.rectTransform.localPosition = new Vector3(startX + (distanceX * increment),
    1069.                 ball.rectTransform.localPosition.y, 0);
    1070.             yield return null;
    1071.         }
    1072.     }
    1073.  
    1074.     private IEnumerator animatePartyIcons()
    1075.     {
    1076.         bool animating = true;
    1077.         while (animating)
    1078.         {
    1079.             for (int i = 0; i < 6; i++)
    1080.             {
    1081.                 pokemonSlotIcon[i].sprite = pokemonIconAnim[i][0];
    1082.             }
    1083.             yield return new WaitForSeconds(0.15f);
    1084.             for (int i = 0; i < 6; i++)
    1085.             {
    1086.                 pokemonSlotIcon[i].sprite = (i == pokePartyPosition) ? pokemonIconAnim[i][1] : pokemonIconAnim[i][0];
    1087.             }
    1088.             yield return new WaitForSeconds(0.15f);
    1089.  
    1090.             for (int i = 0; i < 6; i++)
    1091.             {
    1092.                 pokemonSlotIcon[i].sprite = (i == pokePartyPosition) ? pokemonIconAnim[i][0] : pokemonIconAnim[i][1];
    1093.             }
    1094.             yield return new WaitForSeconds(0.15f);
    1095.             for (int i = 0; i < 6; i++)
    1096.             {
    1097.                 pokemonSlotIcon[i].sprite = pokemonIconAnim[i][1];
    1098.             }
    1099.             yield return new WaitForSeconds(0.15f);
    1100.         }
    1101.     }
    1102.  
    1103.  
    1104.     private IEnumerator stretchBar(Image bar, float targetSize)
    1105.     {
    1106.         yield return StartCoroutine(stretchBar(bar, targetSize, 32f, false, null, null, 0));
    1107.     }
    1108.  
    1109.     private IEnumerator stretchBar(Image bar, float targetSize, float pixelsPerSec)
    1110.     {
    1111.         yield return StartCoroutine(stretchBar(bar, targetSize, pixelsPerSec, false, null, null, 0));
    1112.     }
    1113.  
    1114.     private IEnumerator stretchBar(Image bar, float targetSize, float pixelsPerSec, bool isHP, Text hpText,
    1115.         Text hpTextShadow, int endValue)
    1116.     {
    1117.         float increment = 0f;
    1118.         if (pixelsPerSec <= 0)
    1119.         {
    1120.             pixelsPerSec = 32;
    1121.         }
    1122.         float startSize = bar.rectTransform.sizeDelta.x;
    1123.         float distance = targetSize - startSize;
    1124.         float time = Mathf.Abs(distance) / pixelsPerSec;
    1125.  
    1126.         int startValue = (hpText != null) ? int.Parse(hpText.text) : 0;
    1127.         float valueDistance = endValue - startValue;
    1128.  
    1129.         while (increment < 1)
    1130.         {
    1131.             increment += (1 / time) * Time.deltaTime;
    1132.             if (increment > 1)
    1133.             {
    1134.                 increment = 1;
    1135.             }
    1136.  
    1137.             bar.rectTransform.sizeDelta = new Vector2(startSize + (distance * increment), bar.rectTransform.sizeDelta.y);
    1138.  
    1139.             if (isHP)
    1140.             {
    1141.                 setHPBarColor(bar, 48f);
    1142.             }
    1143.             if (hpText != null)
    1144.             {
    1145.                 hpText.text = "" + (startValue + Mathf.FloorToInt(valueDistance * increment));
    1146.                 if (hpTextShadow != null)
    1147.                 {
    1148.                     hpTextShadow.text = hpText.text;
    1149.                 }
    1150.             }
    1151.             yield return null;
    1152.         }
    1153.     }
    1154.  
    1155.     //////////////////////////////////
    1156.  
    1157.  
    1158.     //////////////////////////////////
    1159.     /// GUI Display Updaters
    1160.     //
    1161.     /// updates the displayed task.
    1162.     /// 0 = task choice, 1 = move choice, 2 = bag choice, 3 = pokemon choice, 4 = item list, 5 = summary, 6 = moves
    1163.     private void updateCurrentTask(int newState)
    1164.     {
    1165.         if (currentTask == 0)
    1166.         {
    1167.             buttonBag.gameObject.SetActive(false);
    1168.             buttonFight.gameObject.SetActive(false);
    1169.             buttonPoke.gameObject.SetActive(false);
    1170.             buttonRun.gameObject.SetActive(false);
    1171.         }
    1172.         else if (currentTask == 1)
    1173.         {
    1174.             buttonMove[0].gameObject.SetActive(false);
    1175.             buttonMove[1].gameObject.SetActive(false);
    1176.             buttonMove[2].gameObject.SetActive(false);
    1177.             buttonMove[3].gameObject.SetActive(false);
    1178.             buttonMegaEvolution.gameObject.SetActive(false);
    1179.             buttonMoveReturn.gameObject.SetActive(false);
    1180.         }
    1181.         else if (currentTask == 2)
    1182.         {
    1183.             //Bag
    1184.             bagObject.SetActive(false);
    1185.             buttonItemCategory[0].gameObject.SetActive(false);
    1186.             buttonItemCategory[1].gameObject.SetActive(false);
    1187.             buttonItemCategory[2].gameObject.SetActive(false);
    1188.             buttonItemCategory[3].gameObject.SetActive(false);
    1189.             buttonItemLastUsed.gameObject.SetActive(false);
    1190.         }
    1191.         else if (currentTask == 3)
    1192.         {
    1193.             //Poke
    1194.             pokeObject.SetActive(false);
    1195.             pokemonPartyObject.SetActive(false);
    1196.             StopCoroutine(animatingPartyIcons);
    1197.         }
    1198.         else if (currentTask == 4)
    1199.         {
    1200.             //ItemList
    1201.             bagObject.SetActive(false);
    1202.             itemList.SetActive(false);
    1203.             updateItemListDisplay();
    1204.         }
    1205.         else if (currentTask == 5)
    1206.         {
    1207.             //Summary
    1208.             pokeObject.SetActive(false);
    1209.             buttonSwitch.gameObject.SetActive(false);
    1210.             buttonCheck.gameObject.SetActive(false);
    1211.             pokemonSelectedPokemon.SetActive(false);
    1212.             pokemonSummary.SetActive(false);
    1213.         }
    1214.         else if (currentTask == 6)
    1215.         {
    1216.             //Moves
    1217.             pokeObject.SetActive(false);
    1218.             buttonSwitch.gameObject.SetActive(false);
    1219.             buttonCheck.gameObject.SetActive(false);
    1220.             pokemonSelectedPokemon.SetActive(false);
    1221.             pokemonMoves.SetActive(false);
    1222.         }
    1223.  
    1224.         currentTask = newState;
    1225.  
    1226.         if (currentTask == 0)
    1227.         {
    1228.             buttonBag.gameObject.SetActive(true);
    1229.             buttonFight.gameObject.SetActive(true);
    1230.             buttonPoke.gameObject.SetActive(true);
    1231.             buttonRun.gameObject.SetActive(true);
    1232.         }
    1233.         else if (currentTask == 1)
    1234.         {
    1235.             buttonMove[0].gameObject.SetActive(true);
    1236.             buttonMove[1].gameObject.SetActive(true);
    1237.             buttonMove[2].gameObject.SetActive(true);
    1238.             buttonMove[3].gameObject.SetActive(true);
    1239.             buttonMegaEvolution.gameObject.SetActive(true);
    1240.             buttonMoveReturn.gameObject.SetActive(true);
    1241.         }
    1242.         else if (currentTask == 2)
    1243.         {
    1244.             //Bag
    1245.             bagObject.SetActive(true);
    1246.             buttonItemCategory[0].gameObject.SetActive(true);
    1247.             buttonItemCategory[1].gameObject.SetActive(true);
    1248.             buttonItemCategory[2].gameObject.SetActive(true);
    1249.             buttonItemCategory[3].gameObject.SetActive(true);
    1250.             buttonItemLastUsed.gameObject.SetActive(true);
    1251.             updateSelectedBagCategory(bagCategoryPosition);
    1252.         }
    1253.         else if (currentTask == 3)
    1254.         {
    1255.             //Poke
    1256.             pokeObject.SetActive(true);
    1257.             pokemonPartyObject.SetActive(true);
    1258.             updatePokemonSlotsDisplay();
    1259.             updateSelectedPokemonSlot(pokePartyPosition);
    1260.             animatingPartyIcons = StartCoroutine(animatePartyIcons());
    1261.         }
    1262.         else if (currentTask == 4)
    1263.         {
    1264.             //ItemList
    1265.             bagObject.SetActive(true);
    1266.             itemList.SetActive(true);
    1267.             if (bagCategoryPosition == 0)
    1268.             {
    1269.                 itemListString = SaveData.currentSave.Bag.getBattleTypeArray(ItemData.BattleType.HPPPRESTORE);
    1270.                 itemListCategoryText.text = "HP/PP Restore";
    1271.             }
    1272.             else if (bagCategoryPosition == 1)
    1273.             {
    1274.                 itemListString = SaveData.currentSave.Bag.getBattleTypeArray(ItemData.BattleType.POKEBALLS);
    1275.                 itemListCategoryText.text = "Poké Balls";
    1276.             }
    1277.             else if (bagCategoryPosition == 2)
    1278.             {
    1279.                 itemListString = SaveData.currentSave.Bag.getBattleTypeArray(ItemData.BattleType.STATUSHEALER);
    1280.                 itemListCategoryText.text = "Status Healers";
    1281.             }
    1282.             else if (bagCategoryPosition == 3)
    1283.             {
    1284.                 itemListString = SaveData.currentSave.Bag.getBattleTypeArray(ItemData.BattleType.BATTLEITEMS);
    1285.                 itemListCategoryText.text = "Battle Items";
    1286.             }
    1287.             itemListCategoryTextShadow.text = itemListCategoryText.text;
    1288.             itemListPagePosition = 0;
    1289.  
    1290.             itemListPageCount = Mathf.CeilToInt((float) itemListString.Length / 8f);
    1291.             updateItemListDisplay();
    1292.         }
    1293.         else if (currentTask == 5)
    1294.         {
    1295.             //Summary
    1296.             pokeObject.SetActive(true);
    1297.             buttonSwitch.gameObject.SetActive(true);
    1298.             buttonCheck.gameObject.SetActive(true);
    1299.             buttonCheckText.text = "Check Moves";
    1300.             buttonCheckTextShadow.text = buttonCheckText.text;
    1301.             pokemonSelectedPokemon.SetActive(true);
    1302.             pokemonSummary.SetActive(true);
    1303.             updatePokemonSummaryDisplay(SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    1304.         }
    1305.         else if (currentTask == 6)
    1306.         {
    1307.             //Moves
    1308.             pokeObject.SetActive(true);
    1309.             buttonSwitch.gameObject.SetActive(true);
    1310.             buttonCheck.gameObject.SetActive(true);
    1311.             buttonCheckText.text = "Check Summary";
    1312.             buttonCheckTextShadow.text = buttonCheckText.text;
    1313.             pokemonSelectedPokemon.SetActive(true);
    1314.             pokemonMoves.SetActive(true);
    1315.             updateMovesPosition(5);
    1316.         }
    1317.     }
    1318.  
    1319.     private void updatePokemonStatsDisplay(int position)
    1320.     {
    1321.         if (pokemon[position] != null)
    1322.         {
    1323.             statsName[position].text = pokemon[position].getName();
    1324.             statsNameShadow[position].text = statsName[position].text;
    1325.             if (pokemon[position].getGender() == Pokemon.Gender.FEMALE)
    1326.             {
    1327.                 statsGender[position].text = "♀";
    1328.                 statsGender[position].color = new Color(1, 0.2f, 0.2f, 1);
    1329.             }
    1330.             else if (pokemon[position].getGender() == Pokemon.Gender.MALE)
    1331.             {
    1332.                 statsGender[position].text = "♂";
    1333.                 statsGender[position].color = new Color(0.2f, 0.4f, 1, 1);
    1334.             }
    1335.             else
    1336.             {
    1337.                 statsGender[position].text = null;
    1338.             }
    1339.             statsGenderShadow[position].text = statsGender[position].text;
    1340.             statsLevel[position].text = "" + pokemon[position].getLevel();
    1341.             statsLevelShadow[position].text = statsLevel[position].text;
    1342.             statsHPBar[position].rectTransform.sizeDelta =
    1343.                 new Vector2(Mathf.CeilToInt(pokemon[position].getPercentHP() * 48f), 4f);
    1344.  
    1345.             setHPBarColor(statsHPBar[position], 48f);
    1346.  
    1347.  
    1348.             if (pokemon[position].getStatus() != Pokemon.Status.NONE)
    1349.             {
    1350.                 statsStatus[position].sprite =
    1351.                     Resources.Load<Sprite>("PCSprites/status" + pokemon[position].getStatus().ToString());
    1352.             }
    1353.             else
    1354.             {
    1355.                 statsStatus[position].sprite = Resources.Load<Sprite>("null");
    1356.             }
    1357.             if (position == 0 && pokemonPerSide == 1)
    1358.             {
    1359.                 pokemon0CurrentHP.text = "" + pokemon[0].getCurrentHP();
    1360.                 pokemon0CurrentHPShadow.text = pokemon0CurrentHP.text;
    1361.                 pokemon0MaxHP.text = "" + pokemon[0].getHP();
    1362.                 pokemon0MaxHPShadow.text = pokemon0MaxHP.text;
    1363.                 float expCurrentLevel =
    1364.                     PokemonDatabase.getLevelExp(PokemonDatabase.getPokemon(pokemon[0].getID()).getLevelingRate(),
    1365.                         pokemon[0].getLevel());
    1366.                 float expNextlevel =
    1367.                     PokemonDatabase.getLevelExp(PokemonDatabase.getPokemon(pokemon[0].getID()).getLevelingRate(),
    1368.                         pokemon[0].getLevel() + 1);
    1369.                 float expAlong = pokemon[0].getExp() - expCurrentLevel;
    1370.                 float expDistance = expAlong / (expNextlevel - expCurrentLevel);
    1371.                 pokemon0ExpBar.rectTransform.sizeDelta = new Vector2(Mathf.Floor(expDistance * 80f), 2f);
    1372.             }
    1373.         }
    1374.         else
    1375.         {
    1376.         }
    1377.     }
    1378.  
    1379.     private void updateMovesetDisplay(string[] moveset, int[] PP, int[] maxPP)
    1380.     {
    1381.         for (int i = 0; i < 4; i++)
    1382.         {
    1383.             if (moveset[i] != null)
    1384.             {
    1385.                 PokemonData.Type type = MoveDatabase.getMove(moveset[i]).getType();
    1386.  
    1387.                 if (type == PokemonData.Type.BUG)
    1388.                 {
    1389.                     buttonMoveCover[i].color = new Color(0.47f, 0.57f, 0.06f, 1);
    1390.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1391.                 }
    1392.                 else if (type == PokemonData.Type.DARK)
    1393.                 {
    1394.                     buttonMoveCover[i].color = new Color(0.32f, 0.28f, 0.24f, 1);
    1395.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1396.                 }
    1397.                 else if (type == PokemonData.Type.DRAGON)
    1398.                 {
    1399.                     buttonMoveCover[i].color = new Color(0.32f, 0.25f, 1f, 1);
    1400.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1401.                 }
    1402.                 else if (type == PokemonData.Type.ELECTRIC)
    1403.                 {
    1404.                     buttonMoveCover[i].color = new Color(0.64f, 0.52f, 0.04f, 1);
    1405.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1406.                 }
    1407.                 else if (type == PokemonData.Type.FAIRY)
    1408.                 {
    1409.                     buttonMoveCover[i].color = new Color(0.7f, 0.33f, 0.6f, 1);
    1410.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1411.                 }
    1412.                 else if (type == PokemonData.Type.FIGHTING)
    1413.                 {
    1414.                     buttonMoveCover[i].color = new Color(0.75f, 0.19f, 0.15f, 1);
    1415.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1416.                 }
    1417.                 else if (type == PokemonData.Type.FIRE)
    1418.                 {
    1419.                     buttonMoveCover[i].color = new Color(0.94f, 0.5f, 0.19f, 1);
    1420.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1421.                 }
    1422.                 else if (type == PokemonData.Type.FLYING)
    1423.                 {
    1424.                     buttonMoveCover[i].color = new Color(0.5f, 0.43f, 0.72f, 1);
    1425.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1426.                 }
    1427.                 else if (type == PokemonData.Type.GHOST)
    1428.                 {
    1429.                     buttonMoveCover[i].color = new Color(0.4f, 0.32f, 0.55f, 1);
    1430.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1431.                 }
    1432.                 else if (type == PokemonData.Type.GRASS)
    1433.                 {
    1434.                     buttonMoveCover[i].color = new Color(0.34f, 0.5f, 0.25f, 1);
    1435.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1436.                 }
    1437.                 else if (type == PokemonData.Type.GROUND)
    1438.                 {
    1439.                     buttonMoveCover[i].color = new Color(0.53f, 0.4f, 0.19f, 1);
    1440.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1441.                 }
    1442.                 else if (type == PokemonData.Type.ICE)
    1443.                 {
    1444.                     buttonMoveCover[i].color = new Color(0.4f, 0.6f, 0.6f, 1);
    1445.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1446.                 }
    1447.                 else if (type == PokemonData.Type.NORMAL)
    1448.                 {
    1449.                     buttonMoveCover[i].color = new Color(0.5f, 0.5f, 0.35f, 1);
    1450.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1451.                 }
    1452.                 else if (type == PokemonData.Type.POISON)
    1453.                 {
    1454.                     buttonMoveCover[i].color = new Color(0.63f, 0.25f, 0.63f, 1);
    1455.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1456.                 }
    1457.                 else if (type == PokemonData.Type.PSYCHIC)
    1458.                 {
    1459.                     buttonMoveCover[i].color = new Color(0.75f, 0.25f, 0.4f, 1);
    1460.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1461.                 }
    1462.                 else if (type == PokemonData.Type.ROCK)
    1463.                 {
    1464.                     buttonMoveCover[i].color = new Color(0.48f, 0.35f, 0.14f, 1);
    1465.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1466.                 }
    1467.                 else if (type == PokemonData.Type.STEEL)
    1468.                 {
    1469.                     buttonMoveCover[i].color = new Color(0.6f, 0.6f, 0.67f, 1);
    1470.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1471.                 }
    1472.                 else if (type == PokemonData.Type.WATER)
    1473.                 {
    1474.                     buttonMoveCover[i].color = new Color(0.25f, 0.42f, 0.75f, 1);
    1475.                     buttonMoveType[i].sprite = Resources.Load<Sprite>("PCSprites/type" + type.ToString());
    1476.                 }
    1477.  
    1478.                 buttonMoveName[i].text = moveset[i];
    1479.                 buttonMoveNameShadow[i].text = buttonMoveName[i].text;
    1480.                 buttonMovePP[i].text = PP[i] + "/" + maxPP[i];
    1481.                 buttonMovePPShadow[i].text = buttonMovePP[i].text;
    1482.             }
    1483.             else
    1484.             {
    1485.                 buttonMoveCover[i].color = new Color(0.5f, 0.5f, 0.5f, 1);
    1486.                 buttonMoveType[i].sprite = Resources.Load<Sprite>("null");
    1487.                 buttonMoveName[i].text = "";
    1488.                 buttonMoveNameShadow[i].text = buttonMoveName[i].text;
    1489.                 buttonMovePP[i].text = "";
    1490.                 buttonMovePPShadow[i].text = buttonMovePP[i].text;
    1491.             }
    1492.         }
    1493.     }
    1494.  
    1495.     /// Updates the Item List to show the correct 8 items from the page
    1496.     private void updateItemListDisplay()
    1497.     {
    1498.         if (itemListPageCount < 1)
    1499.         {
    1500.             itemListPageCount = 1;
    1501.         }
    1502.         itemListPageNumber.text = (itemListPagePosition + 1) + "/" + itemListPageCount;
    1503.         itemListPageNumberShadow.text = itemListPageNumber.text;
    1504.  
    1505.         if (itemListPagePosition > 0)
    1506.         {
    1507.             itemListArrowPrev.SetActive(true);
    1508.         }
    1509.         else
    1510.         {
    1511.             itemListArrowPrev.SetActive(false);
    1512.         }
    1513.  
    1514.         if (itemListPagePosition + 1 < itemListPageCount)
    1515.         {
    1516.             itemListArrowNext.SetActive(true);
    1517.         }
    1518.         else
    1519.         {
    1520.             itemListArrowNext.SetActive(false);
    1521.         }
    1522.  
    1523.         string[] itemListPageString = new string[8];
    1524.         for (int i = 0; i < 8; i++)
    1525.         {
    1526.             if (i + (itemListPagePosition * 8) < itemListString.Length)
    1527.             {
    1528.                 itemListPageString[i] = itemListString[i + (itemListPagePosition * 8)];
    1529.             }
    1530.         }
    1531.  
    1532.         for (int i = 0; i < 8; i++)
    1533.         {
    1534.             if (itemListPageString[i] != null)
    1535.             {
    1536.                 buttonItemList[i].gameObject.SetActive(true);
    1537.                 itemListIcon[i].sprite = Resources.Load<Sprite>("Items/" + itemListPageString[i]);
    1538.                 itemListName[i].text = itemListPageString[i];
    1539.                 itemListNameShadow[i].text = itemListName[i].text;
    1540.                 itemListQuantity[i].text = "" + SaveData.currentSave.Bag.getQuantity(itemListPageString[i]);
    1541.                 itemListQuantityShadow[i].text = itemListQuantity[i].text;
    1542.             }
    1543.             else
    1544.             {
    1545.                 buttonItemList[i].gameObject.SetActive(false);
    1546.             }
    1547.         }
    1548.     }
    1549.  
    1550.     /// updates the pokemon slots to show the correct pokemon in the player's party
    1551.     private void updatePokemonSlotsDisplay()
    1552.     {
    1553.         for (int i = 0; i < 6; i++)
    1554.         {
    1555.             Pokemon selectedPokemon = SaveData.currentSave.PC.boxes[0][i];
    1556.             if (selectedPokemon == null)
    1557.             {
    1558.                 buttonPokemonSlot[i].gameObject.SetActive(false);
    1559.             }
    1560.             else
    1561.             {
    1562.                 buttonPokemonSlot[i].gameObject.SetActive(true);
    1563.                 if (i == 0)
    1564.                 {
    1565.                     if (i == pokePartyPosition)
    1566.                     {
    1567.                         if (selectedPokemon.getStatus() != Pokemon.Status.FAINTED)
    1568.                         {
    1569.                             buttonPokemonSlot[i].sprite = buttonPokemonRoundSelTex;
    1570.                         }
    1571.                         else
    1572.                         {
    1573.                             buttonPokemonSlot[i].sprite = buttonPokemonRoundFntSelTex;
    1574.                         }
    1575.                     }
    1576.                     else
    1577.                     {
    1578.                         if (selectedPokemon.getStatus() != Pokemon.Status.FAINTED)
    1579.                         {
    1580.                             buttonPokemonSlot[i].sprite = buttonPokemonRoundTex;
    1581.                         }
    1582.                         else
    1583.                         {
    1584.                             buttonPokemonSlot[i].sprite = buttonPokemonRoundFntTex;
    1585.                         }
    1586.                     }
    1587.                 }
    1588.                 else
    1589.                 {
    1590.                     if (i == pokePartyPosition)
    1591.                     {
    1592.                         if (selectedPokemon.getStatus() != Pokemon.Status.FAINTED)
    1593.                         {
    1594.                             buttonPokemonSlot[i].sprite = buttonPokemonSelTex;
    1595.                         }
    1596.                         else
    1597.                         {
    1598.                             buttonPokemonSlot[i].sprite = buttonPokemonFntSelTex;
    1599.                         }
    1600.                     }
    1601.                     else
    1602.                     {
    1603.                         if (selectedPokemon.getStatus() != Pokemon.Status.FAINTED)
    1604.                         {
    1605.                             buttonPokemonSlot[i].sprite = buttonPokemonTex;
    1606.                         }
    1607.                         else
    1608.                         {
    1609.                             buttonPokemonSlot[i].sprite = buttonPokemonFntTex;
    1610.                         }
    1611.                     }
    1612.                 }
    1613.                 pokemonIconAnim[i] = selectedPokemon.GetIcons_();
    1614.                 pokemonSlotIcon[i].sprite = pokemonIconAnim[i][0];
    1615.                 pokemonSlotName[i].text = selectedPokemon.getName();
    1616.                 pokemonSlotNameShadow[i].text = pokemonSlotName[i].text;
    1617.                 if (selectedPokemon.getGender() == Pokemon.Gender.FEMALE)
    1618.                 {
    1619.                     pokemonSlotGender[i].text = "♀";
    1620.                     pokemonSlotGender[i].color = new Color(1, 0.2f, 0.2f, 1);
    1621.                 }
    1622.                 else if (selectedPokemon.getGender() == Pokemon.Gender.MALE)
    1623.                 {
    1624.                     pokemonSlotGender[i].text = "♂";
    1625.                     pokemonSlotGender[i].color = new Color(0.2f, 0.4f, 1, 1);
    1626.                 }
    1627.                 else
    1628.                 {
    1629.                     pokemonSlotGender[i].text = null;
    1630.                 }
    1631.                 pokemonSlotGenderShadow[i].text = pokemonSlotGender[i].text;
    1632.                 pokemonSlotHPBar[i].rectTransform.sizeDelta =
    1633.                     new Vector2(
    1634.                         Mathf.FloorToInt(48f *
    1635.                                          ((float) selectedPokemon.getCurrentHP() / (float) selectedPokemon.getHP())), 4);
    1636.  
    1637.                 setHPBarColor(pokemonSlotHPBar[i], 48f);
    1638.  
    1639.                 pokemonSlotLevel[i].text = "" + selectedPokemon.getLevel();
    1640.                 pokemonSlotLevelShadow[i].text = pokemonSlotLevel[i].text;
    1641.                 pokemonSlotCurrentHP[i].text = "" + selectedPokemon.getCurrentHP();
    1642.                 pokemonSlotCurrentHPShadow[i].text = pokemonSlotCurrentHP[i].text;
    1643.                 pokemonSlotMaxHP[i].text = "" + selectedPokemon.getHP();
    1644.                 pokemonSlotMaxHPShadow[i].text = pokemonSlotMaxHP[i].text;
    1645.                 if (selectedPokemon.getStatus() != Pokemon.Status.NONE)
    1646.                 {
    1647.                     pokemonSlotStatus[i].sprite =
    1648.                         Resources.Load<Sprite>("PCSprites/status" + selectedPokemon.getStatus().ToString());
    1649.                 }
    1650.                 else
    1651.                 {
    1652.                     pokemonSlotStatus[i].sprite = Resources.Load<Sprite>("null");
    1653.                 }
    1654.                 pokemonSlotItem[i].enabled = !string.IsNullOrEmpty(selectedPokemon.getHeldItem());
    1655.             }
    1656.         }
    1657.     }
    1658.  
    1659.     private void updatePokemonSummaryDisplay(Pokemon selectedPokemon)
    1660.     {
    1661.         pokemonSelectedIcon.sprite = selectedPokemon.GetIcons_()[0];
    1662.         pokemonSelectedName.text = selectedPokemon.getName();
    1663.         pokemonSelectedNameShadow.text = pokemonSelectedName.text;
    1664.         if (selectedPokemon.getGender() == Pokemon.Gender.FEMALE)
    1665.         {
    1666.             pokemonSelectedGender.text = "♀";
    1667.             pokemonSelectedGender.color = new Color(1, 0.2f, 0.2f, 1);
    1668.         }
    1669.         else if (selectedPokemon.getGender() == Pokemon.Gender.MALE)
    1670.         {
    1671.             pokemonSelectedGender.text = "♂";
    1672.             pokemonSelectedGender.color = new Color(0.2f, 0.4f, 1, 1);
    1673.         }
    1674.         else
    1675.         {
    1676.             pokemonSelectedGender.text = null;
    1677.         }
    1678.         pokemonSelectedGenderShadow.text = pokemonSelectedGender.text;
    1679.         pokemonSelectedLevel.text = "" + selectedPokemon.getLevel();
    1680.         pokemonSelectedLevelShadow.text = pokemonSelectedLevel.text;
    1681.         if (selectedPokemon.getStatus() != Pokemon.Status.NONE)
    1682.         {
    1683.             pokemonSelectedStatus.sprite =
    1684.                 Resources.Load<Sprite>("PCSprites/status" + selectedPokemon.getStatus().ToString());
    1685.         }
    1686.         else
    1687.         {
    1688.             pokemonSelectedStatus.sprite = Resources.Load<Sprite>("null");
    1689.         }
    1690.         pokemonSelectedType1.sprite = Resources.Load<Sprite>("null");
    1691.         pokemonSelectedType2.sprite = Resources.Load<Sprite>("null");
    1692.         PokemonData.Type type1 = PokemonDatabase.getPokemon(selectedPokemon.getID()).getType1();
    1693.         PokemonData.Type type2 = PokemonDatabase.getPokemon(selectedPokemon.getID()).getType2();
    1694.         if (type1 != PokemonData.Type.NONE)
    1695.         {
    1696.             pokemonSelectedType1.sprite = Resources.Load<Sprite>("PCSprites/type" + type1.ToString());
    1697.         }
    1698.         if (type2 != PokemonData.Type.NONE)
    1699.         {
    1700.             pokemonSelectedType2.sprite = Resources.Load<Sprite>("PCSprites/type" + type2.ToString());
    1701.         }
    1702.  
    1703.         //Summary
    1704.         float expCurrentLevel =
    1705.             PokemonDatabase.getLevelExp(PokemonDatabase.getPokemon(selectedPokemon.getID()).getLevelingRate(),
    1706.                 selectedPokemon.getLevel());
    1707.         float expNextlevel =
    1708.             PokemonDatabase.getLevelExp(PokemonDatabase.getPokemon(selectedPokemon.getID()).getLevelingRate(),
    1709.                 selectedPokemon.getLevel() + 1);
    1710.         float expAlong = selectedPokemon.getExp() - expCurrentLevel;
    1711.         float expDistance = expAlong / (expNextlevel - expCurrentLevel);
    1712.         pokemonSummaryNextLevelEXP.text = "" + (expNextlevel - selectedPokemon.getExp());
    1713.         pokemonSummaryNextLevelEXPShadow.text = pokemonSummaryNextLevelEXP.text;
    1714.         pokemonSummaryEXPBar.rectTransform.sizeDelta = new Vector2(Mathf.Floor(expDistance * 64), 3f);
    1715.         pokemonSummaryItemIcon.sprite = Resources.Load<Sprite>("null");
    1716.         pokemonSummaryItemName.text = "No held item.";
    1717.         if (!string.IsNullOrEmpty(selectedPokemon.getHeldItem()))
    1718.         {
    1719.             pokemonSummaryItemIcon.sprite = Resources.Load<Sprite>("Items/" + selectedPokemon.getHeldItem());
    1720.             pokemonSummaryItemName.text = selectedPokemon.getHeldItem();
    1721.         }
    1722.  
    1723.         pokemonSummaryItemNameShadow.text = pokemonSummaryItemName.text;
    1724.         //Stats
    1725.         float currentHP = selectedPokemon.getCurrentHP();
    1726.         float maxHP = selectedPokemon.getHP();
    1727.         pokemonSummaryHP.text = currentHP + "/" + maxHP;
    1728.         pokemonSummaryHPShadow.text = pokemonSummaryHP.text;
    1729.         pokemonSummaryHPBar.rectTransform.sizeDelta = new Vector2(Mathf.Floor((1 - (maxHP - currentHP) / maxHP) * 48f),
    1730.             4f);
    1731.  
    1732.         setHPBarColor(pokemonSummaryHPBar, 48f);
    1733.  
    1734.         float[] natureMod = new float[]
    1735.         {
    1736.             NatureDatabase.getNature(selectedPokemon.getNature()).getATK(),
    1737.             NatureDatabase.getNature(selectedPokemon.getNature()).getDEF(),
    1738.             NatureDatabase.getNature(selectedPokemon.getNature()).getSPA(),
    1739.             NatureDatabase.getNature(selectedPokemon.getNature()).getSPD(),
    1740.             NatureDatabase.getNature(selectedPokemon.getNature()).getSPE()
    1741.         };
    1742.         pokemonSummaryStats.text =
    1743.             selectedPokemon.getATK() + "\n" +
    1744.             selectedPokemon.getDEF() + "\n" +
    1745.             selectedPokemon.getSPA() + "\n" +
    1746.             selectedPokemon.getSPD() + "\n" +
    1747.             selectedPokemon.getSPE();
    1748.         pokemonSummaryStatsShadow.text = pokemonSummaryStats.text;
    1749.  
    1750.         string[] statsLines = new string[] {"Attack", "Defence", "Sp. Atk", "Sp. Def", "Speed"};
    1751.         pokemonSummaryStatsTextShadow.text = "";
    1752.         for (int i = 0; i < 5; i++)
    1753.         {
    1754.             if (natureMod[i] > 1)
    1755.             {
    1756.                 pokemonSummaryStatsTextShadow.text += "<color=#A01010FF>" + statsLines[i] + "</color>\n";
    1757.             }
    1758.             else if (natureMod[i] < 1)
    1759.             {
    1760.                 pokemonSummaryStatsTextShadow.text += "<color=#0030A2FF>" + statsLines[i] + "</color>\n";
    1761.             }
    1762.             else
    1763.             {
    1764.                 pokemonSummaryStatsTextShadow.text += statsLines[i] + "\n";
    1765.             }
    1766.         }
    1767.  
    1768.         pokemonSummaryAbilityName.text =
    1769.             PokemonDatabase.getPokemon(selectedPokemon.getID()).getAbility(selectedPokemon.getAbility());
    1770.         pokemonSummaryAbilityNameShadow.text = pokemonSummaryAbilityName.text;
    1771.         //abilities not yet implemented
    1772.         pokemonSummaryAbilityDescription.text = "";
    1773.         pokemonSummaryAbilityDescriptionShadow.text = pokemonSummaryAbilityDescription.text;
    1774.  
    1775.         //Moves
    1776.         string[] moveset = selectedPokemon.getMoveset();
    1777.         int[] maxPP = selectedPokemon.getMaxPP();
    1778.         int[] PP = selectedPokemon.getPP();
    1779.         for (int i = 0; i < 4; i++)
    1780.         {
    1781.             if (moveset[i] != null)
    1782.             {
    1783.                 pokemonMovesName[i].text = moveset[i];
    1784.                 pokemonMovesNameShadow[i].text = pokemonMovesName[i].text;
    1785.                 pokemonMovesType[i].sprite =
    1786.                     Resources.Load<Sprite>("PCSprites/type" + MoveDatabase.getMove(moveset[i]).getType().ToString());
    1787.                 pokemonMovesPPText[i].text = "PP";
    1788.                 pokemonMovesPPTextShadow[i].text = pokemonMovesPPText[i].text;
    1789.                 pokemonMovesPP[i].text = PP[i] + "/" + maxPP[i];
    1790.                 pokemonMovesPPShadow[i].text = pokemonMovesPP[i].text;
    1791.             }
    1792.             else
    1793.             {
    1794.                 pokemonMovesName[i].text = null;
    1795.                 pokemonMovesNameShadow[i].text = pokemonMovesName[i].text;
    1796.                 pokemonMovesType[i].sprite = Resources.Load<Sprite>("null");
    1797.                 pokemonMovesPPText[i].text = null;
    1798.                 pokemonMovesPPTextShadow[i].text = pokemonMovesPPText[i].text;
    1799.                 pokemonMovesPP[i].text = null;
    1800.                 pokemonMovesPPShadow[i].text = pokemonMovesPP[i].text;
    1801.             }
    1802.         }
    1803.     }
    1804.  
    1805.     private void updateSelectedTask(int newPosition)
    1806.     {
    1807.         taskPosition = newPosition;
    1808.  
    1809.         buttonBag.sprite = (taskPosition == 0 || taskPosition == 3) ? buttonBagSelTex : buttonBagTex;
    1810.         buttonFight.sprite = (taskPosition == 1) ? buttonFightSelTex : buttonFightTex;
    1811.         buttonPoke.sprite = (taskPosition == 2 || taskPosition == 5) ? buttonPokeSelTex : buttonPokeTex;
    1812.         buttonRun.sprite = (taskPosition == 4) ? buttonRunSelTex : buttonRunTex;
    1813.     }
    1814.  
    1815.     private void updateSelectedMove(int newPosition)
    1816.     {
    1817.         movePosition = newPosition;
    1818.  
    1819.         if (movePosition == 0)
    1820.         {
    1821.             buttonMegaEvolution.sprite = buttonMegaActiveSelTex;
    1822.         }
    1823.         else
    1824.         {
    1825.             buttonMegaEvolution.sprite = (canMegaEvolve) ? buttonMegaActiveTex : buttonMegaTex;
    1826.         }
    1827.  
    1828.         buttonMove[0].sprite = (movePosition == 1) ? buttonMoveBackgroundSelTex : buttonMoveBackgroundTex;
    1829.         buttonMove[1].sprite = (movePosition == 2) ? buttonMoveBackgroundSelTex : buttonMoveBackgroundTex;
    1830.         buttonMoveReturn.sprite = (movePosition == 3) ? buttonReturnSelTex : buttonReturnTex;
    1831.         buttonMove[2].sprite = (movePosition == 4) ? buttonMoveBackgroundSelTex : buttonMoveBackgroundTex;
    1832.         buttonMove[3].sprite = (movePosition == 5) ? buttonMoveBackgroundSelTex : buttonMoveBackgroundTex;
    1833.     }
    1834.  
    1835.     private void updateSelectedBagCategory(int newPosition)
    1836.     {
    1837.         bagCategoryPosition = newPosition;
    1838.  
    1839.         for (int i = 0; i < 6; i++)
    1840.         {
    1841.             if (i != bagCategoryPosition)
    1842.             {
    1843.                 //deselect
    1844.                 if (i == 4)
    1845.                 {
    1846.                     buttonBackBag.sprite = buttonBackBagTex;
    1847.                 }
    1848.                 else if (i < 4)
    1849.                 {
    1850.                     buttonItemCategory[i].sprite = buttonBagItemCategoryTex;
    1851.                 }
    1852.                 else
    1853.                 {
    1854.                     buttonItemLastUsed.sprite = buttonBlueTex;
    1855.                 }
    1856.             }
    1857.             else
    1858.             {
    1859.                 //select
    1860.                 if (i == 4)
    1861.                 {
    1862.                     buttonBackBag.sprite = buttonBackBagSelTex;
    1863.                 }
    1864.                 else if (i < 4)
    1865.                 {
    1866.                     buttonItemCategory[i].sprite = buttonBagItemCategorySelTex;
    1867.                 }
    1868.                 else
    1869.                 {
    1870.                     buttonItemLastUsed.sprite = buttonBlueSelTex;
    1871.                 }
    1872.             }
    1873.         }
    1874.     }
    1875.  
    1876.     private int updateSelectedItemListSlot(int currentPosition, int modifier)
    1877.     {
    1878.         int newPosition = currentPosition + modifier;
    1879.  
    1880.         //adjust for empty slots
    1881.         if (newPosition < 8)
    1882.         {
    1883.             if (!buttonItemList[newPosition].gameObject.activeSelf)
    1884.             {
    1885.                 bool spaceFound = false;
    1886.                 int checkPosition = currentPosition;
    1887.                 //keep going back by modifier until avaiable position found
    1888.                 while (!spaceFound)
    1889.                 {
    1890.                     checkPosition += modifier;
    1891.                     if (checkPosition < 0)
    1892.                     {
    1893.                         if (buttonItemList[0].gameObject.activeSelf)
    1894.                         {
    1895.                             newPosition = 0; //move to first button
    1896.                         }
    1897.                         else
    1898.                         {
    1899.                             newPosition = 8; //move to back button
    1900.                         }
    1901.                         spaceFound = true;
    1902.                     }
    1903.                     else if (checkPosition > 7)
    1904.                     {
    1905.                         newPosition = 8; //set position to Back button
    1906.                         spaceFound = true;
    1907.                     }
    1908.                     else if (buttonItemList[checkPosition].gameObject.activeSelf)
    1909.                     {
    1910.                         newPosition = checkPosition; //adjust the position
    1911.                         spaceFound = true;
    1912.                     }
    1913.                     if (modifier == 0)
    1914.                     {
    1915.                         modifier = 1; //prevent infinite loops in case the modifier is set to never increment
    1916.                     }
    1917.                 }
    1918.             }
    1919.         }
    1920.         else
    1921.         {
    1922.             newPosition = 8;
    1923.         }
    1924.  
    1925.         for (int i = 0; i < 8; i++)
    1926.         {
    1927.             if (i == newPosition)
    1928.             {
    1929.                 buttonItemList[i].sprite = buttonBagItemListSelTex;
    1930.                 buttonItemList[i].rectTransform.SetSiblingIndex(7);
    1931.             }
    1932.             else
    1933.             {
    1934.                 buttonItemList[i].sprite = buttonBagItemListTex;
    1935.             }
    1936.         }
    1937.         if (newPosition == 8)
    1938.         {
    1939.             buttonBackBag.sprite = buttonBackBagSelTex;
    1940.         }
    1941.         else
    1942.         {
    1943.             buttonBackBag.sprite = buttonBackBagTex;
    1944.         }
    1945.  
    1946.         if (newPosition + (itemListPagePosition * 8) < itemListString.Length)
    1947.         {
    1948.             itemListDescription.text =
    1949.                 ItemDatabase.getItem(itemListString[newPosition + (itemListPagePosition * 8)]).getDescription();
    1950.         }
    1951.         else
    1952.         {
    1953.             itemListDescription.text = "";
    1954.         }
    1955.         itemListDescriptionShadow.text = itemListDescription.text;
    1956.  
    1957.         return newPosition;
    1958.     }
    1959.  
    1960.     private void updateSelectedPokemonSlot(int newPosition)
    1961.     {
    1962.         updateSelectedPokemonSlot(newPosition, true);
    1963.     }
    1964.  
    1965.     private void updateSelectedPokemonSlot(int newPosition, bool backSelectable)
    1966.     {
    1967.         int maxPosition = 5;
    1968.         if (backSelectable)
    1969.         {
    1970.             maxPosition = 6;
    1971.         }
    1972.         if (newPosition < 6)
    1973.         {
    1974.             if (SaveData.currentSave.PC.boxes[0][newPosition] == null)
    1975.             {
    1976.                 int checkPosition = pokePartyPosition;
    1977.                 bool spaceFound = false;
    1978.                 if (newPosition < pokePartyPosition)
    1979.                 {
    1980.                     //keep going back 1 until avaiable position found
    1981.                     while (!spaceFound)
    1982.                     {
    1983.                         checkPosition -= 1;
    1984.                         if (checkPosition < 0)
    1985.                         {
    1986.                             newPosition = pokePartyPosition; //don't move the position
    1987.                             spaceFound = true;
    1988.                         }
    1989.                         else if (SaveData.currentSave.PC.boxes[0][checkPosition] != null)
    1990.                         {
    1991.                             newPosition = checkPosition; //adjust the position
    1992.                             spaceFound = true;
    1993.                         }
    1994.                     }
    1995.                 }
    1996.                 else
    1997.                 {
    1998.                     //keep going forward 1
    1999.                     while (!spaceFound)
    2000.                     {
    2001.                         checkPosition += 1;
    2002.                         if (checkPosition > 5)
    2003.                         {
    2004.                             if (backSelectable)
    2005.                             {
    2006.                                 newPosition = 6;
    2007.                             } //set position to Back button
    2008.                             else
    2009.                             {
    2010.                                 newPosition = 5;
    2011.                                 while (SaveData.currentSave.PC.boxes[0][newPosition] == null && newPosition > 0)
    2012.                                 {
    2013.                                     newPosition -= 1;
    2014.                                 }
    2015.                             }
    2016.                             spaceFound = true;
    2017.                         }
    2018.                         else if (SaveData.currentSave.PC.boxes[0][checkPosition] != null)
    2019.                         {
    2020.                             newPosition = checkPosition; //adjust the position
    2021.                             spaceFound = true;
    2022.                         }
    2023.                     }
    2024.                 }
    2025.             }
    2026.         }
    2027.         else
    2028.         {
    2029.             newPosition = maxPosition;
    2030.             if (newPosition < 6)
    2031.             {
    2032.                 if (SaveData.currentSave.PC.boxes[0][newPosition] == null)
    2033.                 {
    2034.                     int checkPosition = pokePartyPosition;
    2035.                     bool spaceFound = false;
    2036.                     if (newPosition < pokePartyPosition)
    2037.                     {
    2038.                         //keep going back 1 until avaiable position found
    2039.                         while (!spaceFound)
    2040.                         {
    2041.                             checkPosition -= 1;
    2042.                             if (checkPosition < 0)
    2043.                             {
    2044.                                 newPosition = pokePartyPosition; //don't move the position
    2045.                                 spaceFound = true;
    2046.                             }
    2047.                             else if (SaveData.currentSave.PC.boxes[0][checkPosition] != null)
    2048.                             {
    2049.                                 newPosition = checkPosition; //adjust the position
    2050.                                 spaceFound = true;
    2051.                             }
    2052.                         }
    2053.                     }
    2054.                 }
    2055.             }
    2056.         }
    2057.  
    2058.         pokePartyPosition = newPosition;
    2059.  
    2060.         for (int i = 0; i < 7; i++)
    2061.         {
    2062.             if (i != pokePartyPosition)
    2063.             {
    2064.                 //unhighlight
    2065.                 if (i == 0)
    2066.                 {
    2067.                     if (SaveData.currentSave.PC.boxes[0][i] != null)
    2068.                     {
    2069.                         buttonPokemonSlot[i].sprite = (SaveData.currentSave.PC.boxes[0][i].getStatus() !=
    2070.                                                        Pokemon.Status.FAINTED)
    2071.                             ? buttonPokemonRoundTex
    2072.                             : buttonPokemonRoundFntTex;
    2073.                     }
    2074.                 }
    2075.                 else if (i < 6)
    2076.                 {
    2077.                     if (SaveData.currentSave.PC.boxes[0][i] != null)
    2078.                     {
    2079.                         buttonPokemonSlot[i].sprite = (SaveData.currentSave.PC.boxes[0][i].getStatus() !=
    2080.                                                        Pokemon.Status.FAINTED)
    2081.                             ? buttonPokemonTex
    2082.                             : buttonPokemonFntTex;
    2083.                     }
    2084.                 }
    2085.                 else
    2086.                 {
    2087.                     buttonBackPoke.sprite = buttonBackPokeTex;
    2088.                 }
    2089.             }
    2090.             else
    2091.             {
    2092.                 //highlight
    2093.                 if (i == 0)
    2094.                 {
    2095.                     if (SaveData.currentSave.PC.boxes[0][i] != null)
    2096.                     {
    2097.                         buttonPokemonSlot[i].sprite = (SaveData.currentSave.PC.boxes[0][i].getStatus() !=
    2098.                                                        Pokemon.Status.FAINTED)
    2099.                             ? buttonPokemonRoundSelTex
    2100.                             : buttonPokemonRoundFntSelTex;
    2101.                     }
    2102.                 }
    2103.                 else if (i < 6)
    2104.                 {
    2105.                     if (SaveData.currentSave.PC.boxes[0][i] != null)
    2106.                     {
    2107.                         buttonPokemonSlot[i].sprite = (SaveData.currentSave.PC.boxes[0][i].getStatus() !=
    2108.                                                        Pokemon.Status.FAINTED)
    2109.                             ? buttonPokemonSelTex
    2110.                             : buttonPokemonFntSelTex;
    2111.                     }
    2112.                 }
    2113.                 else
    2114.                 {
    2115.                     buttonBackPoke.sprite = buttonBackPokeSelTex;
    2116.                 }
    2117.             }
    2118.         }
    2119.     }
    2120.  
    2121.     private int updateSummaryPosition(int newPosition)
    2122.     {
    2123.         buttonSwitch.sprite = (newPosition == 0) ? buttonBlueSelTex : buttonBlueTex;
    2124.         buttonCheck.sprite = (newPosition == 1) ? buttonBlueSelTex : buttonBlueTex;
    2125.         buttonBackPoke.sprite = (newPosition == 2) ? buttonBackPokeSelTex : buttonBackPokeTex;
    2126.         return newPosition;
    2127.     }
    2128.  
    2129.     private int updateMovesPosition(int newPosition)
    2130.     {
    2131.         Vector3[] positions = new Vector3[]
    2132.         {
    2133.             new Vector3(-36, 51, 0), new Vector3(51, 51, 0),
    2134.             new Vector3(-36, 19, 0), new Vector3(51, 19, 0)
    2135.         };
    2136.  
    2137.         buttonSwitch.sprite = buttonBlueTex;
    2138.         buttonCheck.sprite = buttonBlueTex;
    2139.         buttonBackPoke.sprite = buttonBackPokeTex;
    2140.  
    2141.         if (newPosition < 4)
    2142.         {
    2143.             string[] moveset = SaveData.currentSave.PC.boxes[0][pokePartyPosition].getMoveset();
    2144.             if (string.IsNullOrEmpty(moveset[newPosition]))
    2145.             {
    2146.                 pokemonMovesSelectedCategory.sprite = Resources.Load<Sprite>("null");
    2147.                 pokemonMovesSelectedPower.text = null;
    2148.                 pokemonMovesSelectedPowerShadow.text = pokemonMovesSelectedPower.text;
    2149.                 pokemonMovesSelectedAccuracy.text = null;
    2150.                 pokemonMovesSelectedAccuracyShadow.text = pokemonMovesSelectedAccuracy.text;
    2151.                 pokemonMovesSelectedDescription.text = null;
    2152.                 pokemonMovesSelectedDescriptionShadow.text = pokemonMovesSelectedDescription.text;
    2153.             }
    2154.             else
    2155.             {
    2156.                 MoveData selectedMove = MoveDatabase.getMove(moveset[newPosition]);
    2157.                 pokemonMovesSelectedCategory.sprite =
    2158.                     Resources.Load<Sprite>("PCSprites/category" + selectedMove.getCategory().ToString());
    2159.                 pokemonMovesSelectedPower.text = "" + selectedMove.getPower();
    2160.                 if (pokemonMovesSelectedPower.text == "0")
    2161.                 {
    2162.                     pokemonMovesSelectedPower.text = "-";
    2163.                 }
    2164.                 pokemonMovesSelectedPowerShadow.text = pokemonMovesSelectedPower.text;
    2165.                 pokemonMovesSelectedAccuracy.text = "" + Mathf.Round(selectedMove.getAccuracy() * 100f);
    2166.                 if (pokemonMovesSelectedAccuracy.text == "0")
    2167.                 {
    2168.                     pokemonMovesSelectedAccuracy.text = "-";
    2169.                 }
    2170.                 pokemonMovesSelectedAccuracyShadow.text = pokemonMovesSelectedAccuracy.text;
    2171.                 pokemonMovesSelectedDescription.text = selectedMove.getDescription();
    2172.                 pokemonMovesSelectedDescriptionShadow.text = pokemonMovesSelectedDescription.text;
    2173.  
    2174.                 pokemonMovesSelectedMove.rectTransform.localPosition = positions[newPosition];
    2175.                 pokemonMovesSelectedMove.enabled = true;
    2176.                 if (pokemonMovesSelector.enabled)
    2177.                 {
    2178.                     StartCoroutine(moveMoveSelector(positions[newPosition]));
    2179.                 }
    2180.                 else
    2181.                 {
    2182.                     pokemonMovesSelector.enabled = true;
    2183.                     pokemonMovesSelector.rectTransform.localPosition = positions[newPosition];
    2184.                 }
    2185.             }
    2186.         }
    2187.         else
    2188.         {
    2189.             pokemonMovesSelectedCategory.sprite = Resources.Load<Sprite>("null");
    2190.             pokemonMovesSelectedPower.text = null;
    2191.             pokemonMovesSelectedPowerShadow.text = pokemonMovesSelectedPower.text;
    2192.             pokemonMovesSelectedAccuracy.text = null;
    2193.             pokemonMovesSelectedAccuracyShadow.text = pokemonMovesSelectedAccuracy.text;
    2194.             pokemonMovesSelectedDescription.text = null;
    2195.             pokemonMovesSelectedDescriptionShadow.text = pokemonMovesSelectedDescription.text;
    2196.  
    2197.             pokemonMovesSelectedMove.enabled = false;
    2198.             pokemonMovesSelector.enabled = false;
    2199.             if (newPosition == 4)
    2200.             {
    2201.                 buttonSwitch.sprite = buttonBlueSelTex;
    2202.             }
    2203.             else if (newPosition == 5)
    2204.             {
    2205.                 buttonCheck.sprite = buttonBlueSelTex;
    2206.             }
    2207.             else if (newPosition == 6)
    2208.             {
    2209.                 buttonBackPoke.sprite = buttonBackPokeSelTex;
    2210.             }
    2211.         }
    2212.         return newPosition;
    2213.     }
    2214.  
    2215.     private IEnumerator moveMoveSelector(Vector3 destinationPosition)
    2216.     {
    2217.         Vector3 startPosition = pokemonMovesSelector.rectTransform.localPosition;
    2218.  
    2219.         Vector3 distance = destinationPosition - startPosition;
    2220.  
    2221.         float increment = 0f;
    2222.         float speed = 0.2f;
    2223.         while (increment < 1)
    2224.         {
    2225.             increment += (1f / speed) * Time.deltaTime;
    2226.             if (increment > 1)
    2227.             {
    2228.                 increment = 1;
    2229.             }
    2230.             pokemonMovesSelector.rectTransform.localPosition = startPosition + (distance * increment);
    2231.             yield return null;
    2232.         }
    2233.     }
    2234.  
    2235.  
    2236.     private void setHPBarColor(Image bar, float maxSize)
    2237.     {
    2238.         if (bar.rectTransform.sizeDelta.x < maxSize / 4f)
    2239.         {
    2240.             bar.color = new Color(0.625f, 0.125f, 0, 1);
    2241.         }
    2242.         else if (bar.rectTransform.sizeDelta.x < maxSize / 2f)
    2243.         {
    2244.             bar.color = new Color(0.687f, 0.562f, 0, 1);
    2245.         }
    2246.         else
    2247.         {
    2248.             bar.color = new Color(0.125f, 0.625f, 0, 1);
    2249.         }
    2250.     }
    2251.  
    2252.     //////////////////////////////////
    2253.  
    2254.  
    2255.     //////////////////////////////////
    2256.     /// BATTLE DATA MANAGEMENT
    2257.     //
    2258.     /// Calculates the base damage of an attack (before modifiers are applied).
    2259.     private float calculateDamage(int attackerPosition, int targetPosition, MoveData move)
    2260.     {
    2261.         float baseDamage = 0;
    2262.         if (move.getCategory() == MoveData.Category.PHYSICAL)
    2263.         {
    2264.             baseDamage = ((2f * (float) pokemon[attackerPosition].getLevel() + 10f) / 250f) *
    2265.                          ((float) pokemonStats[0][attackerPosition] / (float) pokemonStats[1][targetPosition]) *
    2266.                          (float) move.getPower() + 2f;
    2267.         }
    2268.         else if (move.getCategory() == MoveData.Category.SPECIAL)
    2269.         {
    2270.             baseDamage = ((2f * (float) pokemon[attackerPosition].getLevel() + 10f) / 250f) *
    2271.                          ((float) pokemonStats[2][attackerPosition] / (float) pokemonStats[3][targetPosition]) *
    2272.                          (float) move.getPower() + 2f;
    2273.         }
    2274.  
    2275.         baseDamage *= Random.Range(0.85f, 1f);
    2276.         return baseDamage;
    2277.     }
    2278.  
    2279.     /// Uses the attacker's total critical ratio to randomly determine whether a Critical Hit should happen or not
    2280.     private bool calculateCritical(int attackerPosition, int targetPosition, MoveData move)
    2281.     {
    2282.         int attackerCriticalRatio = 0;
    2283.         if (focusEnergy[attackerPosition])
    2284.         {
    2285.             attackerCriticalRatio += 1;
    2286.         }
    2287.  
    2288.         if (move.hasMoveEffect(MoveData.Effect.Critical))
    2289.         {
    2290.             attackerCriticalRatio += 1;
    2291.         }
    2292.  
    2293.         bool applyCritical = false;
    2294.         if (move.getCategory() != MoveData.Category.STATUS)
    2295.         {
    2296.             if (attackerCriticalRatio == 0)
    2297.             {
    2298.                 if (Random.value <= 0.0625)
    2299.                 {
    2300.                     applyCritical = true;
    2301.                 }
    2302.             }
    2303.             else if (attackerCriticalRatio == 1)
    2304.             {
    2305.                 if (Random.value <= 0.125)
    2306.                 {
    2307.                     applyCritical = true;
    2308.                 }
    2309.             }
    2310.             else if (attackerCriticalRatio == 2)
    2311.             {
    2312.                 if (Random.value <= 0.5)
    2313.                 {
    2314.                     applyCritical = true;
    2315.                 }
    2316.             }
    2317.             else if (attackerCriticalRatio > 2)
    2318.             {
    2319.                 applyCritical = true;
    2320.             }
    2321.         }
    2322.  
    2323.         return applyCritical;
    2324.     }
    2325.  
    2326.  
    2327.     /// TEMPORARILY USED FOR EVERYTHING NOT COVERED BY AN EXISTING METHOD
    2328.     private float calculateModifiedDamage(int attackerPosition, int targetPosition, MoveData move, float baseDamage,
    2329.         bool applyCritical)
    2330.     {
    2331.         float modifiedDamage = baseDamage;
    2332.  
    2333.         //apply STAB
    2334.         if (pokemonType1[attackerPosition] == move.getType() ||
    2335.             pokemonType2[attackerPosition] == move.getType() ||
    2336.             pokemonType3[attackerPosition] == move.getType())
    2337.         {
    2338.             modifiedDamage *= 1.5f;
    2339.         }
    2340.  
    2341.         //apply Offence/Defence boosts
    2342.         if (move.getCategory() == MoveData.Category.PHYSICAL)
    2343.         {
    2344.             modifiedDamage *= calculateStatModifier(pokemonStatsMod[0][attackerPosition]);
    2345.             if (!applyCritical)
    2346.             {
    2347.                 //exclude defensive buffs in a critical hit
    2348.                 modifiedDamage /= calculateStatModifier(pokemonStatsMod[1][targetPosition]);
    2349.             }
    2350.         }
    2351.         else if (move.getCategory() == MoveData.Category.SPECIAL)
    2352.         {
    2353.             modifiedDamage *= calculateStatModifier(pokemonStatsMod[2][attackerPosition]);
    2354.             if (!applyCritical)
    2355.             {
    2356.                 //exclude defensive buffs in a critical hit
    2357.                 modifiedDamage /= calculateStatModifier(pokemonStatsMod[3][targetPosition]);
    2358.             }
    2359.         }
    2360.  
    2361.  
    2362.         //not yet implemented
    2363.         //apply held item
    2364.         //apply ability
    2365.         //apply field advantages
    2366.         //reflect/lightScreen
    2367.         if (!applyCritical)
    2368.         {
    2369.             if (move.getCategory() == MoveData.Category.PHYSICAL)
    2370.             {
    2371.                 if (reflectTurns[Mathf.FloorToInt((float) targetPosition / 3f)] > 0)
    2372.                 {
    2373.                     modifiedDamage *= 0.5f;
    2374.                 }
    2375.             }
    2376.             else if (move.getCategory() == MoveData.Category.SPECIAL)
    2377.             {
    2378.                 if (lightScreenTurns[Mathf.FloorToInt((float) targetPosition / 3f)] > 0)
    2379.                 {
    2380.                     modifiedDamage *= 0.5f;
    2381.                 }
    2382.             }
    2383.         }
    2384.  
    2385.         //apply multi-target debuff
    2386.  
    2387.         return Mathf.Floor(modifiedDamage);
    2388.     }
    2389.  
    2390.     private float calculateStatModifier(int modifier)
    2391.     {
    2392.         if (modifier > 0)
    2393.         {
    2394.             return ((2f + (float) modifier) / 2f);
    2395.         }
    2396.         else if (modifier < 0)
    2397.         {
    2398.             return (2f / (2f + Mathf.Abs((float) modifier)));
    2399.         }
    2400.         return 1f;
    2401.     }
    2402.  
    2403.     private float calculateAccuracyModifier(int modifier)
    2404.     {
    2405.         if (modifier > 0)
    2406.         {
    2407.             return ((3f + modifier) / 3f);
    2408.         }
    2409.         else if (modifier < 0)
    2410.         {
    2411.             return (3f / (3f + modifier));
    2412.         }
    2413.         return 1f;
    2414.     }
    2415.  
    2416.     /// returns the modifier of a type vs. type. returns as 0f-2f
    2417.     private float getSuperEffectiveModifier(PokemonData.Type attackingType, PokemonData.Type targetType)
    2418.     {
    2419.         if (attackingType == PokemonData.Type.BUG)
    2420.         {
    2421.             if (targetType == PokemonData.Type.DARK || targetType == PokemonData.Type.GRASS ||
    2422.                 targetType == PokemonData.Type.PSYCHIC)
    2423.             {
    2424.                 return 2f;
    2425.             }
    2426.             else if (targetType == PokemonData.Type.FAIRY || targetType == PokemonData.Type.FIGHTING ||
    2427.                      targetType == PokemonData.Type.FIRE || targetType == PokemonData.Type.FLYING ||
    2428.                      targetType == PokemonData.Type.GHOST || targetType == PokemonData.Type.POISON ||
    2429.                      targetType == PokemonData.Type.STEEL)
    2430.             {
    2431.                 return 0.5f;
    2432.             }
    2433.         }
    2434.         else if (attackingType == PokemonData.Type.DARK)
    2435.         {
    2436.             if (targetType == PokemonData.Type.GHOST || targetType == PokemonData.Type.PSYCHIC)
    2437.             {
    2438.                 return 2f;
    2439.             }
    2440.             else if (targetType == PokemonData.Type.DARK || targetType == PokemonData.Type.FAIRY ||
    2441.                      targetType == PokemonData.Type.FIGHTING)
    2442.             {
    2443.                 return 0.5f;
    2444.             }
    2445.         }
    2446.         else if (attackingType == PokemonData.Type.DRAGON)
    2447.         {
    2448.             if (targetType == PokemonData.Type.DRAGON)
    2449.             {
    2450.                 return 2f;
    2451.             }
    2452.             else if (targetType == PokemonData.Type.STEEL)
    2453.             {
    2454.                 return 0.5f;
    2455.             }
    2456.             else if (targetType == PokemonData.Type.FAIRY)
    2457.             {
    2458.                 return 0f;
    2459.             }
    2460.         }
    2461.         else if (attackingType == PokemonData.Type.ELECTRIC)
    2462.         {
    2463.             if (targetType == PokemonData.Type.FLYING || targetType == PokemonData.Type.WATER)
    2464.             {
    2465.                 return 2f;
    2466.             }
    2467.             else if (targetType == PokemonData.Type.DRAGON || targetType == PokemonData.Type.ELECTRIC ||
    2468.                      targetType == PokemonData.Type.GRASS)
    2469.             {
    2470.                 return 0.5f;
    2471.             }
    2472.             else if (targetType == PokemonData.Type.GROUND)
    2473.             {
    2474.                 return 0f;
    2475.             }
    2476.         }
    2477.         else if (attackingType == PokemonData.Type.FAIRY)
    2478.         {
    2479.             if (targetType == PokemonData.Type.DARK || targetType == PokemonData.Type.DRAGON ||
    2480.                 targetType == PokemonData.Type.FIGHTING)
    2481.             {
    2482.                 return 2f;
    2483.             }
    2484.             else if (targetType == PokemonData.Type.FIRE || targetType == PokemonData.Type.POISON ||
    2485.                      targetType == PokemonData.Type.STEEL)
    2486.             {
    2487.                 return 0.5f;
    2488.             }
    2489.         }
    2490.         else if (attackingType == PokemonData.Type.FIGHTING)
    2491.         {
    2492.             if (targetType == PokemonData.Type.DARK || targetType == PokemonData.Type.ICE ||
    2493.                 targetType == PokemonData.Type.NORMAL || targetType == PokemonData.Type.ROCK ||
    2494.                 targetType == PokemonData.Type.STEEL)
    2495.             {
    2496.                 return 2f;
    2497.             }
    2498.             else if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.FAIRY ||
    2499.                      targetType == PokemonData.Type.FLYING || targetType == PokemonData.Type.POISON ||
    2500.                      targetType == PokemonData.Type.PSYCHIC)
    2501.             {
    2502.                 return 0.5f;
    2503.             }
    2504.             else if (targetType == PokemonData.Type.GHOST)
    2505.             {
    2506.                 return 0f;
    2507.             }
    2508.         }
    2509.         else if (attackingType == PokemonData.Type.FIRE)
    2510.         {
    2511.             if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.GRASS ||
    2512.                 targetType == PokemonData.Type.ICE || targetType == PokemonData.Type.STEEL)
    2513.             {
    2514.                 return 2f;
    2515.             }
    2516.             else if (targetType == PokemonData.Type.DRAGON || targetType == PokemonData.Type.FIRE ||
    2517.                      targetType == PokemonData.Type.ROCK || targetType == PokemonData.Type.WATER)
    2518.             {
    2519.                 return 0.5f;
    2520.             }
    2521.         }
    2522.         else if (attackingType == PokemonData.Type.FLYING)
    2523.         {
    2524.             if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.FIGHTING ||
    2525.                 targetType == PokemonData.Type.GRASS)
    2526.             {
    2527.                 return 2f;
    2528.             }
    2529.             else if (targetType == PokemonData.Type.ELECTRIC || targetType == PokemonData.Type.ROCK ||
    2530.                      targetType == PokemonData.Type.STEEL)
    2531.             {
    2532.                 return 0.5f;
    2533.             }
    2534.         }
    2535.         else if (attackingType == PokemonData.Type.GHOST)
    2536.         {
    2537.             if (targetType == PokemonData.Type.GHOST || targetType == PokemonData.Type.PSYCHIC)
    2538.             {
    2539.                 return 2f;
    2540.             }
    2541.             else if (targetType == PokemonData.Type.DARK)
    2542.             {
    2543.                 return 0.5f;
    2544.             }
    2545.             else if (targetType == PokemonData.Type.NORMAL)
    2546.             {
    2547.                 return 0f;
    2548.             }
    2549.         }
    2550.         else if (attackingType == PokemonData.Type.GRASS)
    2551.         {
    2552.             if (targetType == PokemonData.Type.GROUND || targetType == PokemonData.Type.ROCK ||
    2553.                 targetType == PokemonData.Type.WATER)
    2554.             {
    2555.                 return 2f;
    2556.             }
    2557.             else if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.DRAGON ||
    2558.                      targetType == PokemonData.Type.FIRE || targetType == PokemonData.Type.FLYING ||
    2559.                      targetType == PokemonData.Type.GRASS || targetType == PokemonData.Type.POISON ||
    2560.                      targetType == PokemonData.Type.STEEL)
    2561.             {
    2562.                 return 0.5f;
    2563.             }
    2564.         }
    2565.         else if (attackingType == PokemonData.Type.GROUND)
    2566.         {
    2567.             if (targetType == PokemonData.Type.ELECTRIC || targetType == PokemonData.Type.FIRE ||
    2568.                 targetType == PokemonData.Type.POISON || targetType == PokemonData.Type.ROCK ||
    2569.                 targetType == PokemonData.Type.STEEL)
    2570.             {
    2571.                 return 2f;
    2572.             }
    2573.             else if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.GRASS)
    2574.             {
    2575.                 return 0.5f;
    2576.             }
    2577.             else if (targetType == PokemonData.Type.FLYING)
    2578.             {
    2579.                 return 0f;
    2580.             }
    2581.         }
    2582.         else if (attackingType == PokemonData.Type.ICE)
    2583.         {
    2584.             if (targetType == PokemonData.Type.DRAGON || targetType == PokemonData.Type.FLYING ||
    2585.                 targetType == PokemonData.Type.GRASS || targetType == PokemonData.Type.GROUND)
    2586.             {
    2587.                 return 2f;
    2588.             }
    2589.             else if (targetType == PokemonData.Type.FIRE || targetType == PokemonData.Type.ICE ||
    2590.                      targetType == PokemonData.Type.STEEL || targetType == PokemonData.Type.WATER)
    2591.             {
    2592.                 return 0.5f;
    2593.             }
    2594.         }
    2595.         else if (attackingType == PokemonData.Type.NORMAL)
    2596.         {
    2597.             if (targetType == PokemonData.Type.ROCK || targetType == PokemonData.Type.STEEL)
    2598.             {
    2599.                 return 0.5f;
    2600.             }
    2601.             else if (targetType == PokemonData.Type.GHOST)
    2602.             {
    2603.                 return 0f;
    2604.             }
    2605.         }
    2606.         else if (attackingType == PokemonData.Type.POISON)
    2607.         {
    2608.             if (targetType == PokemonData.Type.FAIRY || targetType == PokemonData.Type.GRASS)
    2609.             {
    2610.                 return 2f;
    2611.             }
    2612.             else if (targetType == PokemonData.Type.POISON || targetType == PokemonData.Type.GROUND ||
    2613.                      targetType == PokemonData.Type.ROCK || targetType == PokemonData.Type.GHOST)
    2614.             {
    2615.                 return 0.5f;
    2616.             }
    2617.             else if (targetType == PokemonData.Type.STEEL)
    2618.             {
    2619.                 return 0f;
    2620.             }
    2621.         }
    2622.         else if (attackingType == PokemonData.Type.PSYCHIC)
    2623.         {
    2624.             if (targetType == PokemonData.Type.FIGHTING || targetType == PokemonData.Type.POISON)
    2625.             {
    2626.                 return 2f;
    2627.             }
    2628.             else if (targetType == PokemonData.Type.PSYCHIC || targetType == PokemonData.Type.STEEL)
    2629.             {
    2630.                 return 0.5f;
    2631.             }
    2632.             else if (targetType == PokemonData.Type.DARK)
    2633.             {
    2634.                 return 0f;
    2635.             }
    2636.         }
    2637.         else if (attackingType == PokemonData.Type.ROCK)
    2638.         {
    2639.             if (targetType == PokemonData.Type.BUG || targetType == PokemonData.Type.FIRE ||
    2640.                 targetType == PokemonData.Type.FLYING || targetType == PokemonData.Type.ICE)
    2641.             {
    2642.                 return 2f;
    2643.             }
    2644.             else if (targetType == PokemonData.Type.FIGHTING || targetType == PokemonData.Type.GROUND ||
    2645.                      targetType == PokemonData.Type.STEEL)
    2646.             {
    2647.                 return 0.5f;
    2648.             }
    2649.         }
    2650.         else if (attackingType == PokemonData.Type.STEEL)
    2651.         {
    2652.             if (targetType == PokemonData.Type.FAIRY || targetType == PokemonData.Type.ICE ||
    2653.                 targetType == PokemonData.Type.ROCK)
    2654.             {
    2655.                 return 2f;
    2656.             }
    2657.             else if (targetType == PokemonData.Type.ELECTRIC || targetType == PokemonData.Type.FIRE ||
    2658.                      targetType == PokemonData.Type.STEEL || targetType == PokemonData.Type.WATER)
    2659.             {
    2660.                 return 0.5f;
    2661.             }
    2662.         }
    2663.         else if (attackingType == PokemonData.Type.WATER)
    2664.         {
    2665.             if (targetType == PokemonData.Type.FIRE || targetType == PokemonData.Type.GROUND ||
    2666.                 targetType == PokemonData.Type.ROCK)
    2667.             {
    2668.                 return 2f;
    2669.             }
    2670.             else if (targetType == PokemonData.Type.DRAGON || targetType == PokemonData.Type.GRASS ||
    2671.                      targetType == PokemonData.Type.WATER)
    2672.             {
    2673.                 return 0.5f;
    2674.             }
    2675.         }
    2676.  
    2677.         return 1f;
    2678.     }
    2679.  
    2680.     /// Returns the Pokemon index that should move first, that hasn't moved this turn.
    2681.     private int getHighestSpeedIndex()
    2682.     {
    2683.         int topSpeed = 0;
    2684.         int topPriority = -7;
    2685.         int topSpeedPosition = 0;
    2686.  
    2687.         //calculate the highest speed remaining in the list, the set that speed to -1
    2688.         for (int i = 0; i < 6; i++)
    2689.         {
    2690.             if (!pokemonHasMoved[i])
    2691.             {
    2692.                 //calculate speed
    2693.                 float calculatedPokemonSpeed = 0;
    2694.                 float calculatedPokemonPriority = 0;
    2695.                 calculatedPokemonSpeed = (float) pokemonStats[4][i] * calculateStatModifier(pokemonStatsMod[4][i]);
    2696.                 if (pokemon[i] != null)
    2697.                 {
    2698.                     if (pokemon[i].getStatus() == Pokemon.Status.PARALYZED)
    2699.                     {
    2700.                         calculatedPokemonSpeed /= 4f;
    2701.                     }
    2702.                 }
    2703.  
    2704.                 //only the player gets increased priority on fleeing
    2705.                 if (command[i] == CommandType.Flee && i < 3)
    2706.                 {
    2707.                     calculatedPokemonPriority = 6;
    2708.                 }
    2709.                 else if (command[i] == CommandType.Item)
    2710.                 {
    2711.                     calculatedPokemonPriority = 6;
    2712.                 }
    2713.                 else if (command[i] == CommandType.Move)
    2714.                 {
    2715.                     calculatedPokemonPriority = commandMove[i].getPriority();
    2716.                 }
    2717.                 else if (command[i] == CommandType.Switch)
    2718.                 {
    2719.                     //6 priority for regular swapping out.
    2720.                     calculatedPokemonPriority = 6;
    2721.                 }
    2722.  
    2723.                 //if the top speed is greater than the old, AND the priority is no lower than       OR   the priority is greater than the old
    2724.                 if ((calculatedPokemonSpeed >= topSpeed && calculatedPokemonPriority >= topPriority) ||
    2725.                     calculatedPokemonPriority > topPriority)
    2726.                 {
    2727.                     if (calculatedPokemonSpeed == topSpeed && calculatedPokemonPriority == topPriority)
    2728.                     {
    2729.                         //if the speed/priority is exactly equal to the current highest, then to randomize the order
    2730.                         //in which speed is chosen (to break a speed tie), update the topSpeed position ONLY when a
    2731.                         //random float value (0f-1f) is greater than 0.5f.
    2732.                         if (Random.value > 0.5f)
    2733.                         {
    2734.                             topSpeedPosition = i;
    2735.                         }
    2736.                     }
    2737.                     else
    2738.                     {
    2739.                         topSpeed = Mathf.FloorToInt(calculatedPokemonSpeed);
    2740.                         topPriority = Mathf.FloorToInt(calculatedPokemonPriority);
    2741.                         topSpeedPosition = i;
    2742.                     }
    2743.                 }
    2744.             }
    2745.         }
    2746.         return topSpeedPosition;
    2747.     }
    2748.  
    2749.     /// Switch Pokemon (not yet implemented fully)
    2750.     private bool switchPokemon(int switchPosition, Pokemon newPokemon)
    2751.     {
    2752.         return switchPokemon(switchPosition, newPokemon, false, false);
    2753.     }
    2754.  
    2755.     /// Switch Pokemon
    2756.     private bool switchPokemon(int switchPosition, Pokemon newPokemon, bool batonPass)
    2757.     {
    2758.         return switchPokemon(switchPosition, newPokemon, batonPass, false);
    2759.     }
    2760.  
    2761.     /// Switch Pokemon
    2762.     private bool switchPokemon(int switchPosition, Pokemon newPokemon, bool batonPass, bool forceSwitch)
    2763.     {
    2764.         if (newPokemon == null)
    2765.         {
    2766.             return false;
    2767.         }
    2768.         if (newPokemon.getStatus() == Pokemon.Status.FAINTED)
    2769.         {
    2770.             return false;
    2771.         }
    2772.         // Return false if any condition is preventing the pokemon from switching out
    2773.         if (!forceSwitch)
    2774.         {
    2775.             //no condition can stop a fainted pokemon from switching out
    2776.             if (pokemon[switchPosition] != null)
    2777.             {
    2778.                 if (pokemon[switchPosition].getStatus() != Pokemon.Status.FAINTED)
    2779.                 {
    2780.                 }
    2781.             }
    2782.         }
    2783.  
    2784.         pokemon[switchPosition] = newPokemon;
    2785.         pokemonMoveset[switchPosition] = newPokemon.getMoveset();
    2786.  
    2787.  
    2788.         //set PokemonData
    2789.         updatePokemonStats(switchPosition);
    2790.         pokemonAbility[switchPosition] =
    2791.             PokemonDatabase.getPokemon(newPokemon.getID()).getAbility(newPokemon.getAbility());
    2792.         pokemonType1[switchPosition] = PokemonDatabase.getPokemon(newPokemon.getID()).getType1();
    2793.         pokemonType2[switchPosition] = PokemonDatabase.getPokemon(newPokemon.getID()).getType2();
    2794.         pokemonType3[switchPosition] = PokemonData.Type.NONE;
    2795.  
    2796.         //reset Pokemon Effects
    2797.         confused[switchPosition] = false;
    2798.         infatuatedBy[switchPosition] = -1;
    2799.         flinched[switchPosition] = false;
    2800.         statusEffectTurns[switchPosition] = 0;
    2801.         lockedTurns[switchPosition] = 0;
    2802.         partTrappedTurns[switchPosition] = 0;
    2803.         trapped[switchPosition] = false;
    2804.         charging[switchPosition] = false;
    2805.         recharging[switchPosition] = false;
    2806.         protect[switchPosition] = false;
    2807.         //specific moves
    2808.         seededBy[switchPosition] = -1;
    2809.         destinyBond[switchPosition] = false;
    2810.         minimized[switchPosition] = false;
    2811.         defenseCurled[switchPosition] = false;
    2812.         if (!batonPass)
    2813.         {
    2814.             pokemonStatsMod[0][switchPosition] = 0;
    2815.             pokemonStatsMod[1][switchPosition] = 0;
    2816.             pokemonStatsMod[2][switchPosition] = 0;
    2817.             pokemonStatsMod[3][switchPosition] = 0;
    2818.             pokemonStatsMod[4][switchPosition] = 0;
    2819.             pokemonStatsMod[5][switchPosition] = 0;
    2820.             pokemonStatsMod[6][switchPosition] = 0;
    2821.  
    2822.             //Pokemon Effects
    2823.             focusEnergy[switchPosition] = false;
    2824.         }
    2825.         else
    2826.         {
    2827.         }
    2828.  
    2829.  
    2830.         return true;
    2831.     }
    2832.  
    2833.     private IEnumerator addExp(int position, int exp)
    2834.     {
    2835.         yield return
    2836.             StartCoroutine(drawTextAndWait(pokemon[position].getName() + " gained " + exp + " Exp. Points!", 1.8f, 1.8f))
    2837.             ;
    2838.         Dialog.UndrawDialogBox();
    2839.  
    2840.         int expPool = exp;
    2841.         while (expPool > 0)
    2842.         {
    2843.             int expToNextLevel = pokemon[position].getExpNext() - pokemon[position].getExp();
    2844.  
    2845.             //if enough exp left to level up
    2846.             if (expPool >= expToNextLevel)
    2847.             {
    2848.                 pokemon[position].addExp(expToNextLevel);
    2849.                 expPool -= expToNextLevel;
    2850.  
    2851.                 AudioSource fillSource = SfxHandler.Play(fillExpClip);
    2852.                 yield return StartCoroutine(stretchBar(pokemon0ExpBar, 80f));
    2853.                 SfxHandler.FadeSource(fillSource, 0.2f);
    2854.                 SfxHandler.Play(expFullClip);
    2855.                 yield return new WaitForSeconds(1f);
    2856.  
    2857.                 updatePokemonStats(position);
    2858.                 updatePokemonStatsDisplay(position);
    2859.  
    2860.                 BgmHandler.main.PlayMFX(Resources.Load<AudioClip>("Audio/mfx/GetAverage"));
    2861.                 yield return
    2862.                     StartCoroutine(
    2863.                         drawTextAndWait(
    2864.                             pokemon[position].getName() + " grew to Level " + pokemon[position].getLevel() + "!", 1.8f,
    2865.                             1.8f));
    2866.  
    2867.                 string newMove = pokemon[position].MoveLearnedAtLevel(pokemon[position].getLevel());
    2868.                 if (!string.IsNullOrEmpty(newMove) && !pokemon[position].HasMove(newMove))
    2869.                 {
    2870.                     yield return StartCoroutine(LearnMove(pokemon[position], newMove));
    2871.                 }
    2872.  
    2873.                 Dialog.UndrawDialogBox();
    2874.                 yield return new WaitForSeconds(1f);
    2875.             }
    2876.             else
    2877.             {
    2878.                 pokemon[position].addExp(expPool);
    2879.                 expPool = 0;
    2880.                 float levelStartExp =
    2881.                     PokemonDatabase.getLevelExp(
    2882.                         PokemonDatabase.getPokemon(pokemon[position].getID()).getLevelingRate(),
    2883.                         pokemon[position].getLevel());
    2884.                 float currentExpMinusStart = pokemon[position].getExp() - levelStartExp;
    2885.                 float nextLevelExpMinusStart = pokemon[position].getExpNext() - levelStartExp;
    2886.  
    2887.                 AudioSource fillSource = SfxHandler.Play(fillExpClip);
    2888.                 yield return
    2889.                     StartCoroutine(stretchBar(pokemon0ExpBar, 80f * (currentExpMinusStart / nextLevelExpMinusStart)));
    2890.                 SfxHandler.FadeSource(fillSource, 0.2f);
    2891.                 yield return new WaitForSeconds(1f);
    2892.             }
    2893.  
    2894.  
    2895.             yield return null;
    2896.         }
    2897.     }
    2898.  
    2899.     private IEnumerator LearnMove(Pokemon selectedPokemon, string move)
    2900.     {
    2901.         int chosenIndex = 1;
    2902.         if (chosenIndex == 1)
    2903.         {
    2904.             bool learning = true;
    2905.             while (learning)
    2906.             {
    2907.                 //Moveset is full
    2908.                 if (selectedPokemon.getMoveCount() == 4)
    2909.                 {
    2910.                     yield return
    2911.                         StartCoroutine(
    2912.                             drawTextAndWait(selectedPokemon.getName() + " wants to learn the \nmove " + move + "."));
    2913.                     yield return
    2914.                         StartCoroutine(
    2915.                             drawTextAndWait("However, " + selectedPokemon.getName() + " already \nknows four moves."));
    2916.                     yield return
    2917.                         StartCoroutine(drawTextAndWait("Should a move be deleted and \nreplaced with " + move + "?",
    2918.                             0.1f));
    2919.  
    2920.                     yield return StartCoroutine(Dialog.DrawChoiceBox());
    2921.                     chosenIndex = Dialog.chosenIndex;
    2922.                     Dialog.UndrawChoiceBox();
    2923.                     if (chosenIndex == 1)
    2924.                     {
    2925.                         yield return StartCoroutine(drawTextAndWait("Which move should \nbe forgotten?"));
    2926.  
    2927.                         yield return StartCoroutine(ScreenFade.main.Fade(false, ScreenFade.defaultSpeed));
    2928.  
    2929.                         //Set SceneSummary to be active so that it appears
    2930.                         Scene.main.Summary.gameObject.SetActive(true);
    2931.                         StartCoroutine(Scene.main.Summary.control(selectedPokemon, move));
    2932.                         //Start an empty loop that will only stop when SceneSummary is no longer active (is closed)
    2933.                         while (Scene.main.Summary.gameObject.activeSelf)
    2934.                         {
    2935.                             yield return null;
    2936.                         }
    2937.  
    2938.                         string replacedMove = Scene.main.Summary.replacedMove;
    2939.                         yield return StartCoroutine(ScreenFade.main.Fade(true, ScreenFade.defaultSpeed));
    2940.  
    2941.                         if (!string.IsNullOrEmpty(replacedMove))
    2942.                         {
    2943.                             Dialog.DrawDialogBox();
    2944.                             yield return StartCoroutine(Dialog.DrawTextSilent("1, "));
    2945.                             yield return new WaitForSeconds(0.4f);
    2946.                             yield return StartCoroutine(Dialog.DrawTextSilent("2, "));
    2947.                             yield return new WaitForSeconds(0.4f);
    2948.                             yield return StartCoroutine(Dialog.DrawTextSilent("and... "));
    2949.                             yield return new WaitForSeconds(0.4f);
    2950.                             yield return StartCoroutine(Dialog.DrawTextSilent("... "));
    2951.                             yield return new WaitForSeconds(0.4f);
    2952.                             yield return StartCoroutine(Dialog.DrawTextSilent("... "));
    2953.                             yield return new WaitForSeconds(0.4f);
    2954.                             SfxHandler.Play(pokeballBounceClip);
    2955.                             yield return StartCoroutine(Dialog.DrawTextSilent("Poof!"));
    2956.                             while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back"))
    2957.                             {
    2958.                                 yield return null;
    2959.                             }
    2960.  
    2961.                             yield return
    2962.                                 StartCoroutine(
    2963.                                     drawTextAndWait(selectedPokemon.getName() + " forgot how to \nuse " + replacedMove +
    2964.                                                     "."));
    2965.                             yield return StartCoroutine(drawTextAndWait("And..."));
    2966.  
    2967.                             Dialog.DrawDialogBox();
    2968.                             AudioClip mfx = Resources.Load<AudioClip>("Audio/mfx/GetAverage");
    2969.                             BgmHandler.main.PlayMFX(mfx);
    2970.                             StartCoroutine(Dialog.DrawTextSilent(selectedPokemon.getName() + " learned \n" + move + "!"));
    2971.                             yield return new WaitForSeconds(mfx.length);
    2972.                             while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back"))
    2973.                             {
    2974.                                 yield return null;
    2975.                             }
    2976.                             Dialog.UndrawDialogBox();
    2977.                             learning = false;
    2978.                         }
    2979.                         else
    2980.                         {
    2981.                             //give up?
    2982.                             chosenIndex = 0;
    2983.                         }
    2984.                     }
    2985.                     if (chosenIndex == 0)
    2986.                     {
    2987.                         //NOT ELSE because this may need to run after (chosenIndex == 1) runs
    2988.                         yield return
    2989.                             StartCoroutine(drawTextAndWait("Give up on learning the move \n" + move + "?", 0.1f));
    2990.  
    2991.                         yield return StartCoroutine(Dialog.DrawChoiceBox());
    2992.                         chosenIndex = Dialog.chosenIndex;
    2993.                         Dialog.UndrawChoiceBox();
    2994.                         if (chosenIndex == 1)
    2995.                         {
    2996.                             learning = false;
    2997.                             chosenIndex = 0;
    2998.                         }
    2999.                     }
    3000.                 }
    3001.                 //Moveset is not full, can fit the new move easily
    3002.                 else
    3003.                 {
    3004.                     selectedPokemon.addMove(move);
    3005.  
    3006.                     Dialog.DrawDialogBox();
    3007.                     AudioClip mfx = Resources.Load<AudioClip>("Audio/mfx/GetAverage");
    3008.                     BgmHandler.main.PlayMFX(mfx);
    3009.                     StartCoroutine(Dialog.DrawTextSilent(selectedPokemon.getName() + " learned \n" + move + "!"));
    3010.                     yield return new WaitForSeconds(mfx.length);
    3011.                     while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back"))
    3012.                     {
    3013.                         yield return null;
    3014.                     }
    3015.                     Dialog.UndrawDialogBox();
    3016.                     learning = false;
    3017.                 }
    3018.             }
    3019.         }
    3020.         if (chosenIndex == 0)
    3021.         {
    3022.             //NOT ELSE because this may need to run after (chosenIndex == 1) runs
    3023.             //cancel learning loop
    3024.             yield return StartCoroutine(drawTextAndWait(selectedPokemon.getName() + " did not learn \n" + move + "."));
    3025.         }
    3026.     }
    3027.  
    3028.  
    3029.     private void updatePokemonStats(int position)
    3030.     {
    3031.         //set PokemonData
    3032.         pokemonStats[0][position] = pokemon[position].getATK();
    3033.         pokemonStats[1][position] = pokemon[position].getDEF();
    3034.         pokemonStats[2][position] = pokemon[position].getSPA();
    3035.         pokemonStats[3][position] = pokemon[position].getSPD();
    3036.         pokemonStats[4][position] = pokemon[position].getSPE();
    3037.     }
    3038.  
    3039.  
    3040.     /// Apply the Move Effect to the target pokemon if possible (with animation)
    3041.     private IEnumerator applyEffect(int attackerPosition, int targetPosition, MoveData.Effect effect, float parameter)
    3042.     {
    3043.         yield return StartCoroutine(applyEffect(attackerPosition, targetPosition, effect, parameter, true));
    3044.     }
    3045.  
    3046.     /// Apply the Move Effect to the target pokemon if possible
    3047.     private IEnumerator applyEffect(int attackerPosition, int targetPosition, MoveData.Effect effect, float parameter,
    3048.         bool animate)
    3049.     {
    3050.         //most effects won't happen if a target has fainted.
    3051.         if (pokemon[targetPosition] != null)
    3052.         {
    3053.             if (pokemon[targetPosition].getStatus() != Pokemon.Status.FAINTED)
    3054.             {
    3055.                 if (effect == MoveData.Effect.ATK)
    3056.                 {
    3057.                     yield return StartCoroutine(ModifyStat(targetPosition, 0, parameter, animate));
    3058.                 }
    3059.                 else if (effect == MoveData.Effect.DEF)
    3060.                 {
    3061.                     yield return StartCoroutine(ModifyStat(targetPosition, 1, parameter, animate));
    3062.                 }
    3063.                 else if (effect == MoveData.Effect.SPA)
    3064.                 {
    3065.                     yield return StartCoroutine(ModifyStat(targetPosition, 2, parameter, animate));
    3066.                 }
    3067.                 else if (effect == MoveData.Effect.SPD)
    3068.                 {
    3069.                     yield return StartCoroutine(ModifyStat(targetPosition, 3, parameter, animate));
    3070.                 }
    3071.                 else if (effect == MoveData.Effect.SPE)
    3072.                 {
    3073.                     yield return StartCoroutine(ModifyStat(targetPosition, 4, parameter, animate));
    3074.                 }
    3075.                 else if (effect == MoveData.Effect.ACC)
    3076.                 {
    3077.                     yield return StartCoroutine(ModifyStat(targetPosition, 5, parameter, animate));
    3078.                 }
    3079.                 else if (effect == MoveData.Effect.EVA)
    3080.                 {
    3081.                     yield return StartCoroutine(ModifyStat(targetPosition, 6, parameter, animate));
    3082.                 }
    3083.                 else if (effect == MoveData.Effect.Burn)
    3084.                 {
    3085.                     if (Random.value <= parameter)
    3086.                     {
    3087.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.BURNED))
    3088.                         {
    3089.                             yield return
    3090.                                 StartCoroutine(
    3091.                                     drawTextAndWait(
    3092.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3093.                                         " was burned!", 2.4f));
    3094.                         }
    3095.                     }
    3096.                 }
    3097.                 else if (effect == MoveData.Effect.Freeze)
    3098.                 {
    3099.                     if (Random.value <= parameter)
    3100.                     {
    3101.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.FROZEN))
    3102.                         {
    3103.                             yield return
    3104.                                 StartCoroutine(
    3105.                                     drawTextAndWait(
    3106.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3107.                                         " was frozen solid!", 2.4f));
    3108.                         }
    3109.                     }
    3110.                 }
    3111.                 else if (effect == MoveData.Effect.Paralyze)
    3112.                 {
    3113.                     if (Random.value <= parameter)
    3114.                     {
    3115.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.PARALYZED))
    3116.                         {
    3117.                             yield return
    3118.                                 StartCoroutine(
    3119.                                     drawTextAndWait(
    3120.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3121.                                         " was paralyzed! \\nIt may be unable to move!", 2.4f));
    3122.                         }
    3123.                     }
    3124.                 }
    3125.                 else if (effect == MoveData.Effect.Poison)
    3126.                 {
    3127.                     if (Random.value <= parameter)
    3128.                     {
    3129.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.POISONED))
    3130.                         {
    3131.                             yield return
    3132.                                 StartCoroutine(
    3133.                                     drawTextAndWait(
    3134.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3135.                                         " was poisoned!", 2.4f));
    3136.                         }
    3137.                     }
    3138.                 }
    3139.                 else if (effect == MoveData.Effect.Toxic)
    3140.                 {
    3141.                     if (Random.value <= parameter)
    3142.                     {
    3143.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.POISONED))
    3144.                         {
    3145.                             yield return
    3146.                                 StartCoroutine(
    3147.                                     drawTextAndWait(
    3148.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3149.                                         " was badly posioned!", 2.4f));
    3150.                         }
    3151.                     }
    3152.                 }
    3153.                 else if (effect == MoveData.Effect.Sleep)
    3154.                 {
    3155.                     if (Random.value <= parameter)
    3156.                     {
    3157.                         if (pokemon[targetPosition].setStatus(Pokemon.Status.ASLEEP))
    3158.                         {
    3159.                             yield return
    3160.                                 StartCoroutine(
    3161.                                     drawTextAndWait(
    3162.                                         generatePreString(targetPosition) + pokemon[targetPosition].getName() +
    3163.                                         " fell asleep!", 2.4f));
    3164.                         }
    3165.                     }
    3166.                 }
    3167.             }
    3168.         }
    3169.         //effects that happen regardless of target fainting or not
    3170.         if (effect == MoveData.Effect.ATKself)
    3171.         {
    3172.             yield return StartCoroutine(ModifyStat(attackerPosition, 0, parameter, animate));
    3173.         }
    3174.         else if (effect == MoveData.Effect.DEFself)
    3175.         {
    3176.             yield return StartCoroutine(ModifyStat(attackerPosition, 1, parameter, animate));
    3177.         }
    3178.         else if (effect == MoveData.Effect.SPAself)
    3179.         {
    3180.             yield return StartCoroutine(ModifyStat(attackerPosition, 2, parameter, animate));
    3181.         }
    3182.         else if (effect == MoveData.Effect.SPDself)
    3183.         {
    3184.             yield return StartCoroutine(ModifyStat(attackerPosition, 3, parameter, animate));
    3185.         }
    3186.         else if (effect == MoveData.Effect.SPEself)
    3187.         {
    3188.             yield return StartCoroutine(ModifyStat(attackerPosition, 4, parameter, animate));
    3189.         }
    3190.         else if (effect == MoveData.Effect.ACCself)
    3191.         {
    3192.             yield return StartCoroutine(ModifyStat(attackerPosition, 5, parameter, animate));
    3193.         }
    3194.         else if (effect == MoveData.Effect.EVAself)
    3195.         {
    3196.             yield return StartCoroutine(ModifyStat(attackerPosition, 6, parameter, animate));
    3197.         }
    3198.     }
    3199.  
    3200.     private IEnumerator ModifyStat(int targetPosition, int statIndex, float param, bool animate)
    3201.     {
    3202.         int parameter = Mathf.FloorToInt(param);
    3203.  
    3204.         string[] statName = new string[]
    3205.         {
    3206.             "Attack", "Defense", "Special Attack", "Special Defense", "Speed", "Accuracy", "Evasion"
    3207.         };
    3208.  
    3209.         bool canModify = true;
    3210.         if (pokemonStatsMod[statIndex][targetPosition] >= 6 && parameter > 0)
    3211.         {
    3212.             //can't go higher
    3213.             yield return
    3214.                 StartCoroutine(
    3215.                     drawTextAndWait(
    3216.                         generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3217.                         statName[statIndex] + " \\nwon't go any higher!", 2.4f));
    3218.             canModify = false;
    3219.         }
    3220.         else if (pokemonStatsMod[statIndex][targetPosition] <= -6 && parameter < 0)
    3221.         {
    3222.             //can't go lower
    3223.             yield return
    3224.                 StartCoroutine(
    3225.                     drawTextAndWait(
    3226.                         generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3227.                         statName[statIndex] + " won't go any lower!", 2.4f));
    3228.             canModify = false;
    3229.         }
    3230.  
    3231.         if (canModify)
    3232.         {
    3233.             pokemonStatsMod[statIndex][targetPosition] += parameter;
    3234.             if (pokemonStatsMod[statIndex][targetPosition] > 6)
    3235.             {
    3236.                 pokemonStatsMod[statIndex][targetPosition] = 6;
    3237.             }
    3238.             else if (pokemonStatsMod[statIndex][targetPosition] < -6)
    3239.             {
    3240.                 pokemonStatsMod[statIndex][targetPosition] = -6;
    3241.             }
    3242.  
    3243.             if (animate)
    3244.             {
    3245.                 //multiple pokemon not yet implemented
    3246.                 RawImage overlay = (targetPosition < 3) ? player1Overlay : opponent1Overlay;
    3247.                 if (parameter > 0)
    3248.                 {
    3249.                     SfxHandler.Play(statUpClip);
    3250.                     StartCoroutine(animateOverlayer(overlay, overlayStatUpTex, -1, 0, 1.2f, 0.3f));
    3251.                 }
    3252.                 else if (parameter < 0)
    3253.                 {
    3254.                     SfxHandler.Play(statDownClip);
    3255.                     StartCoroutine(animateOverlayer(overlay, overlayStatDownTex, 1, 0, 1.2f, 0.3f));
    3256.                 }
    3257.  
    3258.                 yield return new WaitForSeconds(statUpClip.length + 0.2f);
    3259.             }
    3260.  
    3261.             if (parameter == 1)
    3262.             {
    3263.                 yield return
    3264.                     StartCoroutine(
    3265.                         drawTextAndWait(
    3266.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3267.                             statName[statIndex] + " \\nrose!", 2.4f));
    3268.             }
    3269.             else if (parameter == -1)
    3270.             {
    3271.                 yield return
    3272.                     StartCoroutine(
    3273.                         drawTextAndWait(
    3274.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3275.                             statName[statIndex] + " \\nfell!", 2.4f));
    3276.             }
    3277.             else if (parameter == 2)
    3278.             {
    3279.                 yield return
    3280.                     StartCoroutine(
    3281.                         drawTextAndWait(
    3282.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3283.                             statName[statIndex] + " \\nrose sharply!", 2.4f));
    3284.             }
    3285.             else if (parameter == -2)
    3286.             {
    3287.                 yield return
    3288.                     StartCoroutine(
    3289.                         drawTextAndWait(
    3290.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3291.                             statName[statIndex] + " \\nharshly fell!", 2.4f));
    3292.             }
    3293.             else if (parameter >= 3)
    3294.             {
    3295.                 yield return
    3296.                     StartCoroutine(
    3297.                         drawTextAndWait(
    3298.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3299.                             statName[statIndex] + " nrose drastically!", 2.4f));
    3300.             }
    3301.             else if (parameter <= -3)
    3302.             {
    3303.                 yield return
    3304.                     StartCoroutine(
    3305.                         drawTextAndWait(
    3306.                             generatePreString(targetPosition) + pokemon[targetPosition].getName() + "'s " +
    3307.                             statName[statIndex] + " \\nseverely fell!", 2.4f));
    3308.             }
    3309.         }
    3310.     }
    3311.  
    3312.  
    3313.     //////////////////////////////////
    3314.  
    3315.     //////////////////////////////////
    3316.     /// REPEATED SEQUENCES
    3317.     //
    3318.     ///This sequence heals a pokemon on the field. Do not use to heal a pokemon in the party.
    3319.     private IEnumerator Heal(int index, float healAmount)
    3320.     {
    3321.         yield return StartCoroutine(Heal(index, healAmount, false));
    3322.     }
    3323.  
    3324.     private IEnumerator Heal(int index, bool curingStatus)
    3325.     {
    3326.         yield return StartCoroutine(Heal(index, -1, curingStatus));
    3327.     }
    3328.  
    3329.     private IEnumerator Heal(int index, float healAmount, bool curingStatus)
    3330.     {
    3331.         //If healing, and HP is already full    OR   if curing status, and status is already none or fainted (fainted pokemon can only be cured off-field).
    3332.         if ((!curingStatus && pokemon[index].getCurrentHP() == pokemon[index].getHP()) ||
    3333.             (curingStatus &&
    3334.              (pokemon[index].getStatus() == Pokemon.Status.NONE || pokemon[index].getStatus() == Pokemon.Status.FAINTED)))
    3335.         {
    3336.             //no effect
    3337.             yield return StartCoroutine(drawTextAndWait("It had no effect...", 2.4f));
    3338.         }
    3339.         else
    3340.         {
    3341.             //SOUND
    3342.             SfxHandler.Play(healFieldClip);
    3343.             //Animate
    3344.             RawImage overlay = (index < 3) ? player1Overlay : opponent1Overlay;
    3345.             yield return new WaitForSeconds(1.2f);
    3346.             yield return StartCoroutine(animateOverlayer(overlay, overlayHealTex, -1, 0, 1.2f, 0.3f));
    3347.             if (curingStatus)
    3348.             {
    3349.                 Pokemon.Status status = pokemon[index].getStatus();
    3350.                 pokemon[index].healStatus();
    3351.                 updatePokemonStatsDisplay(index);
    3352.                 yield return new WaitForSeconds(0.3f);
    3353.                 if (status == Pokemon.Status.ASLEEP)
    3354.                 {
    3355.                     yield return
    3356.                         StartCoroutine(drawTextAndWait(
    3357.                             generatePreString(index) + pokemon[index].getName() + " woke up!", 2.4f));
    3358.                 }
    3359.                 else if (status == Pokemon.Status.BURNED)
    3360.                 {
    3361.                     yield return
    3362.                         StartCoroutine(
    3363.                             drawTextAndWait(
    3364.                                 generatePreString(index) + pokemon[index].getName() + "'s burn was healed!", 2.4f));
    3365.                 }
    3366.                 else if (status == Pokemon.Status.FROZEN)
    3367.                 {
    3368.                     yield return
    3369.                         StartCoroutine(
    3370.                             drawTextAndWait(generatePreString(index) + pokemon[index].getName() + " thawed out!", 2.4f))
    3371.                         ;
    3372.                 }
    3373.                 else if (status == Pokemon.Status.PARALYZED)
    3374.                 {
    3375.                     yield return
    3376.                         StartCoroutine(
    3377.                             drawTextAndWait(
    3378.                                 generatePreString(index) + pokemon[index].getName() + " was cured of its paralysis!",
    3379.                                 2.4f));
    3380.                 }
    3381.                 else if (status == Pokemon.Status.POISONED)
    3382.                 {
    3383.                     yield return
    3384.                         StartCoroutine(
    3385.                             drawTextAndWait(
    3386.                                 generatePreString(index) + pokemon[index].getName() + " was cured of its poison!", 2.4f))
    3387.                         ;
    3388.                 }
    3389.             }
    3390.             else
    3391.             {
    3392.                 //if under 1.01f, heal based on percentage
    3393.                 if (healAmount < 1.01f)
    3394.                 {
    3395.                     healAmount = Mathf.CeilToInt((float) pokemon[index].getHP() * healAmount);
    3396.                 }
    3397.  
    3398.                 //Heal the pokemon and record how much HP was healed
    3399.                 int healedHP = pokemon[index].getCurrentHP();
    3400.                 pokemon[index].healHP(healAmount);
    3401.                 healedHP = pokemon[index].getCurrentHP() - healedHP;
    3402.  
    3403.                 if (index == 0)
    3404.                 {
    3405.                     yield return
    3406.                         StartCoroutine(stretchBar(statsHPBar[index], pokemon[index].getPercentHP() * 48f, 32, true,
    3407.                             pokemon0CurrentHP, pokemon0CurrentHPShadow, pokemon[index].getCurrentHP()));
    3408.                 }
    3409.                 else
    3410.                 {
    3411.                     yield return
    3412.                         StartCoroutine(stretchBar(statsHPBar[index], pokemon[index].getPercentHP() * 48f, 32, true, null,
    3413.                             null, 0));
    3414.                 }
    3415.                 yield return
    3416.                     StartCoroutine(
    3417.                         drawTextAndWait(
    3418.                             generatePreString(index) + pokemon[index].getName() + "'s HP was restored by " + healedHP +
    3419.                             " point(s).", 2.4f));
    3420.             }
    3421.         }
    3422.     }
    3423.  
    3424.  
    3425.     /// Display the a textbox with a message, and wait until Select or Start/Back is pressed.
    3426.     private IEnumerator drawTextAndWait(string message)
    3427.     {
    3428.         yield return StartCoroutine(drawTextAndWait(message, 0, 0, true));
    3429.     }
    3430.  
    3431.     /// Display the a textbox with a message, and wait a set amount of time or until Select or Start/Back is pressed.
    3432.     private IEnumerator drawTextAndWait(string message, float time)
    3433.     {
    3434.         yield return StartCoroutine(drawTextAndWait(message, time, 0, true));
    3435.     }
    3436.  
    3437.     /// Display the a textbox with a message, and wait a set amount of time before until Select or Start/Back is pressed.
    3438.     private IEnumerator drawTextAndWait(string message, float time, float lockedTime)
    3439.     {
    3440.         yield return StartCoroutine(drawTextAndWait(message, time, lockedTime, true));
    3441.     }
    3442.  
    3443.     private IEnumerator drawTextAndWait(string message, bool silent)
    3444.     {
    3445.         yield return StartCoroutine(drawTextAndWait(message, 0, 0, silent));
    3446.     }
    3447.  
    3448.     private IEnumerator drawTextAndWait(string message, float time, float lockedTime, bool silent)
    3449.     {
    3450.         Dialog.DrawDialogBox();
    3451.         float startTime = Time.time;
    3452.         if (silent)
    3453.         {
    3454.             yield return StartCoroutine(Dialog.DrawTextSilent(message));
    3455.         }
    3456.         else
    3457.         {
    3458.             yield return StartCoroutine(Dialog.DrawText(message));
    3459.         }
    3460.  
    3461.         if (lockedTime > 0)
    3462.         {
    3463.             while (Time.time < startTime + lockedTime)
    3464.             {
    3465.                 yield return null;
    3466.             }
    3467.         }
    3468.  
    3469.         if (time > 0)
    3470.         {
    3471.             while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back") && Time.time < startTime + time)
    3472.             {
    3473.                 yield return null;
    3474.             }
    3475.         }
    3476.         else
    3477.         {
    3478.             while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back"))
    3479.             {
    3480.                 yield return null;
    3481.             }
    3482.         }
    3483.     }
    3484.  
    3485.     private string generatePreString(int pokemonPosition)
    3486.     {
    3487.         string preString = "";
    3488.         if (pokemonPosition > 2)
    3489.         {
    3490.             preString = (trainerBattle) ? "The foe's " : "The wild ";
    3491.         }
    3492.         return preString;
    3493.     }
    3494.  
    3495.  
    3496.     private float PlayCry(Pokemon pokemon)
    3497.     {
    3498.         SfxHandler.Play(pokemon.GetCry(), pokemon.GetCryPitch());
    3499.         return pokemon.GetCry().length / pokemon.GetCryPitch();
    3500.     }
    3501.  
    3502.     private IEnumerator PlayCryAndWait(Pokemon pokemon)
    3503.     {
    3504.         yield return new WaitForSeconds(PlayCry(pokemon));
    3505.     }
    3506.  
    3507.  
    3508.     /// Basic Wild Battle
    3509.     public IEnumerator control(Pokemon wildPokemon)
    3510.     {
    3511.         yield return StartCoroutine(control(false, new Trainer(new Pokemon[] {wildPokemon}), false));
    3512.     }
    3513.  
    3514.     /// Basic Trainer Battle
    3515.     public IEnumerator control(Trainer trainer)
    3516.     {
    3517.         yield return StartCoroutine(control(true, trainer, false));
    3518.     }
    3519.  
    3520.     public IEnumerator control(bool isTrainerBattle, Trainer trainer, bool healedOnDefeat)
    3521.     {
    3522.         //Used to compare after the battle to check for evolutions.
    3523.         int[] initialLevels = new int[6];
    3524.         for (int i = 0; i < initialLevels.Length; i++)
    3525.         {
    3526.             if (SaveData.currentSave.PC.boxes[0][i] != null)
    3527.             {
    3528.                 initialLevels[i] = SaveData.currentSave.PC.boxes[0][i].getLevel();
    3529.             }
    3530.         }
    3531.  
    3532.         trainerBattle = isTrainerBattle;
    3533.         Pokemon[] opponentParty = trainer.GetParty();
    3534.         string opponentName = trainer.GetName();
    3535.  
    3536.         //GET BATTLE BACKGROUNDS
    3537.         int currentTileTag = PlayerMovement.player.currentMap.getTileTag(PlayerMovement.player.transform.position);
    3538.         Debug.Log(currentTileTag);
    3539.         background.sprite = PlayerMovement.player.accessedMapSettings.getBattleBackground(currentTileTag);
    3540.  
    3541.         playerBase.sprite = PlayerMovement.player.accessedMapSettings.getBattleBase(currentTileTag);
    3542.         opponentBase.sprite = playerBase.sprite;
    3543.  
    3544.  
    3545.         //Set Trainer Sprites
    3546.         trainer1Animation = new Sprite[] {Resources.Load<Sprite>("null")};
    3547.         if (trainerBattle)
    3548.         {
    3549.             trainer1Animation = trainer.GetSprites();
    3550.         }
    3551.         playerTrainer1Animation =
    3552.             Resources.LoadAll<Sprite>("PlayerSprites/" + SaveData.currentSave.getPlayerSpritePrefix() + "back");
    3553.         playerTrainerSprite1.sprite = playerTrainer1Animation[0];
    3554.         //Note: the player animation should NEVER have no sprites
    3555.         if (trainer1Animation.Length > 0)
    3556.         {
    3557.             trainerSprite1.sprite = trainer1Animation[0];
    3558.         }
    3559.         else
    3560.         {
    3561.             trainerSprite1.sprite = Resources.Load<Sprite>("null");
    3562.         }
    3563.         //Set trainer sprites to the center of the platform initially
    3564.         playerTrainerSprite1.rectTransform.localPosition = new Vector3(0,
    3565.             playerTrainerSprite1.rectTransform.localPosition.y, 0);
    3566.         trainerSprite1.rectTransform.localPosition = new Vector3(0, trainerSprite1.rectTransform.localPosition.y, 0);
    3567.  
    3568.  
    3569.         victor = -1; //0 = player, 1 = opponent, 2 = tie
    3570.  
    3571.         //Reset position variables
    3572.         currentTask = 0;
    3573.         taskPosition = 1;
    3574.         movePosition = 1;
    3575.         bagCategoryPosition = 0;
    3576.         pokePartyPosition = 0;
    3577.         itemListPagePosition = 0;
    3578.         itemListPageCount = 0;
    3579.  
    3580.         updateCurrentTask(-1);
    3581.         updateSelectedTask(1);
    3582.         updateSelectedMove(1);
    3583.  
    3584.  
    3585.         bool running = true;
    3586.         bool runState = true;
    3587.  
    3588.         for (int i = 0; i < 6; i++)
    3589.         {
    3590.             if (SaveData.currentSave.PC.boxes[0][i] != null)
    3591.             {
    3592.                 if (SaveData.currentSave.PC.boxes[0][i].getStatus() != Pokemon.Status.FAINTED)
    3593.                 {
    3594.                     switchPokemon(0, SaveData.currentSave.PC.boxes[0][i], false, true);
    3595.                     i = 6;
    3596.                 }
    3597.             }
    3598.         }
    3599.         switchPokemon(3, opponentParty[0], false, true);
    3600.  
    3601.  
    3602.         player1Animation = pokemon[0].GetBackAnim_();
    3603.         opponent1Animation = pokemon[3].GetFrontAnim_();
    3604.  
    3605.         updatePokemonStatsDisplay(0);
    3606.         updatePokemonStatsDisplay(3);
    3607.  
    3608.         if (pokemon[0] != null)
    3609.         {
    3610.             updateMovesetDisplay(pokemonMoveset[0], pokemon[0].getPP(), pokemon[0].getMaxPP());
    3611.         }
    3612.  
    3613.         //Animate the Pokemon being released into battle
    3614.         player1.transform.parent.parent.gameObject.SetActive(false);
    3615.         opponent1.transform.parent.parent.gameObject.SetActive(false);
    3616.         player1Overlay.gameObject.SetActive(false);
    3617.         opponent1Overlay.gameObject.SetActive(false);
    3618.  
    3619.  
    3620.         animateOpponent1 = StartCoroutine(animatePokemon(opponent1, opponent1Animation));
    3621.         animatePlayer1 = StartCoroutine(animatePokemon(player1, player1Animation));
    3622.  
    3623.         pokemonStatsDisplay[0].gameObject.SetActive(false);
    3624.         pokemonStatsDisplay[3].gameObject.SetActive(false);
    3625.  
    3626.         hidePartyBar(true);
    3627.         hidePartyBar(false);
    3628.  
    3629. //        Debug.Log(pokemon[0].getName()+": HP: "+pokemon[0].getHP()+"ATK: "+pokemon[0].getATK()+"DEF: "+pokemon[0].getDEF()+"SPA: "+pokemon[0].getSPA()+"SPD: "+pokemon[0].getSPD()+"SPE:"+pokemon[0].getSPE());
    3630. //        Debug.Log(pokemon[3].getName()+": HP: "+pokemon[3].getHP()+"ATK: "+pokemon[3].getATK()+"DEF: "+pokemon[3].getDEF()+"SPA: "+pokemon[3].getSPA()+"SPD: "+pokemon[3].getSPD()+"SPE:"+pokemon[3].getSPE());
    3631.  
    3632.  
    3633.         if (trainerBattle)
    3634.         {
    3635.             StartCoroutine(ScreenFade.main.Fade(true, 1.2f));
    3636.             StartCoroutine(slidePokemon(opponentBase, opponent1, false, false, new Vector3(100, 0, 0)));
    3637.             StartCoroutine(slidePokemon(playerBase, player1, false, true, new Vector3(-80, -64, 0)));
    3638.  
    3639.             yield return new WaitForSeconds(0.9f);
    3640.             StartCoroutine(displayPartyBar(true, opponentParty));
    3641.             StartCoroutine(displayPartyBar(false, SaveData.currentSave.PC.boxes[0]));
    3642.  
    3643.             yield return StartCoroutine(drawTextAndWait(opponentName + " wants to fight!", 2.6f, 2.6f));
    3644.  
    3645.             Dialog.DrawDialogBox();
    3646.             StartCoroutine(Dialog.DrawTextSilent(opponentName + " sent out " + pokemon[3].getName() + "!"));
    3647.             StartCoroutine(dismissPartyBar(true));
    3648.             yield return StartCoroutine(slideTrainer(opponentBase, trainerSprite1, true, true));
    3649.             yield return StartCoroutine(releasePokemon(opponent1));
    3650.             PlayCry(pokemon[3]);
    3651.             yield return new WaitForSeconds(0.3f);
    3652.             yield return StartCoroutine(slidePokemonStats(3, false));
    3653.             yield return new WaitForSeconds(0.9f);
    3654.  
    3655.             Dialog.DrawDialogBox();
    3656.             StartCoroutine(Dialog.DrawTextSilent("Go " + pokemon[0].getName() + "!"));
    3657.             StartCoroutine(animatePlayerThrow(playerTrainerSprite1, playerTrainer1Animation, true));
    3658.             yield return new WaitForSeconds(0.2f);
    3659.             StartCoroutine(dismissPartyBar(false));
    3660.             StartCoroutine(slideTrainer(playerBase, playerTrainerSprite1, false, true));
    3661.             yield return new WaitForSeconds(0.5f);
    3662.             yield return StartCoroutine(releasePokemon(player1));
    3663.             PlayCry(pokemon[0]);
    3664.             yield return new WaitForSeconds(0.3f);
    3665.             yield return StartCoroutine(slidePokemonStats(0, false));
    3666.             yield return new WaitForSeconds(0.9f);
    3667.             Dialog.UndrawDialogBox();
    3668.         }
    3669.         else
    3670.         {
    3671.             player1.transform.parent.parent.gameObject.SetActive(false);
    3672.             opponent1.transform.parent.parent.gameObject.SetActive(false);
    3673.  
    3674.             StartCoroutine(ScreenFade.main.Fade(true, ScreenFade.slowedSpeed));
    3675.             StartCoroutine(slidePokemon(opponentBase, opponent1, true, false, new Vector3(92, 0, 0)));
    3676.             yield return StartCoroutine(slidePokemon(playerBase, player1, false, true, new Vector3(-80, -64, 0)));
    3677.             Dialog.DrawDialogBox();
    3678.             StartCoroutine(Dialog.DrawTextSilent("A wild " + pokemon[3].getName() + " appeared!"));
    3679.             PlayCry(pokemon[3]);
    3680.             yield return StartCoroutine(slidePokemonStats(3, false));
    3681.             yield return new WaitForSeconds(1.2f);
    3682.  
    3683.             Dialog.DrawDialogBox();
    3684.             StartCoroutine(Dialog.DrawTextSilent("Go " + pokemon[0].getName() + "!"));
    3685.             StartCoroutine(animatePlayerThrow(playerTrainerSprite1, playerTrainer1Animation, true));
    3686.             yield return new WaitForSeconds(0.2f);
    3687.             StartCoroutine(slideTrainer(playerBase, playerTrainerSprite1, false, true));
    3688.             yield return new WaitForSeconds(0.5f);
    3689.             yield return StartCoroutine(releasePokemon(player1));
    3690.             PlayCry(pokemon[0]);
    3691.             yield return new WaitForSeconds(0.3f);
    3692.             yield return StartCoroutine(slidePokemonStats(0, false));
    3693.             yield return new WaitForSeconds(0.9f);
    3694.             Dialog.UndrawDialogBox();
    3695.         }
    3696.         //
    3697.  
    3698.  
    3699.         updateCurrentTask(0);
    3700.  
    3701.         int playerFleeAttempts = 0;
    3702.         while (running)
    3703.         {
    3704.             //Reset Turn Tasks
    3705.             command = new CommandType[6];
    3706.             commandMove = new MoveData[6];
    3707.             commandTarget = new int[6];
    3708.             commandItem = new ItemData[6];
    3709.             commandPokemon = new Pokemon[6];
    3710.             //
    3711.  
    3712.             //Reset Turn Feedback
    3713.             pokemonHasMoved = new bool[6];
    3714.  
    3715.  
    3716.             if (pokemon[0] != null)
    3717.             {
    3718.                 updateMovesetDisplay(pokemonMoveset[0], pokemon[0].getPP(), pokemon[0].getMaxPP());
    3719.             }
    3720.  
    3721.             updatePokemonStatsDisplay(0);
    3722.             updatePokemonStatsDisplay(3);
    3723.             updateCurrentTask(0);
    3724.  
    3725.             //        Debug.Log(pokemon[0].getName()+": HP: "+pokemon[0].getHP()+"ATK: "+pokemon[0].getATK()+"DEF: "+pokemon[0].getDEF()+"SPA: "+pokemon[0].getSPA()+"SPD: "+pokemon[0].getSPD()+"SPE:"+pokemon[0].getSPE());
    3726.             //        Debug.Log(pokemon[3].getName()+": HP: "+pokemon[3].getHP()+"ATK: "+pokemon[3].getATK()+"DEF: "+pokemon[3].getDEF()+"SPA: "+pokemon[3].getSPA()+"SPD: "+pokemon[3].getSPD()+"SPE:"+pokemon[3].getSPE());
    3727.  
    3728.             ////////////////////////////////////////
    3729.             /// Task Selection State
    3730.             ////////////////////////////////////////
    3731.             runState = true;
    3732.             while (runState)
    3733.             {
    3734.                 //DEBUG OVERLAY TEXTURES
    3735.                 if (Input.GetKeyDown(KeyCode.Y))
    3736.                 {
    3737.                     StartCoroutine(animateOverlayer(opponent1Overlay, overlayHealTex, -1f, 0, 1.2f, 0.3f));
    3738.                 }
    3739.                 if (Input.GetKeyDown(KeyCode.U))
    3740.                 {
    3741.                     StartCoroutine(animateOverlayer(opponent1Overlay, overlayStatUpTex, -1f, 0, 1.2f, 0.3f));
    3742.                 }
    3743.                 if (Input.GetKeyDown(KeyCode.I))
    3744.                 {
    3745.                     StartCoroutine(animateOverlayer(opponent1Overlay, overlayStatDownTex, 1f, 0, 1.2f, 0.3f));
    3746.                 }
    3747.  
    3748.                 //// NAVIGATE MAIN OPTIONS ////
    3749.  
    3750.                 if (Input.GetAxisRaw("Horizontal") < 0)
    3751.                 {
    3752.                     if (taskPosition > 0 && taskPosition != 3)
    3753.                     {
    3754.                         updateSelectedTask(taskPosition - 1);
    3755.                         SfxHandler.Play(scrollClip);
    3756.                         yield return new WaitForSeconds(0.2f);
    3757.                     }
    3758.                 }
    3759.                 else if (Input.GetAxisRaw("Horizontal") > 0)
    3760.                 {
    3761.                     if (taskPosition < 5 && taskPosition != 2)
    3762.                     {
    3763.                         updateSelectedTask(taskPosition + 1);
    3764.                         SfxHandler.Play(scrollClip);
    3765.                         yield return new WaitForSeconds(0.2f);
    3766.                     }
    3767.                 }
    3768.                 else if (Input.GetAxisRaw("Vertical") > 0)
    3769.                 {
    3770.                     if (taskPosition > 2)
    3771.                     {
    3772.                         if (taskPosition == 4)
    3773.                         {
    3774.                             //if run selected
    3775.                             updateSelectedTask(taskPosition - 3);
    3776.                             SfxHandler.Play(scrollClip);
    3777.                             yield return new WaitForSeconds(0.2f);
    3778.                         }
    3779.                         else
    3780.                         {
    3781.                             taskPosition -= 3;
    3782.                         }
    3783.                     }
    3784.                 }
    3785.                 else if (Input.GetAxisRaw("Vertical") < 0)
    3786.                 {
    3787.                     if (taskPosition < 3)
    3788.                     {
    3789.                         if (taskPosition == 1)
    3790.                         {
    3791.                             //if fight selected
    3792.                             updateSelectedTask(taskPosition + 3);
    3793.                             SfxHandler.Play(scrollClip);
    3794.                             yield return new WaitForSeconds(0.2f);
    3795.                         }
    3796.                         else
    3797.                         {
    3798.                             taskPosition += 3;
    3799.                         }
    3800.                     }
    3801.                 }
    3802.                 else if (Input.GetButtonDown("Select"))
    3803.                 {
    3804.                     //// NAVIGATE MOVESET OPTIONS ////
    3805.  
    3806.                     int currentPokemon = 0;
    3807.  
    3808.                     if (taskPosition == 1)
    3809.                     {
    3810.                         updateCurrentTask(1);
    3811.                         SfxHandler.Play(selectClip);
    3812.                         yield return null;
    3813.  
    3814.                         //while still in Move Selection menu
    3815.                         while (currentTask == 1)
    3816.                         {
    3817.                             if (Input.GetAxisRaw("Horizontal") < 0)
    3818.                             {
    3819.                                 if (movePosition == 1)
    3820.                                 {
    3821.                                     if (canMegaEvolve)
    3822.                                     {
    3823.                                         updateSelectedMove(0);
    3824.                                         SfxHandler.Play(scrollClip);
    3825.                                         yield return new WaitForSeconds(0.2f);
    3826.                                     }
    3827.                                     else
    3828.                                     {
    3829.                                         updateSelectedMove(3);
    3830.                                         SfxHandler.Play(scrollClip);
    3831.                                         yield return new WaitForSeconds(0.2f);
    3832.                                     }
    3833.                                 }
    3834.                                 else if (movePosition > 1 && movePosition != 3)
    3835.                                 {
    3836.                                     if (movePosition == 5)
    3837.                                     {
    3838.                                         if (pokemonMoveset[currentPokemon][2] != null)
    3839.                                         {
    3840.                                             //check destination has a move there
    3841.                                             updateSelectedMove(movePosition - 1);
    3842.                                             SfxHandler.Play(scrollClip);
    3843.                                             yield return new WaitForSeconds(0.2f);
    3844.                                         }
    3845.                                     }
    3846.                                     else
    3847.                                     {
    3848.                                         updateSelectedMove(movePosition - 1);
    3849.                                         SfxHandler.Play(scrollClip);
    3850.                                         yield return new WaitForSeconds(0.2f);
    3851.                                     }
    3852.                                 }
    3853.                             }
    3854.                             else if (Input.GetAxisRaw("Horizontal") > 0)
    3855.                             {
    3856.                                 if (movePosition < 5 && movePosition != 2)
    3857.                                 {
    3858.                                     if (movePosition == 1)
    3859.                                     {
    3860.                                         if (pokemonMoveset[currentPokemon][1] != null)
    3861.                                         {
    3862.                                             //check destination has a move there
    3863.                                             updateSelectedMove(movePosition + 1);
    3864.                                             SfxHandler.Play(scrollClip);
    3865.                                             yield return new WaitForSeconds(0.2f);
    3866.                                         }
    3867.                                     }
    3868.                                     else if (movePosition == 3)
    3869.                                     {
    3870.                                         if (pokemonMoveset[currentPokemon][2] != null)
    3871.                                         {
    3872.                                             //check destination has a move there
    3873.                                             updateSelectedMove(movePosition + 1);
    3874.                                             SfxHandler.Play(scrollClip);
    3875.                                             yield return new WaitForSeconds(0.2f);
    3876.                                         }
    3877.                                         else
    3878.                                         {
    3879.                                             updateSelectedMove(1);
    3880.                                             SfxHandler.Play(scrollClip);
    3881.                                             yield return new WaitForSeconds(0.2f);
    3882.                                         }
    3883.                                     }
    3884.                                     else if (movePosition == 4)
    3885.                                     {
    3886.                                         if (pokemonMoveset[currentPokemon][3] != null)
    3887.                                         {
    3888.                                             //check destination has a move there
    3889.                                             updateSelectedMove(movePosition + 1);
    3890.                                             SfxHandler.Play(scrollClip);
    3891.                                             yield return new WaitForSeconds(0.2f);
    3892.                                         }
    3893.                                         else if (pokemonMoveset[currentPokemon][1] != null)
    3894.                                         {
    3895.                                             //check there is a move 2
    3896.                                             updateSelectedMove(2);
    3897.                                             SfxHandler.Play(scrollClip);
    3898.                                             yield return new WaitForSeconds(0.2f);
    3899.                                         }
    3900.                                     }
    3901.                                     else
    3902.                                     {
    3903.                                         updateSelectedMove(movePosition + 1);
    3904.                                         SfxHandler.Play(scrollClip);
    3905.                                         yield return new WaitForSeconds(0.2f);
    3906.                                     }
    3907.                                 }
    3908.                             }
    3909.                             else if (Input.GetAxisRaw("Vertical") > 0)
    3910.                             {
    3911.                                 if (movePosition == 3)
    3912.                                 {
    3913.                                     if (canMegaEvolve)
    3914.                                     {
    3915.                                         updateSelectedMove(movePosition - 3);
    3916.                                         SfxHandler.Play(scrollClip);
    3917.                                         yield return new WaitForSeconds(0.2f);
    3918.                                     }
    3919.                                     else
    3920.                                     {
    3921.                                         //otherwise, go down to return
    3922.                                         updateSelectedMove(1);
    3923.                                         SfxHandler.Play(scrollClip);
    3924.                                         yield return new WaitForSeconds(0.2f);
    3925.                                     }
    3926.                                 }
    3927.                                 else if (movePosition > 3)
    3928.                                 {
    3929.                                     if (movePosition == 5)
    3930.                                     {
    3931.                                         if (pokemonMoveset[currentPokemon][1] != null)
    3932.                                         {
    3933.                                             //check destination has a move there
    3934.                                             updateSelectedMove(movePosition - 3);
    3935.                                             SfxHandler.Play(scrollClip);
    3936.                                             yield return new WaitForSeconds(0.2f);
    3937.                                         }
    3938.                                     }
    3939.                                     else
    3940.                                     {
    3941.                                         updateSelectedMove(movePosition - 3);
    3942.                                         SfxHandler.Play(scrollClip);
    3943.                                         yield return new WaitForSeconds(0.2f);
    3944.                                     }
    3945.                                 }
    3946.                             }
    3947.                             else if (Input.GetAxisRaw("Vertical") < 0)
    3948.                             {
    3949.                                 if (movePosition < 3)
    3950.                                 {
    3951.                                     if (movePosition == 1)
    3952.                                     {
    3953.                                         if (pokemonMoveset[currentPokemon][2] != null)
    3954.                                         {
    3955.                                             //check destination has a move there
    3956.                                             updateSelectedMove(movePosition + 3);
    3957.                                             SfxHandler.Play(scrollClip);
    3958.                                             yield return new WaitForSeconds(0.2f);
    3959.                                         }
    3960.                                         else
    3961.                                         {
    3962.                                             //otherwise, go down to return
    3963.                                             updateSelectedMove(3);
    3964.                                             SfxHandler.Play(scrollClip);
    3965.                                             yield return new WaitForSeconds(0.2f);
    3966.                                         }
    3967.                                     }
    3968.                                     else if (movePosition == 2)
    3969.                                     {
    3970.                                         if (pokemonMoveset[currentPokemon][3] != null)
    3971.                                         {
    3972.                                             //check destination has a move there
    3973.                                             updateSelectedMove(movePosition + 3);
    3974.                                             SfxHandler.Play(scrollClip);
    3975.                                             yield return new WaitForSeconds(0.2f);
    3976.                                         }
    3977.                                         else if (pokemonMoveset[currentPokemon][2] != null)
    3978.                                         {
    3979.                                             //check if there is a move 3
    3980.                                             updateSelectedMove(4);
    3981.                                             SfxHandler.Play(scrollClip);
    3982.                                             yield return new WaitForSeconds(0.2f);
    3983.                                         }
    3984.                                         else
    3985.                                         {
    3986.                                             //otherwise, go down to return
    3987.                                             updateSelectedMove(3);
    3988.                                             SfxHandler.Play(scrollClip);
    3989.                                             yield return new WaitForSeconds(0.2f);
    3990.                                         }
    3991.                                     }
    3992.                                     else
    3993.                                     {
    3994.                                         updateSelectedMove(movePosition + 3);
    3995.                                         SfxHandler.Play(scrollClip);
    3996.                                         yield return new WaitForSeconds(0.2f);
    3997.                                     }
    3998.                                 }
    3999.                             }
    4000.                             else if (Input.GetButtonDown("Select"))
    4001.                             {
    4002.                                 if (movePosition == 0)
    4003.                                 {
    4004.                                     //if mega evolution selected (mega evolution not yet implemented)
    4005.                                 }
    4006.                                 else if (movePosition == 3)
    4007.                                 {
    4008.                                     //if back selected
    4009.                                     SfxHandler.Play(selectClip);
    4010.                                     updateCurrentTask(0);
    4011.                                 }
    4012.                                 else
    4013.                                 {
    4014.                                     //if a move is selected
    4015.                                     //check if struggle is to be used (no PP left in any move)
    4016.                                     if (pokemon[currentPokemon].getPP(0) == 0 && pokemon[currentPokemon].getPP(1) == 0 &&
    4017.                                         pokemon[currentPokemon].getPP(2) == 0 && pokemon[currentPokemon].getPP(3) == 0)
    4018.                                     {
    4019.                                         commandMove[currentPokemon] = MoveDatabase.getMove("Struggle");
    4020.                                         runState = false;
    4021.                                     }
    4022.                                     else
    4023.                                     {
    4024.                                         //convert movePosition to moveset index
    4025.                                         int[] move = new int[] {0, 0, 1, 0, 2, 3};
    4026.                                         if (pokemon[currentPokemon].getPP(move[movePosition]) > 0)
    4027.                                         {
    4028.                                             commandMove[currentPokemon] =
    4029.                                                 MoveDatabase.getMove(pokemonMoveset[currentPokemon][move[movePosition]]);
    4030.                                             runState = false;
    4031.                                         }
    4032.                                         else
    4033.                                         {
    4034.                                             yield return StartCoroutine(drawTextAndWait("That move is out of PP!"));
    4035.                                             Dialog.UndrawDialogBox();
    4036.                                         }
    4037.                                     }
    4038.                                 }
    4039.                                 if (!runState)
    4040.                                 {
    4041.                                     //if a move was chosen.
    4042.                                     SfxHandler.Play(selectClip);
    4043.                                     command[currentPokemon] = CommandType.Move;
    4044.                                     updateCurrentTask(-1);
    4045.                                 }
    4046.                             }
    4047.                             else if (Input.GetButtonDown("Back"))
    4048.                             {
    4049.                                 SfxHandler.Play(selectClip);
    4050.                                 updateCurrentTask(0);
    4051.                             }
    4052.  
    4053.                             yield return null;
    4054.                         }
    4055.                     }
    4056.  
    4057.                     //// ATTEMPT TO FLEE ////
    4058.  
    4059.                     else if (taskPosition == 4)
    4060.                     {
    4061.                         SfxHandler.Play(selectClip);
    4062.                         if (trainerBattle)
    4063.                         {
    4064.                             yield return
    4065.                                 StartCoroutine(drawTextAndWait("No! There's no running from \\na Trainer Battle!"));
    4066.                             Dialog.UndrawDialogBox();
    4067.                         }
    4068.                         else
    4069.                         {
    4070.                             command[currentPokemon] = CommandType.Flee;
    4071.                             runState = false;
    4072.                             updateCurrentTask(-1);
    4073.                         }
    4074.                     }
    4075.  
    4076.                     //// OPEN BAG INTERFACE ////
    4077.  
    4078.                     else if (taskPosition == 0 || taskPosition == 3)
    4079.                     {
    4080.                         updateCurrentTask(2);
    4081.                         SfxHandler.Play(selectClip);
    4082.                         yield return null;
    4083.  
    4084.                         updateSelectedBagCategory(bagCategoryPosition);
    4085.                         //while still in Bag menu
    4086.                         while (currentTask == 2)
    4087.                         {
    4088.                             if (Input.GetAxisRaw("Vertical") < 0)
    4089.                             {
    4090.                                 if (bagCategoryPosition < 4)
    4091.                                 {
    4092.                                     updateSelectedBagCategory(bagCategoryPosition + 2);
    4093.                                     SfxHandler.Play(scrollClip);
    4094.                                     yield return new WaitForSeconds(0.2f);
    4095.                                 }
    4096.                             }
    4097.                             else if (Input.GetAxisRaw("Horizontal") > 0)
    4098.                             {
    4099.                                 if (bagCategoryPosition == 0 || bagCategoryPosition == 2 || bagCategoryPosition == 4)
    4100.                                 {
    4101.                                     updateSelectedBagCategory(bagCategoryPosition + 1);
    4102.                                     SfxHandler.Play(scrollClip);
    4103.                                     yield return new WaitForSeconds(0.2f);
    4104.                                 }
    4105.                             }
    4106.                             else if (Input.GetAxisRaw("Horizontal") < 0)
    4107.                             {
    4108.                                 if (bagCategoryPosition == 1 || bagCategoryPosition == 3 || bagCategoryPosition == 5)
    4109.                                 {
    4110.                                     updateSelectedBagCategory(bagCategoryPosition - 1);
    4111.                                     SfxHandler.Play(scrollClip);
    4112.                                     yield return new WaitForSeconds(0.2f);
    4113.                                 }
    4114.                             }
    4115.                             else if (Input.GetAxisRaw("Vertical") > 0)
    4116.                             {
    4117.                                 if (bagCategoryPosition > 1)
    4118.                                 {
    4119.                                     updateSelectedBagCategory(bagCategoryPosition - 2);
    4120.                                     SfxHandler.Play(scrollClip);
    4121.                                     yield return new WaitForSeconds(0.2f);
    4122.                                 }
    4123.                             }
    4124.                             else if (Input.GetButtonDown("Select"))
    4125.                             {
    4126.                                 if (bagCategoryPosition < 4)
    4127.                                 {
    4128.                                     //Item Category
    4129.                                     updateCurrentTask(4);
    4130.                                     SfxHandler.Play(selectClip);
    4131.  
    4132.                                     int itemListPosition = updateSelectedItemListSlot(0, 0);
    4133.                                     yield return new WaitForSeconds(0.2f);
    4134.                                     while (currentTask == 4)
    4135.                                     {
    4136.                                         if (Input.GetAxisRaw("Vertical") < 0)
    4137.                                         {
    4138.                                             if (itemListPosition < 8)
    4139.                                             {
    4140.                                                 int positionBeforeModification = itemListPosition;
    4141.                                                 if (itemListPosition < 7)
    4142.                                                 {
    4143.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, 2);
    4144.                                                 }
    4145.                                                 else
    4146.                                                 {
    4147.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, 1);
    4148.                                                 }
    4149.                                                 if (positionBeforeModification != itemListPosition)
    4150.                                                 {
    4151.                                                     SfxHandler.Play(scrollClip);
    4152.                                                     yield return new WaitForSeconds(0.2f);
    4153.                                                 }
    4154.                                             }
    4155.                                         }
    4156.                                         else if (Input.GetAxisRaw("Horizontal") > 0)
    4157.                                         {
    4158.                                             if (itemListPosition < 8)
    4159.                                             {
    4160.                                                 if (itemListPosition % 2 == 0)
    4161.                                                 {
    4162.                                                     int positionBeforeModification = itemListPosition;
    4163.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, 1);
    4164.                                                     if (positionBeforeModification != itemListPosition)
    4165.                                                     {
    4166.                                                         SfxHandler.Play(scrollClip);
    4167.                                                         yield return new WaitForSeconds(0.2f);
    4168.                                                     }
    4169.                                                 }
    4170.                                                 //go to next page of items
    4171.                                                 else if (itemListPagePosition < itemListPageCount - 1)
    4172.                                                 {
    4173.                                                     int positionBeforeModification = itemListPosition;
    4174.                                                     itemListPagePosition += 1;
    4175.                                                     updateItemListDisplay();
    4176.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, -1);
    4177.                                                     if (positionBeforeModification != itemListPosition)
    4178.                                                     {
    4179.                                                         SfxHandler.Play(scrollClip);
    4180.                                                         yield return new WaitForSeconds(0.2f);
    4181.                                                     }
    4182.                                                 }
    4183.                                             }
    4184.                                         }
    4185.                                         else if (Input.GetAxisRaw("Horizontal") < 0)
    4186.                                         {
    4187.                                             if (itemListPosition < 8)
    4188.                                             {
    4189.                                                 if (itemListPosition % 2 == 1)
    4190.                                                 {
    4191.                                                     int positionBeforeModification = itemListPosition;
    4192.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, -1);
    4193.                                                     if (positionBeforeModification != itemListPosition)
    4194.                                                     {
    4195.                                                         SfxHandler.Play(scrollClip);
    4196.                                                         yield return new WaitForSeconds(0.2f);
    4197.                                                     }
    4198.                                                 }
    4199.                                                 //go to previous page of items
    4200.                                                 else if (itemListPagePosition > 0)
    4201.                                                 {
    4202.                                                     int positionBeforeModification = itemListPosition;
    4203.                                                     itemListPagePosition -= 1;
    4204.                                                     updateItemListDisplay();
    4205.                                                     itemListPosition = updateSelectedItemListSlot(itemListPosition, 1);
    4206.                                                     if (positionBeforeModification != itemListPosition)
    4207.                                                     {
    4208.                                                         SfxHandler.Play(scrollClip);
    4209.                                                         yield return new WaitForSeconds(0.2f);
    4210.                                                     }
    4211.                                                 }
    4212.                                             }
    4213.                                         }
    4214.                                         else if (Input.GetAxisRaw("Vertical") > 0)
    4215.                                         {
    4216.                                             if (itemListPosition > 1)
    4217.                                             {
    4218.                                                 int positionBeforeModification = itemListPosition;
    4219.                                                 itemListPosition = updateSelectedItemListSlot(itemListPosition, -2);
    4220.                                                 if (positionBeforeModification != itemListPosition)
    4221.                                                 {
    4222.                                                     SfxHandler.Play(scrollClip);
    4223.                                                     yield return new WaitForSeconds(0.2f);
    4224.                                                 }
    4225.                                             }
    4226.                                         }
    4227.                                         else if (Input.GetButtonDown("Select"))
    4228.                                         {
    4229.                                             if (itemListPosition == 8)
    4230.                                             {
    4231.                                                 SfxHandler.Play(selectClip);
    4232.                                                 updateCurrentTask(2);
    4233.                                                 yield return new WaitForSeconds(0.2f);
    4234.                                             }
    4235.                                             else
    4236.                                             {
    4237.                                                 //use item
    4238.                                                 ItemData selectedItem =
    4239.                                                     ItemDatabase.getItem(
    4240.                                                         itemListString[itemListPosition + (8 * itemListPagePosition)]);
    4241.                                                 //Check item can be used
    4242.                                                 if (selectedItem.getItemEffect() == ItemData.ItemEffect.HP)
    4243.                                                 {
    4244.                                                     //Check target pokemon's health is not full
    4245.                                                     int target = 0; //target selection not yet implemented
    4246.                                                     if (pokemon[target].getCurrentHP() < pokemon[target].getHP())
    4247.                                                     {
    4248.                                                         commandItem[currentPokemon] = selectedItem;
    4249.                                                         commandTarget[currentPokemon] = target;
    4250.                                                         SaveData.currentSave.Bag.removeItem(selectedItem.getName(), 1);
    4251.                                                         runState = false;
    4252.                                                     }
    4253.                                                     else
    4254.                                                     {
    4255.                                                         yield return
    4256.                                                             StartCoroutine(drawTextAndWait("It won't have any effect!"))
    4257.                                                             ;
    4258.                                                         Dialog.UndrawDialogBox();
    4259.                                                     }
    4260.                                                 }
    4261.                                                 else if (selectedItem.getItemEffect() == ItemData.ItemEffect.STATUS)
    4262.                                                 {
    4263.                                                     int target = 0; //target selection not yet implemented
    4264.                                                     //Check target pokemon has the status the item cures
    4265.                                                     string statusCurer = selectedItem.getStringParameter().ToUpper();
    4266.                                                     //if an ALL is used, set it to cure anything but FAINTED or NONE.
    4267.                                                     if (statusCurer == "ALL" &&
    4268.                                                         pokemon[target].getStatus().ToString() != "FAINTED" &&
    4269.                                                         pokemon[target].getStatus().ToString() != "NONE")
    4270.                                                     {
    4271.                                                         statusCurer = pokemon[target].getStatus().ToString();
    4272.                                                     }
    4273.  
    4274.                                                     if (pokemon[target].getStatus().ToString() == statusCurer)
    4275.                                                     {
    4276.                                                         commandItem[currentPokemon] = selectedItem;
    4277.                                                         commandTarget[currentPokemon] = target;
    4278.                                                         SaveData.currentSave.Bag.removeItem(
    4279.                                                             itemListString[itemListPosition], 1);
    4280.                                                         runState = false;
    4281.                                                     }
    4282.                                                     else
    4283.                                                     {
    4284.                                                         yield return
    4285.                                                             StartCoroutine(drawTextAndWait("It won't have any effect!"))
    4286.                                                             ;
    4287.                                                         Dialog.UndrawDialogBox();
    4288.                                                     }
    4289.                                                 }
    4290.                                                 else
    4291.                                                 {
    4292.                                                     commandItem[currentPokemon] =
    4293.                                                         ItemDatabase.getItem(itemListString[itemListPosition]);
    4294.                                                     SaveData.currentSave.Bag.removeItem(
    4295.                                                         itemListString[itemListPosition], 1);
    4296.                                                     runState = false;
    4297.                                                 }
    4298.                                                 if (!runState)
    4299.                                                 {
    4300.                                                     //if an item was chosen.
    4301.                                                     SfxHandler.Play(selectClip);
    4302.                                                     command[currentPokemon] = CommandType.Item;
    4303.                                                     updateCurrentTask(-1);
    4304.                                                 }
    4305.                                             }
    4306.                                         }
    4307.                                         else if (Input.GetButtonDown("Back"))
    4308.                                         {
    4309.                                             SfxHandler.Play(selectClip);
    4310.                                             updateCurrentTask(2);
    4311.                                             yield return new WaitForSeconds(0.2f);
    4312.                                         }
    4313.  
    4314.  
    4315.                                         yield return null;
    4316.                                     }
    4317.                                 }
    4318.                                 else if (bagCategoryPosition == 4)
    4319.                                 {
    4320.                                     //Back
    4321.                                     updateCurrentTask(0);
    4322.                                     SfxHandler.Play(selectClip);
    4323.                                     yield return new WaitForSeconds(0.2f);
    4324.                                 }
    4325.                                 else if (bagCategoryPosition == 5)
    4326.                                 {
    4327.                                     //Item used last
    4328.                                     SfxHandler.Play(selectClip);
    4329.                                     yield return new WaitForSeconds(0.2f);
    4330.                                 }
    4331.                             }
    4332.                             else if (Input.GetButtonDown("Back"))
    4333.                             {
    4334.                                 SfxHandler.Play(selectClip);
    4335.                                 updateCurrentTask(0);
    4336.                                 yield return new WaitForSeconds(0.2f);
    4337.                             }
    4338.  
    4339.                             yield return null;
    4340.                         }
    4341.                     }
    4342.  
    4343.                     //// OPEN POKEMON INTERFACE ////
    4344.  
    4345.                     else if (taskPosition == 2 || taskPosition == 5)
    4346.                     {
    4347.                         updateCurrentTask(3);
    4348.                         SfxHandler.Play(selectClip);
    4349.                         yield return null;
    4350.  
    4351.                         //while still in Poke menu
    4352.                         while (currentTask == 3)
    4353.                         {
    4354.                             if (Input.GetAxisRaw("Vertical") < 0)
    4355.                             {
    4356.                                 if (pokePartyPosition < 6)
    4357.                                 {
    4358.                                     if (pokePartyPosition == 5)
    4359.                                     {
    4360.                                         updateSelectedPokemonSlot(pokePartyPosition + 1);
    4361.                                     }
    4362.                                     else
    4363.                                     {
    4364.                                         updateSelectedPokemonSlot(pokePartyPosition + 2);
    4365.                                     }
    4366.                                     SfxHandler.Play(scrollClip);
    4367.                                     yield return new WaitForSeconds(0.2f);
    4368.                                 }
    4369.                             }
    4370.                             else if (Input.GetAxisRaw("Horizontal") > 0)
    4371.                             {
    4372.                                 if (pokePartyPosition < 6)
    4373.                                 {
    4374.                                     updateSelectedPokemonSlot(pokePartyPosition + 1);
    4375.                                     SfxHandler.Play(scrollClip);
    4376.                                     yield return new WaitForSeconds(0.2f);
    4377.                                 }
    4378.                             }
    4379.                             else if (Input.GetAxisRaw("Horizontal") < 0)
    4380.                             {
    4381.                                 if (pokePartyPosition > 0)
    4382.                                 {
    4383.                                     updateSelectedPokemonSlot(pokePartyPosition - 1);
    4384.                                     SfxHandler.Play(scrollClip);
    4385.                                     yield return new WaitForSeconds(0.2f);
    4386.                                 }
    4387.                             }
    4388.                             else if (Input.GetAxisRaw("Vertical") > 0)
    4389.                             {
    4390.                                 if (pokePartyPosition > 1)
    4391.                                 {
    4392.                                     if (pokePartyPosition == 6)
    4393.                                     {
    4394.                                         updateSelectedPokemonSlot(pokePartyPosition - 1);
    4395.                                     }
    4396.                                     else
    4397.                                     {
    4398.                                         updateSelectedPokemonSlot(pokePartyPosition - 2);
    4399.                                     }
    4400.                                     SfxHandler.Play(scrollClip);
    4401.                                     yield return new WaitForSeconds(0.2f);
    4402.                                 }
    4403.                             }
    4404.                             else if (Input.GetButtonDown("Select"))
    4405.                             {
    4406.                                 if (pokePartyPosition == 6)
    4407.                                 {
    4408.                                     //Back
    4409.                                     SfxHandler.Play(selectClip);
    4410.                                     updateCurrentTask(0);
    4411.                                     yield return new WaitForSeconds(0.2f);
    4412.                                 }
    4413.                                 else
    4414.                                 {
    4415.                                     updateCurrentTask(5);
    4416.                                     SfxHandler.Play(selectClip);
    4417.                                     int summaryPosition = updateSummaryPosition(0); //0 = Switch, 1 = Moves, 2 = Back
    4418.  
    4419.                                     yield return new WaitForSeconds(0.2f);
    4420.                                     while (currentTask == 5)
    4421.                                     {
    4422.                                         if (Input.GetAxisRaw("Vertical") < 0)
    4423.                                         {
    4424.                                             if (pokePartyPosition < 5)
    4425.                                             {
    4426.                                                 int positionBeforeModification = pokePartyPosition;
    4427.                                                 updateSelectedPokemonSlot(pokePartyPosition + 1, false);
    4428.                                                 if (positionBeforeModification != pokePartyPosition)
    4429.                                                 {
    4430.                                                     SfxHandler.Play(scrollClip);
    4431.                                                 }
    4432.                                                 updatePokemonSummaryDisplay(
    4433.                                                     SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    4434.                                                 yield return new WaitForSeconds(0.2f);
    4435.                                             }
    4436.                                         }
    4437.                                         else if (Input.GetAxisRaw("Horizontal") > 0)
    4438.                                         {
    4439.                                             if (summaryPosition < 2)
    4440.                                             {
    4441.                                                 summaryPosition = updateSummaryPosition(summaryPosition + 1);
    4442.                                                 SfxHandler.Play(scrollClip);
    4443.                                                 yield return new WaitForSeconds(0.2f);
    4444.                                             }
    4445.                                         }
    4446.                                         else if (Input.GetAxisRaw("Horizontal") < 0)
    4447.                                         {
    4448.                                             if (summaryPosition > 0)
    4449.                                             {
    4450.                                                 summaryPosition = updateSummaryPosition(summaryPosition - 1);
    4451.                                                 SfxHandler.Play(scrollClip);
    4452.                                                 yield return new WaitForSeconds(0.2f);
    4453.                                             }
    4454.                                         }
    4455.                                         else if (Input.GetAxisRaw("Vertical") > 0)
    4456.                                         {
    4457.                                             if (pokePartyPosition > 0)
    4458.                                             {
    4459.                                                 int positionBeforeModification = pokePartyPosition;
    4460.                                                 updateSelectedPokemonSlot(pokePartyPosition - 1, false);
    4461.                                                 if (positionBeforeModification != pokePartyPosition)
    4462.                                                 {
    4463.                                                     SfxHandler.Play(scrollClip);
    4464.                                                 }
    4465.                                                 updatePokemonSummaryDisplay(
    4466.                                                     SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    4467.                                                 yield return new WaitForSeconds(0.2f);
    4468.                                             }
    4469.                                         }
    4470.                                         else if (Input.GetButtonDown("Select"))
    4471.                                         {
    4472.                                             if (summaryPosition == 0)
    4473.                                             {
    4474.                                                 if (SaveData.currentSave.PC.boxes[0][pokePartyPosition].getStatus() !=
    4475.                                                     Pokemon.Status.FAINTED)
    4476.                                                 {
    4477.                                                     //check that pokemon is not on the field
    4478.                                                     bool notOnField = true;
    4479.                                                     for (int i = 0; i < pokemonPerSide; i++)
    4480.                                                     {
    4481.                                                         if (SaveData.currentSave.PC.boxes[0][pokePartyPosition] ==
    4482.                                                             pokemon[i])
    4483.                                                         {
    4484.                                                             notOnField = false;
    4485.                                                             i = pokemonPerSide;
    4486.                                                         }
    4487.                                                     }
    4488.                                                     if (notOnField)
    4489.                                                     {
    4490.                                                         //debug
    4491.                                                         command[currentPokemon] = CommandType.Switch;
    4492.                                                         commandPokemon[currentPokemon] =
    4493.                                                             SaveData.currentSave.PC.boxes[0][pokePartyPosition];
    4494.                                                         runState = false;
    4495.                                                         updateCurrentTask(-1);
    4496.                                                         SfxHandler.Play(selectClip);
    4497.                                                         yield return new WaitForSeconds(0.2f);
    4498.                                                     }
    4499.                                                     else
    4500.                                                     {
    4501.                                                         yield return
    4502.                                                             StartCoroutine(
    4503.                                                                 drawTextAndWait(
    4504.                                                                     SaveData.currentSave.PC.boxes[0][pokePartyPosition]
    4505.                                                                         .getName() + " is already fighting!"));
    4506.                                                         Dialog.UndrawDialogBox();
    4507.                                                     }
    4508.                                                 }
    4509.                                                 else
    4510.                                                 {
    4511.                                                     yield return
    4512.                                                         StartCoroutine(
    4513.                                                             drawTextAndWait(
    4514.                                                                 SaveData.currentSave.PC.boxes[0][pokePartyPosition]
    4515.                                                                     .getName() + " is unable to fight!"));
    4516.                                                     Dialog.UndrawDialogBox();
    4517.                                                 }
    4518.                                             }
    4519.                                             else if (summaryPosition == 1)
    4520.                                             {
    4521. //check moves
    4522.                                                 updateCurrentTask(6);
    4523.                                                 SfxHandler.Play(selectClip);
    4524.                                                 yield return new WaitForSeconds(0.2f);
    4525.  
    4526.                                                 int movesPosition = 5; //0-3 = Moves, 4 = Switch, 5 = Summary, 6 = Back
    4527.                                                 while (currentTask == 6)
    4528.                                                 {
    4529.                                                     if (Input.GetAxisRaw("Vertical") < 0)
    4530.                                                     {
    4531.                                                         if (movesPosition < 4)
    4532.                                                         {
    4533.                                                             if (movesPosition == 2)
    4534.                                                             {
    4535.                                                                 movesPosition = updateMovesPosition(movesPosition + 3);
    4536.                                                             }
    4537.                                                             else
    4538.                                                             {
    4539.                                                                 movesPosition = updateMovesPosition(movesPosition + 2);
    4540.                                                             }
    4541.                                                             SfxHandler.Play(scrollClip);
    4542.                                                             yield return new WaitForSeconds(0.2f);
    4543.                                                         }
    4544.                                                     }
    4545.                                                     else if (Input.GetAxisRaw("Horizontal") > 0)
    4546.                                                     {
    4547.                                                         if (movesPosition != 1 || movesPosition != 3 ||
    4548.                                                             movesPosition != 6)
    4549.                                                         {
    4550.                                                             movesPosition = updateMovesPosition(movesPosition + 1);
    4551.                                                             SfxHandler.Play(scrollClip);
    4552.                                                             yield return new WaitForSeconds(0.2f);
    4553.                                                         }
    4554.                                                     }
    4555.                                                     else if (Input.GetAxisRaw("Horizontal") < 0)
    4556.                                                     {
    4557.                                                         if (movesPosition == 1 || movesPosition == 3 ||
    4558.                                                             movesPosition > 4)
    4559.                                                         {
    4560.                                                             movesPosition = updateMovesPosition(movesPosition - 1);
    4561.                                                             SfxHandler.Play(scrollClip);
    4562.                                                             yield return new WaitForSeconds(0.2f);
    4563.                                                         }
    4564.                                                     }
    4565.                                                     else if (Input.GetAxisRaw("Vertical") > 0)
    4566.                                                     {
    4567.                                                         if (movesPosition > 1)
    4568.                                                         {
    4569.                                                             if (movesPosition > 3)
    4570.                                                             {
    4571.                                                                 movesPosition = updateMovesPosition(2);
    4572.                                                             }
    4573.                                                             else
    4574.                                                             {
    4575.                                                                 movesPosition = updateMovesPosition(movesPosition - 2);
    4576.                                                             }
    4577.                                                             SfxHandler.Play(scrollClip);
    4578.                                                             yield return new WaitForSeconds(0.2f);
    4579.                                                         }
    4580.                                                     }
    4581.                                                     else if (Input.GetButtonDown("Select"))
    4582.                                                     {
    4583.                                                         if (movesPosition == 4)
    4584.                                                         {
    4585.                                                             if (
    4586.                                                                 SaveData.currentSave.PC.boxes[0][pokePartyPosition]
    4587.                                                                     .getStatus() != Pokemon.Status.FAINTED)
    4588.                                                             {
    4589.                                                                 //check that pokemon is not on the field
    4590.                                                                 bool notOnField = true;
    4591.                                                                 for (int i = 0; i < pokemonPerSide; i++)
    4592.                                                                 {
    4593.                                                                     if (
    4594.                                                                         SaveData.currentSave.PC.boxes[0][
    4595.                                                                             pokePartyPosition] == pokemon[i])
    4596.                                                                     {
    4597.                                                                         notOnField = false;
    4598.                                                                         i = pokemonPerSide;
    4599.                                                                     }
    4600.                                                                 }
    4601.                                                                 if (notOnField)
    4602.                                                                 {
    4603.                                                                     //debug
    4604.                                                                     command[currentPokemon] = CommandType.Switch;
    4605.                                                                     commandPokemon[currentPokemon] =
    4606.                                                                         SaveData.currentSave.PC.boxes[0][
    4607.                                                                             pokePartyPosition];
    4608.                                                                     runState = false;
    4609.                                                                     updateCurrentTask(-1);
    4610.                                                                     SfxHandler.Play(selectClip);
    4611.                                                                     yield return new WaitForSeconds(0.2f);
    4612.                                                                 }
    4613.                                                                 else
    4614.                                                                 {
    4615.                                                                     yield return
    4616.                                                                         StartCoroutine(
    4617.                                                                             drawTextAndWait(
    4618.                                                                                 SaveData.currentSave.PC.boxes[0][
    4619.                                                                                     pokePartyPosition].getName() +
    4620.                                                                                 " is already fighting!"));
    4621.                                                                     Dialog.UndrawDialogBox();
    4622.                                                                 }
    4623.                                                             }
    4624.                                                             else
    4625.                                                             {
    4626.                                                                 yield return
    4627.                                                                     StartCoroutine(
    4628.                                                                         drawTextAndWait(
    4629.                                                                             SaveData.currentSave.PC.boxes[0][
    4630.                                                                                 pokePartyPosition].getName() +
    4631.                                                                             " is unable to fight!"));
    4632.                                                                 Dialog.UndrawDialogBox();
    4633.                                                             }
    4634.                                                         }
    4635.                                                         else if (movesPosition == 5)
    4636.                                                         {
    4637. //check summary
    4638.                                                             updateCurrentTask(5);
    4639.                                                             SfxHandler.Play(selectClip);
    4640.                                                             yield return new WaitForSeconds(0.2f);
    4641.                                                         }
    4642.                                                         else if (movesPosition == 6)
    4643.                                                         {
    4644. //back
    4645.                                                             updateCurrentTask(3);
    4646.                                                             SfxHandler.Play(selectClip);
    4647.                                                             yield return new WaitForSeconds(0.2f);
    4648.                                                         }
    4649.                                                     }
    4650.                                                     else if (Input.GetButtonDown("Back"))
    4651.                                                     {
    4652.                                                         updateCurrentTask(3);
    4653.                                                         SfxHandler.Play(selectClip);
    4654.                                                         yield return new WaitForSeconds(0.2f);
    4655.                                                     }
    4656.  
    4657.                                                     yield return null;
    4658.                                                 }
    4659.                                             }
    4660.                                             else if (summaryPosition == 2)
    4661.                                             {
    4662. //back
    4663.                                                 updateCurrentTask(3);
    4664.                                                 SfxHandler.Play(selectClip);
    4665.                                                 yield return new WaitForSeconds(0.2f);
    4666.                                             }
    4667.                                         }
    4668.                                         else if (Input.GetButtonDown("Back"))
    4669.                                         {
    4670.                                             updateCurrentTask(3);
    4671.                                             SfxHandler.Play(selectClip);
    4672.                                             yield return new WaitForSeconds(0.2f);
    4673.                                         }
    4674.  
    4675.                                         yield return null;
    4676.                                     }
    4677.                                 }
    4678.                             }
    4679.                             else if (Input.GetButtonDown("Back"))
    4680.                             {
    4681.                                 SfxHandler.Play(selectClip);
    4682.                                 updateCurrentTask(0);
    4683.                             }
    4684.  
    4685.                             yield return null;
    4686.                         }
    4687.                     }
    4688.                 }
    4689.                 else if (Input.GetButtonDown("Back"))
    4690.                 {
    4691.                 }
    4692.  
    4693.                 yield return null;
    4694.             }
    4695.  
    4696.  
    4697.             ////////////////////////////////////////
    4698.             /// AI turn selection
    4699.             ////////////////////////////////////////
    4700.  
    4701.             //AI not yet implemented properly.
    4702.             //the following code randomly chooses a move to use with no further thought.
    4703.             for (int i = 0; i < pokemonPerSide; i++)
    4704.             {
    4705.                 //do for every pokemon on enemy side
    4706.                 int pi = i + 3;
    4707.                 if (pokemon[pi] != null)
    4708.                 {
    4709.                     //check if struggle is to be used (no PP left in any move)
    4710.                     if (pokemon[pi].getPP(0) == 0 && pokemon[pi].getPP(1) == 0 &&
    4711.                         pokemon[pi].getPP(2) == 0 && pokemon[pi].getPP(3) == 0)
    4712.                     {
    4713.                         commandMove[pi] = MoveDatabase.getMove("Struggle");
    4714.                     }
    4715.                     else
    4716.                     {
    4717.                         //Randomly choose a move from the moveset
    4718.                         int AImoveIndex = Random.Range(0, 4);
    4719.                         while (pokemonMoveset[pi] != null && string.IsNullOrEmpty(pokemonMoveset[pi][AImoveIndex]) &&
    4720.                                pokemon[pi].getPP(AImoveIndex) == 0)
    4721.                         {
    4722.                             AImoveIndex = Random.Range(0, 4);
    4723.                         }
    4724.                         command[pi] = CommandType.Move;
    4725.                         commandMove[pi] = MoveDatabase.getMove(pokemonMoveset[pi][AImoveIndex]);
    4726.                         Debug.Log(commandMove[pi].getName() + ", PP: " + pokemon[pi].getPP(AImoveIndex));
    4727.                     }
    4728.                 }
    4729.             }
    4730.  
    4731.  
    4732.             yield return new WaitForSeconds(0.3f);
    4733.  
    4734.             ////////////////////////////////////////
    4735.             /// Battle State
    4736.             ////////////////////////////////////////
    4737.  
    4738.  
    4739.             //for each pokemon on field, in order of speed/priority, run their command
    4740.             for (int i = 0; i < 6; i++)
    4741.             {
    4742.                 if (running)
    4743.                 {
    4744.                     //running may be set to false by a flee command
    4745.                     int movingPokemon = getHighestSpeedIndex();
    4746.                     if (pokemon[movingPokemon] != null)
    4747.                     {
    4748.                         if (command[movingPokemon] == CommandType.Flee)
    4749.                         {
    4750.                             //RUN
    4751.                             if (movingPokemon < 3)
    4752.                             {
    4753.                                 //player attemps escape
    4754.                                 playerFleeAttempts += 1;
    4755.  
    4756.                                 int fleeChance = (pokemon[movingPokemon].getSPE() * 128) / pokemon[3].getSPE() +
    4757.                                                  30 * playerFleeAttempts;
    4758.                                 if (Random.Range(0, 256) < fleeChance)
    4759.                                 {
    4760.                                     running = false;
    4761.  
    4762.                                     SfxHandler.Play(runClip);
    4763.                                     Dialog.DrawDialogBox();
    4764.                                     yield return StartCoroutine(Dialog.DrawTextSilent("Got away safely!"));
    4765.                                     while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back"))
    4766.                                     {
    4767.                                         yield return null;
    4768.                                     }
    4769.                                     Dialog.UndrawDialogBox();
    4770.                                 }
    4771.                                 else
    4772.                                 {
    4773.                                     yield return StartCoroutine(drawTextAndWait("Can't escape!"));
    4774.                                 }
    4775.                             }
    4776.  
    4777.                             pokemonHasMoved[movingPokemon] = true;
    4778.                         }
    4779.                         else if (command[movingPokemon] == CommandType.Item)
    4780.                         {
    4781.                             //ITEM
    4782.                             //item effects not yet implemented fully
    4783.  
    4784.                             if (i < 3)
    4785.                             {
    4786.                                 if (commandItem[movingPokemon].getItemEffect() == ItemData.ItemEffect.BALL)
    4787.                                 {
    4788.                                     //debug autoselect targetIndex (target selection not yet implemented)
    4789.                                     int targetIndex = 3;
    4790.                                     //
    4791.  
    4792.                                     //pokeball animation not yet implemented
    4793.                                     yield return
    4794.                                         StartCoroutine(
    4795.                                             drawTextAndWait(
    4796.                                                 SaveData.currentSave.playerName + " used one " +
    4797.                                                 commandItem[movingPokemon].getName() + "!", 2.4f));
    4798.                                     yield return new WaitForSeconds(1.2f);
    4799.                                     if (trainerBattle)
    4800.                                     {
    4801.                                         yield return
    4802.                                             StartCoroutine(drawTextAndWait("The trainer blocked the ball!", 2.4f));
    4803.                                         yield return StartCoroutine(drawTextAndWait("Don't be a theif!", 2.4f));
    4804.                                     }
    4805.                                     //calculate catch chance
    4806.                                     else
    4807.                                     {
    4808.                                         float ballRate = (float) commandItem[movingPokemon].getFloatParameter();
    4809.                                         float catchRate =
    4810.                                             (float)
    4811.                                             PokemonDatabase.getPokemon(pokemon[targetIndex].getID()).getCatchRate();
    4812.                                         float statusRate = 1f;
    4813.                                         if ((pokemon[targetIndex].getStatus() != Pokemon.Status.NONE))
    4814.                                         {
    4815.                                             statusRate = (pokemon[targetIndex].getStatus() == Pokemon.Status.ASLEEP ||
    4816.                                                           pokemon[targetIndex].getStatus() == Pokemon.Status.FROZEN)
    4817.                                                 ? 2.5f
    4818.                                                 : 1.5f;
    4819.                                         }
    4820.  
    4821.                                         int modifiedRate =
    4822.                                             Mathf.FloorToInt(((3 * (float) pokemon[targetIndex].getHP() -
    4823.                                                                2 * (float) pokemon[targetIndex].getCurrentHP())
    4824.                                                               * catchRate * ballRate) /
    4825.                                                              (3 * (float) pokemon[targetIndex].getHP()) * statusRate);
    4826.  
    4827.                                         Debug.Log("modifiedRate: " + modifiedRate);
    4828.  
    4829.                                         //GEN VI
    4830.                                         //int shakeProbability = Mathf.FloorToInt(65536f / Mathf.Pow((255f/modifiedRate),0.1875f));
    4831.                                         //GEN V
    4832.                                         int shakeProbability =
    4833.                                             Mathf.FloorToInt(65536f / Mathf.Sqrt(Mathf.Sqrt(255f / modifiedRate)));
    4834.  
    4835.                                         int shakes = 0;
    4836.  
    4837.                                         string debugString = "";
    4838.                                         for (int shake = 0; shake < 4; shake++)
    4839.                                         {
    4840.                                             int shakeCheck = Random.Range(0, 65535);
    4841.                                             debugString += shake + ":(" + shakeCheck + "<" + shakeProbability + ")? ";
    4842.                                             if (shakeCheck < shakeProbability)
    4843.                                             {
    4844.                                                 debugString += "Pass.   ";
    4845.                                                 shakes += 1;
    4846.                                             }
    4847.                                             else
    4848.                                             {
    4849.                                                 debugString += "Fail.   ";
    4850.                                                 shake = 4;
    4851.                                             }
    4852.                                         }
    4853.                                         Debug.Log("(" + shakes + ")" + debugString);
    4854.  
    4855.                                         if (shakes == 4)
    4856.                                         {
    4857.                                             Debug.Log("Caught the " + pokemon[targetIndex].getName());
    4858.                                             running = false;
    4859.  
    4860.                                             //pokeball animation not yet implemented
    4861.                                             yield return StartCoroutine(faintPokemonAnimation(opponent1));
    4862.                                             yield return new WaitForSeconds(1f);
    4863.  
    4864.                                             yield return
    4865.                                                 StartCoroutine(
    4866.                                                     drawTextAndWait(
    4867.                                                         generatePreString(targetIndex) + pokemon[targetIndex].getName() +
    4868.                                                         " \\nwas caught!", 2.4f));
    4869.  
    4870.                                             Dialog.DrawDialogBox();
    4871.                                             yield return
    4872.                                                 StartCoroutine(
    4873.                                                     Dialog.DrawTextSilent(
    4874.                                                         "Would you like to give a nickname \\nto your new " +
    4875.                                                         pokemon[targetIndex].getName() + "?"));
    4876.                                             yield return StartCoroutine(Dialog.DrawChoiceBox());
    4877.                                             int chosenIndex = Dialog.chosenIndex;
    4878.                                             Dialog.UndrawDialogBox();
    4879.                                             Dialog.UndrawChoiceBox();
    4880.  
    4881.                                             string nickname = null;
    4882.                                             if (chosenIndex == 1)
    4883.                                             {
    4884.                                                 //give nickname
    4885.                                                 SfxHandler.Play(selectClip);
    4886.                                                 yield return StartCoroutine(ScreenFade.main.Fade(false, 0.4f));
    4887.  
    4888.                                                 Scene.main.Typing.gameObject.SetActive(true);
    4889.                                                 StartCoroutine(Scene.main.Typing.control(10, "",
    4890.                                                     pokemon[targetIndex].getGender(), pokemon[targetIndex].GetIcons_()));
    4891.                                                 while (Scene.main.Typing.gameObject.activeSelf)
    4892.                                                 {
    4893.                                                     yield return null;
    4894.                                                 }
    4895.                                                 if (Scene.main.Typing.typedString.Length > 0)
    4896.                                                 {
    4897.                                                     nickname = Scene.main.Typing.typedString;
    4898.                                                 }
    4899.  
    4900.                                                 yield return StartCoroutine(ScreenFade.main.Fade(true, 0.4f));
    4901.                                             }
    4902.                                             Debug.Log("CurrentHP" + pokemon[targetIndex].getCurrentHP());
    4903.                                             SaveData.currentSave.PC.addPokemon(new Pokemon(pokemon[targetIndex],
    4904.                                                 nickname, commandItem[movingPokemon].getName()));
    4905.                                         }
    4906.  
    4907.                                         Dialog.UndrawDialogBox();
    4908.                                     }
    4909.                                 }
    4910.                                 else if (commandItem[movingPokemon].getItemEffect() == ItemData.ItemEffect.HP)
    4911.                                 {
    4912.                                     //commandTarget refers to the field position, healing a party member takes place before the turn.
    4913.                                     if (commandTarget[movingPokemon] < 3)
    4914.                                     {
    4915.                                         //if target is player
    4916.                                         yield return
    4917.                                             StartCoroutine(
    4918.                                                 drawTextAndWait(
    4919.                                                     SaveData.currentSave.playerName + " used the " +
    4920.                                                     commandItem[movingPokemon].getName() + "!", 2.4f));
    4921.                                         yield return
    4922.                                             StartCoroutine(Heal(commandTarget[movingPokemon],
    4923.                                                 commandItem[movingPokemon].getFloatParameter()));
    4924.                                     }
    4925.                                 }
    4926.                                 else if (commandItem[movingPokemon].getItemEffect() == ItemData.ItemEffect.STATUS)
    4927.                                 {
    4928.                                     //commandTarget refers to the field position, curing a party member takes place before the turn.
    4929.                                     if (commandTarget[movingPokemon] < 3)
    4930.                                     {
    4931.                                         //if target is player
    4932.                                         yield return
    4933.                                             StartCoroutine(
    4934.                                                 drawTextAndWait(
    4935.                                                     SaveData.currentSave.playerName + " used the " +
    4936.                                                     commandItem[movingPokemon].getName() + "!", 2.4f));
    4937.                                         yield return StartCoroutine(Heal(commandTarget[movingPokemon], true));
    4938.                                     }
    4939.                                 }
    4940.                                 else
    4941.                                 {
    4942.                                     //undefined effect
    4943.                                     yield return
    4944.                                         StartCoroutine(
    4945.                                             drawTextAndWait(
    4946.                                                 SaveData.currentSave.playerName + " used " +
    4947.                                                 commandItem[movingPokemon].getName() + "!", 2.4f));
    4948.                                 }
    4949.                             }
    4950.                             else
    4951.                             {
    4952.                                 yield return
    4953.                                     StartCoroutine(
    4954.                                         drawTextAndWait(
    4955.                                             opponentName + " used " + commandItem[movingPokemon].getName() + "!", 2.4f))
    4956.                                     ;
    4957.                             }
    4958.  
    4959.                             pokemonHasMoved[movingPokemon] = true;
    4960.                         }
    4961.                         else if (command[movingPokemon] == CommandType.Move)
    4962.                         {
    4963.                             //MOVE
    4964.                             //debug autoselect targetIndex (target selection not yet implemented)
    4965.                             int targetIndex = 3;
    4966.                             if (commandMove[movingPokemon].getTarget() == MoveData.Target.SELF ||
    4967.                                 commandMove[movingPokemon].getTarget() == MoveData.Target.ADJACENTALLYSELF)
    4968.                             {
    4969.                                 targetIndex = movingPokemon;
    4970.                             }
    4971.                             else
    4972.                             {
    4973.                                 if (movingPokemon > 2)
    4974.                                 {
    4975.                                     targetIndex = 0;
    4976.                                 }
    4977.                             }
    4978.                             //
    4979.  
    4980.                             if (pokemon[movingPokemon].getStatus() != Pokemon.Status.FAINTED)
    4981.                             {
    4982.                                 //calculate and test accuracy
    4983.                                 float accuracy = commandMove[movingPokemon].getAccuracy() *
    4984.                                                  calculateAccuracyModifier(pokemonStatsMod[5][movingPokemon]) /
    4985.                                                  calculateAccuracyModifier(pokemonStatsMod[6][targetIndex]);
    4986.                                 bool canMove = true;
    4987.                                 if (pokemon[movingPokemon].getStatus() == Pokemon.Status.PARALYZED)
    4988.                                 {
    4989.                                     if (Random.value > 0.75f)
    4990.                                     {
    4991.                                         yield return
    4992.                                             StartCoroutine(
    4993.                                                 drawTextAndWait(
    4994.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    4995.                                                     " is paralyzed! \\nIt can't move!", 2.4f));
    4996.                                         canMove = false;
    4997.                                     }
    4998.                                 }
    4999.                                 else if (pokemon[movingPokemon].getStatus() == Pokemon.Status.FROZEN)
    5000.                                 {
    5001.                                     if (Random.value > 0.2f)
    5002.                                     {
    5003.                                         yield return
    5004.                                             StartCoroutine(
    5005.                                                 drawTextAndWait(
    5006.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5007.                                                     " is \\nfrozen solid!", 2.4f));
    5008.                                         canMove = false;
    5009.                                     }
    5010.                                     else
    5011.                                     {
    5012.                                         pokemon[movingPokemon].setStatus(Pokemon.Status.NONE);
    5013.                                         updatePokemonStatsDisplay(movingPokemon);
    5014.                                         yield return
    5015.                                             StartCoroutine(
    5016.                                                 drawTextAndWait(
    5017.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5018.                                                     " thawed out!", 2.4f));
    5019.                                     }
    5020.                                 }
    5021.                                 else if (pokemon[movingPokemon].getStatus() == Pokemon.Status.ASLEEP)
    5022.                                 {
    5023.                                     pokemon[movingPokemon].removeSleepTurn();
    5024.                                     if (pokemon[movingPokemon].getStatus() == Pokemon.Status.ASLEEP)
    5025.                                     {
    5026.                                         yield return
    5027.                                             StartCoroutine(
    5028.                                                 drawTextAndWait(
    5029.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5030.                                                     " is \\nfast asleep.", 2.4f));
    5031.                                         canMove = false;
    5032.                                     }
    5033.                                     else
    5034.                                     {
    5035.                                         updatePokemonStatsDisplay(movingPokemon);
    5036.                                         yield return
    5037.                                             StartCoroutine(
    5038.                                                 drawTextAndWait(
    5039.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5040.                                                     " woke up!", 2.4f));
    5041.                                     }
    5042.                                 }
    5043.                                 if (canMove)
    5044.                                 {
    5045.                                     //use the move
    5046.                                     //deduct PP from the move
    5047.                                     pokemon[movingPokemon].removePP(commandMove[movingPokemon].getName(), 1);
    5048.                                     yield return
    5049.                                         StartCoroutine(
    5050.                                             drawTextAndWait(
    5051.                                                 generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5052.                                                 " used " + commandMove[movingPokemon].getName() + "!", 1.2f, 1.2f));
    5053.  
    5054.                                     //adjust for accuracy
    5055.                                     if (accuracy != 0 && Random.value > accuracy)
    5056.                                     {
    5057.                                         //if missed, provide missed feedback
    5058.                                         yield return
    5059.                                             StartCoroutine(
    5060.                                                 drawTextAndWait(
    5061.                                                     generatePreString(movingPokemon) + pokemon[movingPokemon].getName() +
    5062.                                                     "'s attack missed!", 2.4f));
    5063.                                         canMove = false;
    5064.                                     }
    5065.                                 }
    5066.                                 if (canMove)
    5067.                                 {
    5068.                                     //if didn't miss
    5069.                                     //set up variables needed later
    5070.                                     float damageToDeal = 0;
    5071.                                     bool applyCritical = false;
    5072.                                     float superEffectiveModifier = -1;
    5073.  
    5074.                                     //check for move effects that change how damage is calculated (Heal / Set Damage / etc.) (not yet implemented fully)
    5075.                                     if (commandMove[movingPokemon].hasMoveEffect(MoveData.Effect.Heal))
    5076.                                     {
    5077.                                         yield return
    5078.                                             StartCoroutine(Heal(targetIndex,
    5079.                                                 commandMove[movingPokemon].getMoveParameter(MoveData.Effect.Heal)));
    5080.                                     }
    5081.                                     else if (commandMove[movingPokemon].hasMoveEffect(MoveData.Effect.SetDamage))
    5082.                                     {
    5083.                                         damageToDeal =
    5084.                                             commandMove[movingPokemon].getMoveParameter(MoveData.Effect.SetDamage);
    5085.                                         //if parameter is 0, then use the pokemon's level
    5086.                                         if (damageToDeal == 0)
    5087.                                         {
    5088.                                             damageToDeal = pokemon[movingPokemon].getLevel();
    5089.                                         }
    5090.                                         //check for any ineffectivity
    5091.                                         superEffectiveModifier =
    5092.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5093.                                                 pokemonType1[targetIndex]) *
    5094.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5095.                                                 pokemonType2[targetIndex]) *
    5096.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5097.                                                 pokemonType3[targetIndex]);
    5098.                                         //if able to hit, set to 1 to prevent super effective messages appearing
    5099.                                         if (superEffectiveModifier > 0f)
    5100.                                         {
    5101.                                             superEffectiveModifier = 1f;
    5102.                                         }
    5103.                                     }
    5104.                                     else
    5105.                                     {
    5106.                                         //calculate damage
    5107.                                         damageToDeal = calculateDamage(movingPokemon, targetIndex,
    5108.                                             commandMove[movingPokemon]);
    5109.                                         applyCritical = calculateCritical(movingPokemon, targetIndex,
    5110.                                             commandMove[movingPokemon]);
    5111.                                         if (applyCritical)
    5112.                                         {
    5113.                                             damageToDeal *= 1.5f;
    5114.                                         }
    5115.                                         superEffectiveModifier =
    5116.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5117.                                                 pokemonType1[targetIndex]) *
    5118.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5119.                                                 pokemonType2[targetIndex]) *
    5120.                                             getSuperEffectiveModifier(commandMove[movingPokemon].getType(),
    5121.                                                 pokemonType3[targetIndex]);
    5122.                                         damageToDeal *= superEffectiveModifier;
    5123.                                         //apply offense/defense boosts.
    5124.                                         float damageBeforeMods = damageToDeal;
    5125.                                         if (commandMove[movingPokemon].getCategory() == MoveData.Category.PHYSICAL)
    5126.                                         {
    5127.                                             if (applyCritical)
    5128.                                             {
    5129.                                                 //if a critical lands
    5130.                                                 if (pokemonStatsMod[0][movingPokemon] > 0)
    5131.                                                 {
    5132.                                                     //only apply ATKmod if positive
    5133.                                                     damageToDeal *=
    5134.                                                         calculateStatModifier(pokemonStatsMod[0][movingPokemon]);
    5135.                                                 }
    5136.                                                 if (pokemonStatsMod[1][targetIndex] < 0)
    5137.                                                 {
    5138.                                                     //only apply DEFmod if negative
    5139.                                                     damageToDeal *=
    5140.                                                         calculateStatModifier(pokemonStatsMod[1][targetIndex]);
    5141.                                                 }
    5142.                                             }
    5143.                                             else
    5144.                                             {
    5145.                                                 //apply ATK and DEF mods normally (also half damage if burned)
    5146.                                                 damageToDeal *= calculateStatModifier(pokemonStatsMod[0][movingPokemon]);
    5147.                                                 damageToDeal /= calculateStatModifier(pokemonStatsMod[1][targetIndex]);
    5148.                                                 if (pokemon[movingPokemon].getStatus() == Pokemon.Status.BURNED)
    5149.                                                 {
    5150.                                                     damageToDeal /= 2f;
    5151.                                                 }
    5152.                                             }
    5153.                                         }
    5154.                                         else if (commandMove[movingPokemon].getCategory() == MoveData.Category.SPECIAL)
    5155.                                         {
    5156.                                             if (applyCritical)
    5157.                                             {
    5158.                                                 //same as above, only using the Special varients
    5159.                                                 if (pokemonStatsMod[2][movingPokemon] > 0)
    5160.                                                 {
    5161.                                                     damageToDeal *=
    5162.                                                         calculateStatModifier(pokemonStatsMod[2][movingPokemon]);
    5163.                                                 }
    5164.                                                 if (pokemonStatsMod[3][targetIndex] < 0)
    5165.                                                 {
    5166.                                                     damageToDeal *=
    5167.                                                         calculateStatModifier(pokemonStatsMod[3][targetIndex]);
    5168.                                                 }
    5169.                                             }
    5170.                                             else
    5171.                                             {
    5172.                                                 damageToDeal *= calculateStatModifier(pokemonStatsMod[2][movingPokemon]);
    5173.                                                 damageToDeal /= calculateStatModifier(pokemonStatsMod[3][targetIndex]);
    5174.                                             }
    5175.                                         }
    5176.                                     }
    5177.  
    5178.                                     //inflict damage
    5179.                                     int DEBUG_beforeHP = pokemon[targetIndex].getCurrentHP();
    5180.                                     pokemon[targetIndex].removeHP(damageToDeal);
    5181.                                     Debug.Log(DEBUG_beforeHP + " - " + damageToDeal + " = " +
    5182.                                               pokemon[targetIndex].getCurrentHP());
    5183.  
    5184.                                     if (damageToDeal > 0)
    5185.                                     {
    5186.                                         if (superEffectiveModifier > 1.01f)
    5187.                                         {
    5188.                                             SfxHandler.Play(hitSuperClip);
    5189.                                         }
    5190.                                         else if (superEffectiveModifier < 0.99f)
    5191.                                         {
    5192.                                             SfxHandler.Play(hitPoorClip);
    5193.                                         }
    5194.                                         else
    5195.                                         {
    5196.                                             SfxHandler.Play(hitClip);
    5197.                                         }
    5198.                                     }
    5199.  
    5200.                                     if (targetIndex == 0)
    5201.                                     {
    5202.                                         //if player pokemon 0 (only stats bar to display HP text)
    5203.                                         yield return
    5204.                                             StartCoroutine(stretchBar(statsHPBar[targetIndex],
    5205.                                                 Mathf.CeilToInt(pokemon[targetIndex].getPercentHP() * 48f), 32f, true,
    5206.                                                 pokemon0CurrentHP, pokemon0CurrentHPShadow,
    5207.                                                 pokemon[targetIndex].getCurrentHP()));
    5208.                                     }
    5209.                                     else
    5210.                                     {
    5211.                                         yield return
    5212.                                             StartCoroutine(stretchBar(statsHPBar[targetIndex],
    5213.                                                 Mathf.CeilToInt(pokemon[targetIndex].getPercentHP() * 48f), 32f, true,
    5214.                                                 null, null, 0));
    5215.                                     }
    5216.                                     yield return new WaitForSeconds(0.4f);
    5217.  
    5218.                                     updatePokemonStatsDisplay(targetIndex);
    5219.  
    5220.                                     //Feedback on the damage dealt
    5221.                                     if (superEffectiveModifier == 0)
    5222.                                     {
    5223.                                         yield return StartCoroutine(drawTextAndWait("It had no effect...", 2.4f));
    5224.                                     }
    5225.                                     else if (commandMove[movingPokemon].getCategory() != MoveData.Category.STATUS)
    5226.                                     {
    5227.                                         if (applyCritical)
    5228.                                         {
    5229.                                             yield return StartCoroutine(drawTextAndWait("A Critical Hit!", 2.4f));
    5230.                                         }
    5231.                                         if (superEffectiveModifier > 1)
    5232.                                         {
    5233.                                             yield return StartCoroutine(drawTextAndWait("It's Super Effective!", 2.4f));
    5234.                                         }
    5235.                                         else if (superEffectiveModifier < 1)
    5236.                                         {
    5237.                                             yield return
    5238.                                                 StartCoroutine(drawTextAndWait("It's not very effective.", 2.4f));
    5239.                                         }
    5240.                                     }
    5241.  
    5242.                                     //Faint the target if nessecary
    5243.                                     if (pokemon[targetIndex].getStatus() == Pokemon.Status.FAINTED)
    5244.                                     {
    5245.                                         //debug = array of GUITextures not yet implemented
    5246.                                         yield return
    5247.                                             StartCoroutine(
    5248.                                                 drawTextAndWait(
    5249.                                                     generatePreString(targetIndex) + pokemon[targetIndex].getName() +
    5250.                                                     " fainted!", 2.4f));
    5251.                                         Dialog.UndrawDialogBox();
    5252.                                         yield return new WaitForSeconds(0.2f);
    5253.                                         yield return new WaitForSeconds(PlayCry(pokemon[targetIndex]));
    5254.                                         //flexible faint animtions not yet implemented
    5255.                                         if (targetIndex == 0)
    5256.                                         {
    5257.                                             StartCoroutine(slidePokemonStats(0, true));
    5258.                                             yield return StartCoroutine(faintPokemonAnimation(player1));
    5259.                                         }
    5260.                                         else if (targetIndex == 3)
    5261.                                         {
    5262.                                             StartCoroutine(slidePokemonStats(3, true));
    5263.                                             yield return StartCoroutine(faintPokemonAnimation(opponent1));
    5264.                                         }
    5265.  
    5266.                                         //give EXP / add EXP
    5267.                                         if (targetIndex > 2)
    5268.                                         {
    5269.                                             for (int i2 = 0; i2 < pokemonPerSide; i2++)
    5270.                                             {
    5271.                                                 if (pokemon[i2].getStatus() != Pokemon.Status.FAINTED)
    5272.                                                 {
    5273.                                                     float isWildMod = (trainerBattle) ? 1.5f : 1f;
    5274.                                                     float baseExpYield =
    5275.                                                         PokemonDatabase.getPokemon(pokemon[targetIndex].getID())
    5276.                                                             .getBaseExpYield();
    5277.                                                     float luckyEggMod = (pokemon[i2].getHeldItem() == "Lucky Egg")
    5278.                                                         ? 1.5f
    5279.                                                         : 1f;
    5280.                                                     float OTMod = (pokemon[i2].getIDno() !=
    5281.                                                                    SaveData.currentSave.playerID)
    5282.                                                         ? 1.5f
    5283.                                                         : 1f;
    5284.                                                     float sharedMod = 1f; //shared experience
    5285.                                                     float IVMod = 0.85f +
    5286.                                                                   (float)
    5287.                                                                   (pokemon[targetIndex].getIV_HP() +
    5288.                                                                    pokemon[targetIndex].getIV_ATK() +
    5289.                                                                    pokemon[targetIndex].getIV_DEF() +
    5290.                                                                    pokemon[targetIndex].getIV_SPA() +
    5291.                                                                    pokemon[targetIndex].getIV_SPD() +
    5292.                                                                    pokemon[targetIndex].getIV_SPE()) / 480f;
    5293.                                                     //IV Mod is unique to Pokemon Unity
    5294.                                                     int exp =
    5295.                                                         Mathf.CeilToInt((isWildMod * baseExpYield * IVMod * OTMod *
    5296.                                                                          luckyEggMod *
    5297.                                                                          (float) pokemon[targetIndex].getLevel()) / 7 *
    5298.                                                                         sharedMod);
    5299.  
    5300.                                                     yield return StartCoroutine(addExp(i2, exp));
    5301.                                                 }
    5302.                                             }
    5303.                                         }
    5304.  
    5305.                                         pokemon[targetIndex] = null;
    5306.                                     }
    5307.  
    5308.                                     //Move effects should not apply to those pokemon that are immune to that move. not yet implemented
    5309.  
    5310.                                     //apply move effects
    5311.                                     MoveData.Effect[] moveEffects = commandMove[movingPokemon].getMoveEffects();
    5312.                                     float[] moveEffectParameters = commandMove[movingPokemon].getMoveParameters();
    5313.  
    5314.                                     //track these and prevent multiple statUp/Down anims
    5315.                                     bool statUpRun = false;
    5316.                                     bool statDownRun = false;
    5317.                                     bool statUpSelfRun = false;
    5318.                                     bool statDownSelfRun = false;
    5319.                                     for (int i2 = 0; i2 < moveEffects.Length; i2++)
    5320.                                     {
    5321.                                         //Check for Chance effect. if failed, no further effects will run
    5322.                                         if (moveEffects[i2] == MoveData.Effect.Chance)
    5323.                                         {
    5324.                                             if (Random.value > moveEffectParameters[i2])
    5325.                                             {
    5326.                                                 i2 = moveEffects.Length;
    5327.                                             }
    5328.                                         }
    5329.                                         else
    5330.                                         {
    5331.                                             //Check these booleans to prevent running an animation twice for one pokemon.
    5332.                                             bool animate = false;
    5333.                                             //check if statUp/Down Effect
    5334.                                             if (moveEffects[i2] == MoveData.Effect.ATK ||
    5335.                                                 moveEffects[i2] == MoveData.Effect.DEF ||
    5336.                                                 moveEffects[i2] == MoveData.Effect.SPA ||
    5337.                                                 moveEffects[i2] == MoveData.Effect.SPD ||
    5338.                                                 moveEffects[i2] == MoveData.Effect.SPE ||
    5339.                                                 moveEffects[i2] == MoveData.Effect.ACC ||
    5340.                                                 moveEffects[i2] == MoveData.Effect.EVA)
    5341.                                             {
    5342.                                                 //if statUp, and haven't run statUp yet, set statUpRun bool to true;
    5343.                                                 if (moveEffectParameters[i2] > 0 && !statUpRun)
    5344.                                                 {
    5345.                                                     statUpRun = true;
    5346.                                                     animate = true;
    5347.                                                 }
    5348.                                                 else if (moveEffectParameters[i2] < 0 && !statDownRun)
    5349.                                                 {
    5350.                                                     statDownRun = true;
    5351.                                                     animate = true;
    5352.                                                 }
    5353.                                             }
    5354.                                             //check if Self statUp/Down Effect
    5355.                                             else if (moveEffects[i2] == MoveData.Effect.ATKself ||
    5356.                                                      moveEffects[i2] == MoveData.Effect.DEFself ||
    5357.                                                      moveEffects[i2] == MoveData.Effect.SPAself ||
    5358.                                                      moveEffects[i2] == MoveData.Effect.SPDself ||
    5359.                                                      moveEffects[i2] == MoveData.Effect.SPEself ||
    5360.                                                      moveEffects[i2] == MoveData.Effect.ACCself ||
    5361.                                                      moveEffects[i2] == MoveData.Effect.EVAself)
    5362.                                             {
    5363.                                                 //if statUp, and haven't run statUp yet, set statUpRun bool to true;
    5364.                                                 if (moveEffectParameters[i2] > 0 && !statUpSelfRun)
    5365.                                                 {
    5366.                                                     statUpSelfRun = true;
    5367.                                                     animate = true;
    5368.                                                 }
    5369.                                                 else if (moveEffectParameters[i2] < 0 && !statDownSelfRun)
    5370.                                                 {
    5371.                                                     statDownSelfRun = true;
    5372.                                                     animate = true;
    5373.                                                 }
    5374.                                             }
    5375.                                             else
    5376.                                             {
    5377.                                                 animate = true;
    5378.                                             }
    5379.  
    5380.                                             yield return
    5381.                                                 StartCoroutine(applyEffect(movingPokemon, targetIndex, moveEffects[i2],
    5382.                                                     moveEffectParameters[i2], animate));
    5383.                                         }
    5384.                                     }
    5385.  
    5386.                                     updatePokemonStatsDisplay(targetIndex);
    5387.                                 }
    5388.                             }
    5389.  
    5390.                             pokemonHasMoved[movingPokemon] = true;
    5391.                         }
    5392.                         else if (command[movingPokemon] == CommandType.Switch)
    5393.                         {
    5394.                             //switch pokemon
    5395.                             //enemy switching not yet implemented
    5396.  
    5397.                             yield return
    5398.                                 StartCoroutine(drawTextAndWait(pokemon[movingPokemon].getName() + ", come back!", 1.5f,
    5399.                                     1.5f));
    5400.                             Dialog.UndrawDialogBox();
    5401.  
    5402.                             StartCoroutine(slidePokemonStats(0, true));
    5403.                             yield return StartCoroutine(withdrawPokemon(player1));
    5404.                             yield return new WaitForSeconds(0.5f);
    5405.  
    5406.                             switchPokemon(movingPokemon, commandPokemon[movingPokemon]);
    5407.  
    5408.                             yield return new WaitForSeconds(0.5f);
    5409.                             yield return
    5410.                                 StartCoroutine(drawTextAndWait("Go! " + pokemon[movingPokemon].getName() + "!", 1.5f,
    5411.                                     1.5f));
    5412.                             Dialog.UndrawDialogBox();
    5413.  
    5414.                             if (i == 0)
    5415.                             {
    5416.                                 //DEBUG
    5417.                                 Debug.Log(pokemon[0].getLongID());
    5418.                                 StopCoroutine(animatePlayer1);
    5419.                                 animatePlayer1 = StartCoroutine(animatePokemon(player1, pokemon[0].GetBackAnim_()));
    5420.                                 yield return new WaitForSeconds(0.2f);
    5421.                                 updatePokemonStatsDisplay(i);
    5422.                                 yield return StartCoroutine(releasePokemon(player1));
    5423.                                 PlayCry(pokemon[0]);
    5424.                                 yield return new WaitForSeconds(0.3f);
    5425.                                 yield return StartCoroutine(slidePokemonStats(0, false));
    5426.                             }
    5427.                             pokemonHasMoved[movingPokemon] = true;
    5428.                         }
    5429.                     }
    5430.                     else
    5431.                     {
    5432.                         //count pokemon as moved as pokemon does not exist.
    5433.                         pokemonHasMoved[movingPokemon] = true;
    5434.                     }
    5435.                 }
    5436.             }
    5437.  
    5438.  
    5439.             ////////////////////////////////////////
    5440.             /// After-Effects State
    5441.             ////////////////////////////////////////
    5442.  
    5443.             if (running)
    5444.             {
    5445.                 //running may be set to false by a successful flee
    5446.                 //Apply after-moved effects
    5447.                 for (int i = 0; i < 6; i++)
    5448.                 {
    5449.                     if (pokemon[i] != null)
    5450.                     {
    5451.                         if (pokemon[i].getStatus() == Pokemon.Status.BURNED ||
    5452.                             pokemon[i].getStatus() == Pokemon.Status.POISONED)
    5453.                         {
    5454.                             pokemon[i].removeHP(Mathf.Floor((float) pokemon[i].getHP() / 8f));
    5455.                             if (pokemon[i].getStatus() == Pokemon.Status.BURNED)
    5456.                             {
    5457.                                 yield return
    5458.                                     StartCoroutine(
    5459.                                         drawTextAndWait(
    5460.                                             generatePreString(i) + pokemon[i].getName() + " is hurt by its burn!", 2.4f))
    5461.                                     ;
    5462.                             }
    5463.                             else if (pokemon[i].getStatus() == Pokemon.Status.POISONED)
    5464.                             {
    5465.                                 yield return
    5466.                                     StartCoroutine(
    5467.                                         drawTextAndWait(
    5468.                                             generatePreString(i) + pokemon[i].getName() + " is hurt by poison!", 2.4f));
    5469.                             }
    5470.  
    5471.                             SfxHandler.Play(hitClip);
    5472.  
    5473.                             if (i == 0)
    5474.                             {
    5475.                                 //if player pokemon 0 (only stats bar to display HP text)
    5476.                                 yield return
    5477.                                     StartCoroutine(stretchBar(statsHPBar[i],
    5478.                                         Mathf.CeilToInt(pokemon[i].getPercentHP() * 48f), 32f, true, pokemon0CurrentHP,
    5479.                                         pokemon0CurrentHPShadow, pokemon[i].getCurrentHP()));
    5480.                             }
    5481.                             else
    5482.                             {
    5483.                                 yield return
    5484.                                     StartCoroutine(stretchBar(statsHPBar[i],
    5485.                                         Mathf.CeilToInt(pokemon[i].getPercentHP() * 48f), 32f, true, null, null, 0));
    5486.                             }
    5487.                             yield return new WaitForSeconds(1.2f);
    5488.  
    5489.                             Dialog.UndrawDialogBox();
    5490.                             updatePokemonStatsDisplay(i);
    5491.                         }
    5492.  
    5493.  
    5494.                         if (pokemon[i].getStatus() == Pokemon.Status.FAINTED)
    5495.                         {
    5496.                             //debug = array of GUITextures not yet implemented
    5497.                             yield return
    5498.                                 StartCoroutine(drawTextAndWait(
    5499.                                     generatePreString(i) + pokemon[i].getName() + " fainted!", 2.4f));
    5500.                             Dialog.UndrawDialogBox();
    5501.                             yield return new WaitForSeconds(0.2f);
    5502.                             yield return new WaitForSeconds(PlayCry(pokemon[i]));
    5503.                             //flexible faint animtions not yet implemented
    5504.                             if (i == 0)
    5505.                             {
    5506.                                 StartCoroutine(slidePokemonStats(0, true));
    5507.                                 yield return StartCoroutine(faintPokemonAnimation(player1));
    5508.                             }
    5509.                             else if (i == 3)
    5510.                             {
    5511.                                 StartCoroutine(slidePokemonStats(3, true));
    5512.                                 yield return StartCoroutine(faintPokemonAnimation(opponent1));
    5513.                             }
    5514.                             pokemon[i] = null;
    5515.                         }
    5516.                     }
    5517.                 }
    5518.             }
    5519.  
    5520.  
    5521.             ////////////////////////////////////////
    5522.             /// Replacement State
    5523.             ////////////////////////////////////////
    5524.  
    5525.             if (running)
    5526.             {
    5527.                 //check if any opponents are left
    5528.                 bool allOpponentsDefeated = true;
    5529.                 for (int i = 0; i < opponentParty.Length; i++)
    5530.                 {
    5531.                     //check each opponent
    5532.                     if (opponentParty[i].getStatus() != Pokemon.Status.FAINTED)
    5533.                     {
    5534.                         allOpponentsDefeated = false;
    5535.                     }
    5536.                 }
    5537.                 //check if any player Pokemon are left
    5538.                 bool allPlayersDefeated = true;
    5539.                 for (int i = 0; i < 6; i++)
    5540.                 {
    5541.                     //check each player
    5542.                     if (SaveData.currentSave.PC.boxes[0][i] != null)
    5543.                     {
    5544.                         if (SaveData.currentSave.PC.boxes[0][i].getStatus() != Pokemon.Status.FAINTED)
    5545.                         {
    5546.                             allPlayersDefeated = false;
    5547.                         }
    5548.                     }
    5549.                 }
    5550.  
    5551.                 //if both sides have Pokemon left
    5552.                 if (!allOpponentsDefeated && !allPlayersDefeated)
    5553.                 {
    5554.                     //replace fainted Opponent Pokemon (switch/set not yet implemented)
    5555.                     for (int i = 0; i < pokemonPerSide; i++)
    5556.                     {
    5557.                         //replace each opponent
    5558.                         if (pokemon[i + 3] == null)
    5559.                         {
    5560.                             //select the first able pokemon
    5561.                             for (int i2 = 0; i2 < opponentParty.Length; i2++)
    5562.                             {
    5563.                                 if (opponentParty[i2].getStatus() != Pokemon.Status.FAINTED)
    5564.                                 {
    5565.                                     //check that pokemon is not on the field
    5566.                                     bool notOnField = true;
    5567.                                     for (int i3 = 0; i3 < pokemonPerSide; i3++)
    5568.                                     {
    5569.                                         //flexible faint animtions not yet implemented
    5570.                                         if (opponentParty[i2] == pokemon[i3 + 3])
    5571.                                         {
    5572.                                             notOnField = false;
    5573.                                             i3 = pokemonPerSide;
    5574.                                         }
    5575.                                     }
    5576.                                     if (notOnField)
    5577.                                     {
    5578.                                         switchPokemon(i + 3, opponentParty[i2]);
    5579.  
    5580.                                         yield return
    5581.                                             StartCoroutine(
    5582.                                                 drawTextAndWait(
    5583.                                                     opponentName + " sent out " + pokemon[i + 3].getName() + "!", 1.5f,
    5584.                                                     1.5f));
    5585.                                         Dialog.UndrawDialogBox();
    5586.                                         if (i == 0)
    5587.                                         {
    5588.                                             //DEBUG
    5589.                                             Debug.Log(pokemon[3].getLongID());
    5590.                                             StopCoroutine(animateOpponent1);
    5591.                                             animateOpponent1 =
    5592.                                                 StartCoroutine(animatePokemon(opponent1, pokemon[3].GetFrontAnim_()));
    5593.                                             yield return new WaitForSeconds(0.2f);
    5594.                                             updatePokemonStatsDisplay(i + 3);
    5595.                                             yield return StartCoroutine(releasePokemon(opponent1));
    5596.                                             PlayCry(pokemon[3]);
    5597.                                             yield return new WaitForSeconds(0.3f);
    5598.                                             yield return StartCoroutine(slidePokemonStats(3, false));
    5599.                                         }
    5600.                                         i = pokemonPerSide;
    5601.                                         i2 = opponentParty.Length;
    5602.                                     }
    5603.                                 }
    5604.                             }
    5605.                         }
    5606.                     }
    5607.  
    5608.                     //replace fainted Player Pokemon
    5609.                     for (int i = 0; i < pokemonPerSide; i++)
    5610.                     {
    5611.                         //replace each player
    5612.                         if (pokemon[i] == null)
    5613.                         {
    5614.                             Dialog.UndrawDialogBox();
    5615.  
    5616.                             updateCurrentTask(3);
    5617.                             updateSelectedPokemonSlot(pokePartyPosition, false);
    5618.                             yield return new WaitForSeconds(0.2f);
    5619.                             while (currentTask == 3)
    5620.                             {
    5621.                                 if (Input.GetAxisRaw("Vertical") < 0)
    5622.                                 {
    5623.                                     if (pokePartyPosition < 5)
    5624.                                     {
    5625.                                         int positionBeforeModification = pokePartyPosition;
    5626.                                         if (pokePartyPosition == 4)
    5627.                                         {
    5628.                                             updateSelectedPokemonSlot(pokePartyPosition + 1, false);
    5629.                                         }
    5630.                                         else
    5631.                                         {
    5632.                                             updateSelectedPokemonSlot(pokePartyPosition + 2, false);
    5633.                                         }
    5634.                                         if (positionBeforeModification != pokePartyPosition)
    5635.                                         {
    5636.                                             SfxHandler.Play(scrollClip);
    5637.                                             yield return new WaitForSeconds(0.2f);
    5638.                                         }
    5639.                                     }
    5640.                                 }
    5641.                                 else if (Input.GetAxisRaw("Horizontal") > 0)
    5642.                                 {
    5643.                                     if (pokePartyPosition < 6)
    5644.                                     {
    5645.                                         int positionBeforeModification = pokePartyPosition;
    5646.                                         updateSelectedPokemonSlot(pokePartyPosition + 1, false);
    5647.                                         if (positionBeforeModification != pokePartyPosition)
    5648.                                         {
    5649.                                             SfxHandler.Play(scrollClip);
    5650.                                             yield return new WaitForSeconds(0.2f);
    5651.                                         }
    5652.                                     }
    5653.                                 }
    5654.                                 else if (Input.GetAxisRaw("Horizontal") < 0)
    5655.                                 {
    5656.                                     if (pokePartyPosition > 0)
    5657.                                     {
    5658.                                         int positionBeforeModification = pokePartyPosition;
    5659.                                         updateSelectedPokemonSlot(pokePartyPosition - 1, false);
    5660.                                         if (positionBeforeModification != pokePartyPosition)
    5661.                                         {
    5662.                                             SfxHandler.Play(scrollClip);
    5663.                                             yield return new WaitForSeconds(0.2f);
    5664.                                         }
    5665.                                     }
    5666.                                 }
    5667.                                 else if (Input.GetAxisRaw("Vertical") > 0)
    5668.                                 {
    5669.                                     if (pokePartyPosition > 1)
    5670.                                     {
    5671.                                         int positionBeforeModification = pokePartyPosition;
    5672.                                         if (pokePartyPosition == 6)
    5673.                                         {
    5674.                                             updateSelectedPokemonSlot(pokePartyPosition - 1, false);
    5675.                                         }
    5676.                                         else
    5677.                                         {
    5678.                                             updateSelectedPokemonSlot(pokePartyPosition - 2, false);
    5679.                                         }
    5680.                                         if (positionBeforeModification != pokePartyPosition)
    5681.                                         {
    5682.                                             SfxHandler.Play(scrollClip);
    5683.                                             yield return new WaitForSeconds(0.2f);
    5684.                                         }
    5685.                                     }
    5686.                                 }
    5687.                                 else if (Input.GetButtonDown("Select"))
    5688.                                 {
    5689.                                     if (pokePartyPosition == 6)
    5690.                                     {
    5691.                                     } //debug
    5692.                                     else if (SaveData.currentSave.PC.boxes[0][pokePartyPosition] != null)
    5693.                                     {
    5694.                                         updateCurrentTask(5);
    5695.                                         SfxHandler.Play(selectClip);
    5696.                                         int summaryPosition = updateSummaryPosition(0);
    5697.                                             //0 = Switch, 1 = Moves, 2 = Back
    5698.  
    5699.                                         yield return new WaitForSeconds(0.2f);
    5700.                                         while (currentTask == 5)
    5701.                                         {
    5702.                                             if (Input.GetAxisRaw("Vertical") < 0)
    5703.                                             {
    5704.                                                 if (pokePartyPosition < 5)
    5705.                                                 {
    5706.                                                     int positionBeforeModification = pokePartyPosition;
    5707.                                                     updateSelectedPokemonSlot(pokePartyPosition + 1, false);
    5708.                                                     if (positionBeforeModification != pokePartyPosition)
    5709.                                                     {
    5710.                                                         SfxHandler.Play(scrollClip);
    5711.                                                     }
    5712.                                                     updatePokemonSummaryDisplay(
    5713.                                                         SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    5714.                                                     yield return new WaitForSeconds(0.2f);
    5715.                                                 }
    5716.                                             }
    5717.                                             else if (Input.GetAxisRaw("Horizontal") > 0)
    5718.                                             {
    5719.                                                 if (summaryPosition < 2)
    5720.                                                 {
    5721.                                                     summaryPosition = updateSummaryPosition(summaryPosition + 1);
    5722.                                                     SfxHandler.Play(scrollClip);
    5723.                                                     yield return new WaitForSeconds(0.2f);
    5724.                                                 }
    5725.                                             }
    5726.                                             else if (Input.GetAxisRaw("Horizontal") < 0)
    5727.                                             {
    5728.                                                 if (summaryPosition > 0)
    5729.                                                 {
    5730.                                                     summaryPosition = updateSummaryPosition(summaryPosition - 1);
    5731.                                                     SfxHandler.Play(scrollClip);
    5732.                                                     yield return new WaitForSeconds(0.2f);
    5733.                                                 }
    5734.                                             }
    5735.                                             else if (Input.GetAxisRaw("Vertical") > 0)
    5736.                                             {
    5737.                                                 if (pokePartyPosition > 0)
    5738.                                                 {
    5739.                                                     int positionBeforeModification = pokePartyPosition;
    5740.                                                     updateSelectedPokemonSlot(pokePartyPosition - 1, false);
    5741.                                                     if (positionBeforeModification != pokePartyPosition)
    5742.                                                     {
    5743.                                                         SfxHandler.Play(scrollClip);
    5744.                                                     }
    5745.                                                     updatePokemonSummaryDisplay(
    5746.                                                         SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    5747.                                                     yield return new WaitForSeconds(0.2f);
    5748.                                                 }
    5749.                                             }
    5750.                                             else if (Input.GetButtonDown("Select"))
    5751.                                             {
    5752.                                                 if (summaryPosition == 0)
    5753.                                                 {
    5754.                                                     // switch
    5755.                                                     if (
    5756.                                                         SaveData.currentSave.PC.boxes[0][pokePartyPosition].getStatus() !=
    5757.                                                         Pokemon.Status.FAINTED)
    5758.                                                     {
    5759.                                                         //check that pokemon is not on the field
    5760.                                                         bool notOnField = true;
    5761.                                                         for (int i2 = 0; i2 < pokemonPerSide; i2++)
    5762.                                                         {
    5763.                                                             if (SaveData.currentSave.PC.boxes[0][pokePartyPosition] ==
    5764.                                                                 pokemon[i2])
    5765.                                                             {
    5766.                                                                 notOnField = false;
    5767.                                                                 i2 = pokemonPerSide;
    5768.                                                             }
    5769.                                                         }
    5770.                                                         if (notOnField)
    5771.                                                         {
    5772.                                                             switchPokemon(i,
    5773.                                                                 SaveData.currentSave.PC.boxes[0][pokePartyPosition]);
    5774.                                                             updateCurrentTask(-1);
    5775.                                                             SfxHandler.Play(selectClip);
    5776.  
    5777.                                                             yield return
    5778.                                                                 StartCoroutine(
    5779.                                                                     drawTextAndWait(
    5780.                                                                         "Go! " + pokemon[i].getName() + "!", 1.5f, 1.5f))
    5781.                                                                 ;
    5782.                                                             Dialog.UndrawDialogBox();
    5783.                                                             if (i == 0)
    5784.                                                             {
    5785.                                                                 //DEBUG
    5786.                                                                 Debug.Log(pokemon[0].getLongID());
    5787.                                                                 StopCoroutine(animatePlayer1);
    5788.                                                                 animatePlayer1 =
    5789.                                                                     StartCoroutine(animatePokemon(player1,
    5790.                                                                         pokemon[0].GetBackAnim_()));
    5791.                                                                 yield return new WaitForSeconds(0.2f);
    5792.                                                                 updatePokemonStatsDisplay(i);
    5793.                                                                 yield return StartCoroutine(releasePokemon(player1));
    5794.                                                                 PlayCry(pokemon[0]);
    5795.                                                                 yield return new WaitForSeconds(0.3f);
    5796.                                                                 yield return StartCoroutine(slidePokemonStats(0, false))
    5797.                                                                     ;
    5798.                                                             }
    5799.                                                         }
    5800.                                                         else
    5801.                                                         {
    5802.                                                             yield return
    5803.                                                                 StartCoroutine(
    5804.                                                                     drawTextAndWait(
    5805.                                                                         SaveData.currentSave.PC.boxes[0][
    5806.                                                                             pokePartyPosition].getName() +
    5807.                                                                         " is already fighting!"));
    5808.                                                             Dialog.UndrawDialogBox();
    5809.                                                         }
    5810.                                                     }
    5811.                                                     else
    5812.                                                     {
    5813.                                                         yield return
    5814.                                                             StartCoroutine(
    5815.                                                                 drawTextAndWait(
    5816.                                                                     SaveData.currentSave.PC.boxes[0][pokePartyPosition]
    5817.                                                                         .getName() + " is unable to fight!"));
    5818.                                                         Dialog.UndrawDialogBox();
    5819.                                                     }
    5820.                                                 }
    5821.                                                 else if (summaryPosition == 1)
    5822.                                                 {
    5823. //check moves
    5824.                                                     updateCurrentTask(6);
    5825.                                                     SfxHandler.Play(selectClip);
    5826.                                                     yield return new WaitForSeconds(0.2f);
    5827.  
    5828.                                                     int movesPosition = 5;
    5829.                                                         //0-3 = Moves, 4 = Switch, 5 = Summary, 6 = Back
    5830.                                                     while (currentTask == 6)
    5831.                                                     {
    5832.                                                         if (Input.GetAxisRaw("Vertical") < 0)
    5833.                                                         {
    5834.                                                             if (movesPosition < 4)
    5835.                                                             {
    5836.                                                                 if (movesPosition == 2)
    5837.                                                                 {
    5838.                                                                     movesPosition =
    5839.                                                                         updateMovesPosition(movesPosition + 3);
    5840.                                                                 }
    5841.                                                                 else
    5842.                                                                 {
    5843.                                                                     movesPosition =
    5844.                                                                         updateMovesPosition(movesPosition + 2);
    5845.                                                                 }
    5846.                                                                 SfxHandler.Play(scrollClip);
    5847.                                                                 yield return new WaitForSeconds(0.2f);
    5848.                                                             }
    5849.                                                         }
    5850.                                                         else if (Input.GetAxisRaw("Horizontal") > 0)
    5851.                                                         {
    5852.                                                             if (movesPosition != 1 || movesPosition != 3 ||
    5853.                                                                 movesPosition != 6)
    5854.                                                             {
    5855.                                                                 movesPosition = updateMovesPosition(movesPosition + 1);
    5856.                                                                 SfxHandler.Play(scrollClip);
    5857.                                                                 yield return new WaitForSeconds(0.2f);
    5858.                                                             }
    5859.                                                         }
    5860.                                                         else if (Input.GetAxisRaw("Horizontal") < 0)
    5861.                                                         {
    5862.                                                             if (movesPosition == 1 || movesPosition == 3 ||
    5863.                                                                 movesPosition > 4)
    5864.                                                             {
    5865.                                                                 movesPosition = updateMovesPosition(movesPosition - 1);
    5866.                                                                 SfxHandler.Play(scrollClip);
    5867.                                                                 yield return new WaitForSeconds(0.2f);
    5868.                                                             }
    5869.                                                         }
    5870.                                                         else if (Input.GetAxisRaw("Vertical") > 0)
    5871.                                                         {
    5872.                                                             if (movesPosition > 1)
    5873.                                                             {
    5874.                                                                 if (movesPosition > 3)
    5875.                                                                 {
    5876.                                                                     movesPosition = updateMovesPosition(2);
    5877.                                                                 }
    5878.                                                                 else
    5879.                                                                 {
    5880.                                                                     movesPosition =
    5881.                                                                         updateMovesPosition(movesPosition - 2);
    5882.                                                                 }
    5883.                                                                 SfxHandler.Play(scrollClip);
    5884.                                                                 yield return new WaitForSeconds(0.2f);
    5885.                                                             }
    5886.                                                         }
    5887.                                                         else if (Input.GetButtonDown("Select"))
    5888.                                                         {
    5889.                                                             if (movesPosition == 4)
    5890.                                                             {
    5891.                                                                 // switch
    5892.                                                                 if (
    5893.                                                                     SaveData.currentSave.PC.boxes[0][pokePartyPosition]
    5894.                                                                         .getStatus() != Pokemon.Status.FAINTED)
    5895.                                                                 {
    5896.                                                                     //check that pokemon is not on the field
    5897.                                                                     bool notOnField = true;
    5898.                                                                     for (int i2 = 0; i2 < pokemonPerSide; i2++)
    5899.                                                                     {
    5900.                                                                         if (
    5901.                                                                             SaveData.currentSave.PC.boxes[0][
    5902.                                                                                 pokePartyPosition] == pokemon[i2])
    5903.                                                                         {
    5904.                                                                             notOnField = false;
    5905.                                                                             i2 = pokemonPerSide;
    5906.                                                                         }
    5907.                                                                     }
    5908.                                                                     if (notOnField)
    5909.                                                                     {
    5910.                                                                         switchPokemon(i,
    5911.                                                                             SaveData.currentSave.PC.boxes[0][
    5912.                                                                                 pokePartyPosition]);
    5913.                                                                         updateCurrentTask(-1);
    5914.                                                                         SfxHandler.Play(selectClip);
    5915.  
    5916.                                                                         yield return
    5917.                                                                             StartCoroutine(
    5918.                                                                                 drawTextAndWait(
    5919.                                                                                     SaveData.currentSave.playerName +
    5920.                                                                                     " sent out " + pokemon[i].getName() +
    5921.                                                                                     "!", 1.5f, 1.5f));
    5922.                                                                         Dialog.UndrawDialogBox();
    5923.                                                                         if (i == 0)
    5924.                                                                         {
    5925.                                                                             //DEBUG
    5926.                                                                             Debug.Log(pokemon[0].getLongID());
    5927.                                                                             StopCoroutine(animatePlayer1);
    5928.                                                                             animatePlayer1 =
    5929.                                                                                 StartCoroutine(animatePokemon(player1,
    5930.                                                                                     pokemon[0].GetBackAnim_()));
    5931.                                                                             yield return new WaitForSeconds(0.2f);
    5932.                                                                             updatePokemonStatsDisplay(i);
    5933.                                                                             yield return
    5934.                                                                                 StartCoroutine(releasePokemon(player1));
    5935.                                                                             PlayCry(pokemon[0]);
    5936.                                                                             yield return new WaitForSeconds(0.3f);
    5937.                                                                             yield return
    5938.                                                                                 StartCoroutine(slidePokemonStats(0,
    5939.                                                                                     false));
    5940.                                                                         }
    5941.                                                                     }
    5942.                                                                     else
    5943.                                                                     {
    5944.                                                                         yield return
    5945.                                                                             StartCoroutine(
    5946.                                                                                 drawTextAndWait(
    5947.                                                                                     SaveData.currentSave.PC.boxes[0][
    5948.                                                                                         pokePartyPosition].getName() +
    5949.                                                                                     " is already fighting!"));
    5950.                                                                         Dialog.UndrawDialogBox();
    5951.                                                                     }
    5952.                                                                 }
    5953.                                                                 else
    5954.                                                                 {
    5955.                                                                     yield return
    5956.                                                                         StartCoroutine(
    5957.                                                                             drawTextAndWait(
    5958.                                                                                 SaveData.currentSave.PC.boxes[0][
    5959.                                                                                     pokePartyPosition].getName() +
    5960.                                                                                 " is unable to fight!"));
    5961.                                                                     Dialog.UndrawDialogBox();
    5962.                                                                 }
    5963.                                                             }
    5964.                                                             else if (movesPosition == 5)
    5965.                                                             {
    5966. //check summary
    5967.                                                                 updateCurrentTask(5);
    5968.                                                                 SfxHandler.Play(selectClip);
    5969.                                                                 yield return new WaitForSeconds(0.2f);
    5970.                                                             }
    5971.                                                             else if (movesPosition == 6)
    5972.                                                             {
    5973. //back
    5974.                                                                 updateCurrentTask(3);
    5975.                                                                 SfxHandler.Play(selectClip);
    5976.                                                                 yield return new WaitForSeconds(0.2f);
    5977.                                                             }
    5978.                                                         }
    5979.                                                         else if (Input.GetButtonDown("Back"))
    5980.                                                         {
    5981.                                                             updateCurrentTask(3);
    5982.                                                             SfxHandler.Play(selectClip);
    5983.                                                             yield return new WaitForSeconds(0.2f);
    5984.                                                         }
    5985.  
    5986.                                                         yield return null;
    5987.                                                     }
    5988.                                                 }
    5989.                                                 else if (summaryPosition == 2)
    5990.                                                 {
    5991. //back
    5992.                                                     updateCurrentTask(3);
    5993.                                                     SfxHandler.Play(selectClip);
    5994.                                                     yield return new WaitForSeconds(0.2f);
    5995.                                                 }
    5996.                                             }
    5997.                                             else if (Input.GetButtonDown("Back"))
    5998.                                             {
    5999.                                                 updateCurrentTask(3);
    6000.                                                 SfxHandler.Play(selectClip);
    6001.                                                 yield return new WaitForSeconds(0.2f);
    6002.                                             }
    6003.  
    6004.                                             yield return null;
    6005.                                         }
    6006.                                     }
    6007.                                 }
    6008.                                 yield return null;
    6009.                             }
    6010.                             updateCurrentTask(-1);
    6011.                         }
    6012.                     }
    6013.                 }
    6014.  
    6015.  
    6016.                 ////////////////////////////////////////
    6017.                 /// End-Check
    6018.                 ////////////////////////////////////////
    6019.  
    6020.                 if (allPlayersDefeated)
    6021.                 {
    6022.                     victor = 1;
    6023.                 }
    6024.                 else if (allOpponentsDefeated)
    6025.                 {
    6026.                     victor = 0;
    6027.                 }
    6028.  
    6029.  
    6030.                 if (victor == 0)
    6031.                 {
    6032.                     if (trainerBattle)
    6033.                     {
    6034.                         if (trainer.victoryBGM == null)
    6035.                         {
    6036.                             BgmHandler.main.PlayOverlay(defaultTrainerVictoryBGM, defaultTrainerVictoryBGMLoopStart);
    6037.                         }
    6038.                         else
    6039.                         {
    6040.                             BgmHandler.main.PlayOverlay(trainer.victoryBGM, trainer.victorySamplesLoopStart);
    6041.                         }
    6042.  
    6043.  
    6044.                         yield return
    6045.                             StartCoroutine(
    6046.                                 drawTextAndWait(SaveData.currentSave.playerName + " defeated " + opponentName + "!",
    6047.                                     2.4f, 2.4f));
    6048.                         Dialog.UndrawDialogBox();
    6049.                         yield return StartCoroutine(slideTrainer(opponentBase, trainerSprite1, true, false));
    6050.                         for (int di = 0; di < trainer.playerVictoryDialog.Length; di++)
    6051.                         {
    6052.                             yield return StartCoroutine(drawTextAndWait(trainer.playerVictoryDialog[di]));
    6053.                         }
    6054.                         Dialog.UndrawDialogBox();
    6055.  
    6056.                         yield return
    6057.                             StartCoroutine(
    6058.                                 drawTextAndWait(SaveData.currentSave.playerName + " received $" +
    6059.                                                 trainer.GetPrizeMoney() + " for winning!"));
    6060.                         SaveData.currentSave.playerMoney += trainer.GetPrizeMoney();
    6061.                     }
    6062.                     else
    6063.                     {
    6064.                         if (trainer.victoryBGM == null)
    6065.                         {
    6066.                             BgmHandler.main.PlayOverlay(defaultWildVictoryBGM, defaultWildVictoryBGMLoopStart);
    6067.                         }
    6068.                         else
    6069.                         {
    6070.                             BgmHandler.main.PlayOverlay(trainer.victoryBGM, trainer.victorySamplesLoopStart);
    6071.                         }
    6072.  
    6073.                         //wild exp print out not yet implemented here
    6074.                     }
    6075.  
    6076.                     yield return new WaitForSeconds(0.2f);
    6077.                     running = false;
    6078.                 }
    6079.                 else if (victor == 1)
    6080.                 {
    6081.                     if (trainerBattle)
    6082.                     {
    6083.                         yield return
    6084.                             StartCoroutine(
    6085.                                 drawTextAndWait(opponentName + " defeated " + SaveData.currentSave.playerName + "!",
    6086.                                     2.4f, 2.4f));
    6087.                         Dialog.UndrawDialogBox();
    6088.                         yield return StartCoroutine(slideTrainer(opponentBase, trainerSprite1, true, false));
    6089.                         for (int di = 0; di < trainer.playerLossDialog.Length; di++)
    6090.                         {
    6091.                             yield return StartCoroutine(drawTextAndWait(trainer.playerLossDialog[di]));
    6092.                         }
    6093.                         Dialog.UndrawDialogBox();
    6094.  
    6095.                         StartCoroutine(ScreenFade.main.Fade(false, 1f));
    6096.                     }
    6097.                     else
    6098.                     {
    6099.                         yield return
    6100.                             StartCoroutine(
    6101.                                 drawTextAndWait(SaveData.currentSave.playerName + " is out of usable Pokémon!", 2f));
    6102.                         yield return
    6103.                             StartCoroutine(drawTextAndWait(SaveData.currentSave.playerName + " dropped $200 in panic!",
    6104.                                 2f));
    6105.                         yield return StartCoroutine(drawTextAndWait("... ... ... ...", 2f));
    6106.  
    6107.                         yield return
    6108.                             StartCoroutine(drawTextAndWait(SaveData.currentSave.playerName + " blacked out!", 1.8f, 1.8f))
    6109.                             ;
    6110.                         Dialog.UndrawDialogBox();
    6111.                         //overlayed dialog box not yet implemented
    6112.                         StartCoroutine(ScreenFade.main.Fade(false, 1f));
    6113.                     }
    6114.                     yield return new WaitForSeconds(0.2f);
    6115.                     running = false;
    6116.  
    6117.                     //fully heal players party so that they cant walk around with a defeated party
    6118.                     for (int i = 0; i < 6; i++)
    6119.                     {
    6120.                         if (SaveData.currentSave.PC.boxes[0][i] != null)
    6121.                         {
    6122.                             SaveData.currentSave.PC.boxes[0][i].healFull();
    6123.                         }
    6124.                     }
    6125.                 }
    6126.                 Dialog.UndrawDialogBox();
    6127.                 yield return new WaitForSeconds(0.4f);
    6128.             }
    6129.         }
    6130.  
    6131.  
    6132.         //if defeated
    6133.         if (victor == 1)
    6134.         {
    6135.             //empty the paused clip, as the paused audio won't be resumed upon respawning
    6136.             BgmHandler.main.ResumeMain(1.4f, null, 0);
    6137.         }
    6138.         else
    6139.         {
    6140.             //if not defeated, the scene won't have faded out already
    6141.             StartCoroutine(ScreenFade.main.Fade(false, 1f));
    6142.             BgmHandler.main.ResumeMain(1.4f);
    6143.         }
    6144.         yield return new WaitForSeconds(1.4f);
    6145.  
    6146.         //check for evolutions to run ONLY if won, or healed on defeat
    6147.         if (victor == 0 || healedOnDefeat)
    6148.         {
    6149.             for (int i = 0; i < initialLevels.Length; i++)
    6150.             {
    6151.                 if (SaveData.currentSave.PC.boxes[0][i] != null)
    6152.                 {
    6153.                     //if level is different to it was at the start of the battle
    6154.                     if (SaveData.currentSave.PC.boxes[0][i].getLevel() != initialLevels[i])
    6155.                     {
    6156.                         //if can evolve
    6157.                         if (SaveData.currentSave.PC.boxes[0][i].canEvolve("Level"))
    6158.                         {
    6159.                             BgmHandler.main.PlayOverlay(null, 0, 0);
    6160.  
    6161.                             //Set SceneEvolution to be active so that it appears
    6162.                             Scene.main.Evolution.gameObject.SetActive(true);
    6163.                             StartCoroutine(Scene.main.Evolution.control(SaveData.currentSave.PC.boxes[0][i], "Level"));
    6164.                             //Start an empty loop that will only stop when SceneEvolution is no longer active (is closed)
    6165.                             while (Scene.main.Evolution.gameObject.activeSelf)
    6166.                             {
    6167.                                 yield return null;
    6168.                             }
    6169.                         }
    6170.                     }
    6171.                 }
    6172.             }
    6173.         }
    6174.  
    6175.  
    6176.         //if defeated
    6177.         if (victor == 1)
    6178.         {
    6179.             if (!healedOnDefeat)
    6180.             {
    6181.                 GlobalVariables.global.Respawn();
    6182.             }
    6183.         }
    6184.  
    6185.         GlobalVariables.global.resetFollower();
    6186.         this.gameObject.SetActive(false);
    6187.     }
    6188. }