Add exchangee stuff

This commit is contained in:
2022-08-06 17:06:05 +02:00
parent 2517149ab4
commit 99c0b26f78
9 changed files with 202 additions and 62 deletions

View File

@@ -554,6 +554,34 @@ export class CrucibleActor extends Actor {
}
}
/* -------------------------------------------- */
rollDefenseMelee(attackRollData) {
let weapon = this.data.items.get(attackRollData.defenseWeaponId)
if (weapon) {
weapon = duplicate(weapon)
let skill = this.data.items.find(item => item.name.toLowerCase() == weapon.data.skill.toLowerCase())
if (skill) {
skill = duplicate(skill)
CrucibleUtility.updateSkill(skill)
let abilityKey = skill.data.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "weapondefense"
rollData.shield = this.getEquippedShield()
rollData.attackRollData = duplicate(attackRollData)
rollData.skill = skill
rollData.weapon = weapon
rollData.img = weapon.img
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
}
} else {
ui.notifications.warn("Weapon not found ! ")
}
}
/* -------------------------------------------- */
rollShieldDie() {
let shield = this.getEquippedShield()

View File

@@ -5,9 +5,11 @@ import { CrucibleCommands } from "./crucible-commands.js";
/* -------------------------------------------- */
const __level2Dice = ["d0", "d4", "d6", "d8", "d10", "d12"];
const __name2DiceValue = { "0": 0, "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10": 10, "d12": 12 }
const __skillLevel2Dice = ["0d8", "1d8", "2d8","3d8", "4d8", '6d8', "8d8", "10d8"]
const __color2RollTable = { blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die",
white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice"}
const __skillLevel2Dice = ["0d8", "1d8", "2d8", "3d8", "4d8", '6d8', "8d8", "10d8"]
const __color2RollTable = {
blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die",
white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice"
}
/* -------------------------------------------- */
export class CrucibleUtility {
@@ -20,7 +22,8 @@ export class CrucibleUtility {
CrucibleUtility.dropItemOnToken(canvas, data)
});
this.rollDataStore = {}
this.rollDataStore = {}
this.defenderStore = {}
CrucibleCommands.init();
@@ -61,13 +64,13 @@ export class CrucibleUtility {
static getShieldSkills() {
return duplicate(this.shieldSkills)
}
/* -------------------------------------------- */
static async ready() {
const skills = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.skills")
this.skills = skills.map(i => i.toObject())
this.weaponSkills = duplicate( this.skills.filter( item => item.data.isweaponskill))
this.shieldSkills = duplicate( this.skills.filter( item => item.data.isshieldskill))
this.weaponSkills = duplicate(this.skills.filter(item => item.data.isweaponskill))
this.shieldSkills = duplicate(this.skills.filter(item => item.data.isshieldskill))
const rollTables = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.rolltables")
this.rollTables = rollTables.map(i => i.toObject())
@@ -87,16 +90,16 @@ export class CrucibleUtility {
}
/* -------------------------------------------- */
static async getRollTableFromDiceColor( diceColor) {
static async getRollTableFromDiceColor(diceColor) {
let rollTableName = __color2RollTable[diceColor]
if (rollTableName) {
const pack = game.packs.get("fvtt-crucible-rpg.rolltables")
const index = await pack.getIndex()
const entry = index.find(e => e.name === rollTableName)
let table = await pack.getDocument(entry._id)
const draw = await table.draw({ displayChat: true, rollMode: "gmroll"})
const draw = await table.draw({ displayChat: true, rollMode: "gmroll" })
return draw.results.length > 0 ? draw.results[0] : undefined
}
}
}
/* -------------------------------------------- */
@@ -105,6 +108,15 @@ export class CrucibleUtility {
html.on("click", '.view-item-from-chat', event => {
game.system.crucible.creator.openItemView(event)
})
html.on("click", '.roll-defense-melee', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = CrucibleUtility.getRollData( rollId )
rollData.defenseWeaponId = $(event.currentTarget).data("defense-weapon-id")
let actor = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (actor && (game.user.isGM || actor.isOwner) ) {
actor.rollDefenseMelee(rollData )
}
})
}
/* -------------------------------------------- */
@@ -214,12 +226,27 @@ export class CrucibleUtility {
return this.rollDataStore[id]
}
/* -------------------------------------------- */
static async displayDefenseMessage(rollData) {
if (rollData.defenderTokenId) {
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (game.user.isGM || (game.user.character && game.user.character.id == defender.id)) {
rollData.defender = defender
rollData.defenderWeapons = defender.getEquippedWeapons()
rollData.isRollTarget = rollData.weapon?.data.isranged
this.createChatWithRollMode(defender.name, {
alias: defender.name,
user: defender.id,
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-request-defense.html`, rollData),
whisper: [defender.id].concat(ChatMessage.getWhisperRecipients('GM')),
})
}
}
}
/* -------------------------------------------- */
static async onSocketMesssage(msg) {
console.log("SOCKET MESSAGE", msg.name)
if (msg.name == "msg_update_defense_state") {
this.updateDefenseState(msg.data.defenderId, msg.data.rollId)
}
if (msg.name == "msg_update_roll") {
this.updateRollData(msg.data)
}
@@ -233,9 +260,6 @@ export class CrucibleUtility {
}
this.addItemDropToActor(actor, item)
}
if (msg.name == "msg_reroll_hero") {
this.rerollHeroRemaining(msg.data.userId, msg.data.rollId)
}
}
/* -------------------------------------------- */
@@ -284,9 +308,9 @@ export class CrucibleUtility {
}
/* -------------------------------------------- */
static updateSkill( skill) {
static updateSkill(skill) {
skill.data.level = skill.data.background + skill.data.basic + skill.data.class + skill.data.explevel
if (skill.data.level > 7) { skill.data.level = 7}
if (skill.data.level > 7) { skill.data.level = 7 }
skill.data.skilldice = __skillLevel2Dice[skill.data.level]
}
@@ -298,13 +322,13 @@ export class CrucibleUtility {
// ability/save => 0
let diceFormula
let startFormula = "0d6cs>=5"
if ( rollData.ability) {
if (rollData.ability) {
startFormula = String(rollData.ability.value) + "d6cs>=5"
}
if ( rollData.save) {
if (rollData.save) {
startFormula = String(rollData.save.value) + "d6cs>=5"
}
if ( rollData.shield) {
if (rollData.shield) {
startFormula = "1" + String(rollData.shield.data.shielddie) + "cs>=5"
}
diceFormula = startFormula
@@ -314,10 +338,10 @@ export class CrucibleUtility {
// bonus => 6
if (rollData.skill) {
let level = rollData.skill.data.level
if (rollData.skill.data.issl2 ) {
if (rollData.skill.data.issl2) {
rollData.hasSLBonus = true
level += 2
if (level > 7) { level = 7}
if (level > 7) { level = 7 }
}
rollData.skill.data.skilldice = __skillLevel2Dice[level]
diceFormula += "+" + String(rollData.skill.data.skilldice) + "cs>=5"
@@ -339,26 +363,26 @@ export class CrucibleUtility {
} else {
diceFormula += `+ 0d6cs>=5`
}
} else {
} else {
diceFormula += `+ 0d8cs=>5 + 0d10cs>=5 + 0d6cs>=5`
}
// advantage => 8
let advFormula = "+ 0d8cs>=5"
if(rollData.advantage == "advantage1") {
if (rollData.advantage == "advantage1") {
advFormula = "+ 1d8cs>=5"
}
if(rollData.advantage == "advantage2") {
if (rollData.advantage == "advantage2") {
advFormula = "+ 2d8cs>=5"
}
diceFormula += advFormula
// disadvantage => 10
let disFormula = "- 0d8cs>=5"
if(rollData.disadvantage == "disadvantage1") {
if (rollData.disadvantage == "disadvantage1") {
disFormula = "- 1d8cs>=5"
}
if(rollData.disadvantage == "disadvantage2") {
if (rollData.disadvantage == "disadvantage2") {
disFormula = "- 2d8cs>=5"
}
diceFormula += disFormula
@@ -370,7 +394,7 @@ export class CrucibleUtility {
skillArmorPenalty += armor.data.skillpenalty
}
}
if (rollData.skill && rollData.skill.data.armorpenalty && skillArmorPenalty > 0 ) {
if (rollData.skill && rollData.skill.data.armorpenalty && skillArmorPenalty > 0) {
rollData.skillArmorPenalty = skillArmorPenalty
diceFormula += `- ${skillArmorPenalty}d8cs>=5`
} else {
@@ -390,12 +414,12 @@ export class CrucibleUtility {
let myRoll2 = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
if (rollData.rollAdvantage == "roll-advantage") {
if ( myRoll2.total > rollData.nbSuccess) {
if (myRoll2.total > rollData.nbSuccess) {
rollData.roll = myRoll2
rollData.nbSuccess = myRoll2.total
}
} else {
if ( myRoll2.total < rollData.nbSuccess) {
if (myRoll2.total < rollData.nbSuccess) {
rollData.roll = myRoll2
rollData.nbSuccess = myRoll2.total
}
@@ -404,23 +428,27 @@ export class CrucibleUtility {
// Manage exp
if (rollData.skill && rollData.skill.data.level > 0) {
let nbSkillSuccess = rollData.roll.terms[2].total
if ( nbSkillSuccess == 0 || nbSkillSuccess == rollData.skill.data.level) {
if (nbSkillSuccess == 0 || nbSkillSuccess == rollData.skill.data.level) {
actor.incrementSkillExp(rollData.skill._id, 1)
}
}
this.saveRollData(rollData)
actor.lastRoll = rollData
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
})
console.log("Rolldata result", rollData)
// Message response
this.displayDefenseMessage(rollData)
// And save the roll
this.saveRollData(rollData)
actor.lastRoll = rollData
}
/* -------------------------------------------- */
static sortArrayObjectsByName( myArray) {
static sortArrayObjectsByName(myArray) {
myArray.sort((a, b) => {
let fa = a.name.toLowerCase();
let fb = b.name.toLowerCase();
@@ -526,22 +554,15 @@ export class CrucibleUtility {
/* -------------------------------------------- */
static updateWithTarget(rollData) {
let objectDefender
let target = CrucibleUtility.getTarget();
let target = CrucibleUtility.getTarget()
if (target) {
let defenderActor = game.actors.get(target.data.actorId)
objectDefender = CrucibleUtility.data(defenderActor)
objectDefender = mergeObject(objectDefender, target.data.actorData)
rollData.defender = objectDefender
rollData.attackerId = this.id
rollData.defenderId = objectDefender._id
defenderActor.addHindrancesList(rollData.effectsList)
rollData.defenderTokenId = target.id
}
}
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
}
/* -------------------------------------------- */