Fix #30 - Global perl select
This commit is contained in:
parent
d484064fdd
commit
cc0dc9e43c
@ -1543,13 +1543,27 @@ export class PegasusActor extends Actor {
|
||||
if (specExist) {
|
||||
specExist = duplicate(specExist)
|
||||
specExist.system.level += inc;
|
||||
let update = { _id: specExist._id, "data.level": specExist.system.level };
|
||||
let update = { _id: specExist._id, "system.level": specExist.system.level };
|
||||
await this.updateEmbeddedDocuments('Item', [update]);
|
||||
} else {
|
||||
spec.system.level += inc;
|
||||
spec.system.level = inc;
|
||||
await this.createEmbeddedDocuments('Item', [spec]);
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async addIncPerk(perk, inc = 1) {
|
||||
console.log("Using perk : ", perk, inc)
|
||||
let perkExist = this.items.find(item => item.type == 'perk' && item.name.toLowerCase() == perk.name.toLowerCase())
|
||||
if (perkExist) {
|
||||
perkExist = duplicate(perkExist)
|
||||
perkExist.system.level += inc;
|
||||
let update = { _id: perkExist._id, "system.level": perkExist.system.level };
|
||||
await this.updateEmbeddedDocuments('Item', [update]);
|
||||
} else {
|
||||
perk.system.level = inc;
|
||||
await this.createEmbeddedDocuments('Item', [perk]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incDecQuantity(objetId, incDec = 0) {
|
||||
|
@ -187,9 +187,16 @@ export class PegasusActorCreate {
|
||||
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.actor.addIncPerk(perk, 1)
|
||||
let excludedPerks = this.actor.items.filter(it => it.type == "perk" && !it.system.upgradable)
|
||||
this.rolePerks = []
|
||||
for (let perk of this.rolePerks) {
|
||||
if ( !excludedPerks.find(it => it.name == perk.name)) {
|
||||
this.rolePerks.push(perk)
|
||||
}
|
||||
}
|
||||
this.rolePerks.sort(function(a, b) { if (a.name < b.name) {return -1} else {return 1} })
|
||||
this.nbPerks--;
|
||||
this.rolePerks = this.rolePerks.filter(item => item._id != itemId);//Remove selected perk
|
||||
if (this.nbPerks == 0 || this.rolePerks.length == 0) {
|
||||
this.nbGlobalSpec = 5
|
||||
this.showGlobalSpec()
|
||||
@ -218,12 +225,26 @@ export class PegasusActorCreate {
|
||||
this.actor.valueStat(statKey, 1)
|
||||
this.nbGlobalStat--
|
||||
if (this.nbGlobalStat == 0) {
|
||||
this.showCharacterEnd()
|
||||
this.nbGlobalPerk = 1
|
||||
this.showGlobalPerk()
|
||||
//this.showCharacterEnd()
|
||||
} else {
|
||||
this.showGlobalStat()
|
||||
}
|
||||
}
|
||||
|
||||
if (step == 'select-global-perk') {
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget))
|
||||
let perk = this.perks.find(item => item._id == itemId);
|
||||
this.actor.addIncPerk(perk, 1)
|
||||
this.nbGlobalPerk--;
|
||||
if (this.nbGlobalPerk == 0) {
|
||||
this.showCharacterEnd()
|
||||
} else {
|
||||
this.showGlobalPerk()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -451,6 +472,27 @@ export class PegasusActorCreate {
|
||||
this.renderChatMessage(formData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showGlobalPerk() {
|
||||
let formData = this.createFormData("select-global-perk")
|
||||
let excludedPerks = this.actor.items.filter(it => it.type == "perk" && !it.system.upgradable)
|
||||
formData.perks = []
|
||||
for (let perk of this.perks) {
|
||||
let isOK = true
|
||||
for (let excluded of excludedPerks) {
|
||||
if (excluded.name == perk.name) {
|
||||
isOK = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (isOK) {
|
||||
formData.perks.push(perk)
|
||||
}
|
||||
}
|
||||
formData.perks.sort(function compare(a, b) { if (a.name < b.name) { return -1 } else { return 1 } })
|
||||
this.renderChatMessage(formData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async showCharacterEnd() {
|
||||
await this.actor.computeNRGHealth()
|
||||
|
Loading…
Reference in New Issue
Block a user