diff --git a/charbuilder/js/plutonium/charactermancer.js b/charbuilder/js/plutonium/charactermancer.js index 1873d25..14778a0 100644 --- a/charbuilder/js/plutonium/charactermancer.js +++ b/charbuilder/js/plutonium/charactermancer.js @@ -2356,8 +2356,7 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { const setNxt = new Set(nxt); if (!CollectionUtil.setEq(setCurr, setNxt)) this._state[propState] = nxt; - } - ; + }; this._addHookBase("ixSet", hk); this._addHookBase("curLevel", hk); this._addHookBase("targetLevel", hk); @@ -2393,7 +2392,8 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { const isInnatePreparedList = this._isAnyInnatePrepared(ix); const isExpandedList = this._isAnyExpanded(ix); - const sortedSpells = Object.values(additionalSpellsFlatBlock.spells).sort((a,b)=>SortUtil.ascSort(a.requiredLevel || 0, b.requiredLevel || 0) || SortUtil.ascSort(a.requiredCasterLevel || 0, b.requiredCasterLevel || 0)); + const sortedSpells = Object.values(additionalSpellsFlatBlock.spells).sort((a,b)=>SortUtil.ascSort(a.requiredLevel || 0, + b.requiredLevel || 0) || SortUtil.ascSort(a.requiredCasterLevel || 0, b.requiredCasterLevel || 0)); const $wrpInnatePreparedHeaders = isInnatePreparedList ? $(`
Level
@@ -2412,6 +2412,7 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { isExpandedMatch: true }) : null; + const $wrpNoneAvailableInnatePrepared = isInnatePreparedList ? $(`
No spells at this level
`) : null; const $wrpNoneAvailableExpanded = isExpandedList ? $(`
No spells at this level
`) : null; @@ -2427,8 +2428,7 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { $wrpExpandedHeaders.toggleVe(isExpandedAvailable); if ($wrpNoneAvailableExpanded) $wrpNoneAvailableExpanded.toggleVe(!isExpandedAvailable); - } - ; + }; this._addHookBase("spellLevelLow", hkSpellsAvailable); this._addHookBase("spellLevelHigh", hkSpellsAvailable); this._addHookBase("isAnyCantrips", hkSpellsAvailable); @@ -2471,8 +2471,9 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { if (this._additionalSpellsFlat.length !== 1) { const hkIsActive = ()=>{ - $btnSelect.toggleClass("active", this._state.ixSet === ix); - $stg.toggleVe(this._state.ixSet === ix); + console.log("hkisactive disabled"); + /* $btnSelect.toggleClass("active", this._state.ixSet === ix); + $stg.toggleVe(this._state.ixSet === ix); */ } ; this._addHookBase("ixSet", hkIsActive); @@ -2723,17 +2724,22 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { if (!isVisible || !isAnyExpanded) return doShowInitialPts(); doShowExpandedPts(); - } - ; + }; this._addHookBase("spellLevelLow", hkLevel); this._addHookBase("spellLevelHigh", hkLevel); this._addHookBase("isAnyCantrips", hkLevel); hkLevel(); } else if (isRequiredLevel) { const hkLevel = ()=>{ - const isVisible = isAnyExpanded ? this._isRequiredLevelInRangeUpper(requiredLevel) : this._isRequiredLevelInRange(requiredLevel); + //TODO: Fix this bug properly + //TEMP: setting isAnyExpanded to true for the meanwhile, since it makes us not care about what curLevel is (curLevel is often incorrectly set after load) + let isExpanded = isAnyExpanded; + isExpanded = true; + + const isVisible = /* isAnyExpanded */ isExpanded? this._isRequiredLevelInRangeUpper(requiredLevel) : this._isRequiredLevelInRange(requiredLevel); + //const isVisible = isAnyExpanded $row.toggleVe(isVisible); - if (!isVisible && !isAnyExpanded) + if (!isVisible && !isExpanded) return doShowInitialPts(); doShowExpandedPts(); } @@ -2760,14 +2766,17 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { } _isRequiredLevelInRange(requiredLevel) { + //The spell's required level has to be between curLevel and targetLevel (or equal to targetLevel) return this._isRequiredLevelInRangeLower(requiredLevel) && this._isRequiredLevelInRangeUpper(requiredLevel); } _isRequiredLevelInRangeLower(requiredLevel) { + //The spell's required level has to be above the curlevel (not to be mixed up with targetLevel) return requiredLevel > (this._state.curLevel ?? Number.MAX_SAFE_INTEGER); } _isRequiredLevelInRangeUpper(requiredLevel) { + //The spell's required level has to be below or equal the targetLevel (not to be mixed up with curlevel) return requiredLevel <= (this._state.targetLevel ?? Number.MIN_SAFE_INTEGER); } @@ -2815,7 +2824,9 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent { if (flat.requiredCasterLevel != null) return this._isRequiredCasterLevelInRange(flat.requiredCasterLevel); else if (flat.requiredLevel != null) - return this._isRequiredLevelInRange(flat.requiredLevel); + { + return this._isRequiredLevelInRange(flat.requiredLevel); + } return true; } ); diff --git a/charbuilder/js/sheet.js b/charbuilder/js/sheet.js index ae7111b..78c5c1f 100644 --- a/charbuilder/js/sheet.js +++ b/charbuilder/js/sheet.js @@ -859,6 +859,7 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{ const spellsKnownByLvl = ActorCharactermancerSheet.getAllSpellsKnown(this._parent.compSpell); const additionalSpells = ActorCharactermancerSheet.getAdditionalRaceSpells(this._parent.compRace, this._parent.compClass, this._parent.compSpell); + const featSpells = ActorCharactermancerSheet.getAdditionalFeatSpells(this._getFeats()); //Add additional cantrips to cantrips list for(let sp of additionalSpells.known[0]){ @@ -1588,7 +1589,7 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{ //Try to get items from bought items (we will do starting items later) const compEquipShop = this._parent.compEquipment._compEquipmentShopGold; - let bestArmorAC = Number.MIN_VALUE; + let bestArmorAC = Number.NEGATIVE_INFINITY; let bestArmor = null; const tryUseArmor = (item) => { @@ -1902,6 +1903,56 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{ return {innate:spellsByLevel_innate, known:spellsByLevel_known, ability:abilityUsed}; } + static getAdditionalFeatSpells(feats){ + console.log(feats); + + let spellsByLevel_innate = [[],[],[],[],[],[],[],[],[],[]]; + let spellsByLevel_known = [[],[],[],[],[],[],[],[],[],[]]; + let abilityUsed = "wis"; + + function serializeSpell(spellName, rechargeMode, charges, spellsByLvl, compSpell){ + let spellLevel = 0; + let source = null; + let name = toUpper(spellName); + const fallbackSource = "PHB"; + let obj = {name:name, source: source==null? fallbackSource : source}; + + let matchedItem = ActorCharactermancerSpell.findSpellByUID(obj.name+"|"+obj.source, compSpell._data.spell); + spellLevel = matchedItem.level; + if(matchedItem==null){throw error();} + spellsByLvl[spellLevel].push({spell:matchedItem, rechargeMode:rechargeMode, charges:charges}); + } + + //Go through custom feats + for(let customFeat of feats.customFeats){ + let feat = customFeat.feat; //This contains info about the feat, but no info regarding what choices we made for it + //For the example feat "Fey Touched", we get misty step and another spell of our choice, and one use of either of them per day + //We should be able to grab misty step straight from the feat info here + if(!!feat.additionalSpells) + { + for(let o of feat.additionalSpells){ + //Check innate + for(let innateKey of Object.keys(o.innate)){ + for(let innateSubKey of Object.keys(o.innate[innateKey])){ + if(innateSubKey == "daily"){ + for(let dailyKey of Object.keys(o.innate[innateKey][innateSubKey])){ + let arr = o.innate[innateKey][innateSubKey][dailyKey]; + for(let e of arr){ + if((typeof e) == "string"){ + console.log("found spell ", e); + //Assume we just found the name of the spell, we need to convert it into a full spell object + serializeSpell(e, "daily", int_numDailyUses, spellsByLevel_innate, compSpell); + } + } + } + } + } + } + } + } + } + + } static getSpellSlotsAtLvl(spellLevel, compClass){ let total = 0; diff --git a/charbuilder/todo b/charbuilder/todo index 6097045..888565b 100644 --- a/charbuilder/todo +++ b/charbuilder/todo @@ -25,7 +25,9 @@ CHARSELECT: SHEET: - Cantrip attacks (sort of solved with hoverable spell popups) - Better attack parsing overall - +FEAT: + - Make spell choices in feats like Fey Touched be save/loaded + - Also make the choice appear in Sheet view CLASS: - Make subclass dropdown be locked until high enough level - Make sure when class is removed, that the Feats menu understands that and doesnt allow feat choices from that class