Fix race
This commit is contained in:
@@ -477,10 +477,24 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async deleteAllItemsByType( itemType) {
|
||||
let items = this.data.items.filter( item => item.type == itemType);
|
||||
await this.deleteEmbeddedDocuments( 'Item', items);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async modStat( key, inc=1) {
|
||||
let stat = duplicate(this.data.data.statistics[key])
|
||||
stat.mod += parseInt(inc)
|
||||
await this.update( { [`data.statistics.${key}`] : stat } )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async applyRace( race ) {
|
||||
let updates = { 'data.racename':race.name }
|
||||
let newItems = []
|
||||
await this.deleteAllItemsByType( 'race')
|
||||
newItems.push(race);
|
||||
|
||||
for (let ability of race.data.abilities) {
|
||||
@@ -501,8 +515,26 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
applyRole( role ) {
|
||||
getIncreaseStatValue( updates, statKey) {
|
||||
let stat = duplicate(this.data.data.statistics[statKey])
|
||||
stat.value += 1;
|
||||
updates[`data.statistics.${statKey}`] = stat
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async applyRole( role ) {
|
||||
console.log("ROLE", role)
|
||||
|
||||
let updates = { 'data.rolename': role.name }
|
||||
let newItems = []
|
||||
await this.deleteAllItemsByType( 'role')
|
||||
newItems.push(role);
|
||||
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease1)
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease2)
|
||||
|
||||
await this.update( updates )
|
||||
await this.createEmbeddedDocuments('Item', newItems)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
@@ -27,7 +27,14 @@ export class PegasusActorCreate {
|
||||
img: this.actor.img,
|
||||
step: step,
|
||||
races: this.races,
|
||||
roles: this.roles
|
||||
roles: this.roles,
|
||||
nboptionnal: this.raceOptionnalAbilities?.nboptionnal?? 0,
|
||||
optionnalabilities: this.raceOptionnalAbilities?.optionnalabilities?? [],
|
||||
}
|
||||
if ( this.raceSelectableStats ) {
|
||||
formData.numberstats = this.raceSelectableStats.numberstats;
|
||||
formData.statsonlyonce = this.raceSelectableStats.statsonlyonce;
|
||||
formData.stats = this.raceSelectableStats.stats;
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
@@ -39,8 +46,103 @@ export class PegasusActorCreate {
|
||||
console.log("Create chat evet", event, itemId, step)
|
||||
if ( step == "select-race") {
|
||||
let race = this.races.find( item => item._id == itemId);
|
||||
this.actor.applyRace( race)
|
||||
this.actor.applyRace( race);
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
if ( race.data.nboptionnal > 0 && race.data.optionnalabilities.length > 0) {
|
||||
this.manageOptionnalAbilities(race);
|
||||
} else {
|
||||
if ( race.data.selectablestats ) {
|
||||
this.manageSelectableStats(race);
|
||||
} else {
|
||||
this.showRoles()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( step == 'select-race-optionnal') {
|
||||
let ability = this.raceOptionnalAbilities.optionnalabilities.find( item => item._id == itemId);
|
||||
this.actor.createEmbeddedDocuments( 'Item', [ability]);
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
this.raceOptionnalAbilities.optionnalabilities = this.raceOptionnalAbilities.optionnalabilities.filter( item => item._id != itemId);
|
||||
this.raceOptionnalAbilities.nboptionnal -= 1;
|
||||
this.processOptionnalAbilitiesStep();
|
||||
}
|
||||
|
||||
if (step == 'select-race-stats') {
|
||||
let statKey = $(event.currentTarget).data("stat-key");
|
||||
this.actor.modStat( statKey, 1);
|
||||
this.raceSelectableStats.stats[statKey].used = true;
|
||||
this.raceSelectableStats.numberstats -=1;
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
this.processSelectableStats();
|
||||
}
|
||||
|
||||
if ( step == 'select-role') {
|
||||
let role = this.roles.find( item => item._id == itemId);
|
||||
this.actor.applyRole( role );
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
manageSelectableStats( race ) {
|
||||
this.raceSelectableStats = {
|
||||
"race": race,
|
||||
"statsonlyonce": race.data.statsonlyonce,
|
||||
"numberstats": race.data.numberstats,
|
||||
"stats": duplicate(this.actor.data.data.statistics)
|
||||
}
|
||||
this.processSelectableStats()
|
||||
}
|
||||
|
||||
/* --------------- ----------------------------- */
|
||||
async processSelectableStats() {
|
||||
// End of race options choice
|
||||
if ( this.raceSelectableStats.numberstats == 0) {
|
||||
this.showRoles()
|
||||
return;
|
||||
}
|
||||
let formData = this.createFormData("select-race-stats")
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
alias : this.actor.name,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
|
||||
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
|
||||
};
|
||||
//console.log("Apply damage chat", chatData );
|
||||
await ChatMessage.create( chatData );
|
||||
}
|
||||
|
||||
/* --------------- ----------------------------- */
|
||||
manageOptionnalAbilities( race) {
|
||||
this.raceOptionnalAbilities = {
|
||||
"nboptionnal": race.data.nboptionnal,
|
||||
"optionnalabilities": duplicate(race.data.optionnalabilities),
|
||||
}
|
||||
this.processOptionnalAbilitiesStep()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processOptionnalAbilitiesStep() {
|
||||
// End of race options choice
|
||||
if ( this.raceOptionnalAbilities.nboptionnal == 0) {
|
||||
if ( this.raceSelectableStats ) {
|
||||
this.manageSelectableStats(this.raceSelectableStats.race);
|
||||
} else {
|
||||
this.showRoles()
|
||||
}
|
||||
}
|
||||
let formData = this.createFormData("select-race-optionnal")
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
alias : this.actor.name,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
|
||||
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
|
||||
};
|
||||
//console.log("Apply damage chat", chatData );
|
||||
await ChatMessage.create( chatData );
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -59,8 +161,14 @@ export class PegasusActorCreate {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showRoles() {
|
||||
console.log("Available roles", roles);
|
||||
|
||||
// TODO : display buttons
|
||||
let formData = this.createFormData("select-role")
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
alias : this.actor.name,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
|
||||
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
|
||||
};
|
||||
await ChatMessage.create( chatData );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,14 +207,22 @@ export class PegasusItemSheet extends ItemSheet {
|
||||
return item;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async addAbility(item, dataItem) {
|
||||
let abilityArray = duplicate(this.object.data.data.abilities);
|
||||
async addAbility(event, item, dataItem) {
|
||||
let newItem = duplicate(item.data);
|
||||
newItem._id = randomID( dataItem.id.length );
|
||||
abilityArray.push( newItem);
|
||||
await this.object.update( { 'data.abilities': abilityArray} );
|
||||
console.log("ABB", event, item, dataItem)
|
||||
if ( event.toElement.className == 'drop-abilities') {
|
||||
let abilityArray = duplicate(this.object.data.data.abilities);
|
||||
abilityArray.push( newItem);
|
||||
await this.object.update( { 'data.abilities': abilityArray} );
|
||||
}
|
||||
if ( event.toElement.className == 'drop-optionnal-abilities') {
|
||||
let abilityArray = duplicate(this.object.data.data.optionnalabilities);
|
||||
abilityArray.push( newItem);
|
||||
await this.object.update( { 'data.optionnalabilities': abilityArray} );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addSpecialisation(item, dataItem) {
|
||||
let newItem = duplicate(item.data);
|
||||
@@ -306,13 +314,13 @@ export class PegasusItemSheet extends ItemSheet {
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
//console.log(event);
|
||||
if (this.object.type == 'race' ) {
|
||||
if (this.object.type == 'race' ) {
|
||||
let data = event.dataTransfer.getData('text/plain');
|
||||
if (data) {
|
||||
let dataItem = JSON.parse( data );
|
||||
let item = await this.searchItem( dataItem);
|
||||
if ( item.data.type == 'ability') {
|
||||
return this.addAbility( item, dataItem);
|
||||
return this.addAbility( event, item, dataItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { PegasusUtility } from "./pegasus-utility.js";
|
||||
export const defaultItemImg = {
|
||||
specialisation: "systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp",
|
||||
perk: "systems/fvtt-pegasus-rpg/images/icons/icon_perk.webp",
|
||||
ability: "systems/fvtt-pegasus-rpg/images/icons/icon_ability.webp",
|
||||
ability: "systems/fvtt-pegasus-rpg/images/icons/icon_raceability.webp",
|
||||
armor: "systems/fvtt-pegasus-rpg/images/icons/icon_armor.webp",
|
||||
weapon: "systems/fvtt-pegasus-rpg/images/icons/icon_weapon.webp",
|
||||
equipment: "systems/fvtt-pegasus-rpg/images/icons/icon_equipment.webp",
|
||||
|
||||
@@ -137,6 +137,35 @@ export class PegasusUtility {
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static removeChatMessageId(messageId) {
|
||||
if (messageId){
|
||||
game.messages.get(messageId)?.delete();
|
||||
}
|
||||
}
|
||||
|
||||
static findChatMessageId(current) {
|
||||
return PegasusUtility.getChatMessageId(PegasusUtility.findChatMessage(current));
|
||||
}
|
||||
|
||||
static getChatMessageId(node) {
|
||||
return node?.attributes.getNamedItem('data-message-id')?.value;
|
||||
}
|
||||
|
||||
static findChatMessage(current) {
|
||||
return PegasusUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'));
|
||||
}
|
||||
|
||||
static findNodeMatching(current, predicate) {
|
||||
if (current) {
|
||||
if (predicate(current)) {
|
||||
return current;
|
||||
}
|
||||
return PegasusUtility.findNodeMatching(current.parentElement, predicate);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static templateData(it) {
|
||||
return PegasusUtility.data(it)?.data ?? {}
|
||||
|
||||
Reference in New Issue
Block a user