Skip to content

Commit

Permalink
Merge pull request #200 from SolarBear/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SolarBear authored Jul 23, 2021
2 parents 1aa84c8 + b0edcd2 commit dcee611
Show file tree
Hide file tree
Showing 22 changed files with 515 additions and 314 deletions.
16 changes: 13 additions & 3 deletions module/actor/NumeneraPCActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ export class NumeneraPCActor extends Actor {
switch (this.data.data.damageTrack) {
case 2:
ui.notifications.warn(game.i18n.localize("NUMENERA.pc.damageTrack.debilitated.warning"));
return;
return false;

case 3:
ui.notifications.warn(game.i18n.localize("NUMENERA.pc.damageTrack.dead.warning"));
return;
return false;
}

if (rollData) {
Expand Down Expand Up @@ -157,6 +157,8 @@ export class NumeneraPCActor extends Actor {
{
rollMode: rollData.rollMode,
});

return true;
}

/**
Expand Down Expand Up @@ -427,6 +429,14 @@ export class NumeneraPCActor extends Actor {
return this.useAbility(item);

case NumeneraSkillItem.type:
//Get the related ability if there is one, and use it: this way we make sure the
//abiity cost will be substracted from its pool.
const relatedAbility = await item.getRelatedAbility();
if (relatedAbility)
return this.useItem(relatedAbility);

return item.use();

case NumeneraWeaponItem.type:
return item.use();

Expand Down Expand Up @@ -635,7 +645,7 @@ export class NumeneraPCActor extends Actor {
for (const updatedItem of updatedItems) {
switch (updatedItem.type) {
case NumeneraAbilityItem.type:
const relatedSkill = this.items.find(i => i.data.data.relatedAbilityId === updatedItem._id);
const relatedSkill = this.items.find(i => i.data.data.relatedAbilityId === updatedItem.id);
if (!relatedSkill)
break;

Expand Down
25 changes: 24 additions & 1 deletion module/actor/sheets/NumeneraPCActorSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export class NumeneraPCActorSheet extends ActorSheet {
const abilitiesTable = html.find("table.abilities");
abilitiesTable.on("click", ".ability-create", this.onAbilityCreate.bind(this));
abilitiesTable.on("click", ".ability-delete", this.onAbilityDelete.bind(this));
abilitiesTable.on("click", ".ability-to-chat", this.onAbilityDelete.bind(this));
abilitiesTable.on("click", "a.ability-to-chat", this.onItemToChat.bind(this));
abilitiesTable.on("blur", "input,select,textarea", this.onAbilityEdit.bind(this));
abilitiesTable.on("click", "a.rollable", this.onAbilityUse.bind(this));

Expand Down Expand Up @@ -581,10 +581,12 @@ export class NumeneraPCActorSheet extends ActorSheet {

const artifactsList = html.find("ul.artifacts");
html.find("ul.artifacts").on("click", ".artifact-delete", this.onArtifactDelete.bind(this));
html.find("ul.artifacts").on("click", ".artifact-to-chat", this.onItemToChat.bind(this));
html.find("ul.artifacts").on("click", ".artifact-depletion-roll", this.onArtifactDepletionRoll.bind(this));

const cyphersList = html.find("ul.cyphers");
html.find("ul.cyphers").on("click", ".cypher-delete", this.onCypherDelete.bind(this));
html.find("ul.cyphers").on("click", ".cypher-to-chat", this.onItemToChat.bind(this));

if (game.settings.get("numenera", "usePowerShifts")) {
const powerShiftsTable = html.find("table.powerShifts");
Expand Down Expand Up @@ -870,6 +872,27 @@ export class NumeneraPCActorSheet extends ActorSheet {
super._onChangeInput(event);
}

async onItemToChat(event) {
event.preventDefault();
event.stopPropagation(); //Important! otherwise we get double rendering

const elem = event.currentTarget.closest(".item");

if (!elem)
throw new Error(`Missing .item class element`);
else if (!elem.dataset.itemId)
throw new Error(`No itemID on .item element`);

const item = await this.actor.getEmbeddedDocument("Item", elem.dataset.itemId);

if (!!!item.toChatMessage) {
console.warn(`Tried to output ${item.type} type to chat, which is currently not supported`);
return;
}

await item.toChatMessage();
}

async _onDropItem(event, data) {
const items = await super._onDropItem(event, data);
let item = await items[0];
Expand Down
8 changes: 4 additions & 4 deletions module/apps/EffortDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class EffortDialog extends FormApplication {

//Fetch the skill, might be one of these weird kind-of-Item objects
if (skill._id)
skill = this.object.actor.items.get(this.object.skill._id);
skill = this.object.actor.items.get(this.object.skill.id);

actor.rollSkill(skill, rollData, this.object.ability);
}
Expand All @@ -449,7 +449,7 @@ export class EffortDialog extends FormApplication {

const poolProp = `data.stats.${shortStat}.pool.value`;

const data = { _id: actor._id };
const data = { _id: actor.id };
data[poolProp] = poolValue - cost;

//TIME TO PAY THE PRICE MWAHAHAHAHAHAHAH
Expand All @@ -475,7 +475,7 @@ export class EffortDialog extends FormApplication {
result: game.i18n.localize("NUMENERA.effort.failAutomatically"),
}),
});

this.close();
}

Expand Down Expand Up @@ -513,7 +513,7 @@ export class EffortDialog extends FormApplication {
formData.stat = getShortStat(formData.stat);

// Did the skill change?
if (formData.skill && (this.object.skill == null || formData.skill !== this.object.skill._id)) {
if (formData.skill && (this.object.skill == null || formData.skill !== this.object.skill.id)) {
//In that case, update the stat to be the skill's stat
this.object.skill = this.object.actor.items.get(formData.skill);

Expand Down
6 changes: 5 additions & 1 deletion module/handlebarHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export function registerHandlebarHelpers() {
if (value == this.switch_value) {
return options.fn(this);
}
});
});

Handlebars.registerHelper('capitalize', phrase =>
phrase.charAt(0).toUpperCase() + phrase.slice(1)
);
}
28 changes: 25 additions & 3 deletions module/item/NumeneraAbilityItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class NumeneraAbilityItem extends Item {
* @returns {Boolean} True if the ability was used, false otherwise.
* @memberof NumeneraAbilityItem
*/
async use() {
async use(event = null) {
//An ability must be related to an Actor to be used
if (this.actor === null) {
ui.notifications.error(game.i18n.localize("NUMENERA.item.ability.useNotLinkedToActor"));
Expand Down Expand Up @@ -130,8 +130,30 @@ export class NumeneraAbilityItem extends Item {
skill = NumeneraSkillItem.fromOwnedItem(skill, this.actor);
}

skill.use();
return true;
return skill.use(event, this);
}

async toChatMessage() {
const data = {
type: this.type,
name: this.data.name,
img: this.data.img,
form: this.data.data.form,
abilityType: this.data.data.abilityType,
cost: this.data.data.cost.amount,
stat: this.data.data.cost.pool,
range: this.data.data.range,
description: this.data.data.notes,
};

await ChatMessage.create({
user: game.user.id,
speaker: ChatMessage.getSpeaker({user: game.user}),
content: await renderTemplate(
"systems/numenera/templates/chat/items/ability.html",
data,
)
});
}

/**
Expand Down
29 changes: 29 additions & 0 deletions module/item/NumeneraArtifactItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,33 @@ export class NumeneraArtifactItem extends Item {
itemData.levelDie = itemData.levelDie || "";
itemData.level = itemData.level || "";
}

async toChatMessage() {
const data = {
type: this.type,
name: this.data.name,
img: this.data.img,
form: this.data.data.form,
level: this.data.data.level,
effect: this.data.data.effect,
laws: this.data.data.laws,
depletion: this.data.data.depletion,
};

if (!this.data.data.identified) {
data.name = game.i18n.localize("NUMENERA.pc.numenera.artifact.unidentified");
data.level = game.i18n.localize("NUMENERA.unknown");
data.effect = game.i18n.localize("NUMENERA.unknown");
data.depletion = null;
}

await ChatMessage.create({
user: game.user._id,
speaker: ChatMessage.getSpeaker({user: game.user}),
content: await renderTemplate(
"systems/numenera/templates/chat/items/artifact.html",
data,
)
});
}
}
35 changes: 34 additions & 1 deletion module/item/NumeneraCypherItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ export class NumeneraCypherItem extends Item {
return "cypher";
}

static get name() {
return game.i18n.localize("NUMENERA.pc.numenera.cypher.unidentified");
}

/**
* Transform the current cypher so it doesn't look identified.
*
* @memberof NumeneraCypherItem
*/
static asUnidentified(cypher) {
debugger;
if (cypher.constructor === Object)
cypher = NumeneraCypherItem.fromOwnedItem(cypher);

Expand Down Expand Up @@ -67,6 +70,7 @@ export class NumeneraCypherItem extends Item {
itemData = itemData.data;

itemData.name = this.data.name || game.i18n.localize("NUMENERA.item.cypher.newCypher");
itemData.identified = itemData.identified || false;
itemData.level = itemData.level || null;
itemData.levelDie = itemData.levelDie || "";
itemData.form = itemData.form || "";
Expand All @@ -75,6 +79,35 @@ export class NumeneraCypherItem extends Item {
itemData.cypherType = itemData.cypherType || "";
}

async toChatMessage() {
const data = {
type: this.type,
name: this.data.name,
img: this.data.img,
form: this.data.data.form,
useCypherType: !!NumeneraCypherItem.cypherTypeFlavor,
cypherType: this.data.data.cypherType,
level: this.data.data.level,
effect: this.data.data.effect,
};

if (!this.data.data.identified) {
data.name = game.i18n.localize("NUMENERA.pc.numenera.cypher.unidentified");
data.level = game.i18n.localize("NUMENERA.unknown");
data.effect = game.i18n.localize("NUMENERA.unknown");
data.cypherType = game.i18n.localize("NUMENERA.unknown");;
}

await ChatMessage.create({
user: game.user.id,
speaker: ChatMessage.getSpeaker({user: game.user}),
content: await renderTemplate(
"systems/numenera/templates/chat/items/cypher.html",
data,
)
});
}

/**
* Get the cypher type flavor used.
*
Expand Down
Loading

0 comments on commit dcee611

Please sign in to comment.