mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-08 13:48:11 +02:00
Compare commits
No commits in common. "ac010482fe352942d2fc439228bd2e0e9a7b5d21" and "13bcadf1425d6738396573ce6f85feb8bd7de7e8" have entirely different histories.
ac010482fe
...
13bcadf142
1 changed files with 11 additions and 18 deletions
|
|
@ -153,13 +153,10 @@ export default class DhpActor extends Actor {
|
||||||
async updateLevel(newLevel) {
|
async updateLevel(newLevel) {
|
||||||
if (!['character', 'companion'].includes(this.type) || newLevel === this.system.levelData.level.changed) return;
|
if (!['character', 'companion'].includes(this.type) || newLevel === this.system.levelData.level.changed) return;
|
||||||
|
|
||||||
const tiers = Object.values(game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers);
|
|
||||||
const maxLevel = tiers.reduce((acc, tier) => Math.max(acc, tier.levels.end), 0);
|
|
||||||
const multiclassMinLevel = Math.min(
|
|
||||||
maxLevel,
|
|
||||||
...tiers.filter(t => t.options.multiclass).map(t => t.levels.start)
|
|
||||||
);
|
|
||||||
if (newLevel > this.system.levelData.level.current) {
|
if (newLevel > this.system.levelData.level.current) {
|
||||||
|
const maxLevel = Object.values(
|
||||||
|
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers
|
||||||
|
).reduce((acc, tier) => Math.max(acc, tier.levels.end), 0);
|
||||||
if (newLevel > maxLevel) {
|
if (newLevel > maxLevel) {
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.tooHighLevel'));
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.tooHighLevel'));
|
||||||
}
|
}
|
||||||
|
|
@ -234,19 +231,18 @@ export default class DhpActor extends Actor {
|
||||||
this.system.multiclass.subclass.update({ 'system.featureState': subclassFeatureState.multiclass });
|
this.system.multiclass.subclass.update({ 'system.featureState': subclassFeatureState.multiclass });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove multiclass if we're removing a multiclass feature or if we're below the multiclass minimum level
|
if (multiclass) {
|
||||||
// Multclasses cannot be manually removed on the sheet, so this allows recovering in the case of errors
|
const multiclassItem = this.items.find(x => x.uuid === multiclass.itemUuid);
|
||||||
if (multiclass || newLevel < multiclassMinLevel) {
|
const multiclassFeatures = this.items.filter(
|
||||||
const multiclassItems = this.items.filter(
|
x => x.system.originItemType === 'class' && x.system.multiclassOrigin
|
||||||
x =>
|
);
|
||||||
x.uuid === multiclass?.itemUuid ||
|
const subclassFeatures = this.items.filter(
|
||||||
x.system.isMulticlass ||
|
x => x.system.originItemType === 'subclass' && x.system.multiclassOrigin
|
||||||
(['class', 'subclass'].includes(x.system.originItemType) && x.system.multiclassOrigin)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.deleteEmbeddedDocuments(
|
this.deleteEmbeddedDocuments(
|
||||||
'Item',
|
'Item',
|
||||||
multiclassItems.map(x => x.id)
|
[multiclassItem, ...multiclassFeatures, ...subclassFeatures].map(x => x.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.update({
|
this.update({
|
||||||
|
|
@ -398,7 +394,6 @@ export default class DhpActor extends Actor {
|
||||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...multiclassData,
|
...multiclassData,
|
||||||
uuid: multiclassItem.uuid, // todo: replace with setting an id and using keepId
|
|
||||||
_stats: getStatsWithSource(multiclassItem),
|
_stats: getStatsWithSource(multiclassItem),
|
||||||
system: {
|
system: {
|
||||||
...multiclassData.system,
|
...multiclassData.system,
|
||||||
|
|
@ -412,7 +407,6 @@ export default class DhpActor extends Actor {
|
||||||
await this.createEmbeddedDocuments('Item', [
|
await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...subclassData,
|
...subclassData,
|
||||||
uuid: subclassItem.uuid, // todo: replace with setting an id and using keepId
|
|
||||||
_stats: getStatsWithSource(subclassItem),
|
_stats: getStatsWithSource(subclassItem),
|
||||||
system: {
|
system: {
|
||||||
...subclassData.system,
|
...subclassData.system,
|
||||||
|
|
@ -433,7 +427,6 @@ export default class DhpActor extends Actor {
|
||||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...cardData,
|
...cardData,
|
||||||
uuid: cardItem.uuid, // todo: replace with setting an id and using keepId
|
|
||||||
_stats: getStatsWithSource(cardItem),
|
_stats: getStatsWithSource(cardItem),
|
||||||
system: {
|
system: {
|
||||||
...cardData.system,
|
...cardData.system,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue