fix enc
Browse files
src/lib/components/Pages/Encounters.svelte
CHANGED
|
@@ -60,11 +60,11 @@
|
|
| 60 |
}
|
| 61 |
|
| 62 |
async function loadPicletImages() {
|
| 63 |
-
const
|
| 64 |
-
e.type === EncounterType.WILD_PICLET && e.picletTypeId
|
| 65 |
);
|
| 66 |
|
| 67 |
-
for (const encounter of
|
| 68 |
if (!encounter.picletTypeId) continue;
|
| 69 |
|
| 70 |
// Find a piclet instance with this typeId
|
|
@@ -103,7 +103,10 @@
|
|
| 103 |
}
|
| 104 |
|
| 105 |
async function handleEncounterTap(encounter: Encounter) {
|
| 106 |
-
if (encounter.type === EncounterType.
|
|
|
|
|
|
|
|
|
|
| 107 |
// Regular wild encounter - start battle
|
| 108 |
await startBattle(encounter);
|
| 109 |
} else if (encounter.type === EncounterType.SHOP) {
|
|
@@ -136,6 +139,45 @@
|
|
| 136 |
console.error('Error at health center:', error);
|
| 137 |
}
|
| 138 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
async function forceEncounterRefresh() {
|
| 141 |
isRefreshing = true;
|
|
@@ -157,6 +199,8 @@
|
|
| 157 |
return '❤️';
|
| 158 |
case EncounterType.TRAINER_BATTLE:
|
| 159 |
return '🏆';
|
|
|
|
|
|
|
| 160 |
case EncounterType.WILD_PICLET:
|
| 161 |
default:
|
| 162 |
return '⚔️';
|
|
@@ -167,6 +211,8 @@
|
|
| 167 |
switch (encounter.type) {
|
| 168 |
case EncounterType.WILD_PICLET:
|
| 169 |
return '#4caf50';
|
|
|
|
|
|
|
| 170 |
case EncounterType.TRAINER_BATTLE:
|
| 171 |
return '#ff9800';
|
| 172 |
case EncounterType.SHOP:
|
|
@@ -335,11 +381,11 @@
|
|
| 335 |
disabled={isRefreshing}
|
| 336 |
>
|
| 337 |
<div class="encounter-icon">
|
| 338 |
-
{#if encounter.type === EncounterType.WILD_PICLET && encounter.picletTypeId}
|
| 339 |
{#if monsterImages.has(encounter.picletTypeId)}
|
| 340 |
<img
|
| 341 |
src={monsterImages.get(encounter.picletTypeId)}
|
| 342 |
-
alt="
|
| 343 |
/>
|
| 344 |
{:else}
|
| 345 |
<div class="fallback-icon">{getEncounterIcon(encounter)}</div>
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
async function loadPicletImages() {
|
| 63 |
+
const picletEncounters = encounters.filter(e =>
|
| 64 |
+
(e.type === EncounterType.WILD_PICLET || e.type === EncounterType.FIRST_PICLET) && e.picletTypeId
|
| 65 |
);
|
| 66 |
|
| 67 |
+
for (const encounter of picletEncounters) {
|
| 68 |
if (!encounter.picletTypeId) continue;
|
| 69 |
|
| 70 |
// Find a piclet instance with this typeId
|
|
|
|
| 103 |
}
|
| 104 |
|
| 105 |
async function handleEncounterTap(encounter: Encounter) {
|
| 106 |
+
if (encounter.type === EncounterType.FIRST_PICLET) {
|
| 107 |
+
// First piclet encounter - direct catch
|
| 108 |
+
await handleFirstPicletEncounter(encounter);
|
| 109 |
+
} else if (encounter.type === EncounterType.WILD_PICLET && encounter.picletTypeId) {
|
| 110 |
// Regular wild encounter - start battle
|
| 111 |
await startBattle(encounter);
|
| 112 |
} else if (encounter.type === EncounterType.SHOP) {
|
|
|
|
| 139 |
console.error('Error at health center:', error);
|
| 140 |
}
|
| 141 |
}
|
| 142 |
+
|
| 143 |
+
async function handleFirstPicletEncounter(encounter: Encounter) {
|
| 144 |
+
try {
|
| 145 |
+
if (!encounter.picletInstanceId) {
|
| 146 |
+
throw new Error('No piclet instance specified for first piclet encounter');
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// Get the specific piclet instance
|
| 150 |
+
const picletInstance = await db.picletInstances.get(encounter.picletInstanceId);
|
| 151 |
+
if (!picletInstance) {
|
| 152 |
+
throw new Error('Piclet instance not found');
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// Mark the piclet as caught and set it as the first roster piclet
|
| 156 |
+
await db.picletInstances.update(encounter.picletInstanceId, {
|
| 157 |
+
caught: true,
|
| 158 |
+
caughtAt: new Date(),
|
| 159 |
+
isInRoster: true,
|
| 160 |
+
rosterPosition: 0
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
// Get the updated piclet instance
|
| 164 |
+
const caughtPiclet = await db.picletInstances.get(encounter.picletInstanceId);
|
| 165 |
+
|
| 166 |
+
// Show the newly caught piclet detail page
|
| 167 |
+
newlyCaughtPiclet = caughtPiclet!;
|
| 168 |
+
showNewlyCaught = true;
|
| 169 |
+
|
| 170 |
+
// Update counters and progress
|
| 171 |
+
incrementCounter('picletsCapured');
|
| 172 |
+
addProgressPoints(100);
|
| 173 |
+
|
| 174 |
+
// Force refresh encounters to remove the first piclet encounter
|
| 175 |
+
await forceEncounterRefresh();
|
| 176 |
+
} catch (error) {
|
| 177 |
+
console.error('Error handling first piclet encounter:', error);
|
| 178 |
+
alert('Something went wrong. Please try again.');
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
|
| 182 |
async function forceEncounterRefresh() {
|
| 183 |
isRefreshing = true;
|
|
|
|
| 199 |
return '❤️';
|
| 200 |
case EncounterType.TRAINER_BATTLE:
|
| 201 |
return '🏆';
|
| 202 |
+
case EncounterType.FIRST_PICLET:
|
| 203 |
+
return '✨';
|
| 204 |
case EncounterType.WILD_PICLET:
|
| 205 |
default:
|
| 206 |
return '⚔️';
|
|
|
|
| 211 |
switch (encounter.type) {
|
| 212 |
case EncounterType.WILD_PICLET:
|
| 213 |
return '#4caf50';
|
| 214 |
+
case EncounterType.FIRST_PICLET:
|
| 215 |
+
return '#ffd700';
|
| 216 |
case EncounterType.TRAINER_BATTLE:
|
| 217 |
return '#ff9800';
|
| 218 |
case EncounterType.SHOP:
|
|
|
|
| 381 |
disabled={isRefreshing}
|
| 382 |
>
|
| 383 |
<div class="encounter-icon">
|
| 384 |
+
{#if (encounter.type === EncounterType.WILD_PICLET || encounter.type === EncounterType.FIRST_PICLET) && encounter.picletTypeId}
|
| 385 |
{#if monsterImages.has(encounter.picletTypeId)}
|
| 386 |
<img
|
| 387 |
src={monsterImages.get(encounter.picletTypeId)}
|
| 388 |
+
alt="Piclet"
|
| 389 |
/>
|
| 390 |
{:else}
|
| 391 |
<div class="fallback-icon">{getEncounterIcon(encounter)}</div>
|
src/lib/db/encounterService.ts
CHANGED
|
@@ -112,9 +112,10 @@ export class EncounterService {
|
|
| 112 |
const displayName = latestPiclet.nickname || latestPiclet.typeId.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
|
| 113 |
|
| 114 |
return {
|
| 115 |
-
type: EncounterType.
|
| 116 |
title: 'Your First Piclet!',
|
| 117 |
description: `A friendly ${displayName} appears! This one seems easy to catch.`,
|
|
|
|
| 118 |
picletTypeId: latestPiclet.typeId,
|
| 119 |
enemyLevel: 5, // Easy level for first encounter
|
| 120 |
createdAt: new Date()
|
|
|
|
| 112 |
const displayName = latestPiclet.nickname || latestPiclet.typeId.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
|
| 113 |
|
| 114 |
return {
|
| 115 |
+
type: EncounterType.FIRST_PICLET,
|
| 116 |
title: 'Your First Piclet!',
|
| 117 |
description: `A friendly ${displayName} appears! This one seems easy to catch.`,
|
| 118 |
+
picletInstanceId: latestPiclet.id, // Reference to the specific piclet instance
|
| 119 |
picletTypeId: latestPiclet.typeId,
|
| 120 |
enemyLevel: 5, // Easy level for first encounter
|
| 121 |
createdAt: new Date()
|