#include "GameState.h"

void GameState :: gamestateBattleShowRewardsStartup ()
{
  //see if the character levels up. If so, announce.
  levelUps.clear ();
  levelUps.resize (1);
  levelUps.at (0) = 0;

  storeLevelUp ();
}

void GameState :: gamestateBattleShowRewardsAfterDraw (uint8_t numButtonsToShow)
{
  inputBufferIterator = inputBuffer.begin ();
  while (inputBufferIterator < inputBuffer.end ())
    {
      if (SDL_GetTicks () >= 1000 + startTime && inputBufferIterator -> getInput () == INPUT_MOUSEUP)
        {
          setNewGameState (GAMESTATE_MAP);
          rulez.clearIntroBattle ();
          clearButtons (numButtonsToShow);

          if (isMouseOnHotSpot((*inputBufferIterator), buttonVect[0], false))
            {
              setNewGameState (GAMESTATE_GAME_MENU);
            }
          else
            rulez.deleteBattle ();
        }
      if (inputBufferIterator -> getInput () == INPUT_MOUSEDOWN)
        {
          buttonUpdateClickStatus ((*inputBufferIterator), numButtonsToShow);
        }

      if (inputBufferIterator -> getInput () == INPUT_QUITGAME)
        {
          addQuitCommand ();
        }
      inputBufferIterator ++;
    }
}


void GameState :: storeLevelUp ()
{
  //store before stats
  Player p = rulez.getPlayer ();

  uint8_t oldHealth = p.getHealth ();
  uint8_t oldArmor = p.getArmor ();
  uint8_t oldAcc = p.getAccuracy ();
  uint8_t oldDam = p.getDamage ();
  uint8_t oldPie = p.getPierce ();
  uint8_t oldEva = p.getEvade ();
  uint8_t oldLuck = p.getLuck ();
  uint8_t oldAbils = p.numAbilitiesAtCurrentLevel ();
  uint8_t oldXP = p.getExperience ();
  uint8_t oldMoney = p.getMoney ();

  rulez.applyVictory ();
  if (rulez.getPlayer().checkForLevelUp ())
    {
      //set flag & level up stats here
      levelUps.at (0) = 1;
    }
  rulez.getPlayer().levelUp ();

  p = rulez.getPlayer();

  levelUps.push_back (p.getExperience () - oldXP);
  levelUps.push_back (p.getMoney () - oldMoney);
  levelUps.push_back (p.getHealth () - oldHealth);
  levelUps.push_back (p.getArmor () - oldArmor);
  levelUps.push_back (p.getAccuracy () - oldAcc);
  levelUps.push_back (p.getDamage () - oldDam);
  levelUps.push_back (p.getPierce () - oldPie);
  levelUps.push_back (p.getEvade () - oldEva);
  levelUps.push_back (p.getLuck () - oldLuck);
  levelUps.push_back (p.numAbilitiesAtCurrentLevel () - oldAbils);
}
