Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add experience part 1 #448

Merged
merged 11 commits into from
Aug 30, 2023
1 change: 1 addition & 0 deletions .env.development.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
REACT_APP_API_ROOT=http://localhost:3001/
REACT_APP_ENABLE_KEGS=true
REACT_APP_ENABLE_EXPERIENCE=true
7 changes: 4 additions & 3 deletions src/components/Farmhand/Farmhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ import NotificationSystem, {
} from '../NotificationSystem'
import DebugMenu from '../DebugMenu'
import theme from '../../mui-theme'
import { levelAchieved } from '../../utils/levelAchieved'
import {
computeMarketPositions,
createNewField,
doesMenuObstructStage,
farmProductsSold,
generateCow,
getAvailableShopInventory,
getItemCurrentValue,
getPeerMetadata,
inventorySpaceRemaining,
levelAchieved,
moneyTotal,
nullArray,
reduceByPersistedKeys,
Expand Down Expand Up @@ -381,7 +380,7 @@ export default class Farmhand extends FarmhandReducers {

get levelEntitlements() {
return getLevelEntitlements(
levelAchieved(farmProductsSold(this.state.itemsSold))
levelAchieved({ itemsSold: this.state.itemsSold })
)
}

Expand Down Expand Up @@ -425,6 +424,7 @@ export default class Farmhand extends FarmhandReducers {
cowTradeTimeoutId: -1,
cropsHarvested: {},
dayCount: 0,
experience: 0,
farmName: 'Unnamed',
field: createNewField(),
fieldMode: OBSERVE,
Expand Down Expand Up @@ -497,6 +497,7 @@ export default class Farmhand extends FarmhandReducers {
[toolType.WATERING_CAN]: toolLevel.DEFAULT,
},
useAlternateEndDayButtonPosition: false,
useLegacyLevelingSystem: true,
jeremyckahn marked this conversation as resolved.
Show resolved Hide resolved
valueAdjustments: {},
version: process.env.REACT_APP_VERSION ?? '',
}
Expand Down
10 changes: 3 additions & 7 deletions src/components/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import Plot from '../Plot'
import QuickSelect from '../QuickSelect'
import { fieldMode } from '../../enums'
import tools from '../../data/tools'
import {
doesInventorySpaceRemain,
farmProductsSold,
levelAchieved,
nullArray,
} from '../../utils'
import { levelAchieved } from '../../utils/levelAchieved'
import { doesInventorySpaceRemain, nullArray } from '../../utils'
import { getLevelEntitlements } from '../../utils/getLevelEntitlements'

import './Field.sass'
Expand Down Expand Up @@ -74,7 +70,7 @@ export const isInHoverRange = ({
switch (fieldMode) {
case SET_SPRINKLER:
hoveredPlotRangeSizeToRender = getLevelEntitlements(
levelAchieved(farmProductsSold(itemsSold))
levelAchieved({ itemsSold })
).sprinklerRange

break
Expand Down
6 changes: 3 additions & 3 deletions src/components/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import Typography from '@material-ui/core/Typography'
import { array, bool, func, number, object, string } from 'prop-types'

import FarmhandContext from '../Farmhand/Farmhand.context'
import { farmProductsSold } from '../../utils/farmProductsSold'
import { levelAchieved } from '../../utils/levelAchieved'
import {
doesInventorySpaceRemain,
farmProductSalesVolumeNeededForLevel,
farmProductsSold,
integerString,
inventorySpaceConsumed,
levelAchieved,
scaleNumber,
} from '../../utils'
import { dialogView } from '../../enums'
Expand Down Expand Up @@ -225,7 +225,7 @@ export const Navigation = ({
viewList,

totalFarmProductsSold = farmProductsSold(itemsSold),
currentLevel = levelAchieved(totalFarmProductsSold),
currentLevel = levelAchieved({ itemsSold }),
levelPercent = scaleNumber(
totalFarmProductsSold,
farmProductSalesVolumeNeededForLevel(currentLevel),
Expand Down
13 changes: 3 additions & 10 deletions src/components/OnlinePeersView/OnlinePeer/OnlinePeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import CardHeader from '@material-ui/core/CardHeader'
import CowCard from '../../CowCard'

import { moneyString } from '../../../utils/moneyString'
import {
getPlayerName,
farmProductsSold,
integerString,
levelAchieved,
} from '../../../utils'
import { levelAchieved } from '../../../utils/levelAchieved'
import { getPlayerName, integerString } from '../../../utils'

import './OnlinePeer.sass'

Expand All @@ -28,10 +24,7 @@ const OnlinePeer = ({
subheader: (
<div>
<p>Day: {integerString(dayCount)}</p>
<p>
Level:{' '}
{integerString(levelAchieved(farmProductsSold(itemsSold)))}
</p>
<p>Level: {integerString(levelAchieved({ itemsSold }))}</p>
<p>Money: {moneyString(money)}</p>
</div>
),
Expand Down
5 changes: 3 additions & 2 deletions src/components/OnlinePeersView/OnlinePeersView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { array, number, object, string } from 'prop-types'

import BailOutErrorBoundary from '../BailOutErrorBoundary'

import { getPlayerName, farmProductsSold, levelAchieved } from '../../utils'
import { levelAchieved } from '../../utils/levelAchieved'
import { getPlayerName } from '../../utils'
import FarmhandContext from '../Farmhand/Farmhand.context'

import CowCard from '../CowCard'
Expand Down Expand Up @@ -58,7 +59,7 @@ const OnlinePeersView = ({
{sortBy(populatedPeers, [
peerId =>
// Use negative value to reverse sort order
-levelAchieved(farmProductsSold(peers[peerId].itemsSold || 0)),
-levelAchieved({ itemsSold: peers[peerId].itemsSold || 0 }),
]).map(peerId => (
<BailOutErrorBoundary {...{ key: peerId }}>
<OnlinePeer {...{ peer: peers[peerId] }} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Recipe/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import CardActions from '@material-ui/core/CardActions'
import Typography from '@material-ui/core/Typography'
import { array, func, number, object } from 'prop-types'

import { totalIngredientsInRecipe } from '../../utils/totalIngredientsInRecipe'
import {
canMakeRecipe,
doesInventorySpaceRemain,
dollarString,
maxYieldOfRecipe,
integerString,
totalIngredientsInRecipe,
} from '../../utils'
import { itemsMap } from '../../data/maps'
import { craftedItems } from '../../img'
Expand Down
20 changes: 19 additions & 1 deletion src/components/SettingsView/SettingsView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react'
import { bool, func } from 'prop-types'
import { bool, func, object } from 'prop-types'
import Button from '@material-ui/core/Button'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
Expand All @@ -21,6 +21,7 @@ import './SettingsView.sass'

const SettingsView = ({
allowCustomPeerCowNames,
features,
handleAllowCustomPeerCowNamesChange,
handleClearPersistedDataClick,
handleExportDataClick,
Expand All @@ -29,8 +30,10 @@ const SettingsView = ({
handleShowNotificationsChange,
handleUseAlternateEndDayButtonPositionChange,
handleShowHomeScreenChange,
handleUseLegacyLevelSystemChange,
showNotifications,
useAlternateEndDayButtonPosition,
useLegacyLevelingSystem,
showHomeScreen,
}) => {
const [isClearDataDialogOpen, setIsClearDataDialogOpen] = useState(false)
Expand Down Expand Up @@ -99,6 +102,19 @@ const SettingsView = ({
}
label="Display custom names for cows received from other players"
/>
{features.EXPERIENCE ? (
<FormControlLabel
control={
<Switch
color="primary"
checked={useLegacyLevelingSystem}
onChange={handleUseLegacyLevelSystemChange}
name="use-legacy-leveling-system"
/>
}
label="Use legacy leveling system (experience is only gained by selling items)"
/>
) : null}
</FormGroup>
</FormControl>

Expand Down Expand Up @@ -199,6 +215,7 @@ const SettingsView = ({

SettingsView.propTypes = {
allowCustomPeerCowNames: bool.isRequired,
features: object.isRequired,
handleAllowCustomPeerCowNamesChange: func.isRequired,
handleClearPersistedDataClick: func.isRequired,
handleExportDataClick: func.isRequired,
Expand All @@ -210,6 +227,7 @@ SettingsView.propTypes = {
showHomeScreen: bool.isRequired,
showNotifications: bool.isRequired,
useAlternateEndDayButtonPosition: bool.isRequired,
useLegacyLevelingSystem: bool,
}

export default function Consumer(props) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/StatsView/StatsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import sortBy from 'lodash.sortby'
import { itemsMap } from '../../data/maps'
import FarmhandContext from '../Farmhand/Farmhand.context'
import { moneyString } from '../../utils/moneyString'
import { farmProductsSold } from '../../utils/farmProductsSold'
import { levelAchieved } from '../../utils/levelAchieved'
import {
farmProductSalesVolumeNeededForLevel,
farmProductsSold,
get7DayAverage,
getProfit,
getProfitRecord,
integerString,
levelAchieved,
moneyTotal,
} from '../../utils'
import {
Expand Down Expand Up @@ -51,7 +51,7 @@ const StatsView = ({
todaysRevenue,

totalFarmProductsSold = farmProductsSold(itemsSold),
currentLevel = levelAchieved(totalFarmProductsSold),
currentLevel = levelAchieved({ itemsSold }),
}) => (
<div className="StatsView">
<TableContainer {...{ component: ElevatedPaper }}>
Expand Down
7 changes: 2 additions & 5 deletions src/components/UpgradePurchase/UpgradePurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import { array, func, number, object } from 'prop-types'

import IngredientsList from '../IngredientsList'

import {
canMakeRecipe,
doesInventorySpaceRemain,
totalIngredientsInRecipe,
} from '../../utils'
import { totalIngredientsInRecipe } from '../../utils/totalIngredientsInRecipe'
import { canMakeRecipe, doesInventorySpaceRemain } from '../../utils'

import { craftedItems } from '../../img'

Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const PERSISTED_STATE_KEYS = [
'cowsTraded',
'cropsHarvested',
'dayCount',
'experience',
'farmName',
'field',
'historicalDailyLosses',
Expand Down Expand Up @@ -182,6 +183,7 @@ export const PERSISTED_STATE_KEYS = [
'todaysStartingInventory',
'toolLevels',
'useAlternateEndDayButtonPosition',
'useLegacyLevelingSystem',
'valueAdjustments',
'version',
]
Expand Down
11 changes: 11 additions & 0 deletions src/game-logic/reducers/addExperience.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param {farmhand.state} state
* @param {number} amount
* @returns {farmhand.state}
*/
export const addExperience = (state, amount) => {
return {
...state,
experience: state.experience + amount,
}
}
11 changes: 11 additions & 0 deletions src/game-logic/reducers/addExperience.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { addExperience } from './addExperience'

describe('addExperience', () => {
it('adds experience to current experience', () => {
const gameState = { experience: 0, itemsSold: {} }

const newState = addExperience(gameState, 100)

expect(newState.experience).toEqual(100)
})
})
5 changes: 2 additions & 3 deletions src/game-logic/reducers/generatePriceEvents.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { levelAchieved } from '../../utils/levelAchieved'
import {
farmProductsSold,
filterItemIdsToSeeds,
getPriceEventForCrop,
getRandomUnlockedCrop,
levelAchieved,
} from '../../utils'
import { getLevelEntitlements } from '../../utils/getLevelEntitlements'
import { PRICE_EVENT_CHANCE } from '../../constants'
Expand All @@ -29,7 +28,7 @@ export const generatePriceEvents = state => {
// less-than check.
if (random() < PRICE_EVENT_CHANCE) {
const { items: unlockedItems } = getLevelEntitlements(
levelAchieved(farmProductsSold(state.itemsSold))
levelAchieved({ itemsSold: state.itemsSold })
)

const cropItem = getRandomUnlockedCrop(
Expand Down
7 changes: 3 additions & 4 deletions src/game-logic/reducers/processLevelUp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { levels } from '../../data/levels'
import { levelAchieved } from '../../utils/levelAchieved'
import {
farmProductsSold,
getRandomLevelUpReward,
getRandomLevelUpRewardQuantity,
levelAchieved,
unlockTool,
} from '../../utils'
import { getLevelEntitlements } from '../../utils/getLevelEntitlements'
Expand All @@ -20,7 +19,7 @@ import { showNotification } from './showNotification'
*/
export const processLevelUp = (state, oldLevel) => {
const { itemsSold, selectedItemId } = state
const newLevel = levelAchieved(farmProductsSold(itemsSold))
const newLevel = levelAchieved({ itemsSold })

// Loop backwards so that the notifications appear in descending order.
for (let i = newLevel; i > oldLevel; i--) {
Expand Down Expand Up @@ -48,7 +47,7 @@ export const processLevelUp = (state, oldLevel) => {
selectedItemId === SPRINKLER_ITEM_ID
) {
const { sprinklerRange } = getLevelEntitlements(
levelAchieved(farmProductsSold(itemsSold))
levelAchieved({ itemsSold })
)

if (sprinklerRange > state.hoveredPlotRangeSize) {
Expand Down
12 changes: 3 additions & 9 deletions src/game-logic/reducers/processSprinklers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { itemType } from '../../enums'
import {
farmProductsSold,
getPlotContentType,
getRangeCoords,
levelAchieved,
} from '../../utils'
import { levelAchieved } from '../../utils/levelAchieved'
import { getPlotContentType, getRangeCoords } from '../../utils'
import { getLevelEntitlements } from '../../utils/getLevelEntitlements'

import { setWasWatered } from './helpers'
Expand All @@ -19,9 +15,7 @@ export const processSprinklers = state => {
const crops = new Map()
let modifiedField = [...field]

const { sprinklerRange } = getLevelEntitlements(
levelAchieved(farmProductsSold(itemsSold))
)
const { sprinklerRange } = getLevelEntitlements(levelAchieved({ itemsSold }))

field.forEach((row, plotY) => {
row.forEach((plot, plotX) => {
Expand Down
Loading
Loading