Fix preventing of removing points when it would bring us below the minimum for talents learnt further down the tree

This commit is contained in:
Melvin Valster
2019-07-21 13:04:05 +02:00
parent eddb47e8b1
commit 431f944b50
4 changed files with 53 additions and 19 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
# TODO # TODO
- [ ] Add react-router
- [ ] Add redux - [ ] Add redux
- [ ] Prevent reducing talent points on a row when it is a dependency for points already spent in the next row
- [ ] Prevent reducing talent points on a talent that is a requirement for another talent with points in it - [ ] Prevent reducing talent points on a talent that is a requirement for another talent with points in it
- [ ] Talent tooltips - [ ] Talent tooltips
- [ ] Change class
- [ ] Generate URL for chosen talents - [ ] Generate URL for chosen talents
- [ ] Responsive on mobile - [ ] Responsive on mobile
- [ ] Pretty ClassPicker
- [x] Add react-router
- [x] Prevent reducing talent points on a row when it is a dependency for points already spent in the next row
+1 -1
View File
@@ -68,4 +68,4 @@ export const TalentSlot: FC<Props> = (props) => {
TalentSlot.defaultProps = defaultProps TalentSlot.defaultProps = defaultProps
// ;(TalentSlot as any).whyDidYouRender = true ;(TalentSlot as any).whyDidYouRender = true
+6 -1
View File
@@ -3744,9 +3744,14 @@ export const talentsBySpec: Root = {
} }
} }
export const talentToSpec: {[key: number]: number} = {} export const talentsById: {[key: number]: TalentData} = {}
export const talentsBySpecArray: {[key: number]: TalentData[]} = {}
export const talentToSpec: {[key: number]: number} = {}
for (let specId in talentsBySpec) { for (let specId in talentsBySpec) {
for (let talentId in talentsBySpec[specId]) { for (let talentId in talentsBySpec[specId]) {
talentsById[talentId] = talentsBySpec[specId][talentId]
talentsBySpecArray[specId] = Object.values(talentsBySpec[specId])
talentToSpec[talentId] = parseInt(specId, 10) talentToSpec[talentId] = parseInt(specId, 10)
} }
} }
+42 -13
View File
@@ -1,7 +1,8 @@
import { List, Map, fromJS } from 'immutable' import { List, Map, fromJS } from 'immutable'
import { talentsBySpec, talentToSpec } from '../data/talents'; import { talentsBySpec, talentToSpec, talentsById } from '../data/talents';
export const MAX_POINTS = 51 export const MAX_POINTS = 51
export const MAX_ROWS = 7
/** /**
* Returns the overall points spent in the tree. * Returns the overall points spent in the tree.
@@ -36,13 +37,18 @@ export function calcMeetsRequirements(talent: TalentData, known: Map<number, num
export const addTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => { export const addTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => {
const currentPoints = known.get(talent.id, 0) const currentPoints = known.get(talent.id, 0)
// Support for specific Talent dependency requirement. // Reached the max rank?
if (talent.requires.length > 0 && !calcMeetsRequirements(talent, known)) { if (currentPoints >= talent.ranks.length) {
return known
}
// Spend a maximum of 51 points
if (calcAvailablePoints(known) === 0) {
return known return known
} }
// Spend a maximum of 51 points // Support for specific Talent dependency requirement.
if (calcAvailablePoints(known) === 0) { if (talent.requires.length > 0 && !calcMeetsRequirements(talent, known)) {
return known return known
} }
@@ -52,11 +58,6 @@ export const addTalentPoint = (known: Map<number, number>, talent: TalentData):
if (requiredPoints > pointsInSpec) { if (requiredPoints > pointsInSpec) {
return known return known
} }
// Reached the max rank?
if (currentPoints >= talent.ranks.length) {
return known
}
return known.set(talent.id, currentPoints + 1) return known.set(talent.id, currentPoints + 1)
} }
@@ -66,13 +67,41 @@ export const addTalentPoint = (known: Map<number, number>, talent: TalentData):
*/ */
export const removeTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => { export const removeTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => {
const currentPoints = known.get(talent.id, 0) const currentPoints = known.get(talent.id, 0)
const specId = talentToSpec[talent.id]
// TODO: We should prevent reducing talent points on a row when it is a dependency for points already spent in the next row.
// Already no points for this talent // No points to reduce for this talent
if (currentPoints === 0) { if (currentPoints === 0) {
return known return known
} }
let highestRow = 0
let cumulativePointsPerRow = {}
known.forEach((points, talentId) => {
const t = talentsBySpec[specId][talentId]
if (t) {
highestRow = t.row > highestRow ? t.row : highestRow
for (let row = t.row; row < MAX_ROWS; row++) {
cumulativePointsPerRow[row] = (cumulativePointsPerRow[row] || 0) + points
}
}
})
// Check if removing this talent would not break the requirements for talents spent in later rows
const pointsUntilHighestRow = cumulativePointsPerRow[highestRow - 1]
const targetPointsHighestRow = highestRow * 5
if (talent.row < highestRow && pointsUntilHighestRow - 1 < targetPointsHighestRow) {
return known
}
// TODO: Prevent if another talent depends on this
// const isDependency = known.reduce((prev, current, key) => {
// if (prev) return prev
// const t = talentsBySpec[specId][key]
// if (t.requires.length === 0) {
// return false
// }
// t.requires.map((d) => d.id === talent.id ? d : undefined)
// }, false)
return currentPoints === 1 return currentPoints === 1
? known.remove(talent.id) ? known.remove(talent.id)