First v10 release

This commit is contained in:
2022-10-19 17:30:47 +02:00
parent 46d666b779
commit 66e83ec8f0
25 changed files with 419 additions and 552 deletions

View File

@@ -15,8 +15,8 @@ export class Imperium5ActorSheet extends ActorSheet {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-imperium5", "sheet", "actor"],
template: "systems/fvtt-imperium5/templates/actor-sheet.html",
width: 800,
height: 720,
width: 720,
height: 760,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
@@ -24,20 +24,18 @@ export class Imperium5ActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
async getData() {
const objectData = Imperium5Utility.data(this.object);
let actorData = duplicate(Imperium5Utility.templateData(this.object));
async getData() {
let actorData = duplicate(this.object.system)
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: actorData,
system: actorData,
archetype: this.actor.getArchetype(),
specialites: this.actor.getSpecialites(),
familiarites: this.actor.getFamiliarites(),
@@ -75,7 +73,7 @@ export class Imperium5ActorSheet extends ActorSheet {
/* -------------------------------------------- */
async rollIDR( itemId, diceValue) {
let item = this.actor.data.items.get( itemId) ?? {name: "Unknown"}
let item = this.actor.items.get( itemId) ?? {name: "Unknown"}
let myRoll = new Roll(diceValue+"x").roll({ async: false })
await Imperium5Utility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
let chatData = {
@@ -112,17 +110,6 @@ export class Imperium5ActorSheet extends ActorSheet {
Imperium5Utility.confirmDelete(this, li);
});
html.find('.spec-group-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerActivate( itemId)
});
html.find('.spec-group-deactivate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.specPowerDeactivate( itemId)
});
html.find('.equip-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
@@ -134,37 +121,6 @@ export class Imperium5ActorSheet extends ActorSheet {
this.actor.equipDeactivate( itemId)
});
html.find('.effect-used').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.perkEffectUsed( itemId)
});
html.find('.perk-status').change(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.updatePerkStatus( itemId, ev.currentTarget.value)
});
html.find('.power-cost-spent').change(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
this.actor.updatePowerSpentCost( itemId, ev.currentTarget.value)
});
html.find('.power-dmg-roll').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
this.actor.powerDmgRoll( itemId )
})
html.find('.perk-used').change(ev => {
const li = $(ev.currentTarget).parents(".item")
let itemId = li.data("item-id")
let index = Number($(ev.currentTarget).data("use-index") )
this.actor.updatePerkUsed( itemId, index, ev.currentTarget.checked )
});
html.find('.subactor-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
@@ -186,81 +142,17 @@ export class Imperium5ActorSheet extends ActorSheet {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), +1 );
} );
html.find('.ammo-minus').click(event => {
const li = $(event.currentTarget).parents(".item")
this.actor.incDecAmmo( li.data("item-id"), -1 );
} );
html.find('.ammo-plus').click(event => {
const li = $(event.currentTarget).parents(".item")
this.actor.incDecAmmo( li.data("item-id"), +1 )
} );
html.find('.momentum-minus').click(event => {
this.actor.modifyMomentum( -1 )
} )
html.find('.momentum-plus').click(event => {
this.actor.modifyMomentum( 1 )
} )
html.find('.unarmed-attack').click((event) => {
this.actor.rollUnarmedAttack();
});
html.find('.generic-pool-roll').click((event) => {
this.openGenericRoll()
} );
html.find('.attack-melee').click((event) => {
this.actor.rollPool( 'com');
});
html.find('.attack-ranged').click((event) => {
this.actor.rollPool( 'agi');
});
html.find('.defense-roll').click((event) => {
this.actor.rollPool( 'def', true);
});
html.find('.damage-melee').click((event) => {
this.actor.rollPool( 'str');
});
html.find('.damage-ranged').click((event) => {
this.actor.rollPool( 'per');
});
html.find('.damage-resistance').click((event) => {
this.actor.rollPool( 'phy');
});
html.find('.roll-stat').click((event) => {
const statId = $(event.currentTarget).data("stat-key");
this.actor.rollStat(statId);
html.find('.roll-ame').click((event) => {
const ameKey = $(event.currentTarget).data("ame-key")
this.actor.rollAme(ameKey)
});
html.find('.roll-mr').click((event) => {
this.actor.rollMR();
});
html.find('.roll-idr').click((event) => {
const diceValue = $(event.currentTarget).data("dice-value")
const li = $(event.currentTarget).parents(".item")
this.rollIDR( li.data("item-id"), diceValue)
})
html.find('.roll-spec').click((event) => {
const li = $(event.currentTarget).parents(".item");
const specId = li.data("item-id");
this.actor.rollSpec(specId);
});
html.find('.power-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const powerId = li.data("item-id");
this.actor.rollPower(powerId);
});
html.find('.weapon-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId);
});
html.find('.armor-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armorId = li.data("item-id");
this.actor.rollArmor(armorId);
});
html.find('.weapon-damage-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
@@ -268,12 +160,6 @@ export class Imperium5ActorSheet extends ActorSheet {
this.actor.rollWeapon(weaponId, true);
});
html.find('.weapon-damage').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.getOwnedItem(li.data("item-id"));
this.actor.rollDamage(weapon, 'damage');
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
@@ -288,29 +174,11 @@ export class Imperium5ActorSheet extends ActorSheet {
this.actor.equipItem( li.data("item-id") );
this.render(true);
});
html.find('.power-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.activatePower( li.data("item-id") );
this.render(true);
});
html.find('.change-worstfear').change(ev => {
this.actor.manageWorstFear( ev.currentTarget.checked )
});
html.find('.change-desires').change(ev => {
this.actor.manageDesires( ev.currentTarget.checked )
});
html.find('.update-field').change(ev => {
const fieldName = $(ev.currentTarget).data("field-name");
let value = Number(ev.currentTarget.value);
this.actor.update( { [`${fieldName}`]: value } );
});
html.find('.perk-active').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.activatePerk( li.data("item-id") );
this.render(true);
});
}
@@ -325,7 +193,7 @@ export class Imperium5ActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
async _onDropItemUNUSED(event, dragData) {
console.log(">>>>>> DROPPED!!!!")
let item = await Imperium5Utility.searchItem( dragData)
if (item == undefined) {

View File

@@ -28,7 +28,7 @@ export class Imperium5Actor extends Actor {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
if (items) {
let actor = super.create(data, options);
return actor;
}
@@ -53,7 +53,7 @@ export class Imperium5Actor extends Actor {
prepareDerivedData() {
if (this.type == 'character') {
//this.data.data.encCapacity = this.getEncumbranceCapacity()
//this.system.encCapacity = this.getEncumbranceCapacity()
//this.buildContainerTree()
}
console.log("Acteur : ", this)
@@ -68,49 +68,61 @@ export class Imperium5Actor extends Actor {
/* -------------------------------------------- */
getArchetype() {
let item = duplicate( this.data.items.find( it => it.type == "archetype") || [])
let item = duplicate( this.items.find( it => it.type == "archetype") || [])
return item
}
getSpecialites() {
let item = duplicate(this.data.items.filter( it => it.type == "specialite") || [] )
let item = duplicate(this.items.filter( it => it.type == "specialite") || [] )
return item
}
getFamiliarites() {
let item = duplicate(this.data.items.filter( it => it.type == "familiarite") || [] )
let item = duplicate(this.items.filter( it => it.type == "familiarite") || [] )
return item
}
getNatureProfonde() {
let item = duplicate( this.data.items.find( it => it.type == "nature") || [])
let item = duplicate( this.items.find( it => it.type == "nature") || [])
return item
}
getTraits() {
let item = duplicate(this.data.items.filter( it => it.type == "trait") || [] )
let item = duplicate(this.items.filter( it => it.type == "trait") || [] )
return item
}
getSymbioses() {
let item = duplicate(this.data.items.filter( it => it.type == "symbiose") || [] )
let item = duplicate(this.items.filter( it => it.type == "symbiose") || [] )
return item
}
getEquipements() {
let item = duplicate(this.data.items.filter( it => it.type == "equipement") || [] )
let item = duplicate(this.items.filter( it => it.type == "equipement") || [] )
return item
}
getCapacites() {
let item = duplicate(this.data.items.filter( it => it.type == "capacite") || [] )
let item = duplicate(this.items.filter( it => it.type == "capacite") || [] )
return item
}
getUnusedCapacites(){
let item = this.items.filter( it => it.type == "capacite") || []
return item
}
getSingularites(){
let item = duplicate(this.data.items.filter( it => it.type == "singularite") || [] )
let item = duplicate(this.items.filter( it => it.type == "singularite") || [] )
return item
}
getContacts(){
let item = duplicate(this.data.items.filter( it => it.type == "contact") || [] )
let item = duplicate(this.items.filter( it => it.type == "contact") || [] )
return item
}
/* -------------------------------------------- */
incDecKarma( value ) {
let karma = duplicate(this.system.karma)
karma.value += value
karma.value = Math.max(karma.value, 0)
this.update( { 'system.karma': karma})
}
/* -------------------------------------------- */
getItemById(id) {
let item = this.data.items.find(item => item.id == id)
let item = this.items.find(item => item.id == id)
if (item) {
item = duplicate(item)
}
@@ -135,7 +147,7 @@ export class Imperium5Actor extends Actor {
}
/* -------------------------------------------- */
getEffectByLabel(label) {
return this.getActiveEffects().find(it => it.data.label == label);
return this.getActiveEffects().find(it => it.label == label);
}
/* -------------------------------------------- */
getEffectById(id) {
@@ -154,21 +166,21 @@ export class Imperium5Actor extends Actor {
/* -------------------------------------------- */
getSubActors() {
let subActors = [];
for (let id of this.data.data.subactors) {
for (let id of this.system.subactors) {
subActors.push(duplicate(game.actors.get(id)))
}
return subActors;
}
/* -------------------------------------------- */
async addSubActor(subActorId) {
let subActors = duplicate(this.data.data.subactors);
let subActors = duplicate(this.system.subactors);
subActors.push(subActorId);
await this.update({ 'data.subactors': subActors });
}
/* -------------------------------------------- */
async delSubActor(subActorId) {
let newArray = [];
for (let id of this.data.data.subactors) {
for (let id of this.system.subactors) {
if (id != subActorId) {
newArray.push(id);
}
@@ -176,25 +188,16 @@ export class Imperium5Actor extends Actor {
await this.update({ 'data.subactors': newArray });
}
/* -------------------------------------------- */
syncRoll(rollData) {
let linkedRollId = Imperium5Utility.getDefenseState(this.id);
if (linkedRollId) {
rollData.linkedRollId = linkedRollId;
}
this.lastRollId = rollData.rollId;
Imperium5Utility.saveRollData(rollData);
}
/* -------------------------------------------- */
async deleteAllItemsByType(itemType) {
let items = this.data.items.filter(item => item.type == itemType);
let items = this.items.filter(item => item.type == itemType);
await this.deleteEmbeddedDocuments('Item', items);
}
/* -------------------------------------------- */
async addItemWithoutDuplicate(newItem) {
let item = this.data.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
let item = this.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
if (!item) {
await this.createEmbeddedDocuments('Item', [newItem]);
}
@@ -202,9 +205,9 @@ export class Imperium5Actor extends Actor {
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
let objetQ = this.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.quantity + incDec
let newQ = objetQ.system.quantity + incDec
if (newQ >= 0) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]) // pdates one EmbeddedEntity
}
@@ -217,34 +220,43 @@ export class Imperium5Actor extends Actor {
/* -------------------------------------------- */
addEffects(rollData) {
let effects = this.data.items.filter(item => item.type == 'effect')
let effects = this.items.filter(item => item.type == 'effect')
for (let effect of effects) {
effect = duplicate(effect)
if (!effect.data.hindrance
&& (effect.data.stataffected != "notapplicable" || effect.data.specaffected.length > 0)
&& effect.data.stataffected != "special") {
if (effect.data.effectstatlevel) {
effect.data.effectlevel = this.data.data.statistics[effect.data.effectstat].value
if (!effect.system.hindrance
&& (effect.system.stataffected != "notapplicable" || effect.system.specaffected.length > 0)
&& effect.system.stataffected != "special") {
if (effect.system.effectstatlevel) {
effect.system.effectlevel = this.system.statistics[effect.system.effectstat].value
}
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel })
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.system.effectlevel })
}
}
}
/* -------------------------------------------- */
getCommonRollData(statKey = undefined, useShield = false) {
rollAme( ameKey) {
let rollData = this.getCommonRollData()
rollData.ame = duplicate(this.system.ames[ameKey])
rollData.ameMalus = this.system.amestype[rollData.ame.type].malus
this.startRoll(rollData)
}
/* -------------------------------------------- */
getCommonRollData() {
let rollData = Imperium5Utility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.capacites = this.getUnusedCapacites()
rollData.karma = this.system.karma.value
return rollData
}
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData)
let rollDialog = await Imperium5RollDialog.create(this, rollData)
console.log(rollDialog)
rollDialog.render(true)

View File

@@ -50,25 +50,24 @@ export class Imperium5ItemSheet extends ItemSheet {
/* -------------------------------------------- */
async getData() {
const objectData = Imperium5Utility.data(this.object);
const objectData = duplicate(this.object.system)
let itemData = foundry.utils.deepClone(Imperium5Utility.templateData(this.object));
let formData = {
title: this.title,
id: this.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
type: this.object.type,
img: this.object.img,
name: this.object.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: itemData,
system: objectData,
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM
}
this.options.editable = !(this.object.data.origin == "embeddedItem");
this.options.editable = !(this.object.system.origin == "embeddedItem");
console.log("ITEM DATA", formData, this);
return formData;
}
@@ -87,7 +86,7 @@ export class Imperium5ItemSheet extends ItemSheet {
/* -------------------------------------------- */
postItem() {
let chatData = duplicate( Imperium5Utility.data(this.item) )
let chatData = duplicate( this.item.system)
if (this.actor) {
chatData.actor = { id: this.actor.id }
}
@@ -112,7 +111,7 @@ export class Imperium5ItemSheet extends ItemSheet {
async viewSubitem(ev) {
let field = $(ev.currentTarget).data('type');
let idx = Number($(ev.currentTarget).data('index'));
let itemData = this.object.data.data[field][idx];
let itemData = this.object.system[field][idx];
if (itemData.name != 'None') {
let spec = await Item.create(itemData, { temporary: true });
spec.data.origin = "embeddedItem";
@@ -124,8 +123,8 @@ export class Imperium5ItemSheet extends ItemSheet {
async deleteSubitem(ev) {
let field = $(ev.currentTarget).data('type');
let idx = Number($(ev.currentTarget).data('index'));
let oldArray = this.object.data.data[field];
let itemData = this.object.data.data[field][idx];
let oldArray = this.object.system[field];
let itemData = this.object.system[field][idx];
if (itemData.name != 'None') {
let newArray = [];
for (var i = 0; i < oldArray.length; i++) {
@@ -139,7 +138,7 @@ export class Imperium5ItemSheet extends ItemSheet {
/* -------------------------------------------- */
async manageSpec() {
let itemData = this.object.data.data.specialisation[0];
let itemData = this.object.system.specialisation[0];
if (itemData.name != 'None') {
let spec = await Item.create(itemData, { temporary: true });
spec.data.origin = "embeddedItem";

View File

@@ -5,7 +5,7 @@ export class Imperium5RollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData ) {
let options = { classes: ["Imperium5Dialog"], width: 620, height: 380, 'z-index': 99999 }
let options = { classes: ["Imperium5Dialog"], width: 320, height: 380, 'z-index': 99999 }
let html = await renderTemplate('systems/fvtt-imperium5/templates/roll-dialog-generic.html', rollData)
return new Imperium5RollDialog(actor, rollData, html, options )
@@ -41,6 +41,11 @@ export class Imperium5RollDialog extends Dialog {
Imperium5Utility.rollImperium5( this.rollData )
}
/* -------------------------------------------- */
updatePCPool() {
let value = Imperium5Utility.computeDiceReserve(this.rollData)
$('#ame-total').html(value )
}
/* -------------------------------------------- */
activateListeners(html) {
@@ -48,7 +53,29 @@ export class Imperium5RollDialog extends Dialog {
var dialog = this
function onLoad() {
dialog.updatePCPool()
}
$(function () { onLoad(); })
$(function () { onLoad(); })
html.find('#select-realite-dice').change(async (event) => {
this.rollData.realiteDice = Number(event.currentTarget.value)
})
html.find('#select-capacite').change(async (event) => {
this.rollData.usedCapacite = String(event.currentTarget.value)
this.updatePCPool()
})
html.find('#select-use-archetype').change(async (event) => {
this.rollData.useArchetype = event.currentTarget.checked
this.updatePCPool()
})
html.find('#select-use-aide').change(async (event) => {
this.rollData.useAide = event.currentTarget.checked
this.updatePCPool()
})
html.find('#select-use-karma').change(async (event) => {
this.rollData.useKarma = event.currentTarget.checked
this.updatePCPool()
})
}
}

View File

@@ -13,7 +13,7 @@ export class Imperium5Utility {
/* -------------------------------------------- */
static async init() {
Hooks.on('renderChatLog', (log, html, data) => Imperium5Utility.chatListeners(html));
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
Imperium5Utility.pushInitiativeOptions(html, options);
})
@@ -113,7 +113,7 @@ export class Imperium5Utility {
effectName = effectName.toLowerCase()
let effect = game.items.contents.find(item => item.type == 'effect' && item.name.toLowerCase() == effectName)
if (!effect) {
let effects = await this.loadCompendium('fvtt-pegasus.effect', item => item.name.toLowerCase() == effectName)
let effects = await this.loadCompendium('fvtt-imperium5.effect', item => item.name.toLowerCase() == effectName)
let objs = effects.map(i => i.toObject())
effect = objs[0]
} else {
@@ -153,19 +153,6 @@ export class Imperium5Utility {
return undefined;
}
/* -------------------------------------------- */
static templateData(it) {
return Imperium5Utility.data(it)?.data ?? {}
}
/* -------------------------------------------- */
static data(it) {
if (it instanceof Actor || it instanceof Item || it instanceof Combatant) {
return it.data;
}
return it;
}
/* -------------------------------------------- */
static createDirectOptionList(min, max) {
let options = {};
@@ -204,7 +191,7 @@ export class Imperium5Utility {
}
/* -------------------------------------------- */
static saveRollData(rollData) {
game.socket.emit("system.pegasus-rpg", {
game.socket.emit("system.fvtt-imperium5", {
name: "msg_update_roll", data: rollData
}); // Notify all other clients of the roll
this.updateRollData(rollData);
@@ -282,75 +269,55 @@ export class Imperium5Utility {
}
/* -------------------------------------------- */
static async rollImperium5(rollData) {
static computeDiceReserve(rollData) {
let capaDice = 0
if (rollData.usedCapacite != "none") {
let capa = rollData.capacites.find(c => c._id == rollData.usedCapacite)
capaDice = capa.system.aide
}
let val = rollData.ame.value + capaDice + ((rollData.useKarma) ? 1 : 0) + ((rollData.useArchetype) ? 1 : 0) + ((rollData.useAide) ? 1 : 0) + rollData.ameMalus
return Math.max(val, 0)
}
let dicePool = [{ name: "stat", level: 0, statmod: 0 }, { name: "spec", level: 0 }, { name: "bonus", level: 0 }, { name: "hindrance", level: 0 }, { name: "other", level: 0 }];
if (rollData.stat) {
dicePool[0].level += Number(rollData.stat.value);
dicePool[0].statmod = Number(rollData.stat.mod);
/* -------------------------------------------- */
static async rollImperium5(rollData) {
// Karma management
let actor = game.actors.get(rollData.actorId)
rollData.nbKarma = 0
if ( rollData.useKarma ) {
actor.incDecKarma(-1)
rollData.nbKarma++
}
if (rollData.statDicesLevel) {
dicePool[0].level = rollData.statDicesLevel;
}
if (rollData.selectedSpec && rollData.selectedSpec != "0") {
rollData.spec = rollData.specList.find(item => item._id == rollData.selectedSpec);
rollData.spec.data.dice = Imperium5Utility.getDiceFromLevel(rollData.spec.data.level);
}
if (rollData.spec) {
dicePool[1].level += Number(rollData.spec.data.level);
}
if (rollData.specDicesLevel) {
dicePool[1].level = rollData.specDicesLevel;
}
if (rollData.bonusDicesLevel) {
dicePool[2].level += Number(rollData.bonusDicesLevel);
}
if (rollData.hindranceDicesLevel) {
dicePool[3].level += Number(rollData.hindranceDicesLevel);
}
if (rollData.otherDicesLevel) {
dicePool[4].level += Number(rollData.otherDicesLevel);
if ( rollData.usedCapacite != "none" ) {
actor.incDecKarma(-1)
rollData.nbKarma++
}
let diceFormulaTab = [];
for (let diceGroup of dicePool) {
diceFormulaTab.push(this.getFoundryDiceFromLevel(diceGroup.level))
}
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh';
let nbAmeDice = this.computeDiceReserve( rollData )
let diceFormula = `${nbAmeDice}d8[green] + 1d8[blue] + ${rollData.realiteDice}d8[red]`
let humanFormula = `${nbAmeDice}d8, 1d8, ${rollData.realiteDice}d8`
// Performs roll
let myRoll = rollData.roll;
let myRoll = rollData.roll
if (!myRoll) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false });
console.log("ROLL : ", diceFormula)
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll
rollData.diceFormula = diceFormula
rollData.humanFormula = humanFormula
}
// Final score and keep data
rollData.finalScore = myRoll.total + dicePool[0].statmod;
// Calcul réussites
rollData.successPC = myRoll.terms[0].results.filter(res => res.result <= 2).length
rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= 2).length
rollData.bonPresage = myRoll.terms[2].results[0].result == 1
rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8
rollData.nbUnitesNarration = Math.max( rollData.successPC-1, 0)
if (rollData.damages) {
let dmgFormula = this.getFoundryDiceFromLevel(rollData.damages.value)
let dmgRoll = new Roll(dmgFormula).roll({ async: false });
await this.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode"));
rollData.dmgResult = dmgRoll.total;
}
this.createChatWithRollMode(rollData.alias, {
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
});
// Init stuf
if (rollData.isInit) {
let combat = game.combats.get(rollData.combatId)
combat.updateEmbeddedDocuments("Combatant", [{ _id: rollData.combatantId, initiative: rollData.finalScore }]);
}
//this.removeUsedPerkEffects( rollData) // Unused for now
// And save the roll
this.saveRollData(rollData);
})
msg.setFlag("world", "rolldata", rollData)
}
/* ------------------------- ------------------- */
@@ -387,7 +354,6 @@ export class Imperium5Utility {
static async rerollDice(actorId, diceIndex = -1) {
let actor = game.actors.get(actorId)
let rollData = actor.getRollData()
}
/* -------------------------------------------- */
@@ -426,7 +392,7 @@ export class Imperium5Utility {
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id)
} else {
item = game.items.get(dataItem.id)
}
}
return item
}
@@ -466,7 +432,7 @@ export class Imperium5Utility {
break;
}
chatOptions.alias = chatOptions.alias || name;
ChatMessage.create(chatOptions);
return ChatMessage.create(chatOptions)
}
/* -------------------------------------------- */
@@ -474,11 +440,12 @@ export class Imperium5Utility {
let rollData = {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
effectsList: [],
armorsList: [],
weaponsList: [],
equipmentsList: [],
optionsDiceList: Imperium5Utility.getOptionsDiceList()
realiteDice: 0,
ameMalus: 0,
useArchetype: false,
useAide: false,
useKarma: false,
usedCapacite: "none"
}
Imperium5Utility.updateWithTarget(rollData)
return rollData
@@ -490,17 +457,17 @@ export class Imperium5Utility {
let target = Imperium5Utility.getTarget()
if (target) {
let defenderActor = game.actors.get(target.data.actorId)
objectDefender = Imperium5Utility.data(defenderActor)
objectDefender = defenderActor
objectDefender = mergeObject(objectDefender, target.data.actorData)
rollData.defender = objectDefender
rollData.attackerId = this.id
rollData.defenderId = objectDefender._id
rollData.defenderId = objectDefender.id
}
}
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
return this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
}
/* -------------------------------------------- */