v0.5 fixes

This commit is contained in:
2022-07-19 00:18:46 +02:00
parent bf52b61a0d
commit 2ab1cbe24c
12 changed files with 255 additions and 52 deletions

View File

@@ -57,6 +57,8 @@ export class PegasusActorSheet extends ActorSheet {
role: duplicate(this.actor.getRole()),
effects: duplicate(this.actor.getEffects()),
moneys: duplicate(this.actor.getMoneys()),
virtues: duplicate(this.actor.getVirtues()),
vices: duplicate(this.actor.getVices()),
encCapacity: this.actor.getEncumbranceCapacity(),
levelRemainingList: this.actor.getLevelRemainingList(),
containersTree: this.actor.containersTree,
@@ -321,7 +323,12 @@ export class PegasusActorSheet extends ActorSheet {
this.actor.activatePower( li.data("item-id") );
this.render(true);
});
html.find('.vice-virtue-activate').click(ev => {
const li = $(ev.currentTarget).parents(".item")
this.actor.activateViceOrVirtue( li.data("item-id") )
this.render(true);
})
html.find('.change-worstfear').change(ev => {
this.actor.manageWorstFear( ev.currentTarget.checked )
});

View File

@@ -110,6 +110,16 @@ export class PegasusActor extends Actor {
return comp;
}
/* -------------------------------------------- */
getVirtues() {
let comp = this.data.items.filter(item => item.type == 'virtue');
return comp;
}
/* -------------------------------------------- */
getVices() {
let comp = this.data.items.filter(item => item.type == 'vice');
return comp;
}
/* -------------------------------------------- */
getArmors() {
let comp = duplicate(this.data.items.filter(item => item.type == 'armor') || []);
return comp;
@@ -222,6 +232,37 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
async activateViceOrVirtue(itemId) {
let item = this.data.items.find(item => item.id == itemId)
if (item && item.data.data) {
let nrg = duplicate(this.data.data.nrg)
if (!item.data.data.activated) { // Current value
let effects = []
for (let effect of item.data.data.effectsgained) {
effect.data.powerId = itemId // Link to the perk, in order to dynamically remove them
effects.push(effect)
}
if (effects.length) {
await this.createEmbeddedDocuments('Item', effects)
}
} else {
let toRem = []
for (let item of this.data.items) {
if (item.type == 'effect' && item.data.data.powerId == itemId) {
toRem.push(item.id)
}
}
if (toRem.length) {
await this.deleteEmbeddedDocuments('Item', toRem)
}
}
let update = { _id: item.id, "data.activated": !item.data.data.activated }
await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
async activatePower(itemId) {
let item = this.data.items.find(item => item.id == itemId)
@@ -444,6 +485,9 @@ export class PegasusActor extends Actor {
chatData.content = `<div>${this.name} has used a Momentum</div`
}
ChatMessage.create(chatData)
if (incDec < 0) {
PegasusUtility.showMomentumDialog(this.id)
}
} else {
ui.notifications.warn("Momentum cannot go below 0")
}
@@ -862,10 +906,10 @@ export class PegasusActor extends Actor {
return this.data.data.biodata.currentlevelremaining
}
/* -------------------------------------------- */
modifyHeroLevelRemaining( incDec) {
modifyHeroLevelRemaining(incDec) {
let biodata = duplicate(this.data.data.biodata)
biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining+incDec, 0)
this.update( {"data.biodata": biodata} )
biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining + incDec, 0)
this.update({ "data.biodata": biodata })
return biodata.currentlevelremaining
}
@@ -1236,7 +1280,7 @@ export class PegasusActor extends Actor {
}
let diceKey = PegasusUtility.getDiceFromLevel(rollData.stat.value)
rollData.dicePool.push({
name: "stat", key: diceKey, mod: rollData.stat.mod,
name: "stat", key: diceKey, level: rollData.stat.value, mod: rollData.stat.mod,
img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp`
})
}
@@ -1245,15 +1289,16 @@ export class PegasusActor extends Actor {
this.addArmorsShields(rollData, statKey, useShield)
this.addWeapons(rollData, statKey, useShield)
this.addEquipments(rollData, statKey)
console.log("ROLLDATA", rollData)
return rollData
}
/* -------------------------------------------- */
getLevelRemainingList( ) {
getLevelRemainingList() {
let options = []
for (let i=0; i<=this.data.data.biodata.maxlevelremaining; i++) {
options.push( `<option value="${i}">${i}</option>`)
for (let i = 0; i <= this.data.data.biodata.maxlevelremaining; i++) {
options.push(`<option value="${i}">${i}</option>`)
}
return options.join("\n")
}
@@ -1262,10 +1307,9 @@ export class PegasusActor extends Actor {
async startRoll(rollData) {
this.syncRoll(rollData);
//console.log("ROLL DATA", rollData)
let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog);
let rollDialog = await PegasusRollDialog.create(this, rollData)
console.log(rollDialog)
rollDialog.render(true);
}
/* -------------------------------------------- */

View File

@@ -48,7 +48,7 @@ export class PegasusRollDialog extends Dialog {
if (effect) {
effect.applied = toggled
let level, genre, idVal
let level, genre, idVal, key
if (effect.type == 'hindrance') {
level = effect.value
genre = 'positive'
@@ -61,30 +61,36 @@ export class PegasusRollDialog extends Dialog {
effectData.data.isUsed = toggled
if (effectData.data.reducedicevalue || effectData.data.statdice) {
idVal = "#statDicesLevel"
key = "statLevelBonus"
}
if (effectData.data.otherdice) {
idVal = "#damageDiceLevel"
key = "damageLevelBonus"
}
if (effectData.data.hindrance) {
idVal = "#hindranceDicesLevel"
genre = 'positive' // Dynamic fix
key = "hindranceLevelBonus"
}
}
// Now process the dice level update
if (idVal) {
let newLevel = Number($(idVal).val())
if (toggled) {
let newLevel = Number($(idVal).val())
console.log("Ongoing", newLevel, toggled, idVal)
if (genre == 'positive') {
if (genre == 'positive') {
newLevel += Number(level)
this.rollData[key] += Number(level)
} else {
newLevel -= Number(level)
this.rollData[key] -= Number(level)
}
} else {
if (genre == 'positive') {
newLevel -= Number(level)
this.rollData[key] -= Number(level)
} else {
newLevel += Number(level)
this.rollData[key] += Number(level)
}
}
newLevel = (newLevel < 0) ? 0 : newLevel
@@ -210,7 +216,7 @@ export class PegasusRollDialog extends Dialog {
html.find('#statDicesLevel').change((event) => {
this.rollData.statDicesLevel = Number(event.currentTarget.value)
});
html.find('#specDicesLevel').change( async (event) => {
html.find('#specDicesLevel').change(async (event) => {
this.rollData.specDicesLevel = Number(event.currentTarget.value)
PegasusUtility.updateSpecDicePool(this.rollData)
this.refreshDialog()
@@ -244,15 +250,16 @@ export class PegasusRollDialog extends Dialog {
html.find('.pool-add-dice').click(async (event) => {
let diceKey = $(event.currentTarget).data("dice-key")
PegasusUtility.addDicePool( this.rollData, diceKey)
let diceLevel = $(event.currentTarget).data("dice-level")
PegasusUtility.addDicePool(this.rollData, diceKey, diceLevel)
this.refreshDialog()
})
html.find('.pool-remove-dice').click(async (event) => {
let idx = $(event.currentTarget).data("dice-idx")
PegasusUtility.removeFromDicePool( this.rollData, idx)
PegasusUtility.removeFromDicePool(this.rollData, idx)
this.refreshDialog()
})
}
}

View File

@@ -60,9 +60,9 @@ export class PegasusUtility {
/* -------------------------------------------- */
static getDiceList() {
return [{ key: "d4", img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" },
{ key: "d8", img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" },
{ key: "d12", img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }]
return [{ key: "d4", level: 1, img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", level: 2, img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" },
{ key: "d8", level: 3, img: "systems/fvtt-pegasus-rpg/images/dice/d8.webp" }, { key: "d10", level: 4, img: "systems/fvtt-pegasus-rpg/images/dice/d10.webp" },
{ key: "d12", level: 5, img: "systems/fvtt-pegasus-rpg/images/dice/d12.webp" }]
}
/* -------------------------------------------- */
@@ -72,7 +72,7 @@ export class PegasusUtility {
if (effect && effect.applied && effect.effect.data.bonusdice) {
let diceKey = PegasusUtility.getDiceFromLevel(effect.effect.data.effectlevel)
let newDice = {
name: "effect-bonus-dice", key: diceKey, effect: effect.effect.name,
name: "effect-bonus-dice", key: diceKey, level: effect.effect.data.effectlevel, effect: effect.effect.name,
img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp`
}
newDicePool.push(newDice)
@@ -90,7 +90,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for(let myDice of diceList) {
let newDice = {
name: "damage", key: myDice,
name: "damage", key: myDice, level: rollData.damageDiceLevel,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@@ -108,7 +108,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for(let myDice of diceList) {
let newDice = {
name: "spec", key: myDice,
name: "spec", key: myDice, level: rollData.specDicesLevel,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@@ -118,9 +118,9 @@ export class PegasusUtility {
}
/* -------------------------------------------- */
static addDicePool(rollData, diceKey) {
static addDicePool(rollData, diceKey, level) {
let newDice = {
name: "dice-click", key: diceKey,
name: "dice-click", key: diceKey, level: level,
img: `systems/fvtt-pegasus-rpg/images/dice/${diceKey}.webp`
}
rollData.dicePool.push(newDice)
@@ -451,22 +451,22 @@ export class PegasusUtility {
/* -------------------------------------------- */
static updateRollData(rollData) {
let id = rollData.rollId;
let oldRollData = this.rollDataStore[id] || {};
let newRollData = mergeObject(oldRollData, rollData);
this.rollDataStore[id] = newRollData;
let id = rollData.rollId
let oldRollData = this.rollDataStore[id] || {}
let newRollData = mergeObject(oldRollData, rollData)
this.rollDataStore[id] = newRollData
}
/* -------------------------------------------- */
static saveRollData(rollData) {
game.socket.emit("system.pegasus-rpg", {
name: "msg_update_roll", data: rollData
}); // Notify all other clients of the roll
this.updateRollData(rollData);
this.updateRollData(rollData)
}
/* -------------------------------------------- */
static getRollData(id) {
return this.rollDataStore[id];
return this.rollDataStore[id]
}
/* -------------------------------------------- */
@@ -570,15 +570,51 @@ export class PegasusUtility {
for (let effect of rollData.effectsList) {
if (effect.effect.data.isUsed && effect.effect.data.oneuse) {
toRem.push(effect.effect._id)
ChatMessage.create({content: `One used effect ${effect.effect.name} has been auto-deleted.`})
}
}
if (toRem.length > 0) {
console.log("Going to remove one use effects", toRem)
//console.log("Going to remove one use effects", toRem)
let actor = game.actors.get(rollData.actorId)
actor.deleteEmbeddedDocuments('Item', toRem)
}
}
/* -------------------------------------------- */
static async momentumReroll(actorId) {
let actor = game.actors.get(actorId)
let rollData = actor.lastRoll
if (rollData) {
rollData.rerollMomentum = true
PegasusUtility.rollPegasus(rollData)
this.actor.lastRoll = undefined
} else {
ui.notifications.warn("No last roll registered....")
}
}
/* -------------------------------------------- */
static async showMomentumDialog( actorId) {
let d = new Dialog({
title: "Momentum reroll",
content: "<p>Do you want to re-roll your last roll ?</p>",
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "Cancel",
callback: () => this.close()
},
two: {
icon: '<i class="fas fa-times"></i>',
label: "Reroll",
callback: () => PegasusUtility.momentumReroll(actorId)
}
},
default: "Reroll",
})
d.render(true)
}
/* -------------------------------------------- */
static async rollPegasus(rollData) {
@@ -626,13 +662,17 @@ export class PegasusUtility {
let diceFormulaTab = []
for (let dice of rollData.dicePool) {
diceFormulaTab.push(dice.key)
let level = dice.level
if (dice.name == "stat" ) {
level += rollData.statLevelBonus
}
diceFormulaTab.push( this.getFoundryDiceFromLevel(level) )
}
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh + ' + (rollData.stat?.mod || 0)
// Performs roll
let myRoll = rollData.roll
if (!myRoll || rollData.reroll) { // New rolls only of no rerolls
if (!myRoll || rollData.reroll || rollData.rerollMomentum) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll
@@ -669,7 +709,8 @@ export class PegasusUtility {
this.removeOneUseEffects(rollData) // Unused for now
// And save the roll
this.saveRollData(rollData);
this.saveRollData(rollData)
actor.lastRoll = rollData
}
/* -------------------------------------------- */
@@ -812,6 +853,10 @@ export class PegasusUtility {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
bonusDicesLevel: 0,
statLevelBonus: 0,
damageLevelBonus: 0,
specLevelBonus: 0,
hindranceLevelBonus: 0,
hindranceDicesLevel: 0,
otherDicesLevel: 0,
statDicesLevel: 0,