function useItem() {

    // Only use potion if the user has a potion to use
    if (player.potions > 0) {
      let restoredHP = 20;  // The default amount that a potion restores
      let newPotionNum = player.potions - 1;  // Reduce the amount of potions that the user has
      let newHP = player.currentHP + restoredHP;  // Realistically, the user's new HP (but gets adjusted below)

      // A player's HP should never exceed their max HP through potion use
      if (newHP > player.maxHP) {

        // Only restore as much HP as needed to reach the player's maxHP
        restoredHP = player.maxHP - player.currentHP;

        dispatch({
          type: ADJUST_HP,
          payload: player.maxHP,
        })

        // Otherwise, heal for the standard amount
      } else {
        // Subtract damage from enemy HP
        dispatch({
          type: ADJUST_HP,
          payload: newHP,
        })
      }

      dispatch({
        type: USE_POTION,
        payload: {
          message: `You used a potion and restored ${restoredHP} HP`,
          potions: newPotionNum
        }
      })

      // If the player has no potions to use, don't adjust any values and just change message
    } else {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You don't have any potions left!!!`,
      })
    }

    // Regardless, the player's turn ends (harsh, I know, but this makes it easier for now)
    setPlayerTurn(false);
    setCommandAvailability(false);

  }
// The player decides to use an item (currently only potion)
The player decides to use an item (currently only potion)
The player decides to use an item ( currently only potion )
function useItem() {
    if (player.potions > 0) {
      let restoredHP = 20;  
      let newPotionNum = player.potions - 1;  
      let newHP = player.currentHP + restoredHP;  
      if (newHP > player.maxHP) {
        restoredHP = player.maxHP - player.currentHP;
        dispatch({
          type: ADJUST_HP,
          payload: player.maxHP,
        })
      } else {
        dispatch({
          type: ADJUST_HP,
          payload: newHP,
        })
      }
      dispatch({
        type: USE_POTION,
        payload: {
          message: `You used a potion and restored ${restoredHP} HP`,
          potions: newPotionNum
        }
      })
    } else {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You don't have any potions left!!!`,
      })
    }
    setPlayerTurn(false);
    setCommandAvailability(false);
  }
function useItem ( ) { if ( player . potions > 0 ) { let restoredHP = 20 ; let newPotionNum = player . potions - 1 ; let newHP = player . currentHP + restoredHP ; if ( newHP > player . maxHP ) { restoredHP = player . maxHP - player . currentHP ; dispatch ( { type : ADJUST_HP , payload : player . maxHP , } ) } else { dispatch ( { type : ADJUST_HP , payload : newHP , } ) } dispatch ( { type : USE_POTION , payload : { message : ` ${ restoredHP } ` , potions : newPotionNum } } ) } else { dispatch ( { type : CHANGE_MESSAGE , payload : ` ` , } ) } setPlayerTurn ( false ) ; setCommandAvailability ( false ) ; }
The player decides to use an item (currently only potion)
The player decides to use an item ( currently only potion )
// Only use potion if the user has a potion to use // The default amount that a potion restores // Reduce the amount of potions that the user has // Realistically, the user's new HP (but gets adjusted below) // A player's HP should never exceed their max HP through potion use // Only restore as much HP as needed to reach the player's maxHP // Otherwise, heal for the standard amount // Subtract damage from enemy HP // If the player has no potions to use, don't adjust any values and just change message // Regardless, the player's turn ends (harsh, I know, but this makes it easier for now)