function reducer(state = initialState, action) {
  switch (action.type) {

    case SET_STATISTICS: 
    return {
      ...state,
      player: {
        ...state.player,
        characterName: action.payload.characterName,
        maxHP: action.payload.maxHP,
        currentHP: action.payload.currentHP,
        damMod: action.payload.damMod,
        evaMod: action.payload.evaMod,
        gold: action.payload.gold,
        exp: action.payload.exp,
        potions: action.payload.potions,
        statistics: {
          ...state.player.statistics,
          strength: action.payload.strength,
          agility: action.payload.agility,
          endurance: action.payload.endurance,
        }
      }
    }

    case CHANGE_MESSAGE:
      return {
        ...state,
        message: action.payload,
      }

    case ADJUST_HP:
      return {
        ...state,
        player: {
          ...state.player,
          currentHP: action.payload
        },
      }

    case USE_POTION:
      return {
        ...state,
        player: {
          ...state.player,
          potions: action.payload.potions
        },

        message: action.payload.message,
      }

    case GAIN_LOOT:
      return {
        ...state,
        player: {
          ...state.player,
          gold: action.payload.gold,
          exp: action.payload.exp,
          potions: action.payload.potions
        },
        message: action.payload.message
      }

    case REST:
      return {
        ...state,
        player: {
          ...state.player,
          currentHP: action.payload.hp,
          gold: action.payload.gold,
        },
        message: action.payload.message
      }

    case BUY_POTION:
      return {
        ...state,
        player: {
          ...state.player,
          potions: action.payload.potions,
          gold: action.payload.gold,
        },
        message: action.payload.message
      }

    default:
      return state;
  }
}
// The reducer is a function that accepts the current state and an action. It returns a new state based on that action.
The reducer is a function that accepts the current state and an action. It returns a new state based on that action.
The reducer is a function that accepts the current state and an action . It returns a new state based on that action .
function reducer(state = initialState, action) {
  switch (action.type) {
    case SET_STATISTICS: 
    return {
      ...state,
      player: {
        ...state.player,
        characterName: action.payload.characterName,
        maxHP: action.payload.maxHP,
        currentHP: action.payload.currentHP,
        damMod: action.payload.damMod,
        evaMod: action.payload.evaMod,
        gold: action.payload.gold,
        exp: action.payload.exp,
        potions: action.payload.potions,
        statistics: {
          ...state.player.statistics,
          strength: action.payload.strength,
          agility: action.payload.agility,
          endurance: action.payload.endurance,
        }
      }
    }
    case CHANGE_MESSAGE:
      return {
        ...state,
        message: action.payload,
      }
    case ADJUST_HP:
      return {
        ...state,
        player: {
          ...state.player,
          currentHP: action.payload
        },
      }
    case USE_POTION:
      return {
        ...state,
        player: {
          ...state.player,
          potions: action.payload.potions
        },
        message: action.payload.message,
      }
    case GAIN_LOOT:
      return {
        ...state,
        player: {
          ...state.player,
          gold: action.payload.gold,
          exp: action.payload.exp,
          potions: action.payload.potions
        },
        message: action.payload.message
      }
    case REST:
      return {
        ...state,
        player: {
          ...state.player,
          currentHP: action.payload.hp,
          gold: action.payload.gold,
        },
        message: action.payload.message
      }
    case BUY_POTION:
      return {
        ...state,
        player: {
          ...state.player,
          potions: action.payload.potions,
          gold: action.payload.gold,
        },
        message: action.payload.message
      }
    default:
      return state;
  }
}
function reducer ( state = initialState , action ) { switch ( action . type ) { case SET_STATISTICS : return { ... state , player : { ... state . player , characterName : action . payload . characterName , maxHP : action . payload . maxHP , currentHP : action . payload . currentHP , damMod : action . payload . damMod , evaMod : action . payload . evaMod , gold : action . payload . gold , exp : action . payload . exp , potions : action . payload . potions , statistics : { ... state . player . statistics , strength : action . payload . strength , agility : action . payload . agility , endurance : action . payload . endurance , } } } case CHANGE_MESSAGE : return { ... state , message : action . payload , } case ADJUST_HP : return { ... state , player : { ... state . player , currentHP : action . payload } , } case USE_POTION : return { ... state , player : { ... state . player , potions : action . payload . potions } , message : action . payload . message , } case GAIN_LOOT : return { ... state , player : { ... state . player , gold : action . payload . gold , exp : action . payload . exp , potions : action . payload . potions } , message : action . payload . message } case REST : return { ... state , player : { ... state . player , currentHP : action . payload . hp , gold : action . payload . gold , } , message : action . payload . message } case BUY_POTION : return { ... state , player : { ... state . player , potions : action . payload . potions , gold : action . payload . gold , } , message : action . payload . message } default : return state ; } }
The reducer is a function that accepts the current state and an action.
The reducer is a function that accepts the current state and an action .