Sync effetcts + initiative

This commit is contained in:
2022-01-28 10:05:54 +01:00
parent a203163b12
commit 68d7344e90
17 changed files with 755 additions and 624 deletions

View File

@ -261,124 +261,12 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
getInitiativeScore() {
getInitiativeScore( combatId, combatantId) {
if (this.type == 'character') {
// TODO
this.rollMR(true, combatId, combatantId)
}
return 0.0;
}
/* -------------------------------------------- */
getArmorModifier() {
let armors = this.getArmors();
let modifier = 0;
for (let armor of armors) {
if (armor.data.data.equipped) {
if (armor.data.data.type == 'light') modifier += 5;
if (armor.data.data.type == 'medium') modifier += 10;
if (armor.data.data.type == 'heavy') modifier += 15;
}
}
return modifier;
}
/* -------------------------------------------- */
async applyDamageLoss(damage) {
let chatData = {
user: game.user.id,
alias: this.name,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
};
//console.log("Apply damage chat", chatData );
if (damage > 0) {
let health = duplicate(this.data.data.secondary.health);
health.value -= damage;
if (health.value < 0) health.value = 0;
this.update({ "data.secondary.health.value": health.value });
chatData.content = `${this.name} looses ${damage} health. New health value is : ${health.value}`;
} else {
chatData.content = `No health loss for ${this.name} !`;
}
await ChatMessage.create(chatData);
}
/* -------------------------------------------- */
processNoDefense(attackRollData) {
let defenseRollData = {
mode: "nodefense",
finalScore: 0,
defenderName: this.name,
attackerName: attackRollData.alias,
armorModifier: this.getArmorModifier(),
actorId: this.id,
alias: this.name,
result: 0,
}
this.syncRoll(defenseRollData);
this.processDefenseResult(defenseRollData, attackRollData);
}
/* -------------------------------------------- */
async processApplyDamage(defenseRollData, attackRollData) { // Processed by the defender actor
if (attackRollData && attackRollData) {
let result = attackRollData.finalScore;
defenseRollData.damageDices = WotGUtility.getDamageDice(result);
defenseRollData.damageRoll = await this.rollDamage(defenseRollData);
chatData.damages = true;
chatData.damageDices = defenseRollData.damageDices;
WotGUtility.createChatWithRollMode(this.name, {
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-damages.html`, chatData)
});
}
}
/* -------------------------------------------- */
async processDefenseResult(defenseRollData, attackRollData) { // Processed by the defenser
if (defenseRollData && attackRollData) {
let result = attackRollData.finalScore - defenseRollData.finalScore;
defenseRollData.defenderName = this.name,
defenseRollData.attackerName = attackRollData.alias
defenseRollData.result = result
defenseRollData.damages = false
defenseRollData.damageDices = 0;
if (result > 0) {
defenseRollData.damageDices = WotGUtility.getDamageDice(result);
defenseRollData.damageRoll = await this.rollDamage(defenseRollData, attackRollData);
defenseRollData.damages = true;
defenseRollData.finalDamage = defenseRollData.damageRoll.total;
WotGUtility.updateRollData(defenseRollData);
console.log("DAMAGE ROLL OBJECT", defenseRollData);
WotGUtility.createChatWithRollMode(this.name, {
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-damage.html`, defenseRollData)
});
} else {
WotGUtility.updateRollData(defenseRollData);
WotGUtility.createChatWithRollMode(this.name, {
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-fail.html`, defenseRollData)
});
}
}
}
/* -------------------------------------------- */
async rollDamage(defenseRollData, attackRollData) {
let weaponDamage = 0;
if (attackRollData.weapon?.data?.damage) {
weaponDamage = Number(attackRollData.weapon.data.damage);
}
let formula = defenseRollData.damageDices + "d10+" + defenseRollData.armorModifier + "+" + weaponDamage;
console.log("ROLL : ", formula);
let myRoll = new Roll(formula).roll({ async: false });
await WotGUtility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
return myRoll;
console.log("Init required !!!!")
return -1;
}
/* -------------------------------------------- */
@ -406,20 +294,6 @@ export class PegasusActor extends Actor {
await this.update({ 'data.subactors': newArray });
}
/* -------------------------------------------- */
setDefenseMode(rollData) {
console.log("DEFENSE MODE IS SET FOR", this.name);
this.data.defenseRollData = rollData;
this.data.defenseDefenderId = rollData.defenderId;
this.data.defenseAttackerId = rollData.attackerId;
}
/* -------------------------------------------- */
clearDefenseMode() {
this.data.defenseDefenderId = undefined;
this.data.defenseAttackerId = undefined;
this.data.defenseRollData = undefined;
}
/* -------------------------------------------- */
syncRoll(rollData) {
let linkedRollId = PegasusUtility.getDefenseState(this.id);
@ -460,126 +334,6 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
getCommonRollData() {
let rollData = {
rollId: randomID(16),
alias: this.name,
actorImg: this.img,
actorId: this.id,
img: this.img,
rollMode: game.settings.get("core", "rollMode"),
activePerks: duplicate(this.getActivePerks()),
optionsDiceList: PegasusUtility.getOptionsDiceList(),
bonusDicesLevel: 0,
hindranceDicesLevel: 0,
otherDicesLevel: 0,
}
return rollData
}
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData);
let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog);
rollDialog.render(true);
}
/* -------------------------------------------- */
getShieldDice() {
let shields = this.data.items.filter(item => item.type == "shield" && item.data.data.equipped)
let def = 0
for (let sh of shields) {
def += sh.data.data.level
}
return def
}
/* -------------------------------------------- */
rollPool(statKey, useShield = false) {
let stat = this.getStat(statKey);
if (stat) {
let rollData = this.getCommonRollData()
rollData.mode = "stat"
rollData.specList = this.getRelevantSpec(statKey)
rollData.selectedSpec = "0"
rollData.stat = stat;
if (useShield) {
rollData.otherDicesLevel = this.getShieldDice()
}
this.startRoll(rollData);
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
rollUnarmedAttack() {
let stat = this.getStat('com');
if (stat) {
let rollData = this.getCommonRollData()
rollData.mode = "stat"
rollData.title = `Unarmed Attack`;
rollData.stat = stat;
rollData.damages = this.getStat('str');
this.startRoll(rollData);
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
rollStat(statKey) {
let stat = this.getStat(statKey);
if (stat) {
let rollData = this.getCommonRollData()
rollData.specList = this.getRelevantSpec(statKey)
rollData.mode = "stat"
rollData.title = `Stat ${stat.label}`;
rollData.stat = stat;
this.startRoll(rollData);
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
async rollSpec(specId) {
let spec = this.getOneSpec(specId)
if (spec) {
let rollData = this.getCommonRollData()
rollData.mode = "spec"
rollData.title = `Spec. : ${spec.name} `,
rollData.stat = this.getStat(spec.data.statistic)
rollData.spec = spec
this.startRoll(rollData);
} else {
ui.notifications.warn("Specialisation not found !");
}
}
/* -------------------------------------------- */
async rollMR() {
let mr = duplicate(this.data.data.mr);
if (mr) {
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
let rollData = this.getCommonRollData()
rollData.mode = "MR"
rollData.stat = mr
rollData.activePerks = duplicate(this.getActivePerks()),
rollData.specList = this.getRelevantSpec('mr'),
this.startRoll(rollData);
} else {
ui.notifications.warn("MR not found !");
}
}
/* -------------------------------------------- */
async deleteAllItemsByType(itemType) {
let items = this.data.items.filter(item => item.type == itemType);
@ -636,7 +390,7 @@ export class PegasusActor extends Actor {
updates['data.momentum.max'] = momentum
}
let mrLevel = (this.data.data.statistics.agi.value + this.data.data.statistics.str.value) - this.data.data.statistics.phy.value
let mrLevel = (this.data.data.statistics.agi.value + this.data.data.statistics.str.value) - this.data.data.statistics.phy.value
mrLevel = (mrLevel < 1) ? 1 : mrLevel;
if (mrLevel != this.data.data.mr.value) {
updates['data.mr.value'] = mrLevel
@ -685,15 +439,15 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
async incDecQuantity( objetId, incDec = 0 ) {
let objetQ = this.data.items.get(objetId )
if (objetQ) {
let newQ = objetQ.data.data.quantity + incDec;
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity
}
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.quantity + incDec;
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity
}
}
/* -------------------------------------------- */
applyAbility(ability, updates = []) {
if (ability.data.affectedstat != "notapplicable") {
@ -768,74 +522,182 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
async rollPower(powId) {
let power = this.data.items.find(item => item.type == 'power' && item.id == powId);
if (power) {
let rollData = {
mode: "power",
alias: this.name,
actorImg: this.img,
actorId: this.id,
img: power.img,
rollMode: game.settings.get("core", "rollMode"),
title: `Power ${power.name} `,
power: duplicate(power),
activePerks: duplicate(this.getActivePerks()),
optionsDiceList: PegasusUtility.getOptionsDiceList(),
bonusDicesLevel: 0,
hindranceDicesLevel: 0,
otherDicesLevel: 0,
getShieldValue() {
let shields = this.data.items.filter(item => item.type == "shield" && item.data.data.equipped)
let def = 0
for (let sh of shields) {
def += sh.data.data.level
}
return def
}
/* -------------------------------------------- */
addHindrancesList( effectsList ) {
if (this.data.data.combat.stunlevel > 0) {
effectsList.push( { label: "Stun Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.stunlevel } )
}
let effects = this.data.items.filter( item => item.type == 'effect' )
for( let effect of effects) {
effect = duplicate(effect)
if (effect.data.hindrance) {
effectsList.push( { label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel } )
}
this.updateWithTarget(rollData);
this.syncRoll(rollData);
let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog);
rollDialog.render(true);
} else {
ui.notifications.warn("Technique not found !");
}
}
/* -------------------------------------------- */
updateWithTarget(rollData) {
let objectDefender
let target = PegasusUtility.getTarget();
if (!target) {
ui.notifications.warn("You are using a Weapon without a Target.");
} else {
let defenderActor = game.actors.get(target.data.actorId);
objectDefender = PegasusUtility.data(defenderActor);
objectDefender = mergeObject(objectDefender, target.data.actorData);
rollData.defender = objectDefender;
rollData.attackerId = this.id;
rollData.defenderId = objectDefender._id;
//console.log("ROLLDATA DEFENDER !!!", rollData);
/* ROLL SECTION
/* -------------------------------------------- */
/* -------------------------------------------- */
addEffects( rollData) {
let effects = this.data.items.filter( item => item.type == 'effect' )
for( let effect of effects) {
effect = duplicate(effect)
if ( !effect.data.hindrance
&& effect.data.stataffected != "notapplicable"
&& effect.data.stataffected != "special"
&& effect.data.stataffected != "all") {
rollData.effectsList.push( { label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel } )
}
}
}
/* -------------------------------------------- */
addArmorsShields( rollData) {
let armors = this.getArmors()
let armorLevel = 0
for (let armor of armors) {
armorLevel += armor.data.resistance
}
rollData.armorsList.push( {label: 'Total armor level', type: "other", applied: false, value: armorLevel } )
rollData.armorsList.push( {label: 'Shield level', type: "other", applied: false, value: this.getShieldValue() } )
}
/* -------------------------------------------- */
getCommonRollData(statKey = undefined) {
let rollData = PegasusUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.activePerks = duplicate(this.getActivePerks())
if ( statKey) {
rollData.statKey = statKey
rollData.stat = this.getStat(statKey)
rollData.statDicesLevel = rollData.stat.value
rollData.statMod = rollData.stat.mod
rollData.specList = this.getRelevantSpec(statKey)
rollData.selectedSpec = "0"
}
this.addEffects( rollData)
this.addArmorsShields(rollData)
return rollData
}
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData);
console.log("ROLL DATA", rollData)
let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog);
rollDialog.render(true);
}
/* -------------------------------------------- */
rollPool(statKey, useShield = false) {
let stat = this.getStat(statKey);
if (stat) {
let rollData = this.getCommonRollData(statKey)
rollData.mode = "stat"
this.startRoll(rollData)
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
rollUnarmedAttack() {
let stat = this.getStat('com');
if (stat) {
let rollData = this.getCommonRollData(statKey)
rollData.mode = "stat"
rollData.title = `Unarmed Attack`;
rollData.damages = this.getStat('str');
this.startRoll(rollData);
} else {
ui.notifications.warn("Statistic not found !");
}
}
/*-------------------------------------------- */
rollStat(statKey) {
let stat = this.getStat(statKey);
if (stat) {
let rollData = this.getCommonRollData(statKey)
rollData.mode = "stat"
rollData.title = `Stat ${stat.label}`;
this.startRoll(rollData)
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
async rollSpec(specId) {
let spec = this.getOneSpec(specId)
if (spec) {
let rollData = this.getCommonRollData(spec.data.statistic)
rollData.mode = "spec"
rollData.title = `Spec. : ${spec.name} `
rollData.specList = [ spec ]
this.startRoll(rollData)
} else {
ui.notifications.warn("Specialisation not found !");
}
}
/* -------------------------------------------- */
async rollMR( isInit = false, combatId = 0, combatantId = 0) {
let mr = duplicate(this.data.data.mr)
if (mr) {
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
let rollData = this.getCommonRollData("mr")
rollData.mode = "MR"
rollData.isInit = isInit
rollData.combatId = combatId
rollData.combatantId = combatantId
this.startRoll(rollData);
} else {
ui.notifications.warn("MR not found !");
}
}
/* -------------------------------------------- */
async rollArmor(armorId) {
let armor = this.data.items.get(armorId)
if (armor) {
let rollData = this.getCommonRollData()
let rollData = this.getCommonRollData(armor.data.statistic)
armor = duplicate(armor);
this.checkAndPrepareArmor(armor);
rollData.mode = "armor"
rollData.img = armor.img
rollData.armor = armor
rollData.title = `Armor : ${armor.name}`
rollData.stat = this.getStat(armor.data.statistic)
rollData.specList = this.getRelevantSpec(armor.data.statistic)
rollData.activePerks = duplicate(this.getActivePerks())
rollData.isResistance = true;
rollData.otherDicesLevel = armor.data.resistance
//this.updateWithTarget(rollData);
this.startRoll(rollData);
} else {
ui.notifications.warn("Armor not found !", weaponId);
@ -847,26 +709,19 @@ export class PegasusActor extends Actor {
let weapon = this.data.items.get(weaponId)
if (weapon) {
let rollData = this.getCommonRollData()
weapon = duplicate(weapon);
this.checkAndPrepareWeapon(weapon);
weapon = duplicate(weapon)
this.checkAndPrepareWeapon(weapon)
let rollData = this.getCommonRollData(weapon.data.statistic)
rollData.mode = "weapon"
rollData.img = weapon.img
rollData.weapon = weapon
rollData.title = `Weapon : ${weapon.name}`
rollData.specList = this.getRelevantSpec(weapon.data.statistic)
rollData.activePerks = duplicate(this.getActivePerks())
if (damage) {
rollData.stat = this.getStat(weapon.data.damagestatistic)
rollData.isDamage = true;
rollData.otherDicesLevel = weapon.data.damage
} else {
rollData.stat = this.getStat(weapon.data.statistic)
}
}
//this.updateWithTarget(rollData);
this.startRoll(rollData);
} else {
ui.notifications.warn("Weapon not found !", weaponId);
@ -878,20 +733,15 @@ export class PegasusActor extends Actor {
let power = this.data.items.get(powerId)
if (power) {
let rollData = this.getCommonRollData()
power = duplicate(power);
power = duplicate(power)
let rollData = this.getCommonRollData(power.data.statistic)
rollData.mode = "power"
rollData.img = power.img
rollData.power = power
rollData.title = `Power : ${power.name}`
rollData.stat = this.getStat(power.data.statistic)
rollData.specList = this.getRelevantSpec(power.data.statistic)
rollData.activePerks = duplicate(this.getActivePerks())
this.startRoll(rollData);
} else {
ui.notifications.warn("Power not found !", powerId);
}
}
}