ENH: Fix formula formatting, Morale check

master
U~man 2020-07-05 14:43:27 +02:00
parent 401d78f435
commit 70309c960e
10 changed files with 130 additions and 30 deletions

View File

@ -146,6 +146,11 @@ export class OseActorSheetCharacter extends OseActorSheet {
actorObject.rollCheck(score, { event: event });
});
html.find(".hit-dice .attribute-name a").click((ev) => {
let actorObject = this.actor;
actorObject.rollHitDice({ event: event });
});
html.find(".exploration .attribute-name a").click((ev) => {
let actorObject = this.actor;
let element = event.currentTarget;

View File

@ -37,8 +37,8 @@ export class OseActor extends Actor {
...this.data,
...{
rollData: {
type: "Save",
stat: save,
type: "Above",
target: this.data.data.saves[save].value,
},
},
};
@ -54,6 +54,32 @@ export class OseActor extends Actor {
});
}
rollMorale(options = {}) {
const label = game.i18n.localize(`OSE.Morale`);
const rollParts = ["2d6"];
const data = {
...this.data,
...{
rollData: {
type: "Below",
target: this.data.data.details.morale,
},
},
};
// Roll and return
return OseDice.Roll({
event: options.event,
parts: rollParts,
data: data,
skipDialog: true,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${label} ${game.i18n.localize("OSE.Roll")}`,
title: `${label} ${game.i18n.localize("OSE.Roll")}`,
});
}
rollCheck(score, options = {}) {
const label = game.i18n.localize(`OSE.scores.${score}.long`);
const rollParts = ["1d20"];
@ -79,6 +105,31 @@ export class OseActor extends Actor {
});
}
rollHitDice(options = {}) {
const label = game.i18n.localize(`OSE.HitDice`);
const rollParts = [this.data.data.hp.hd];
const data = {
...this.data,
...{
rollData: {
type: "Hit Dice"
},
},
};
// Roll and return
return OseDice.Roll({
event: options.event,
parts: rollParts,
data: data,
skipDialog: true,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${label} ${game.i18n.localize("OSE.Roll")}`,
title: `${label} ${game.i18n.localize("OSE.Roll")}`,
});
}
rollExploration(expl, options = {}) {
const label = game.i18n.localize(`OSE.exploration.${expl}.long`);
const rollParts = ["1d6"];

View File

@ -135,6 +135,11 @@ export class OseActorSheetMonster extends OseActorSheet {
return this.actor.createOwnedItem(itemData, {});
});
html.find(".morale-check a").click((ev) => {
let actorObject = this.actor;
actorObject.rollMorale({ event: event });
});
// Handle default listeners last so system listeners are triggered first
super.activateListeners(html);
}

View File

@ -34,16 +34,23 @@ export class OseDice {
-3,
9
)}</b> (${thac})</div>`;
// ADD DAMAGE ROLL
}
} else if (data.rollData.type == "Save") {
} else if (data.rollData.type == "Above") {
// SAVING THROWS
let sv = data.data.saves[data.rollData.stat].value;
let sv = data.rollData.target;
if (roll.total >= sv) {
details = `<div class='roll-result roll-success'><b>Success!</b> (${sv})</div>`;
} else {
details = `<div class='roll-result roll-fail'><b>Failure</b> (${sv})</div>`;
}
} else if (data.rollData.type == "Below") {
// Morale
let m = data.rollData.target;
if (roll.total <= m) {
details = `<div class='roll-result roll-success'><b>Success!</b> (${m})</div>`;
} else {
details = `<div class='roll-result roll-fail'><b>Failure</b> (${m})</div>`;
}
} else if (data.rollData.type == "Check") {
// SCORE CHECKS
let sc = data.data.scores[data.rollData.stat].value;

View File

@ -1,3 +1,5 @@
import { OseDice } from "../dice.js";
/**
* Override and extend the basic :class:`Item` implementation
*/
@ -48,7 +50,6 @@ export class OseItem extends Item {
}
rollWeapon() {
console.log("WEAPON");
if (this.data.data.missile) {
this.actor.rollAttack({type: 'missile', label: this.name, dmg: this.data.data.damage});
} else if (this.data.data.melee) {
@ -60,25 +61,32 @@ export class OseItem extends Item {
}
async rollFormula(options={}) {
console.log("FORMULA");
if ( !this.data.data.roll ) {
throw new Error("This Item does not have a formula to roll!");
}
// Define Roll Data
const rollData = {
item: this.data.data
};
const title = `${this.name} - Roll`;
const label = `${this.name}`;
const rollParts = [this.data.data.roll];
// Invoke the roll and submit it to chat
const roll = new Roll(rollData.item.roll, rollData).roll();
roll.toMessage({
speaker: ChatMessage.getSpeaker({actor: this.actor}),
flavor: this.data.data.chatFlavor || title,
rollMode: game.settings.get("core", "rollMode")
const data = {
...this.data,
...{
rollData: {
type: "Formula"
},
},
};
// Roll and return
return OseDice.Roll({
event: options.event,
parts: rollParts,
data: data,
skipDialog: true,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${label} ${game.i18n.localize("OSE.Roll")}`,
title: `${label} ${game.i18n.localize("OSE.Roll")}`,
});
return roll;
}
/**

View File

@ -1,6 +1,17 @@
.ose.actor.monster {
min-height: 565px;
min-width: 460px;
.header-details {
.summary {
.morale-check {
line-height: 35px;
flex: 0 0 20px;
&:hover {
color: $colorDark;
}
}
}
}
.sheet-body {
.editor {
height: 300px;

View File

@ -29,11 +29,21 @@
}
},
"saves": {
"death": 10,
"wand": 10,
"paralysis": 10,
"breath": 10,
"spell": 10
"death": {
"value": 10
},
"wand": {
"value": 10
},
"paralysis": {
"value": 10
},
"breath": {
"value": 10
},
"spell": {
"value": 10
}
},
"movement": {
"base": 120

View File

@ -126,9 +126,9 @@
</div>
<div class="flexrow">
<ul class="attributes flexrow">
<li class="attribute">
<li class="attribute hit-dice">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.HitDice' }}">
{{ localize "OSE.HitDiceShort" }}
<a>{{ localize "OSE.HitDiceShort" }}</a>
</h4>
<div class="attribute-value">
<input name="data.hp.hd" type="text" value="{{data.hp.hd}}" placeholder=""

View File

@ -13,9 +13,12 @@
<label>{{localize 'OSE.Appearing'}}</label>
</li>
{{#if config.morale}}
<li>
<input type="text" name="data.details.morale" value="{{data.details.morale}}" />
<label>{{localize 'OSE.Morale'}}</label>
<li class="flexrow">
<div>
<input type="text" name="data.details.morale" value="{{data.details.morale}}" />
<label>{{localize 'OSE.Morale'}}</label>
</div>
<div class="morale-check"><a><i class="fas fa-dice"></i></a></div>
</li>
{{/if}}
</ul>

View File

@ -29,7 +29,7 @@
{{/if}}
{{#if data.roll}}
<button data-action="formula">{{ localize "OSE.Roll"}}</button>
<button data-action="formula">{{ localize "OSE.Roll"}} {{data.roll}}</button>
{{/if}}
</div>