Fraser commited on
Commit
80baaa7
·
1 Parent(s): d1ebfb6
src/lib/components/Pages/Battle.svelte CHANGED
@@ -173,7 +173,7 @@
173
  // Capture successful - end battle and add to roster
174
  setTimeout(() => {
175
  battleEnded = true;
176
- onBattleEnd(true, 'captured'); // Pass special 'captured' result
177
  }, 1000);
178
  } else {
179
  // Capture failed - continue battle
 
173
  // Capture successful - end battle and add to roster
174
  setTimeout(() => {
175
  battleEnded = true;
176
+ onBattleEnd(currentEnemyPiclet); // Pass captured Piclet to add to roster
177
  }, 1000);
178
  } else {
179
  // Capture failed - continue battle
src/lib/components/Pages/Encounters.svelte CHANGED
@@ -321,6 +321,51 @@
321
 
322
  return enemyPiclet;
323
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
 
325
  function handleBattleEnd(result: any) {
326
  showBattle = false;
@@ -333,8 +378,9 @@
333
  // Defeat or ran away
334
  console.log('Battle lost or fled');
335
  } else if (result && result.id) {
336
- // Caught a piclet
337
  console.log('Piclet caught!', result);
 
338
  incrementCounter('picletsCapured');
339
  addProgressPoints(100);
340
  }
 
321
 
322
  return enemyPiclet;
323
  }
324
+
325
+ async function addCapturedPicletToRoster(capturedPiclet: PicletInstance) {
326
+ try {
327
+ // Get all roster piclets to find the next available position
328
+ const allPiclets = await db.picletInstances.toArray();
329
+ const rosterPiclets = allPiclets.filter(p =>
330
+ p.rosterPosition !== undefined &&
331
+ p.rosterPosition !== null &&
332
+ p.rosterPosition >= 0 &&
333
+ p.rosterPosition <= 5
334
+ );
335
+
336
+ // Find next available roster position (0-5)
337
+ let nextPosition = 0;
338
+ const occupiedPositions = new Set(rosterPiclets.map(p => p.rosterPosition));
339
+ while (occupiedPositions.has(nextPosition) && nextPosition <= 5) {
340
+ nextPosition++;
341
+ }
342
+
343
+ if (nextPosition > 5) {
344
+ // Roster is full - for now just add to position 5 (could implement storage system later)
345
+ console.warn('Roster is full, overriding position 5');
346
+ nextPosition = 5;
347
+ }
348
+
349
+ // Update the captured piclet to be in roster
350
+ await db.picletInstances.update(capturedPiclet.id, {
351
+ caught: true,
352
+ caughtAt: new Date(),
353
+ isInRoster: true,
354
+ rosterPosition: nextPosition
355
+ });
356
+
357
+ console.log(`Added captured Piclet ${capturedPiclet.nickname} to roster position ${nextPosition}`);
358
+
359
+ // Get the updated piclet instance and show detail page
360
+ const updatedPiclet = await db.picletInstances.get(capturedPiclet.id);
361
+ if (updatedPiclet) {
362
+ newlyCaughtPiclet = updatedPiclet;
363
+ showNewlyCaught = true;
364
+ }
365
+ } catch (error) {
366
+ console.error('Error adding captured Piclet to roster:', error);
367
+ }
368
+ }
369
 
370
  function handleBattleEnd(result: any) {
371
  showBattle = false;
 
378
  // Defeat or ran away
379
  console.log('Battle lost or fled');
380
  } else if (result && result.id) {
381
+ // Caught a piclet - add to roster
382
  console.log('Piclet caught!', result);
383
+ addCapturedPicletToRoster(result);
384
  incrementCounter('picletsCapured');
385
  addProgressPoints(100);
386
  }