Char creation
This commit is contained in:
@@ -483,6 +483,24 @@ export class PegasusActor extends Actor {
|
||||
await this.deleteEmbeddedDocuments( 'Item', items);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addItemWithoutDuplicate( newItem ) {
|
||||
let item = this.data.items.filter( item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase() )
|
||||
if ( !item ) {
|
||||
await this.createEmbeddedDocuments( 'Item', [newItem]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeNRGHealth( ) {
|
||||
let focValue = this.data.data.statistics.foc.value;
|
||||
this.update( {'data.secondary.nrg.max': focValue, 'data.secondary.nrg.value': focValue} )
|
||||
let phyValue = this.data.data.statistics.phy.value;
|
||||
this.update( {'data.secondary.health.max': phyValue, 'data.secondary.health.value': phyValue} )
|
||||
let mndValue = this.data.data.statistics.mnd.value;
|
||||
this.update( {'data.secondary.delirium.max': mndValue, 'data.secondary.delirium.value': mndValue} )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async modStat( key, inc=1) {
|
||||
let stat = duplicate(this.data.data.statistics[key])
|
||||
@@ -490,6 +508,29 @@ export class PegasusActor extends Actor {
|
||||
await this.update( { [`data.statistics.${key}`] : stat } )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async valueStat( key, inc=1) {
|
||||
key = key.toLowerCase()
|
||||
let stat = duplicate( this.data.data.statistics[key] )
|
||||
stat.value += parseInt(inc)
|
||||
await this.update( { [`data.statistics.${key}`] : stat } )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addIncSpec( spec, inc=1) {
|
||||
console.log("Using spec : ", spec, inc)
|
||||
let specExist = this.data.items.find( item => item.type == 'specialisation' && item.name.toLowerCase() == spec.name.toLowerCase())
|
||||
if (specExist) {
|
||||
specExist = duplicate(specExist)
|
||||
specExist.data.level += inc;
|
||||
let update = { _id: specExist._id, "data.level": specExist.data.level };
|
||||
await this.updateEmbeddedDocuments('Item', [ update ]);
|
||||
} else {
|
||||
spec.data.level += inc;
|
||||
await this.createEmbeddedDocuments( 'Item', [ spec ]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async applyRace( race ) {
|
||||
let updates = { 'data.racename':race.name }
|
||||
@@ -533,6 +574,9 @@ export class PegasusActor extends Actor {
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease1)
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease2)
|
||||
|
||||
newItems = newItems.concat(duplicate(role.data.specialisationsplus1))
|
||||
newItems = newItems.concat(duplicate(role.data.specialperk))
|
||||
|
||||
await this.update( updates )
|
||||
await this.createEmbeddedDocuments('Item', newItems)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,66 @@ export class PegasusActorCreate {
|
||||
|
||||
if ( step == 'select-role') {
|
||||
let role = this.roles.find( item => item._id == itemId);
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
this.actor.applyRole( role );
|
||||
this.currentRole = role;
|
||||
this.nbRoleStat = 2;
|
||||
this.roleStats = duplicate(role.data.statincreasechoice)
|
||||
this.showRoleStat( );
|
||||
}
|
||||
|
||||
if ( step == 'select-role-stat') {
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
let statKey = $(event.currentTarget).data("stat-key");
|
||||
this.actor.valueStat( statKey, 1);
|
||||
|
||||
for (let stat of this.roleStats ) {
|
||||
if ( stat.name.toLowerCase() == statKey.toLowerCase()) {
|
||||
stat.flag = false
|
||||
}
|
||||
}
|
||||
this.nbRoleStat--;
|
||||
if ( this.nbRoleStat == 0 || this.roleStats.length == 0) {
|
||||
this.roleSpec = duplicate(this.currentRole.data.specincrease)
|
||||
this.nbDT2 = 1;
|
||||
this.nbDT1 = 2;
|
||||
this.showRoleSpecialisations()
|
||||
} else{
|
||||
this.showRoleStat( );
|
||||
}
|
||||
}
|
||||
|
||||
if (step == 'select-role-spec') {
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
let spec = this.roleSpec.find( item => item._id == itemId);
|
||||
if (this.nbDT2 > 0) {
|
||||
this.actor.addIncSpec(spec, 2)
|
||||
this.nbDT2--;
|
||||
} else {
|
||||
this.actor.addIncSpec(spec, 1)
|
||||
this.nbDT1--;
|
||||
}
|
||||
this.roleSpec = this.roleSpec.filter( item => item._id != itemId);//Remove selected spec
|
||||
if ( this.nbDT1 == 0 || this.roleSpec.length == 0) {
|
||||
this.rolePerks = duplicate(this.currentRole.data.perks)
|
||||
this.nbPerks = 2;
|
||||
this.showRolePerks()
|
||||
} else {
|
||||
this.showRoleSpecialisations()
|
||||
}
|
||||
}
|
||||
|
||||
if (step == 'select-role-perk') {
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
let perk = this.rolePerks.find( item => item._id == itemId);
|
||||
this.actor.addItemWithoutDuplicate(perk)
|
||||
this.nbPerks--;
|
||||
this.rolePerks = this.rolePerks.filter( item => item._id != itemId);//Remove selected perk
|
||||
if (this.nbPerks == 0 || this.rolePerks.length == 0) {
|
||||
this.showCharacterEnd()
|
||||
} else {
|
||||
this.showRolePerks()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,4 +230,72 @@ export class PegasusActorCreate {
|
||||
};
|
||||
await ChatMessage.create( chatData );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showRoleStat( ) {
|
||||
let formData = this.createFormData("select-role-stat")
|
||||
formData.rolestats = []
|
||||
for(let stat of this.roleStats) {
|
||||
if (stat.flag) {
|
||||
formData.rolestats.push( duplicate(this.actor.data.data.statistics[stat.name.toLowerCase()]) )
|
||||
}
|
||||
}
|
||||
console.log("STAT", this.roleStats, formData)
|
||||
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 );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showRoleSpecialisations() {
|
||||
let formData = this.createFormData("select-role-spec")
|
||||
formData.rolespec = duplicate(this.roleSpec)
|
||||
formData.dt = 1
|
||||
if (this.nbDT2 > 0 ) {
|
||||
formData.dt = 2
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showRolePerks() {
|
||||
let formData = this.createFormData("select-role-perk")
|
||||
formData.roleperks = duplicate(this.rolePerks)
|
||||
formData.nbperks = this.nbPerks
|
||||
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 );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showCharacterEnd() {
|
||||
this.actor.computeNRGHealth()
|
||||
let formData = this.createFormData("character-end")
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user