Skip to content

Commit

Permalink
feat(gathering): gathering locations tell you when their cooldown is up
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Mar 27, 2023
1 parent 3693908 commit 0f2599e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/helpers/cooldowns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StateContext } from '@ngxs/store';
import { patch } from '@ngxs/store/operators';
import { IGameGatherLocation, IGameGathering } from '../../interfaces';
import { NotifyInfo } from '../../stores/game/game.actions';

export function lowerGatheringCooldowns(ctx: StateContext<IGameGathering>, ticks = 1) {
const state = ctx.getState();
Expand All @@ -14,6 +15,7 @@ export function lowerGatheringCooldowns(ctx: StateContext<IGameGathering>, ticks

if(cooldowns[locationKey] <= 0) {
delete cooldowns[locationKey];
ctx.dispatch(new NotifyInfo(`${locationKey} can be gathered from again!`));
}
});

Expand Down Expand Up @@ -43,10 +45,12 @@ export function putLocationOnCooldown(

const locationCooldownReduction = location.cooldownTime * cdrPercent;

const newCooldownTime = Math.max(0, location.cooldownTime - (locationCooldownReduction || 0) - (cdrValue || 0));

ctx.setState(patch<IGameGathering>({
cooldowns: {
...state.cooldowns,
[location.name]: Math.max(0, location.cooldownTime - (locationCooldownReduction || 0) - (cdrValue || 0))
[location.name]: newCooldownTime
}
}));
}

0 comments on commit 0f2599e

Please sign in to comment.