Add fight options

This commit is contained in:
2022-03-10 21:05:53 +01:00
parent eacd32927c
commit 02b3dd5e0f
24 changed files with 447 additions and 227 deletions

View File

@ -42,7 +42,12 @@ export class BoLActorSheet extends ActorSheet {
html.find('.create_item').click(ev => {
this.actor.createEmbeddedDocuments('Item', [{ name: "Nouvel Equipement", type: "item" }], { renderSheet: true });
});
html.find(".toggle-fight-option").click((ev) => {
const li = $(ev.currentTarget).parents(".item")
this.actor.toggleFightOption( li.data("itemId") )
})
html.find(".inc-dec-btns-alchemy").click((ev) => {
const li = $(ev.currentTarget).parents(".item");
this.actor.spendAlchemyPoint( li.data("itemId"), 1)
@ -97,17 +102,6 @@ export class BoLActorSheet extends ActorSheet {
// Rollable abilities.
html.find('.rollable').click(this._onRoll.bind(this));
// html.find('.roll-attribute').click(ev => {
// this.actor.rollAttributeAptitude( $(ev.currentTarget).data("attr-key") );
// });
// html.find('.roll-career').click(ev => {
// const li = $(ev.currentTarget).parents(".item");
// this.actor.rollCareer( li.data("itemId") );
// });
// html.find('.roll-weapon').click(ev => {
// const li = $(ev.currentTarget).parents(".item");
// this.actor.rollWeapon( li.data("itemId") );
// });
}
/* -------------------------------------------- */
@ -131,11 +125,11 @@ export class BoLActorSheet extends ActorSheet {
formData.alchemy = this.actor.alchemy
formData.containers = this.actor.containers
formData.treasure = this.actor.treasure
formData.treasure = this.actor.treasure
formData.treasure = this.actor.alchemyrecipe
formData.vehicles = this.actor.vehicles;
formData.ammos = this.actor.ammos;
formData.misc = this.actor.misc;
formData.alchemyrecipe = this.actor.alchemyrecipe
formData.vehicles = this.actor.vehicles
formData.fightoptions = this.actor.fightoptions
formData.ammos = this.actor.ammos
formData.misc = this.actor.misc
formData.combat = this.actor.buildCombat()
formData.features = this.actor.buildFeatures()
formData.isGM = game.user.isGM
@ -148,9 +142,9 @@ export class BoLActorSheet extends ActorSheet {
formData.isAlchemist = this.actor.isAlchemist()
formData.isPriest = this.actor.isPriest()
formData.isGM= game.user.isGM
formData.isGM = game.user.isGM
console.log("ACTORDATA", formData);
console.log("ACTORDATA", formData)
return formData;
}
/* -------------------------------------------- */

View File

@ -22,11 +22,6 @@ export class BoLActor extends Actor {
super.prepareData();
}
/* -------------------------------------------- */
//_onUpdate(changed, options, user) {
//
//}
/* -------------------------------------------- */
updateResourcesData( ) {
if ( this.type == 'character') {
@ -50,22 +45,92 @@ export class BoLActor extends Actor {
/* -------------------------------------------- */
get itemData(){
return Array.from(this.data.items.values()).map(i => i.data);
return Array.from(this.data.items.values()).map(i => i.data)
}
get details() {
return this.data.data.details;
return this.data.data.details
}
get attributes() {
return Object.values(this.data.data.attributes);
return Object.values(this.data.data.attributes)
}
get aptitudes() {
return Object.values(this.data.data.aptitudes);
return Object.values(this.data.data.aptitudes)
}
/* -------------------------------------------- */
get defenseValue() {
return this.data.data.aptitudes.def.value;
let defMod = 0
let fo = this.getActiveFightOption()
if (fo && fo.data.properties.fightoptiontype == "intrepid" ) {
defMod += -2
}
if (fo && fo.data.properties.fightoptiontype == "fulldefense" ) {
defMod += 2
}
if (fo && fo.data.properties.fightoptiontype == "twoweaponsdef" && !fo.data.properties.used) {
defMod += 1
this.updateEmbeddedDocuments("Item", [ {_id: fo._id, 'data.properties.used': true}] )
}
if (fo && fo.data.properties.fightoptiontype == "defense" ) {
defMod += 1
}
if (fo && fo.data.properties.fightoptiontype == "attack" ) {
defMod += -1
}
return this.data.data.aptitudes.def.value + defMod
}
/* -------------------------------------------- */
getActiveFightOption( ) {
let it = this.itemData.find(i => i.type === "feature" && i.data.subtype === "fightoption" && i.data.properties.activated)
if (it) {
return duplicate(it)
}
return undefined
}
/* -------------------------------------------- */
async toggleFightOption( itemId) {
let fightOption = this.data.items.get(itemId)
let state
let updates = []
if ( fightOption) {
fightOption = duplicate(fightOption)
if (fightOption.data.properties.activated) {
state = false
} else {
state = true
}
updates.push( {_id: fightOption._id, 'data.properties.activated': state} ) // Update the selected one
await this.updateEmbeddedDocuments("Item", updates) // Apply all changes
// Then notify
ChatMessage.create({
alias: this.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.name),
content: await renderTemplate('systems/bol/templates/chat/chat-activate-fight-option.hbs', { name: this.name, img: fightOption.img, foName: fightOption.name, state: state} )
})
}
}
/* -------------------------------------------- */
get armorMalusValue() { // used for Fight Options
for(let armor of this.armors) {
if (armor.data.properties.armorQuality.includes("light")) {
return 1
}
if (armor.data.properties.armorQuality.includes("medium")) {
return 2
}
if (armor.data.properties.armorQuality.includes("heavy")) {
return 3
}
}
return 0
}
get resources() {
return Object.values(this.data.data.resources);
return Object.values(this.data.data.resources)
}
get boons() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "boon");
@ -83,13 +148,16 @@ export class BoLActor extends Actor {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "race");
}
get languages() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "language");
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "language")
}
get fightoptions() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "fightoption")
}
get features() {
return this.itemData.filter(i => i.type === "feature");
return this.itemData.filter(i => i.type === "feature")
}
get equipment() {
return this.itemData.filter(i => i.type === "item");
return this.itemData.filter(i => i.type === "item")
}
get armors() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "armor");
@ -100,7 +168,7 @@ export class BoLActor extends Actor {
get shields() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "shield");
}
get weapons() {
return this.itemData.filter(i => i.type === "item" && i.data.category === "equipment" && i.data.subtype === "weapon");
}
@ -267,9 +335,15 @@ export class BoLActor extends Actor {
"label": "BOL.featureCategory.languages",
"ranked": false,
"items": this.languages
},
"fightoptions": {
"label": "BOL.featureCategory.fightoptions",
"ranked": false,
"items": this.fightoptions
}
};
}
}
buildCombat(){
return {
"melee" : {
@ -278,6 +352,7 @@ export class BoLActor extends Actor {
"protection" : false,
"blocking" : false,
"ranged" : false,
"options": false,
"items" : this.melee
},
"ranged" : {
@ -286,6 +361,7 @@ export class BoLActor extends Actor {
"protection" : false,
"blocking" : false,
"ranged" : true,
"options": false,
"items" : this.ranged
},
"protections" : {
@ -294,6 +370,7 @@ export class BoLActor extends Actor {
"protection" : true,
"blocking" : false,
"ranged" : false,
"options": false,
"items" : this.protections
},
"shields" : {
@ -302,9 +379,19 @@ export class BoLActor extends Actor {
"protection" : false,
"blocking" : true,
"ranged" : false,
"options": false,
"items" : this.shields
},
"fightoptions" : {
"label" : "BOL.combatCategory.fightOptions",
"weapon" : false,
"protection" : false,
"blocking" : false,
"ranged" : false,
"options": true,
"items" : this.fightoptions
}
};
}
}
/*-------------------------------------------- */