Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.6.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyorl committed Jun 1, 2022
2 parents e0b9117 + 5e06e31 commit b81f78f
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 28 deletions.
6 changes: 4 additions & 2 deletions dnd5e.css
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@
.dnd5e .items-list .item .item-name .item-image {
flex: 0 0 30px;
height: 30px;
background-size: 30px;
background-size: cover;
background-position: 50% 0;
border: none;
margin-right: 5px;
}
Expand Down Expand Up @@ -1383,7 +1384,8 @@
.dnd5e.advancement.flow .item-name .item-image {
flex: 0 0 30px;
height: 30px;
background-size: 30px;
background-size: cover;
background-position: 50% 0;
margin-inline-end: 5px;
}
.dnd5e.advancement.flow .item-name label {
Expand Down
3 changes: 2 additions & 1 deletion less/advancement.less
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
.item-image {
flex: 0 0 30px;
height: 30px;
background-size: 30px;
background-size: cover;
background-position: 50% 0;
margin-inline-end: 5px;
}
label {
Expand Down
3 changes: 2 additions & 1 deletion less/apps.less
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@
.item-image {
flex: 0 0 30px;
height: 30px;
background-size: 30px;
background-size: cover;
background-position: 50% 0;
border: none;
margin-right: 5px;
}
Expand Down
29 changes: 17 additions & 12 deletions module/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,17 @@ export default class Actor5e extends Actor {

/* -------------------------------------------- */

/** @inheritdoc */
getRollData() {
const data = super.getRollData();
/**
* @inheritdoc
* @param {object} [options]
* @param {boolean} [options.deterministic] Whether to force deterministic values for data properties that could be
* either a die term or a flat term.
*/
getRollData({ deterministic=false }={}) {
const data = foundry.utils.deepClone(super.getRollData());
data.prof = new Proficiency(this.data.data.attributes.prof, 1);
if ( deterministic ) data.prof = data.prof.flat;

data.classes = {};
for ( const [identifier, cls] of Object.entries(this.classes) ) {
data.classes[identifier] = cls.data.data;
Expand Down Expand Up @@ -592,15 +599,13 @@ export default class Actor5e extends Actor {

// Tabulate the total spell-casting progression
for ( let cls of Object.values(this.classes) ) {
const classData = cls.data.data;
const subclassProg = cls.subclass?.data.data.spellcasting.progression;
const prog = ( subclassProg && (subclassProg !== "none") ) ? subclassProg : classData.spellcasting.progression;
const prog = cls.spellcasting.progression;
if ( prog === "none" ) continue;
const levels = classData.levels;
const levels = cls.data.data.levels;

// Accumulate levels
if ( prog !== "pact" ) {
caster = classData;
caster = cls;
progression.total++;
}
switch (prog) {
Expand All @@ -614,13 +619,13 @@ export default class Actor5e extends Actor {

// EXCEPTION: single-classed non-full progression rounds up, rather than down
const isSingleClass = (progression.total === 1) && (progression.slot > 0);
if (!isNPC && isSingleClass && ["half", "third"].includes(caster.spellcasting.progression) ) {
if ( !isNPC && isSingleClass && ["half", "third"].includes(caster.spellcasting.progression) ) {
const denom = caster.spellcasting.progression === "third" ? 3 : 2;
progression.slot = Math.ceil(caster.levels / denom);
progression.slot = Math.ceil(caster.data.data.levels / denom);
}

// EXCEPTION: NPC with an explicit spell-caster level
if (isNPC && actorData.data.details.spellLevel) {
if ( isNPC && actorData.data.details.spellLevel ) {
progression.slot = actorData.data.details.spellLevel;
}

Expand Down Expand Up @@ -708,7 +713,7 @@ export default class Actor5e extends Actor {

default:
let formula = ac.calc === "custom" ? ac.formula : cfg.formula;
const rollData = foundry.utils.deepClone(this.getRollData());
const rollData = this.getRollData({ deterministic: true });
if ( armors.length ) {
if ( armors.length > 1 ) ac.warnings.push("DND5E.WarnMultipleArmor");
const armorData = armors[0].data.data.armor;
Expand Down
2 changes: 1 addition & 1 deletion module/actor/proficiency.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export default class Proficiency {
* @returns {string} Flat proficiency value.
*/
toString() {
return this.flat;
return this.term;
}
}
2 changes: 1 addition & 1 deletion module/actor/sheets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ export default class ActorSheet5e extends ActorSheet {
const existingTooltip = event.currentTarget.querySelector("div.tooltip");
const property = event.currentTarget.dataset.property;
if ( existingTooltip || !property ) return;
const data = this.actor.data.data;
const data = this.actor.getRollData({ deterministic: true });
let attributions;
switch ( property ) {
case "attributes.ac": attributions = this._prepareArmorClassAttribution(data); break;
Expand Down
3 changes: 2 additions & 1 deletion module/actor/sheets/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export default class ActorSheet5eCharacter extends ActorSheet5e {
return { level, delta, disabled: delta > maxLevelDelta };
});
arr.push(cls);
const subclass = subclasses.findSplice(s => s.data.classIdentifier === cls.data.identifier);
const identifier = cls.data.identifier || cls.name.slugify({strict: true});
const subclass = subclasses.findSplice(s => s.data.classIdentifier === identifier);
if ( subclass ) arr.push(subclass);
return arr;
}, []);
Expand Down
2 changes: 1 addition & 1 deletion module/actor/sheets/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export default class ActorSheet5eVehicle extends ActorSheet5e {
event.preventDefault();
const row = event.currentTarget.closest(".item");
if (row.classList.contains("cargo-row")) {
const idx = Number(row.dataset.itemId);
const idx = Number(row.dataset.itemIndex);
const type = row.classList.contains("crew") ? "crew" : "passengers";
const cargo = foundry.utils.deepClone(this.actor.data.data.cargo[type]).filter((_, i) => i !== idx);
return this.actor.update({[`data.cargo.${type}`]: cargo});
Expand Down
21 changes: 20 additions & 1 deletion module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ export default class Item5e extends Item {

/* -------------------------------------------- */

/**
* Retrieve the spellcasting for a class or subclass. For classes, this will return the spellcasting
* of the subclass if it overrides the class. For subclasses, this will return the class's spellcasting
* if no spellcasting is defined on the subclass.
* @type {object} Spellcasting object containing progression & ability.
*/
get spellcasting() {
const spellcasting = this.data.data.spellcasting;
if ( !spellcasting ) return spellcasting;
const isSubclass = this.type === "subclass";
const classSpellcasting = isSubclass ? this.class?.data.data.spellcasting : spellcasting;
const subclassSpellcasting = isSubclass ? spellcasting : this.subclass?.data.data.spellcasting;
if ( subclassSpellcasting && subclassSpellcasting.progression !== "none" ) return subclassSpellcasting;
return classSpellcasting;
}

/* -------------------------------------------- */

/**
* Should this item's active effects be suppressed.
* @type {boolean}
Expand Down Expand Up @@ -602,7 +620,8 @@ export default class Item5e extends Item {
if (this.isOwned && !Number.isNumeric(max)) {
if (this.actor.data === undefined) return;
try {
max = Roll.replaceFormulaData(max, this.actor.getRollData(), {missing: 0, warn: true});
const rollData = this.actor.getRollData({ deterministic: true });
max = Roll.replaceFormulaData(max, rollData, {missing: 0, warn: true});
max = Roll.safeEval(max);
} catch(e) {
console.error("Problem preparing Max uses for", this.data.name, e);
Expand Down
3 changes: 2 additions & 1 deletion module/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ function _migrateArmorType(item, updateData) {
* @private
*/
function _migrateItemCriticalData(item, updateData) {
if ( foundry.utils.getType(item.data.critical) === "Object" ) return updateData;
const hasCritData = game.system.template.Item[item.type]?.templates?.includes("action");
if ( !hasCritData || (foundry.utils.getType(item.data.critical) === "Object") ) return updateData;
updateData["data.critical"] = {
threshold: null,
damage: null
Expand Down
12 changes: 8 additions & 4 deletions module/pixi/ability-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export default class AbilityTemplate extends MeasuredTemplate {
if ( now - moveTime <= 20 ) return;
const center = event.data.getLocalPosition(this.layer);
const snapped = canvas.grid.getSnappedPosition(center.x, center.y, 2);
this.data.update({x: snapped.x, y: snapped.y});
if ( game.release.generation < 10 ) this.data.update({x: snapped.x, y: snapped.y});
else this.document.updateSource({x: snapped.x, y: snapped.y});
this.refresh();
moveTime = now;
};
Expand All @@ -110,8 +111,9 @@ export default class AbilityTemplate extends MeasuredTemplate {
handlers.lc = event => {
handlers.rc(event);
const destination = canvas.grid.getSnappedPosition(this.data.x, this.data.y, 2);
this.data.update(destination);
canvas.scene.createEmbeddedDocuments("MeasuredTemplate", [this.data]);
if ( game.release.generation < 10 ) this.data.update(destination);
else this.document.updateSource(destination);
canvas.scene.createEmbeddedDocuments("MeasuredTemplate", [this.data.toObject()]);
};

// Rotate the template by 3 degree increments (mouse-wheel)
Expand All @@ -120,7 +122,9 @@ export default class AbilityTemplate extends MeasuredTemplate {
event.stopPropagation();
let delta = canvas.grid.type > CONST.GRID_TYPES.SQUARE ? 30 : 15;
let snap = event.shiftKey ? delta : 5;
this.data.update({direction: this.data.direction + (snap * Math.sign(event.deltaY))});
const update = {direction: this.data.direction + (snap * Math.sign(event.deltaY))};
if ( game.release.generation < 10 ) this.data.update(update);
else this.document.updateSource(update);
this.refresh();
};

Expand Down
4 changes: 2 additions & 2 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dnd5e",
"title": "DnD5e - Fifth Edition System",
"description": "A system for playing the fifth edition of the worlds most popular role-playing game in the Foundry Virtual Tabletop environment.",
"version": "1.6.1",
"version": "1.6.2",
"author": "Atropos",
"scripts": [],
"esmodules": ["dnd5e.js"],
Expand Down Expand Up @@ -117,5 +117,5 @@
"compatibleCoreVersion": "9",
"url": "https://gitlab.com/foundrynet/dnd5e",
"manifest": "https://gitlab.com/api/v4/projects/foundrynet%2Fdnd5e/packages/generic/dnd5e/latest/system.json",
"download": "https://gitlab.com/foundrynet/dnd5e/-/releases/release-1.6.1/downloads/dnd5e-release-1.6.1.zip"
"download": "https://gitlab.com/foundrynet/dnd5e/-/releases/release-1.6.2/downloads/dnd5e-release-1.6.2.zip"
}

0 comments on commit b81f78f

Please sign in to comment.