Skip to content

Commit

Permalink
fix(achievements): canceling recipes should not give achievement prog…
Browse files Browse the repository at this point in the history
…ress
  • Loading branch information
seiyria committed Mar 14, 2023
1 parent 0eff8c5 commit 1d5f3b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 1 addition & 3 deletions content/data/jewelcrafting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ recipes:
Dandelion: 12
require:
- Dandelion
preserve:
- Dandelion
maxWorkers: 1

- result: Braided Anklet
Expand Down Expand Up @@ -245,4 +243,4 @@ recipes:
- Iron Jewelry Tools
preserve:
- Iron Jewelry Tools
maxWorkers: 1
maxWorkers: 1
11 changes: 9 additions & 2 deletions src/app/helpers/refined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ export function getRecipeIngredientCosts(recipe: IGameRecipe, amount = 1): Recor
}

export function startRefineJob(ctx: StateContext<IGameRefining>, job: IGameRecipe, quantity: number, refundItems: IGameItem[] = []) {

const recipeCosts = getRecipeIngredientCosts(job, quantity);
const doesRecipeCostAnything = Object.keys(recipeCosts).length > 0;

if(doesRecipeCostAnything) {
ctx.dispatch(new GainResources(recipeCosts));
}

ctx.dispatch([
new GainResources(getRecipeIngredientCosts(job, quantity)),
...refundItems.map(item => new RemoveItemFromInventory(item)),
new PlaySFX('tradeskill-start')
]);
Expand Down Expand Up @@ -113,7 +120,7 @@ export function cancelRefineJob(ctx: StateContext<IGameRefining>, jobIndex: numb
.filter(Boolean)
.reduce((acc, cur) => merge(acc, cur), {});

ctx.dispatch(new GainResources(resourceRefunds, false));
ctx.dispatch(new GainResources(resourceRefunds, false, false));

const itemRefunds = job.refundItems.map(item => new AddItemToInventory(item));
ctx.dispatch(itemRefunds);
Expand Down
2 changes: 1 addition & 1 deletion src/stores/charselect/charselect.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class DiscoverResourceOrItem {

export class GainResources {
static type = '[CharSelect] Gain Resources';
constructor(public resources: Record<string, number>, public shouldNotify = true) {}
constructor(public resources: Record<string, number>, public shouldNotify = true, public countsForAchievements = true) {}
}

export class GainItemOrResource {
Expand Down
8 changes: 5 additions & 3 deletions src/stores/charselect/charselect.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ export function setActiveCharacter(ctx: StateContext<ICharSelect>, { charSlot }:
}));
}

export function gainResources(ctx: StateContext<ICharSelect>, { resources }: GainResources) {
export function gainResources(ctx: StateContext<ICharSelect>, { resources, countsForAchievements }: GainResources) {
const state = ctx.getState();
const currentCharacter = state.characters[state.currentCharacter];
if(!currentCharacter) {
return;
}

const gainedResources = sum(Object.values(resources));
ctx.dispatch(new IncrementStat(AchievementStat.ResourcesGained, gainedResources));
const gainedResources = sum(Object.values(resources).filter(x => x > 0));
if(countsForAchievements && gainedResources > 0) {
ctx.dispatch(new IncrementStat(AchievementStat.ResourcesGained, gainedResources));
}

Object.keys(resources).forEach(resource => {
if(!currentCharacter.resources[resource]) {
Expand Down
2 changes: 2 additions & 0 deletions src/stores/charselect/charselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export class CharSelectState {
return;
}

console.log(resources, shouldNotify);

const resourceNames = Object.keys(resources);
const earnedNothing = resourceNames.length === 0 || (resourceNames.includes('nothing') && resourceNames.length === 1);

Expand Down

0 comments on commit 1d5f3b4

Please sign in to comment.