FIX: Monster rolls

master
U~man 2020-07-04 23:02:03 +02:00
parent 573c9fe23c
commit ebcdcc8465
8 changed files with 109 additions and 116 deletions

View File

@ -51,8 +51,6 @@ export class OseActorSheetCharacter extends OseActorSheet {
data.config.ascendingAC = game.settings.get("ose", "ascendingAC"); data.config.ascendingAC = game.settings.get("ose", "ascendingAC");
data.config.individualInit = game.settings.get("ose", "individualInit"); data.config.individualInit = game.settings.get("ose", "individualInit");
data.mods = this.actor.computeModifiers();
// Compute treasure // Compute treasure
let total = 0; let total = 0;
data.owned.items.forEach(item => { data.owned.items.forEach(item => {

View File

@ -9,12 +9,14 @@ export class OseActor extends Actor {
super.prepareData(); super.prepareData();
const data = this.data.data; const data = this.data.data;
// Compute modifiers from actor scores
this.computeModifiers();
// Determine Initiative // Determine Initiative
if (game.settings.get("ose", "individualInit")) { if (game.settings.get("ose", "individualInit")) {
data.initiative.value = data.initiative.mod; data.initiative.value = data.initiative.mod;
if (this.data.type == "character") { if (this.data.type == "character") {
const mods = this.computeModifiers(); data.initiative.value += data.scores.dex.mod;
data.initiative.value += mods.dex;
} }
} else { } else {
data.initiative.value = 0; data.initiative.value = 0;
@ -105,111 +107,101 @@ export class OseActor extends Actor {
rollAttack(attack, options = {}) { rollAttack(attack, options = {}) {
const label = game.i18n.localize(`OSE.${attack}`); const label = game.i18n.localize(`OSE.${attack}`);
const rollParts = ["1d20"]; const rollParts = ["1d20"];
const data = this.data.data;
const mods = this.computeModifiers();
if (attack == "Missile") { if (attack == "Missile") {
rollParts.push( rollParts.push(
"+", "+",
mods.dex.toString(), data.scores.dex.mod.toString(),
"+", "+",
this.data.data.thac0.mod.missile.toString() data.thac0.mod.missile.toString()
); );
} else if (attack == "Melee") { } else if (attack == "Melee") {
rollParts.push( rollParts.push(
"+", "+",
mods.str.toString(), data.scores.str.mod.toString(),
"+", "+",
this.data.data.thac0.mod.melee.toString() data.thac0.mod.melee.toString()
); );
} }
if (game.settings.get("ose", "ascendingAC")) { if (game.settings.get("ose", "ascendingAC")) {
rollParts.push("+", this.data.data.thac0.bba.toString()); rollParts.push("+", this.data.data.thac0.bba.toString());
} }
const data = { const rollData = {
...this.data, ...this.data,
...{ ...{
rollData: { rollData: {
type: "Attack", type: "Attack",
stat: attack, stat: attack,
mods: mods, scores: data.scores,
}, },
}, },
}; };
// Roll and return // Roll and return
return OseDice.Roll({ return OseDice.Roll({
event: options.event, event: options.event,
parts: rollParts, parts: rollParts,
data: data, data: rollData,
speaker: ChatMessage.getSpeaker({ actor: this }), speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${label} ${game.i18n.localize("OSE.Attack")}`, flavor: `${label} ${game.i18n.localize("OSE.Attack")}`,
title: `${label} ${game.i18n.localize("OSE.Attack")}`, title: `${label} ${game.i18n.localize("OSE.Attack")}`,
}); });
} }
static _valueToMod(val) {
switch (val) {
case 3:
return -3;
case 4:
case 5:
return -2;
case 6:
case 7:
case 8:
return -1;
case 9:
case 10:
case 11:
case 12:
return 0;
case 13:
case 14:
case 15:
return 1;
case 16:
case 17:
return 2;
case 18:
return 3;
default:
return 0;
}
}
static _cappedMod(val) {
let mod = OseActor._valueToMod(val);
if (mod > 1) {
mod -= 1;
} else if (mod < -1) {
mod += 1;
}
return mod;
}
computeModifiers() { computeModifiers() {
if (this.data.type != "character") { if (this.data.type != "character") {
return { return;
str: 0,
dex: 0,
int: 0,
con: 0,
wis: 0,
cha: 0,
npc: 0,
init: 0,
};
} }
let _valueToMod = (val) => { const data = this.data.data;
switch (val) { data.scores.str.mod = OseActor._valueToMod(this.data.data.scores.str.value);
case 3: data.scores.int.mod = OseActor._valueToMod(this.data.data.scores.int.value);
return -3; data.scores.dex.mod = OseActor._valueToMod(this.data.data.scores.dex.value);
case 4: data.scores.cha.mod = OseActor._valueToMod(this.data.data.scores.cha.value);
case 5: data.scores.wis.mod = OseActor._valueToMod(this.data.data.scores.wis.value);
return -2; data.scores.con.mod = OseActor._valueToMod(this.data.data.scores.con.value);
case 6:
case 7: data.scores.dex.init = OseActor._cappedMod(this.data.data.scores.dex.value);
case 8: data.scores.cha.npc = OseActor._cappedMod(this.data.data.scores.cha.value);
return -1;
case 9:
case 10:
case 11:
case 12:
return 0;
case 13:
case 14:
case 15:
return 1;
case 16:
case 17:
return 2;
case 18:
return 3;
default:
return 0;
}
};
let mods = {
str: _valueToMod(this.data.data.scores.str.value),
int: _valueToMod(this.data.data.scores.int.value),
dex: _valueToMod(this.data.data.scores.dex.value),
init: _valueToMod(this.data.data.scores.dex.value),
cha: _valueToMod(this.data.data.scores.cha.value),
npc: _valueToMod(this.data.data.scores.cha.value),
wis: _valueToMod(this.data.data.scores.wis.value),
con: _valueToMod(this.data.data.scores.con.value),
};
if (mods.init > 1) {
mods.init -= 1;
} else if (mods.init < -1) {
mods.init += 1;
}
if (mods.npc > 1) {
mods.npc -= 1;
} else if (mods.npc < -1) {
mods.npc += 1;
}
return mods;
} }
} }

View File

@ -1,16 +1,17 @@
export class OseDice { export class OseDice {
static digestResult(data, roll) { static digestResult(data, roll) {
let details = ""; let details = "";
// ATTACKS // ATTACKS
let die = roll.parts[0].total; let die = roll.parts[0].total;
if (data.rollData.type == "Attack") { if (data.rollData.type == "Attack") {
if (game.settings.get("ose", "ascendingAC")) { if (game.settings.get("ose", "ascendingAC")) {
let bba = data.data.thac0.bba; let bba = data.data.thac0.bba;
bba += if (data.rollData.stat == "Melee") {
data.rollData.stat == "Melee" bba += data.data.thac0.mod.melee + data.rollData.scores.str.mod;
? data.data.thac0.mod.melee + data.rollData.mods.str } else if (data.rollData.stat == "Missile") {
: data.data.thac0.mod.missile + data.rollData.mods.dex; bba += data.data.thac0.mod.missile + data.rollData.scores.dex.mod;
}
details = `<div class='roll-result roll-fail'><b>Failure</b> (${bba})</div>`; details = `<div class='roll-result roll-fail'><b>Failure</b> (${bba})</div>`;
if (die == 1) { if (die == 1) {
return details; return details;
@ -19,11 +20,11 @@ export class OseDice {
} else { } else {
// B/X Historic THAC0 Calculation // B/X Historic THAC0 Calculation
let thac = data.data.thac0.value; let thac = data.data.thac0.value;
thac -= if (data.rollData.stat == "Melee") {
data.rollData.stat == "Melee" thac -= data.data.thac0.mod.melee + data.rollData.scores.str.mod;
? data.data.thac0.mod.melee + data.rollData.mods.str } else if (data.rollData.stat == "Missile") {
: data.data.thac0.mod.missile + data.rollData.mods.dex; thac -= data.data.thac0.mod.missile + data.rollData.scores.dex.mod;
}
details = `<div class='roll-result roll-fail'><b>Failure</b> (${thac})</div>`; details = `<div class='roll-result roll-fail'><b>Failure</b> (${thac})</div>`;
if (thac - roll.total > 9) { if (thac - roll.total > 9) {
return details; return details;

View File

@ -54,6 +54,8 @@ export class OseItem extends Item {
} else if (this.data.data.melee) { } else if (this.data.data.melee) {
this.actor.rollAttack('Melee'); this.actor.rollAttack('Melee');
return true; return true;
} else {
this.actor.rollAttack();
} }
return false; return false;
} }
@ -84,6 +86,7 @@ export class OseItem extends Item {
* @return {Promise} * @return {Promise}
*/ */
async roll({ configureDialog = true } = {}) { async roll({ configureDialog = true } = {}) {
console.log(this.data);
if (this.data.type == 'weapon') { if (this.data.type == 'weapon') {
if (this.rollWeapon()) return; if (this.rollWeapon()) return;
} }

View File

@ -72,8 +72,7 @@
position: absolute; position: absolute;
transform: rotate(90deg); transform: rotate(90deg);
top: 365px; top: 365px;
right: -168px; right: -169px;
border-bottom: 1px solid black;
width: 320px; width: 320px;
z-index: -1; z-index: -1;
.item { .item {

View File

@ -97,27 +97,27 @@
"scores": { "scores": {
"str": { "str": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
}, },
"int": { "int": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
}, },
"wis": { "wis": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
}, },
"dex": { "dex": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
}, },
"con": { "con": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
}, },
"cha": { "cha": {
"value": 0, "value": 0,
"mod": 0 "bonus": 0
} }
}, },
"encumbrance": { "encumbrance": {

View File

@ -11,7 +11,7 @@
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
<div class="attribute-bonuses"> <div class="attribute-bonuses">
{{localize 'OSE.Melee'}} ({{mods.str}})<br/> {{localize 'OSE.Melee'}} ({{data.scores.str.mod}})<br/>
{{localize 'OSE.exploration.od.long'}} {{localize 'OSE.exploration.od.long'}}
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
@ -39,7 +39,7 @@
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
<div class="attribute-bonuses"> <div class="attribute-bonuses">
{{localize 'OSE.saves.magic.long'}}({{mods.wis}}) {{localize 'OSE.saves.magic.long'}}({{data.scores.wis.mod}})
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
</li> </li>
@ -52,9 +52,9 @@
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
<div class="attribute-bonuses"> <div class="attribute-bonuses">
{{localize 'OSE.Missile'}} ({{mods.dex}})<br/> {{localize 'OSE.Missile'}} ({{data.scores.dex.mod}})<br/>
{{localize 'OSE.Initiative'}} ({{mods.init}})<br/> {{localize 'OSE.Initiative'}} ({{data.scores.dex.init}})<br/>
{{localize 'OSE.ArmorClass'}} ({{mods.dex}}) {{localize 'OSE.ArmorClass'}} ({{data.scores.dex.mod}})
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
</li> </li>
@ -67,7 +67,7 @@
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
<div class="attribute-bonuses"> <div class="attribute-bonuses">
{{localize 'OSE.Health'}} ({{mods.con}}) {{localize 'OSE.Health'}} ({{data.scores.con.mod}})
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
</li> </li>
@ -80,9 +80,9 @@
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
<div class="attribute-bonuses"> <div class="attribute-bonuses">
{{localize 'OSE.NPCReaction'}} ({{mods.npc}})<br/> {{localize 'OSE.NPCReaction'}} ({{data.scores.cha.npc}})<br/>
{{localize 'OSE.RetainersMax'}} ({{add mods.cha 4}})<br/> {{localize 'OSE.RetainersMax'}} ({{add data.scores.cha.mod 4}})<br/>
{{localize 'OSE.Loyalty'}} ({{add mods.cha 7}}) {{localize 'OSE.Loyalty'}} ({{add data.scores.cha.mod 7}})
<span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span> <span class="attribute-mod"><a><i class="fas fa-circle"></i></a></span>
</div> </div>
</li> </li>
@ -114,12 +114,12 @@
{{#if config.ascendingAC}} {{#if config.ascendingAC}}
<input class="health-top" name="data.aac.value" type="text" value="{{data.aac.value}}" <input class="health-top" name="data.aac.value" type="text" value="{{data.aac.value}}"
data-dtype="Number" placeholder="0" title="{{localize 'OSE.ArmorClass'}}" /> data-dtype="Number" placeholder="0" title="{{localize 'OSE.ArmorClass'}}" />
<input class="health-bottom" type="text" value="{{add 10 mods.dex}}" <input class="health-bottom" type="text" value="{{add 10 data.scores.dex.mod}}"
title="{{localize 'OSE.ArmorClassNaked'}}" disabled /> title="{{localize 'OSE.ArmorClassNaked'}}" disabled />
{{else}} {{else}}
<input class="health-top" name="data.ac.value" type="text" value="{{data.ac.value}}" data-dtype="Number" <input class="health-top" name="data.ac.value" type="text" value="{{data.ac.value}}" data-dtype="Number"
placeholder="0" title="{{localize 'OSE.ArmorClass'}}" /> placeholder="0" title="{{localize 'OSE.ArmorClass'}}" />
<input class="health-bottom" type="text" value="{{subtract mods.dex 9}}" <input class="health-bottom" type="text" value="{{subtract data.scores.dex.mod 9}}"
title="{{localize 'OSE.ArmorClass'}}" disabled /> title="{{localize 'OSE.ArmorClass'}}" disabled />
{{/if}} {{/if}}
</div> </div>
@ -140,8 +140,8 @@
<h4 class="attribute-name box-title" title="{{ localize 'OSE.Initiative' }}"> <h4 class="attribute-name box-title" title="{{ localize 'OSE.Initiative' }}">
{{ localize "OSE.InitiativeShort" }}</h4> {{ localize "OSE.InitiativeShort" }}</h4>
<div class="attribute-value" <div class="attribute-value"
title="{{localize 'OSE.scores.dex.long'}}({{mods.init}}) + {{localize 'OSE.Modifier'}}({{data.initiative.mod}})"> title="{{localize 'OSE.scores.dex.long'}}({{data.scores.dex.init}}) + {{localize 'OSE.Modifier'}}({{data.initiative.mod}})">
{{add mods.init data.initiative.mod}} {{add data.scores.dex.init data.initiative.mod}}
</div> </div>
</li> </li>
{{/if}} {{/if}}
@ -155,13 +155,13 @@
<div class="flexrow"> <div class="flexrow">
{{#if config.ascendingAC}} {{#if config.ascendingAC}}
<div class="attribute-value" <div class="attribute-value"
title="{{localize 'OSE.AB'}}({{data.thac0.bba}}) + {{localize 'OSE.scores.str.long'}}({{mods.str}}) + {{localize 'OSE.Modifier'}}({{data.thac0.mod.melee}})"> title="{{localize 'OSE.AB'}}({{data.thac0.bba}}) + {{localize 'OSE.scores.str.long'}}({{data.scores.str.mod}}) + {{localize 'OSE.Modifier'}}({{data.thac0.mod.melee}})">
{{add data.thac0.mod.melee (add mods.str data.thac0.bba)}} {{add data.thac0.mod.melee (add data.scores.str.mod data.thac0.bba)}}
</div> </div>
{{else}} {{else}}
<div class="attribute-value" <div class="attribute-value"
title="{{localize 'OSE.Thac0'}}({{data.thac0.value}}) - {{localize 'OSE.scores.str.long'}}({{mods.str}}) - {{localize 'OSE.Modifier'}}({{data.thac0.mod.melee}})"> title="{{localize 'OSE.Thac0'}}({{data.thac0.value}}) - {{localize 'OSE.scores.str.long'}}({{data.scores.str.mod}}) - {{localize 'OSE.Modifier'}}({{data.thac0.mod.melee}})">
{{subtract data.thac0.mod.melee (subtract mods.str data.thac0.value)}} {{subtract data.thac0.mod.melee (subtract data.scores.str.mod data.thac0.value)}}
</div> </div>
{{/if}} {{/if}}
</div> </div>
@ -195,13 +195,13 @@
<div class="flexrow"> <div class="flexrow">
{{#if config.ascendingAC}} {{#if config.ascendingAC}}
<div class="attribute-value" <div class="attribute-value"
title="{{localize 'OSE.AB'}}({{data.thac0.bba}}) + {{localize 'OSE.scores.dex.long'}}({{mods.dex}}) + {{localize 'OSE.Modifier'}}({{data.thac0.mod.missile}})"> title="{{localize 'OSE.AB'}}({{data.thac0.bba}}) + {{localize 'OSE.scores.dex.long'}}({{data.scores.dex.mod}}) + {{localize 'OSE.Modifier'}}({{data.thac0.mod.missile}})">
{{add data.thac0.mod.missile (add mods.dex data.thac0.bba)}} {{add data.thac0.mod.missile (add data.scores.dex.mod data.thac0.bba)}}
</div> </div>
{{else}} {{else}}
<div class="attribute-value" <div class="attribute-value"
title="{{localize 'OSE.Thac0'}}({{data.thac0.value}}) - {{localize 'OSE.scores.dex.long'}}({{mods.dex}}) - {{localize 'OSE.Modifier'}}({{data.thac0.mod.missile}})"> title="{{localize 'OSE.Thac0'}}({{data.thac0.value}}) - {{localize 'OSE.scores.dex.long'}}({{data.scores.dex.mod}}) - {{localize 'OSE.Modifier'}}({{data.thac0.mod.missile}})">
{{subtract data.thac0.mod.missile (subtract mods.dex data.thac0.value)}} {{subtract data.thac0.mod.missile (subtract data.scores.dex.mod data.thac0.value)}}
</div> </div>
{{/if}} {{/if}}
</div> </div>
@ -280,8 +280,8 @@
<li class="attribute saving-throw"> <li class="attribute saving-throw">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.magic.long' }}"> <h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.magic.long' }}">
{{ localize "OSE.saves.magic.long"}}</h4> {{ localize "OSE.saves.magic.long"}}</h4>
<div class="attribute-value flat" title="{{localize 'OSE.scores.wis.long'}}({{mods.wis}})"> <div class="attribute-value flat" title="{{localize 'OSE.scores.wis.long'}}({{data.scores.wis.mod}})">
{{mods.wis}} {{data.scores.wis.mod}}
</div> </div>
</li> </li>
</ul> </ul>

View File

@ -32,7 +32,7 @@
</div> </div>
{{/if}} {{/if}}
</li> </li>
<li class="attribute attack" data-attack="Melee"> <li class="attribute attack" data-attack="Attack">
{{#if config.ascendingAC}} {{#if config.ascendingAC}}
<h4 class="attribute-name box-title" title="{{localize 'OSE.AB'}}"><a>{{ localize "OSE.ABShort" }}</a></h4> <h4 class="attribute-name box-title" title="{{localize 'OSE.AB'}}"><a>{{ localize "OSE.ABShort" }}</a></h4>
<div class="attribute-value"> <div class="attribute-value">
@ -130,7 +130,7 @@
<div class="attribute-group"> <div class="attribute-group">
<div class="attacks-description"> <div class="attacks-description">
<label>{{ localize "OSE.Attacks" }}</label> <label>{{ localize "OSE.Attacks" }}</label>
<input name="data.att" type="text" value="{{data.att}}" placeholder="0" data-dtype="String" /> <input name="data.att" type="text" value="{{data.att}}" data-dtype="String" />
</div> </div>
<ul class="attributes"> <ul class="attributes">
<li class="attribute saving-throw" data-save="death"> <li class="attribute saving-throw" data-save="death">