Skip to content

Commit

Permalink
fix(files): changes now reflected in src files
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyronda committed Jan 24, 2022
1 parent 9abce87 commit 3c4478d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 67 deletions.
52 changes: 29 additions & 23 deletions dist/module/combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,57 +65,63 @@ export class OseCombat {

static async individualInitiative(combat, data) {
let updates = [];
let rolls = []
let rolls = [];
for (let i = 0; i < combat.data.combatants.size; i++) {
let c = combat.data.combatants.contents[i];
// This comes from foundry.js, had to remove the update turns thing
// Roll initiative
const cf = await c._getInitiativeFormula(c);
const roll = await c.getInitiativeRoll(cf)
rolls.push(roll)
const data = { _id: c.id };
const roll = await c.getInitiativeRoll(cf);
rolls.push(roll);
const data = { _id: c.id };
updates.push(data);
}
//combine init rolls
const pool = PoolTerm.fromRolls(rolls);
const combinedRoll = await Roll.fromTerms([pool]);
//get evaluated chat message
const evalRoll = await combinedRoll.toMessage({},{create: false})
let rollArr = combinedRoll.terms[0].rolls
let msgContent = ``
for(let i = 0; i < rollArr.length; i++){
let roll = rollArr[i]
const evalRoll = await combinedRoll.toMessage({}, { create: false });
let rollArr = combinedRoll.terms[0].rolls;
let msgContent = ``;
for (let i = 0; i < rollArr.length; i++) {
let roll = rollArr[i];
//get combatant
let cbt = game.combats.viewed.combatants.find(c=>c.id == updates[i]._id)
//add initiative value to update
//check if actor is slow
let value = cbt.actor.data.data.isSlow ? OseCombat.STATUS_SLOW : roll.total;
let cbt = game.combats.viewed.combatants.find(
(c) => c.id == updates[i]._id
);
//add initiative value to update
//check if actor is slow
let value = cbt.actor.data.data.isSlow
? OseCombat.STATUS_SLOW
: roll.total;
//check if actor is defeated
if (combat.settings.skipDefeated &&cbt.isDefeated) {
if (combat.settings.skipDefeated && cbt.isDefeated) {
value = OseCombat.STATUS_DIZZY;
}
updates[i].initiative = value
updates[i].initiative = value;

//render template
let template = "systems/ose/dist/templates/chat/roll-individual-initiative.html"
let template =
"systems/ose/dist/templates/chat/roll-individual-initiative.html";
let tData = {
name: cbt.name,
formula: roll.formula,
result: roll.result,
total: roll.total,
}
let rendered = await renderTemplate(template, tData)
msgContent += rendered
};
let rendered = await renderTemplate(template, tData);
msgContent += rendered;
}
evalRoll.content = `
<details>
<summary>${game.i18n.localize('OSE.roll.individualInitGroup')}</summary>
<summary>${game.i18n.localize("OSE.roll.individualInitGroup")}</summary>
${msgContent}
</details>`
</details>`;
ChatMessage.create(evalRoll);
//update tracker
if (game.user.isGM) await combat.updateEmbeddedDocuments('Combatant', updates);
data.turn = 0;
if (game.user.isGM)
await combat.updateEmbeddedDocuments("Combatant", updates);
data.turn = 0;
}

static format(object, html, user) {
Expand Down
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"OSE.roll.reaction": "Reaction roll",
"OSE.roll.initiative": "Group {group} rolls for Initiative!",
"OSE.roll.individualInit": "{name} rolls for Initiative!",
"OSE.roll.individualInitGroup": "Initiative Rolls",

"OSE.table.treasure.roll": "Roll Treasure",

Expand Down
87 changes: 46 additions & 41 deletions src/module/combat.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,57 +65,62 @@ export class OseCombat {

static async individualInitiative(combat, data) {
let updates = [];
let messages = [];

let rolls = [];
for (let i = 0; i < combat.data.combatants.size; i++) {
let c = combat.data.combatants.contents[i];

// This comes from foundry.js, had to remove the update turns thing
// Roll initiative
const cf = await c._getInitiativeFormula(c);
const roll = await c.getInitiativeRoll(cf).evaluate({ async: true });

let value = roll.total;
if (combat.settings.skipDefeated && c.defeated) {
const roll = await c.getInitiativeRoll(cf);
rolls.push(roll);
const data = { _id: c.id };
updates.push(data);
}
//combine init rolls
const pool = PoolTerm.fromRolls(rolls);
const combinedRoll = await Roll.fromTerms([pool]);
//get evaluated chat message
const evalRoll = await combinedRoll.toMessage({}, { create: false });
let rollArr = combinedRoll.terms[0].rolls;
let msgContent = ``;
for (let i = 0; i < rollArr.length; i++) {
let roll = rollArr[i];
//get combatant
let cbt = game.combats.viewed.combatants.find(
(c) => c.id == updates[i]._id
);
//add initiative value to update
//check if actor is slow
let value = cbt.actor.data.data.isSlow
? OseCombat.STATUS_SLOW
: roll.total;
//check if actor is defeated
if (combat.settings.skipDefeated && cbt.isDefeated) {
value = OseCombat.STATUS_DIZZY;
}
const data = { _id: c.id, initiative: value };

updates.push(data);

// Determine the roll mode
let rollMode = game.settings.get("core", "rollMode");
if ((c.token.hidden || c.hidden) && rollMode === "roll")
rollMode = "gmroll";
updates[i].initiative = value;

// Construct chat message data
let messageData = foundry.utils.mergeObject(
{
speaker: {
scene: combat.scene.id,
actor: c.actor?.id,
token: c.token?.id,
alias: c.name,
},
flavor: game.i18n.format("OSE.roll.individualInit", {
name: c.token.name,
}),
flags: { "ose.initiativeRoll": true },
},
{}
);
const chatData = await roll.toMessage(messageData, {
rollMode: c.hidden && rollMode === "roll" ? "gmroll" : rollMode,
create: false,
});
if (i > 0) chatData.sound = null; // Only play 1 sound for the whole set
messages.push(chatData);
//render template
let template =
"systems/ose/dist/templates/chat/roll-individual-initiative.html";
let tData = {
name: cbt.name,
formula: roll.formula,
result: roll.result,
total: roll.total,
};
let rendered = await renderTemplate(template, tData);
msgContent += rendered;
}
if (game.user.isGM) {
evalRoll.content = `
<details>
<summary>${game.i18n.localize("OSE.roll.individualInitGroup")}</summary>
${msgContent}
</details>`;
ChatMessage.create(evalRoll);
//update tracker
if (game.user.isGM)
await combat.updateEmbeddedDocuments("Combatant", updates);
}

await ChatMessage.implementation.create(messages);
data.turn = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ export class OseItem extends Item {
return this.update({ data: newData });
}

roll() {
roll(options = {}) {
switch (this.type) {
case "weapon":
this.rollWeapon();
this.rollWeapon(options);
break;
case "spell":
this.spendSpell();
this.spendSpell(options);
break;
case "ability":
if (this.data.data.roll) {
Expand Down
23 changes: 23 additions & 0 deletions src/templates/chat/roll-individual-initiative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div><b>{{name}}</b></div>
<div class="dice-roll">
<div class="dice-result">
<div class="dice-formula">{{formula}}</div>
<div class="dice-tooltip expanded" style="display: none">
<section class="tooltip-part">
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">{{result}}</span>

<span class="part-total">{{total}}</span>
</header>
<ol class="dice-rolls">
<li class="roll die d6">{{total}}</li>
</ol>
</div>
</section>
</div>

<h4 class="dice-total">{{total}}</h4>
</div>
</div>
</br>

0 comments on commit 3c4478d

Please sign in to comment.