Skip to content

Commit

Permalink
Bug fixes as part of 0.6.6 development
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclayton committed Jun 25, 2023
1 parent 9aa85cc commit 52df6ce
Show file tree
Hide file tree
Showing 84 changed files with 355 additions and 305 deletions.
2 changes: 1 addition & 1 deletion crucible.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Hooks.once("ready", async function() {
/* -------------------------------------------- */

Hooks.on("getChatLogEntryContext", chat.addChatMessageContextOptions);
Hooks.on("createMessage", chat.onCreateMessage);
Hooks.on("createChatMessage", chat.onCreateChatMessage);
Hooks.on("renderChatMessage", chat.renderChatMessage);
Hooks.on("targetToken", dice.ActionUseDialog.debounceChangeTarget);
Hooks.on("preDeleteChatMessage", models.CrucibleAction.onDeleteChatMessage);
Expand Down
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"ARCHETYPE.Clear": "Clear Archetype",
"ARCHETYPE.Configure": "Archetype",
"ARCHETYPE.Abilities": "Ability Scaling",
"ARCHETYPE.AbilitiesHint": "Define how the ability scores for creatures of this Archetype scale as they advance in level. Allocate 18 points across all Ability scores. Each ability score must be between zero and 8. Scores with a lower value advance more frequently. For example a score with the value of 2 will increase every 2nd level while a score with a value of 5 will advance every 5 levels.",
"ARCHETYPE.AbilitiesHint": "Define how the ability scores for creatures of this Archetype scale as they advance in level. Allocate 18 points across all Ability scores. Each ability score must be between zero and 8. Adversaries will increase their abilities by 1 point each level. Scores with a higher value advance more frequently.",
"ARCHETYPE.Talents": "Granted Talents",
"ARCHETYPE.AddTalentHint": "Add a talent to this Archetype by dragging and dropping from the Talents compendium pack.",

Expand Down
16 changes: 11 additions & 5 deletions module/applications/sheets/archetype.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,27 @@ export default class ArchetypeSheet extends CrucibleSheetMixin(ItemSheet) {

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

#onClickAction(event) {
async #onClickAction(event) {
event.preventDefault();
const button = event.currentTarget;
switch ( button.dataset.action ) {
case "removeTalent":
button.closest(".talent").remove();
const fd = this._getSubmitData();
const removeUuid = button.closest(".talent").dataset.uuid;
fd["system.talents"] ||= [];
fd["system.talents"].findSplice(uuid => uuid === removeUuid);
return this._updateObject(event, fd);
await this._updateObject(event, fd);
this.setPosition({height: "auto"});
}
}

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

/** @override */
_canDragDrop(selector) {
return this.isEditable;
}

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

/** @inheritdoc */
async _onDrop(event) {
if ( !this.isEditable ) return;
Expand Down
18 changes: 13 additions & 5 deletions module/applications/sheets/background.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,27 @@ export default class BackgroundSheet extends CrucibleSheetMixin(ItemSheet) {

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

#onClickAction(event) {
async #onClickAction(event) {
event.preventDefault();
const button = event.currentTarget;
switch ( button.dataset.action ) {
case "removeTalent":
button.closest(".talent").remove();
const fd = this._getSubmitData();
fd["system.talents"] = [];
return this._updateObject(event, fd);
await this._updateObject(event, fd);
this.setPosition({height: "auto"});
}
}

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

/** @override */
_canDragDrop(selector) {
return this.isEditable;
}

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

/** @inheritdoc */
async _onDrop(event) {
if ( !this.isEditable ) return;
Expand All @@ -135,8 +143,8 @@ export default class BackgroundSheet extends CrucibleSheetMixin(ItemSheet) {
if ( talent.system.node.tier !== 0 ) {
return ui.notifications.error("BACKGROUND.TalentTierError", {localize: true});
}
const talents = this.element[0].querySelector(".talents");
talents.innerHTML = await this.#renderTalentHTML(talent);
const talents = this.element[0].querySelector(".talents .droppable");
talents.insertAdjacentHTML("beforebegin", await this.#renderTalentHTML(talent));
this.setPosition({height: "auto"});
}

Expand Down
9 changes: 7 additions & 2 deletions module/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ export function addChatMessageContextOptions(html, options) {
* @param {object} options Message creation options
* @param {string} userId The creating user ID
*/
export function onCreateMessage(message, data, options, userId) {
export async function onCreateChatMessage(message, data, options, userId) {
if ( game.user !== game.users.activeGM ) return;
const flags = message.flags.crucible || {};
if ( !flags.action || flags.confirmed ) return;

// Wait for DSN animation if applicable
if ( message.rolls.length && ("dice3d" in game) ) await game.dice3d.waitFor3DAnimationByMessageID(message.id);

// Confirm the message
const action = CrucibleAction.fromChatMessage(message);
const canConfirm = action.canAutoConfirm();
if ( canConfirm ) CrucibleAction.confirm(message, {action});
if ( canConfirm ) await CrucibleAction.confirm(message, {action});
}

/* -------------------------------------------- */
Expand Down
22 changes: 17 additions & 5 deletions module/config/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ export const TAGS = {
action.usage.context.tags.add(`Rune: ${action.rune.name}`);
action.usage.context.tags.add(`Gesture: ${action.gesture.name}`);
if ( action.inflection ) action.usage.context.tags.add(action.inflection.name);
action.usage.actorFlags.lastSpell = action.id;
},
roll: (actor, action, target) => {
action.usage.actorUpdates["system.status.hasCast"] = true;
return actor.castSpell(action, target)
},
post: (actor, action) => action.usage.actorFlags.lastSpell = action.id
}
},

summon: {
Expand All @@ -359,9 +359,18 @@ export const TAGS = {

// Import or reference the Actor to summon
let summonActor = await fromUuid(action.usage.summon);
if ( game.actors.has(summonActor.id) ) summonActor = game.actors.get(summonActor.id);
const ownership = game.users.reduce((obj, u) => {
if ( u.isGM || !actor.testUserPermission(u, "OWNER") ) return obj;
obj[u.id] = CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;
return obj;
}, {});
if ( game.actors.has(summonActor.id) ) {
summonActor = game.actors.get(summonActor.id);
await summonActor.update({ownership});
}
else {
const summonData = game.actors.fromCompendium(summonActor, {keepId: true});
const summonData = game.actors.fromCompendium(summonActor, {keepId: true, clearOwnership: true});
summonData.ownership = ownership;
summonActor = await summonActor.constructor.create(summonData, {keepId: true});
}

Expand All @@ -384,7 +393,10 @@ export const TAGS = {
}
});
token = await token.constructor.create(token, {parent: canvas.scene});
foundry.utils.setProperty(outcomes.get(actor).effects[0], "flags.crucible.summon", token.uuid);

// Record summon ID on the active effect
const ae = outcomes.get(actor).effects?.[0];
if ( ae ) foundry.utils.setProperty(ae, "flags.crucible.summon", token.uuid);

// Create a Combatant
if ( actor.inCombat ) {
Expand Down
32 changes: 18 additions & 14 deletions module/config/actions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ export default {
}
},
shieldBash: {
can: (actor, action) => {
if ( !actor.system.status.basicStrike ) throw new Error("You can only perform Shield Bash after a basic Strike.");
if ( actor.system.status.shieldBash ) throw new Error("You cannot use Shield Bash again this Turn.");
},
post: async (actor, action) => action.usage.actorUpdates["system.status.shieldBash"] = true
can: (actor) => {
const {basicStrike, lastAction} = actor.system.status;
if ( !basicStrike || (lastAction !== "strike") ) {
throw new Error("You can only perform Shield Bash after a basic Strike which did not critically miss.");
}
}
},
strike: {
post: async (actor, action, target, rolls) => {
Expand All @@ -143,10 +144,12 @@ export default {
},
offhandStrike: {
prepare: (actor, action) => {
const {basicStrike, offhandStrike} = actor.system.status;
if ( basicStrike && !offhandStrike ) action.cost.action = 0;
},
post: async (actor, action) => action.usage.actorUpdates["system.status.offhandStrike"] = true
const {basicStrike, offhandStrike, lastAction} = actor.system.status;
if ( basicStrike && (lastAction === "strike") && !offhandStrike ) {
action.cost.action = 0;
action.usage.actorUpdates["system.status.offhandStrike"] = true;
}
}
},
refocus: {
confirm: async (actor, action, outcomes) => {
Expand All @@ -164,11 +167,12 @@ export default {
post: async (actor, action) => action.usage.actorUpdates["system.status.reloaded"] = true
},
uppercut: {
can: (actor, action) => {
if ( !actor.system.status.basicStrike ) throw new Error("You can only perform Uppercut after a basic Strike.");
if ( actor.system.status.uppercut ) throw new Error("You cannot use Uppercut again this Turn.");
},
post: async (actor, action, target) => action.usage.actorUpdates["system.status.uppercut"] = true
can: (actor) => {
const {basicStrike, lastAction} = actor.system.status;
if ( basicStrike && (lastAction !== "strike") ) {
throw new Error("You can only perform Uppercut after a basic Strike which did not critically miss.");
}
}
},
vampiricBite: {
pre: (actor, action) => {
Expand Down
3 changes: 2 additions & 1 deletion module/config/spellcraft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ export const GESTURES = Object.seal({
scaling: "dexterity",
target: {
type: "ray",
distance: 4
distance: 4,
scope: 1 // self
},
tier: 1
},
Expand Down
10 changes: 7 additions & 3 deletions module/data/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default class CrucibleAction extends foundry.abstract.DataModel {
}

// Record the action as a chat message
if ( chatMessage ) await this.toMessage(targets, {
const message = chatMessage && await this.toMessage(targets, {
...chatMessageOptions,
confirmed,
rollMode: this.usage.rollMode
Expand All @@ -354,7 +354,10 @@ export default class CrucibleAction extends foundry.abstract.DataModel {
await this.actor.update({"flags.crucible": this.usage.actorFlags});

// Auto-confirm the action?
if ( confirmed ) await this.confirm();
if ( confirmed ) {
if ( message?.rolls.length && ("dice3d" in game) ) await game.dice3d.waitFor3DAnimationByMessageID(message.id);
await this.confirm();
}
return outcomes;
}

Expand Down Expand Up @@ -606,6 +609,7 @@ export default class CrucibleAction extends foundry.abstract.DataModel {

// Record actor updates to apply
foundry.utils.mergeObject(self.actorUpdates, this.usage.actorUpdates);
self.actorUpdates["system.status.lastAction"] = this.id;

// Incur resource cost
for ( const [k, v] of Object.entries(this.cost) ) {
Expand Down Expand Up @@ -807,7 +811,7 @@ export default class CrucibleAction extends foundry.abstract.DataModel {
// Action Tags
for (let t of this.tags) {
const tag = SYSTEM.ACTION.TAGS[t];
if ( !tag.label ) continue;
if ( !tag?.label ) continue;
else tags.action[tag.tag] = game.i18n.localize(tag.label);
}

Expand Down
2 changes: 1 addition & 1 deletion module/data/archetype.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class CrucibleArchetype extends foundry.abstract.DataModel {
name: new fields.StringField(),
description: new fields.HTMLField(),
abilities: new fields.SchemaField(Object.values(SYSTEM.ABILITIES).reduce((obj, ability) => {
obj[ability.id] = new fields.NumberField({...nullableInteger, initial: 3, min: 0, max: 6})
obj[ability.id] = new fields.NumberField({...nullableInteger, initial: 3, min: 0, max: 8})
return obj;
}, {}), {validate: CrucibleArchetype.#validateAbilities}),
talents: new fields.SetField(new fields.StringField({required: true},
Expand Down
Loading

0 comments on commit 52df6ce

Please sign in to comment.