Skip to content

Commit

Permalink
address Lurkars#451, Lurkars#456, Lurkars#465, some scenario summary …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
Lurkars authored and rdoll committed Dec 31, 2023
1 parent aabde30 commit 82e301a
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 26 deletions.
2 changes: 1 addition & 1 deletion data/fh/scenarios/057.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
}
],
"objectives": [
1
"1:C < 3 ? 1 : 0"
]
}
]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloomhavensecretariat",
"version": "0.83.5",
"version": "0.83.6",
"license": "AGPL3",
"description": "Gloomhaven Secretariat is a Gloomhaven Companion app.",
"homepage": "https://gloomhaven-secretariat.de",
Expand Down
4 changes: 4 additions & 0 deletions src/app/game/businesslogic/CharacterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ export class CharacterManager {
}
});

if (figure instanceof Character && figure.tags.find((tag) => tag === 'time_tokens') && figure.primaryToken == 0) {
figure.identity = 0;
}

if (figure.progress.equippedItems.find((identifier) => identifier.edition == 'cs' && identifier.name == '57') && gameManager.entityManager.hasCondition(figure, new Condition(ConditionName.wound)) && !gameManager.entityManager.hasCondition(figure, new Condition(ConditionName.regenerate))) {
gameManager.entityManager.addCondition(figure, new Condition(ConditionName.regenerate), figure.active, figure.off);
}
Expand Down
10 changes: 0 additions & 10 deletions src/app/game/businesslogic/ScenarioManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@ export class ScenarioManager {
})
}

if (rewards.collectiveResources) {
rewards.collectiveResources.forEach((item) => {
this.game.party.loot[item.type] = (this.game.party.loot[item.type] || 0) + EntityValueFunction(item.value);

if ((this.game.party.loot[item.type] || 0) < 0) {
this.game.party.loot[item.type] = 0;
}
})
}

if (rewards.calendarSection) {
rewards.calendarSection.forEach((calendarSection) => {
if (calendarSection.split('-').length > 1) {
Expand Down
1 change: 1 addition & 0 deletions src/app/game/model/data/ScenarioData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class ScenarioFinish {
success: boolean = false;
battleGoals: number[] = [];
collectiveGold: number[] = [];
collectiveResources: Partial<Record<LootType, number>>[] = [];
items: number[][] = [];
chooseLocation: string | undefined;
chooseUnlockCharacter: string | undefined;
Expand Down
18 changes: 17 additions & 1 deletion src/app/ui/footer/scenario/summary/scenario-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
<span class="head-col calc-col"><span [ghs-label]="'scenario.summary.loot'"></span></span>
<span class="calc-col" *ngFor="let character of characters; let index = index;">
<span *ngIf="!gameManager.game.lootDeck.cards.length">{{character.loot | ghsValueSign}}</span>
<span *ngIf="gameManager.game.lootDeck.cards.length">{{character.lootCards.length}}/{{gameManager.game.lootDeck.cards.length}}</span>
<span
*ngIf="gameManager.game.lootDeck.cards.length">{{character.lootCards.length}}/{{gameManager.game.lootDeck.cards.length}}</span>
</span>

<ng-container *ngIf="success && rewards && rewards.gold">
Expand All @@ -60,6 +61,21 @@
</span>
</ng-container>

<ng-container *ngIf="success && rewards && rewards.collectiveResources">
<ng-container *ngFor="let value of rewards.collectiveResources">


<span class="head-col calc-col"><span [ghs-label]="'scenario.summary.rewards.collectiveResoruce'"
[ghs-label-args]="[value.type]"></span></span>
<span class="calc-col" *ngFor="let character of characters; let index = index;">
<input type="number" min="0" [max]="(collectiveResources[index][value.type] || 0) + availableCollectiveResource(value.type)"
[value]="(collectiveResources[index][value.type] || 0)" (change)="changeCollectiveResource($event, index, value.type)">
</span>

</ng-container>

</ng-container>

<span class="head-col">
<span *ngIf="!totalGold" [ghs-label]="'scenario.summary.gold'"></span>
<ng-container *ngIf="totalGold">
Expand Down
73 changes: 62 additions & 11 deletions src/app/ui/footer/scenario/summary/scenario-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class ScenarioSummaryComponent {
characters: Character[];
battleGoals: number[] = [];
collectiveGold: number[] = [];
collectiveResources: Partial<Record<LootType, number>>[] = [];
lootColumns: LootType[] = [];
lootColumnsLooted: number[] = [];
lootColumnsTotal: number[] = [];
Expand Down Expand Up @@ -178,6 +179,7 @@ export class ScenarioSummaryComponent {
finish.chooseLocation = this.chooseLocation;
finish.chooseUnlockCharacter = this.chooseUnlockCharacter;
finish.collectiveGold = this.collectiveGold;
finish.collectiveResources = this.collectiveResources;
finish.items = this.items;
finish.calendarSectionManual = this.calendarSectionManual;
finish.randomItem = this.randomItem ? new Identifier('' + this.randomItem.id, this.randomItem.edition) : undefined;
Expand All @@ -198,6 +200,7 @@ export class ScenarioSummaryComponent {
this.chooseLocation = finish.chooseLocation;
this.chooseUnlockCharacter = finish.chooseUnlockCharacter;
this.collectiveGold = finish.collectiveGold;
this.collectiveResources = finish.collectiveResources;
this.items = finish.items;
this.calendarSectionManual = finish.calendarSectionManual || finish.calenderSectionManual;
this.randomItem = finish.randomItem ? gameManager.itemManager.getItem(+finish.randomItem.name, finish.randomItem.edition, true) : undefined;
Expand Down Expand Up @@ -233,7 +236,18 @@ export class ScenarioSummaryComponent {

if (settingsManager.settings.scenarioRewards && this.rewards) {
if (this.rewards.collectiveGold) {
this.characters.forEach((char, index) => this.collectiveGold[index] = 0);
this.characters.forEach((char, index) => {
if (!this.collectiveGold[index]) {
this.collectiveGold[index] = 0
}
});
}
if (this.rewards.collectiveResources) {
this.characters.forEach((char, index) => {
if (!this.collectiveResources[index]) {
this.collectiveResources[index] = {};
}
});
}
if (this.rewards.items) {
this.rewards.items.forEach((item, index) => {
Expand Down Expand Up @@ -261,24 +275,25 @@ export class ScenarioSummaryComponent {
})
}
if (this.rewards.chooseItem) {
this.characters.forEach((char, index) => this.items[index] = []);
let index = 0;
this.rewards.chooseItem.forEach((itemList) => {
itemList.forEach((item, index) => {
itemList.forEach((item) => {
const itemData = gameManager.itemManager.getItem(+item.split(':')[0].split('-')[0], item.split(':')[0].split('-').slice(1).join('-') || this.scenario.edition, true);
if (itemData) {
this.rewardItems.push(itemData);
this.rewardItemCount.push(item.indexOf(':') == -1 ? 1 : +item.split(':')[1]);
this.rewardItems[index] = itemData;
this.rewardItemCount[index] = item.indexOf(':') == -1 ? 1 : +item.split(':')[1];
index++;
} else {
console.error("Unknown Item '" + item + "' for scenario '" + this.scenario.index + " (" + this.scenario.edition + ")")
}

})
})
}
if (this.rewards.chooseLocation && this.rewards.chooseLocation.length > 0) {
if (this.rewards.chooseLocation && this.rewards.chooseLocation.length > 0 && !this.chooseLocation) {
this.chooseLocation = this.rewards.chooseLocation[0];
}
if (this.rewards.chooseUnlockCharacter && this.rewards.chooseUnlockCharacter.length > 0) {
if (this.rewards.chooseUnlockCharacter && this.rewards.chooseUnlockCharacter.length > 0 && !this.chooseUnlockCharacter) {
let index = 0;
while (index < this.rewards.chooseUnlockCharacter.length && gameManager.game.unlockedCharacters.indexOf(this.rewards.chooseUnlockCharacter[index]) != -1) {
index++;
Expand All @@ -288,14 +303,18 @@ export class ScenarioSummaryComponent {
}
}
if (this.rewards.calendarSectionManual) {
this.rewards.calendarSectionManual.forEach((section, index) => this.calendarSectionManual[index] = 0);
this.rewards.calendarSectionManual.forEach((section, index) => {
if (!this.calendarSectionManual[index]) {
this.calendarSectionManual[index] = 0;
}
});
}

if (settingsManager.settings.scenarioRewardsItems && this.rewards.randomItemBlueprint && this.randomItemBlueprints.length < this.rewards.randomItemBlueprint) {
for (let i = this.randomItemBlueprints.length; i < this.rewards.randomItemBlueprint; i++) {
let itemData = gameManager.itemManager.drawRandomItem(this.scenario.edition, true);
let item: Identifier | undefined = itemData ? new Identifier('' + itemData.id, itemData.edition) : undefined;
this.randomItemBlueprints.push(item ? (+item.name) : -1);
this.randomItemBlueprints[i] = item ? (+item.name) : -1;
}
}

Expand All @@ -319,13 +338,13 @@ export class ScenarioSummaryComponent {
for (let i = this.randomItems.length; i < this.characters.length; i++) {
const character = this.characters[i];
if (character.absent) {
this.randomItems.push(undefined);
this.randomItems[i] = undefined;
} else {
let itemData = gameManager.itemManager.drawRandomItem(itemEdition, false, from, to);
if (character.progress.items.find((owned) => itemData && owned.name == itemData.id + '' && owned.edition == itemData.edition)) {
itemData = undefined;
}
this.randomItems.push(itemData ? itemData : undefined);
this.randomItems[i] = itemData ? itemData : undefined;
}
}
}
Expand Down Expand Up @@ -378,6 +397,14 @@ export class ScenarioSummaryComponent {
return this.rewards && this.rewards.collectiveGold && this.collectiveGold.length > 0 && (this.rewards.collectiveGold - this.collectiveGold.reduce((a, b) => a + b)) || 0;
}

availableCollectiveResource(type: LootType): number {
const resource: { type: LootType, value: number | string } = this.rewards && this.rewards.collectiveResources && this.rewards.collectiveResources.find((value) => value.type == type) || { type: type, value: 0 };

const value = EntityValueFunction(resource.value);

return value > 0 && (value - this.collectiveResources.map((value) => value[type] || 0).reduce((a, b) => a + b)) || 0;
}

lootValue(character: Character, lootType: LootType): number {
let value = 0;

Expand Down Expand Up @@ -513,6 +540,14 @@ export class ScenarioSummaryComponent {
gameManager.stateManager.after();
}

changeCollectiveResource(event: any, index: number, type: LootType) {
gameManager.stateManager.before("finishScenario.dialog.collectiveResource", type, '' + index, event.target.value);
this.collectiveResources[index] = this.collectiveResources[index] || {};
this.collectiveResources[index][type] = +event.target.value;
this.updateFinish();
gameManager.stateManager.after();
}

changeCalendarSectionManual(event: any, index: number) {
gameManager.stateManager.before("finishScenario.dialog.calendarSectionManual", '' + index, event.target.value);
this.calendarSectionManual[index] = +event.target.value;
Expand Down Expand Up @@ -577,6 +612,13 @@ export class ScenarioSummaryComponent {
character.progress.gold += this.collectiveGold[index];
}

if (this.collectiveResources[index]) {
Object.keys(this.collectiveResources[index]).forEach((value) => {
const lootType: LootType = value as LootType;
character.progress.loot[lootType] = (character.progress.loot[lootType] || 0) + (this.collectiveResources[index][lootType] || 0);
})
}

this.rewardItems.forEach((item, itemIndex) => {
if (this.items.every((items) => items.indexOf(itemIndex) == -1)) {
this.items[index].push(itemIndex);
Expand All @@ -599,6 +641,15 @@ export class ScenarioSummaryComponent {
}
})

if (this.rewards && this.rewards.collectiveResources) {
this.rewards.collectiveResources.forEach((value) => {
const available = this.availableCollectiveResource(value.type);
if (available) {
gameManager.game.party.loot[value.type] = (gameManager.game.party.loot[value.type] || 0) + available;
}
})
}

if (this.chooseLocation) {
gameManager.game.party.manualScenarios.push(new GameScenarioModel(this.chooseLocation, this.scenario.edition, this.scenario.group));
}
Expand Down

0 comments on commit 82e301a

Please sign in to comment.