fix: discipline reset on mana depletion and re-activation after stop
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m35s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m35s
- #143: processTick now removes drained disciplines from activeIds and calls onStopPracticing so currentAction resets to 'meditate' - #144: Removed paused guard from canProceedDiscipline so stopped disciplines can be re-activated - Updated test to match new expected behavior for paused disciplines
This commit is contained in:
@@ -230,12 +230,12 @@ describe('canProceedDiscipline', () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when discipline is paused', () => {
|
||||
it('should return true when discipline is paused (paused state is handled by activate, not canProceedDiscipline)', () => {
|
||||
const state: DisciplineState = { id: 'raw-mastery', xp: 0, paused: true };
|
||||
const result = canProceedDiscipline(rawMastery, state, {
|
||||
rawMana: 1000,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when raw mana is sufficient', () => {
|
||||
|
||||
@@ -154,6 +154,7 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
const newUnlockedEffects: string[] = [];
|
||||
const newProcessedPerks = [...s.processedPerks];
|
||||
|
||||
const drainedIds: string[] = [];
|
||||
for (const id of s.activeIds) {
|
||||
const disc = newDisciplines[id];
|
||||
if (!disc) continue;
|
||||
@@ -168,6 +169,7 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
|
||||
if (!available || available < drain) {
|
||||
newDisciplines[id] = { ...disc, paused: true };
|
||||
drainedIds.push(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -206,8 +208,15 @@ export const useDisciplineStore = create<DisciplineStore>()(
|
||||
MAX_CONCURRENT_DISCIPLINES + 3
|
||||
);
|
||||
|
||||
// Remove mana-drained disciplines from activeIds so onStopPracticing fires
|
||||
const newActiveIds = s.activeIds.filter((aid) => !drainedIds.includes(aid));
|
||||
if (newActiveIds.length === 0 && s.activeIds.length > 0) {
|
||||
get().practicingCallbacks?.onStopPracticing?.();
|
||||
}
|
||||
|
||||
set({
|
||||
disciplines: newDisciplines,
|
||||
activeIds: newActiveIds,
|
||||
totalXP: newXP,
|
||||
concurrentLimit: Math.max(s.concurrentLimit, newLimit),
|
||||
processedPerks: newProcessedPerks,
|
||||
|
||||
@@ -68,7 +68,6 @@ export function canProceedDiscipline(
|
||||
gameState?: { elements?: Record<string, any>; rawMana?: number }
|
||||
): boolean {
|
||||
if (!disciplineState) return true;
|
||||
if (disciplineState.paused) return false;
|
||||
|
||||
// If no game state provided, allow activation (optimistic)
|
||||
if (!gameState) return true;
|
||||
|
||||
Reference in New Issue
Block a user