Sync compendiums

This commit is contained in:
sladecraven 2022-11-30 12:00:09 +01:00
parent efb55ff829
commit 8cc2380f0a
4 changed files with 49 additions and 38 deletions

View File

@ -53,7 +53,7 @@ export class PegasusActorSheet extends ActorSheet {
powers: duplicate(this.actor.getPowers()),
subActors: duplicate(this.actor.getSubActors()),
race: duplicate(this.actor.getRace()),
role: duplicate(this.actor.getRole()),
role: this.actor.getRole(),
effects: duplicate(this.actor.getEffects()),
moneys: duplicate(this.actor.getMoneys()),
virtues: duplicate(this.actor.getVirtues()),

View File

@ -275,8 +275,8 @@ export class PegasusActor extends Actor {
return race[0] ?? [];
}
getRole() {
let role = this.items.filter(item => item.type == 'role')
return role[0] ?? [];
let role = this.items.find(item => item.type == 'role')
return role;
}
/* -------------------------------------------- */
getRoleLevel() {
@ -758,10 +758,11 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
modifyStun(incDec) {
let combat = duplicate(this.system.combat)
let myself = this
let combat = duplicate(myself.system.combat)
combat.stunlevel += incDec
if (combat.stunlevel >= 0) {
this.update({ 'system.combat': combat })
myself.update({ 'system.combat': combat } )
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
@ -781,9 +782,9 @@ export class PegasusActor extends Actor {
ChatMessage.create({ content: `${this.name} Stun threshold has been exceeded.` })
}
if (incDec > 0 && stunAbove > 0) {
let delirium = duplicate(this.system.secondary.delirium)
let delirium = duplicate(myself.system.secondary.delirium)
delirium.value -= incDec
this.update({ 'system.secondary.delirium': delirium })
myself.update({ 'system.secondary.delirium': delirium })
}
}
@ -1922,15 +1923,15 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
addRoleBonus(rollData, statKey, subKey) {
let role = this.getRole()
if (role.name.toLowerCase() == "ranged" && subKey == "ranged-dmg") {
if (role && role.name.toLowerCase() == "ranged" && subKey == "ranged-dmg") {
rollData.effectsList.push({ label: "Ranged Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() })
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Ranged Role Bonus"))
}
if (role.name.toLowerCase() == "defender" && subKey == "defence") {
if (role && role.name.toLowerCase() == "defender" && subKey == "defence") {
rollData.effectsList.push({ label: "Defender Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() })
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Defender Role Bonus"))
}
if (role.name.toLowerCase() == "scrapper" && statKey == "com") {
if (role && role.name.toLowerCase() == "scrapper" && statKey == "com") {
rollData.effectsList.push({ label: "Scrapper Role Bonus", type: "effect", applied: true, isdynamic: true, value: this.getRoleLevel() })
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("effect-bonus-dice", this.getRoleLevel(), 0, "Scrapper Role Bonus"))
}
@ -2019,7 +2020,8 @@ export class PegasusActor extends Actor {
let rollData = PegasusUtility.getBasicRollData(isInit)
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.tokenId = this.token?.id
rollData.actorId = (this.token) ? this.token.actor.id : this.id
rollData.img = this.img
rollData.traumaState = this.getTraumaState()
rollData.levelRemaining = this.getLevelRemaining()

View File

@ -803,6 +803,12 @@ export class PegasusUtility {
/* -------------------------------------------- */
static async rollPegasus(rollData) {
let actor = game.actors.get(rollData.actorId)
if (rollData.tokenId) {
let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId)
if (token) {
actor = token.actor
}
}
let diceFormulaTab = []
for (let dice of rollData.dicePool) {
@ -1115,7 +1121,7 @@ export class PegasusUtility {
let friends = canvas.tokens.placeables.filter(newToken => newToken.actor.type == "character" && !newToken.document.hidden && newToken.document.disposition == token.document.disposition)
for (let friend of friends) {
if (friend.actor.id != token.actor.id) {
let existing = toApply[friend.actor.id] || { actor: friend.actor, add: false, level: 0, names: [] }
let existing = toApply[friend.id] || { token: friend, add: false, level: 0, names: [] }
let visible = canvas.effects.visibility.testVisibility(friend.center, { object: token })
console.log("parse visible TACTICIAN : ", visible, token.name, friend.name)
if (visible) {
@ -1123,22 +1129,22 @@ export class PegasusUtility {
existing.level += token.actor.getRoleLevel()
existing.names.push(token.actor.name)
}
toApply[friend.actor.id] = existing
toApply[friend.id] = existing
}
}
}
for (let id in toApply) {
let applyDef = toApply[id]
let hasBonus = applyDef.actor.hasTacticianBonus()
let hasBonus = applyDef.token.actor.hasTacticianBonus()
if (applyDef.add) {
if (!hasBonus) {
applyDef.actor.addTacticianEffect(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.addTacticianEffect(applyDef.names.toString(), applyDef.level)
} else if (applyDef.level != hasBonus.system.effectlevel) {
await applyDef.actor.removeTacticianEffect()
applyDef.actor.addTacticianEffect(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.removeTacticianEffect()
await applyDef.token.actor.addTacticianEffect(applyDef.names.toString(), applyDef.level)
}
} else if (hasBonus) {
applyDef.actor.removeTacticianEffect()
await applyDef.token.actor.removeTacticianEffect()
}
}
//Delete all effects if no more tacticians (ie deleted case)
@ -1146,7 +1152,7 @@ export class PegasusUtility {
let allTokens = canvas.tokens.placeables.filter(token => token.actor.type == "character")
for (let token of allTokens) {
if (token.actor.hasTacticianBonus()) {
token.actor.removeTacticianEffect()
await token.actor.removeTacticianEffect()
}
}
}
@ -1163,7 +1169,7 @@ export class PegasusUtility {
let friends = canvas.tokens.placeables.filter(newToken => newToken.actor.type == "character" && !newToken.document.hidden && newToken.document.disposition == token.document.disposition)
for (let friend of friends) {
if (friend.actor.id != token.actor.id) {
let existing = toApply[friend.actor.id] || { actor: friend.actor, add: false, level: 0, names: [] }
let existing = toApply[friend.id] || { token: friend, add: false, level: 0, names: [] }
let visible = canvas.effects.visibility.testVisibility(friend.center, { object: token })
console.log("parse visible ENHANCER: ", visible, token.name, friend.name)
if (visible) {
@ -1174,22 +1180,22 @@ export class PegasusUtility {
existing.names.push(token.actor.name)
}
}
toApply[friend.actor.id] = existing
toApply[friend.id] = existing
}
}
}
for (let id in toApply) {
let applyDef = toApply[id]
let hasBonus = applyDef.actor.hasEnhancerBonus()
let hasBonus = applyDef.token.actor.hasEnhancerBonus()
if (applyDef.add) {
if (!hasBonus) {
applyDef.actor.addEnhancerEffect(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.addEnhancerEffect(applyDef.names.toString(), applyDef.level)
} else if (applyDef.level != hasBonus.system.effectlevel) {
await applyDef.actor.removeEnhancerEffect()
applyDef.actor.addEnhancerEffect(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.removeEnhancerEffect()
await applyDef.token.actor.addEnhancerEffect(applyDef.names.toString(), applyDef.level)
}
} else if (hasBonus) {
applyDef.actor.removeEnhancerEffect()
await applyDef.token.actor.removeEnhancerEffect()
}
}
// Delete all effects if no more tacticians (ie deleted case)
@ -1197,7 +1203,7 @@ export class PegasusUtility {
let allTokens = canvas.tokens.placeables.filter(token => token.actor.type == "character")
for (let token of allTokens) {
if (token.actor.hasEnhancerBonus()) {
token.actor.removeEnhancerEffect()
await token.actor.removeEnhancerEffect()
}
}
}
@ -1220,9 +1226,11 @@ export class PegasusUtility {
if (token.document.disposition == 0) {
ennemies = canvas.tokens.placeables.filter(newToken => newToken.actor.type == "character" && !newToken.document.hidden && (newToken.document.disposition == -1 || newToken.document.disposition == 1 ))
}
console.log("Ennemies for token", token.actor.name, ennemies)
for (let ennemy of ennemies) {
if (ennemy.actor.id != token.actor.id) {
let existing = toApply[ennemy.actor.id] || { actor: ennemy.actor, add: false, level: 0, names: [] }
//console.log("Adding ennemy", ennemy.id)
let existing = toApply[ennemy.id] || { token: ennemy, add: false, level: 0, names: [] }
let visible = canvas.effects.visibility.testVisibility(ennemy.center, { object: token })
if (visible) {
let dist = canvas.grid.measureDistances([{ ray: new Ray(token.center, ennemy.center) }], { gridSpaces: false })
@ -1232,30 +1240,31 @@ export class PegasusUtility {
existing.names.push(token.actor.name)
}
}
toApply[ennemy.actor.id] = existing
toApply[ennemy.id] = existing
}
}
}
//console.log("To apply stuff : ", toApply)
for (let id in toApply) {
let applyDef = toApply[id]
let hasHindrance = applyDef.actor.hasAgitatorHindrance()
let hasHindrance = applyDef.token.actor.hasAgitatorHindrance()
if (applyDef.add) {
if (!hasHindrance) {
applyDef.actor.addAgitatorHindrance(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.addAgitatorHindrance(applyDef.names.toString(), applyDef.level)
} else if (applyDef.level != hasHindrance.system.effectlevel) {
await applyDef.actor.removeAgitatorHindrance()
applyDef.actor.addAgitatorHindrance(applyDef.names.toString(), applyDef.level)
await applyDef.token.actor.removeAgitatorHindrance()
await applyDef.token.actor.addAgitatorHindrance(applyDef.names.toString(), applyDef.level)
}
} else if (hasHindrance) {
applyDef.actor.removeAgitatorHindrance()
await applyDef.token.actor.removeAgitatorHindrance()
}
}
// Delete all effects if no more agtators (ie deleted case)
// Delete all effects if no more agitators (ie deleted case)
if (agitatorTokens.length == 0) {
let allTokens = canvas.tokens.placeables.filter(token => token.actor.type == "character")
for (let token of allTokens) {
if (token.actor.hasAgitatorHindrance()) {
token.actor.removeAgitatorHindrance()
await token.actor.removeAgitatorHindrance()
}
}
}

View File

@ -253,7 +253,7 @@
],
"title": "Pegasus RPG",
"url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg",
"version": "10.2.6",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.2.6.zip",
"version": "10.2.7",
"download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.2.7.zip",
"background": "systems/fvtt-pegasus-rpg/images/ui/pegasus_welcome_page.webp"
}