Skip to content

Commit

Permalink
Merge pull request #117 from BaptisteLongy/gold-planner-rework
Browse files Browse the repository at this point in the history
Gold planner rework
  • Loading branch information
fayaine authored Jul 10, 2024
2 parents 8a6b79a + 36ede1c commit 31aa9fb
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export class SettingsService extends FirestoreStorage<Settings> {
switchMap(uid => {
return this.getOne(uid).pipe(
switchMap(settings => {
if (settings.notFound || Object.keys(settings).length < 6) {
if (settings.notFound || Object.keys(settings).length < 7) {
const result = {
...settings,
hiddenOnCompletion: false,
crystallineAura: true,
lazytracking: {},
chestConfiguration: {},
goldPlannerConfiguration: {},
forceAbyss: {}
};
return this.setOne(uid, result).pipe(
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/app/model/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export interface Settings extends DataModel {
manualGoldEntries: Record<string, ManualWeeklyGoldEntry>;
// True = skip chest, False = take chest
chestConfiguration: Record<string, boolean>;
// True = skip gold, False = take gold
goldPlannerConfiguration: Record<string, boolean>;
forceAbyss: Record<string, boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@
*ngFor="let flag of row.flags; index as i; trackBy: trackByIndex">
<div class="cell-container">
<ng-container *ngIf="flag.value !== null || flag.force">
<nz-switch nzCheckedChildren="Taking"
nzUnCheckedChildren="Skipping"
[ngModel]="!flag.value"
(ngModelChange)="setChestFlag(settings.$key, display.tracking, row.gTask, roster[i], $event)"></nz-switch>
(<img src="./assets/icons/gold.png" class="gold-icon" alt="gold">{{row.gTask.chestPrice}})
<div class="switch-container">
<nz-switch nzCheckedChildren="Taking gold"
nzUnCheckedChildren="Skipping gold"
[ngModel]="!flag.taking"
(ngModelChange)="setGoldTakingFlag(settings.$key, display.tracking, row.gTask, roster[i], $event)"></nz-switch>
</div>
<div class="switch-container">
<nz-switch nzCheckedChildren="Taking chest"
nzUnCheckedChildren="Skipping chest"
[ngModel]="!flag.value"
(ngModelChange)="setChestFlag(settings.$key, display.tracking, row.gTask, roster[i], $event)"
class="chest-switch"></nz-switch>
( -{{row.gTask.chestPrice}}<img src="./assets/icons/gold.png" class="gold-icon" alt="gold"> )
</div>
</ng-container>
<div *ngIf="(flag.value === null || flag.force) && (flag.force !== null)">
<label nz-checkbox [(ngModel)]="flag.force"
Expand All @@ -51,12 +60,12 @@
</td>
</tr>
</ng-container>
<tr>
<!-- <tr>
<td nzLeft nzWidth="300px">Large Gold Chest(s) - (<img src="./assets/icons/gold.png"
class="gold-icon" alt="gold">{{display.chestGold | number}})</td>
<td [attr.colspan]="display.total.length" class="roster-income">
</td>
</tr>
</tr> -->
<tr>
<td nzLeft nzWidth="300px">Chaos Dungeons</td>
<td class="manual-row" *ngFor="let character of roster">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@
.cell-container {
width: 200px;
display: flex;
flex-direction: column;
flex-wrap: wrap;

> div {
margin-left: 5px;
}
}

.switch-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-bottom: 5px;
}

.chest-switch {
margin-right: 5px;
}

.total-cell {
font-size: 14px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { Character } from "../../../model/character/character";
import { TimeService } from "../../../core/time.service";
import { ManualWeeklyGoldEntry, Settings } from "../../../model/settings";
import { UpdateData } from "@angular/fire/firestore";

import { getCompletionEntry } from '../../../core/get-completion-entry-key';

interface GoldPlannerDisplay {
chestsData: {
task?: LostarkTask,
gTask: GoldTask,
flags: { value: boolean | null, force: boolean | null }[]
flags: { value: boolean | null, force: boolean | null, taking: boolean | null }[]
}[];
chaos: Record<string, number>;
other: Record<string, number>;
Expand All @@ -33,6 +33,7 @@ interface GoldPlannerDisplay {
styleUrls: ["./gold-planner.component.less"]
})
export class GoldPlannerComponent {
public rawRoster$ = this.rosterService.roster$;
public roster$ = this.rosterService.roster$.pipe(
map(roster => roster.characters)
);
Expand All @@ -41,14 +42,14 @@ export class GoldPlannerComponent {

public tasks$ = this.tasksService.tasks$;

public tracking$ = this.settings.settings$.pipe(pluck("chestConfiguration"));
public tracking$ = this.settings.settings$.pipe(pluck("goldPlannerConfiguration"));
public manualGoldEntries$ = this.settings.settings$.pipe(pluck("manualGoldEntries"));
public forceAbyss$ = this.settings.settings$.pipe(pluck("forceAbyss"));

private goldChestRewardPerIlvl = {
1302: 2 * 1250,
1415: 3 * 1250,
1490: 4 * 1250
1490: 4 * 1250
};

public display$: Observable<GoldPlannerDisplay> = combineLatest([
Expand All @@ -58,9 +59,10 @@ export class GoldPlannerComponent {
of(goldTasks),
this.forceAbyss$,
this.manualGoldEntries$,
this.timeService.lastWeeklyReset$
this.timeService.lastWeeklyReset$,
this.rawRoster$
]).pipe(
map(([roster, tasks, tracking, gTasks, forceAbyss, manualGoldEntries, weeklyReset]) => {
map(([roster, tasks, tracking, gTasks, forceAbyss, manualGoldEntries, weeklyReset, rawRoster]) => {
const chestsData = gTasks
.map(gTask => {
if (gTask.taskName) {
Expand All @@ -83,7 +85,15 @@ export class GoldPlannerComponent {
if (!task || !character.weeklyGold) {
return {
force: null,
value: null
value: null,
taking: null
};
}
if (getCompletionEntry(rawRoster.trackedTasks, character, task, true) === false) {
return {
force: null,
value: null,
taking: null
};
}
const cantDoTask = task && (!task.enabled || character.ilvl < (task.minIlvl || 0) || character.ilvl >= (task.maxIlvl || Infinity));
Expand All @@ -99,28 +109,27 @@ export class GoldPlannerComponent {
if (highestPossible.gTask.name !== gTask.name) {
return {
force: null,
value: null
value: null,
taking: null
};
}
}
if (cantDoTask || ilvlTooLow || ilvlTooHigh) {
if (!forceFlag) {
return {
force: gTask.canForce && !ilvlTooHigh ? false : null,
value: null
value: null,
taking: null
};
}
}
const flag = tracking[this.getGoldChestFlag(character.name, gTask)];
if (flag === undefined) {
return {
force: forceFlag,
value: true
};
}
const goldChestflag = tracking[this.getGoldChestFlag(character.name, gTask)];
const takingFlag = tracking[this.getGoldTakingFlag(character.name, gTask)];

return {
force: forceFlag,
value: flag
value: goldChestflag === undefined ? true : goldChestflag,
taking: takingFlag === undefined ? true : takingFlag
};
});
return {
Expand Down Expand Up @@ -155,21 +164,21 @@ export class GoldPlannerComponent {
.reduce((acc, row) => {
const { gTask, flags } = row;
flags.forEach((flag, i) => {
// True = skip gold, False = take gold
if (flag.taking === false) {
acc[i] += gTask.goldReward
}

let chestPrice = (gTask.chestPrice || 0);
if (gTask.chestId && flag.value === false) {
if (chestIdsDone[`${gTask.chestId}:${i}`]) {
chestPrice = 0;
}
chestIdsDone[`${gTask.chestId}:${i}`] = true;
}
// Switch case to avoid null == false
switch (flag.value) {
case true:
acc[i] += (gTask.goldReward || 0);
break;
case false:
acc[i] += (gTask.goldReward || 0) - chestPrice;
break;
// True = skip chest, False = take chest
if (flag.value === false) {
acc[i] -= chestPrice
}
});
return acc;
Expand All @@ -190,7 +199,7 @@ export class GoldPlannerComponent {
total,
forceAbyss,
tracking,
grandTotal: total.reduce((acc, v) => acc + v, chestGold),
grandTotal: total.reduce((acc, v) => acc + v, 0),
chestGold,
chaos,
other
Expand All @@ -215,9 +224,9 @@ export class GoldPlannerComponent {
);

constructor(private rosterService: RosterService,
private tasksService: TasksService,
private settings: SettingsService,
private timeService: TimeService) {
private tasksService: TasksService,
private settings: SettingsService,
private timeService: TimeService) {
}

private getGoldChestFlag(characterName: string, gTask: GoldTask): string {
Expand All @@ -227,6 +236,10 @@ export class GoldPlannerComponent {
return `${characterName}:gold:${gTask.name}`;
}

private getGoldTakingFlag(characterName: string, gTask: GoldTask): string {
return `${characterName}:gold:taking:${gTask.name}`;
}

private getGoldEntry(type: string, characterName: string, weeklyReset: number, data: Record<string, ManualWeeklyGoldEntry>): number {
const entry: ManualWeeklyGoldEntry = data[`${type}:${characterName}`] || { amount: 0, timestamp: Date.now() };
if (entry.timestamp < weeklyReset) {
Expand All @@ -245,7 +258,15 @@ export class GoldPlannerComponent {
tracking[this.getGoldChestFlag(character.name, gTask)] = !flag;
this.settings.patch({
$key: settingsKey,
chestConfiguration: tracking
goldPlannerConfiguration: tracking
});
}

setGoldTakingFlag(settingsKey: string, tracking: Record<string, boolean>, gTask: GoldTask, character: Character, flag: boolean): void {
tracking[this.getGoldTakingFlag(character.name, gTask)] = !flag;
this.settings.patch({
$key: settingsKey,
goldPlannerConfiguration: tracking
});
}

Expand All @@ -262,10 +283,9 @@ export class GoldPlannerComponent {
}

manualGoldFormatter(value: number | string): number {
if(!value || typeof value === 'string' ) {
if (!value || typeof value === 'string') {
return 0;
}

return Math.floor(value);
};
}

0 comments on commit 31aa9fb

Please sign in to comment.