Skip to content

Commit

Permalink
fixed a bug regardin worn armor AC and innate spells depending on cha…
Browse files Browse the repository at this point in the history
…r lvl
  • Loading branch information
Zakkon committed Aug 27, 2024
1 parent 5a44111 commit d71a8d2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 14 deletions.
35 changes: 23 additions & 12 deletions charbuilder/js/plutonium/charactermancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ? $(`<div class="ve-flex-v-center py-1">
<div class="col-3 ve-text-center">Level</div>
Expand All @@ -2412,6 +2412,7 @@ class Charactermancer_AdditionalSpellsSelect extends BaseComponent {
isExpandedMatch: true
}) : null;


const $wrpNoneAvailableInnatePrepared = isInnatePreparedList ? $(`<div class="ve-small ve-flex-v-center my-1 w-100 italic ve-muted">No spells at this level</div>`) : null;
const $wrpNoneAvailableExpanded = isExpandedList ? $(`<div class="ve-small ve-flex-v-center my-1 w-100 italic ve-muted">No spells at this level</div>`) : null;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
);
Expand Down
53 changes: 52 additions & 1 deletion charbuilder/js/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]){
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion charbuilder/todo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d71a8d2

Please sign in to comment.