enc svc
Browse files
src/lib/components/Pages/Encounters.svelte
CHANGED
@@ -29,24 +29,30 @@
|
|
29 |
async function loadEncounters() {
|
30 |
isLoading = true;
|
31 |
try {
|
32 |
-
//
|
33 |
-
const
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
if (
|
41 |
-
//
|
42 |
-
console.log('
|
43 |
encounters = await EncounterService.generateEncounters();
|
44 |
} else {
|
45 |
-
//
|
46 |
-
console.log('
|
47 |
-
|
|
|
48 |
}
|
49 |
|
|
|
|
|
50 |
// Load monster images for wild piclet encounters
|
51 |
await loadMonsterImages();
|
52 |
} catch (error) {
|
|
|
29 |
async function loadEncounters() {
|
30 |
isLoading = true;
|
31 |
try {
|
32 |
+
// Check if we have discovered monsters first
|
33 |
+
const discoveredMonsters = await db.monsters.toArray();
|
34 |
+
const playerPiclets = await db.picletInstances.toArray();
|
35 |
|
36 |
+
if (discoveredMonsters.length === 0) {
|
37 |
+
// No monsters discovered - show empty state
|
38 |
+
encounters = [];
|
39 |
+
isLoading = false;
|
40 |
+
return;
|
41 |
+
}
|
42 |
|
43 |
+
if (playerPiclets.length === 0) {
|
44 |
+
// First catch scenario - generate first catch encounter only
|
45 |
+
console.log('First catch scenario - generating first catch encounter');
|
46 |
encounters = await EncounterService.generateEncounters();
|
47 |
} else {
|
48 |
+
// Player has piclets - always generate fresh encounters with wild piclets
|
49 |
+
console.log('Player has piclets - generating fresh encounters with wild piclets');
|
50 |
+
await EncounterService.forceEncounterRefresh();
|
51 |
+
encounters = await EncounterService.generateEncounters();
|
52 |
}
|
53 |
|
54 |
+
console.log('Final encounters:', encounters.map(e => ({ type: e.type, title: e.title })));
|
55 |
+
|
56 |
// Load monster images for wild piclet encounters
|
57 |
await loadMonsterImages();
|
58 |
} catch (error) {
|
src/lib/db/encounterService.ts
CHANGED
@@ -75,8 +75,14 @@ export class EncounterService {
|
|
75 |
}
|
76 |
|
77 |
// Player has piclets - generate normal encounters
|
|
|
78 |
|
79 |
-
//
|
|
|
|
|
|
|
|
|
|
|
80 |
encounters.push({
|
81 |
type: EncounterType.SHOP,
|
82 |
title: 'Piclet Shop',
|
@@ -90,10 +96,6 @@ export class EncounterService {
|
|
90 |
description: 'Heal your piclets back to full health',
|
91 |
createdAt: new Date()
|
92 |
});
|
93 |
-
|
94 |
-
// Generate wild piclet encounters
|
95 |
-
const wildEncounters = await this.generateWildEncounters();
|
96 |
-
encounters.push(...wildEncounters);
|
97 |
|
98 |
// Clear existing encounters and add new ones
|
99 |
await db.encounters.clear();
|
@@ -128,16 +130,19 @@ export class EncounterService {
|
|
128 |
|
129 |
// Get all discovered monsters
|
130 |
const discoveredMonsters = await db.monsters.toArray();
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
136 |
|
137 |
-
//
|
138 |
-
const availableMonsters = discoveredMonsters;
|
|
|
139 |
|
140 |
const encounterCount = MIN_WILD_ENCOUNTERS + Math.floor(Math.random() * (MAX_WILD_ENCOUNTERS - MIN_WILD_ENCOUNTERS + 1));
|
|
|
141 |
|
142 |
for (let i = 0; i < encounterCount; i++) {
|
143 |
// Pick a random monster from discovered ones
|
@@ -146,16 +151,20 @@ export class EncounterService {
|
|
146 |
const levelVariance = Math.floor(Math.random() * (LEVEL_VARIANCE * 2 + 1)) - LEVEL_VARIANCE;
|
147 |
const enemyLevel = Math.max(1, avgLevel + levelVariance);
|
148 |
|
149 |
-
|
150 |
type: EncounterType.WILD_PICLET,
|
151 |
title: `Wild ${monster.name} Appeared!`,
|
152 |
description: `A level ${enemyLevel} ${monster.name} blocks your path!`,
|
153 |
picletTypeId: monster.name.toLowerCase().replace(/\s+/g, '-'),
|
154 |
enemyLevel,
|
155 |
createdAt: new Date()
|
156 |
-
}
|
|
|
|
|
|
|
157 |
}
|
158 |
|
|
|
159 |
return encounters;
|
160 |
}
|
161 |
|
|
|
75 |
}
|
76 |
|
77 |
// Player has piclets - generate normal encounters
|
78 |
+
console.log('Generating encounters for player with piclets');
|
79 |
|
80 |
+
// Generate wild piclet encounters FIRST to ensure they're included
|
81 |
+
const wildEncounters = await this.generateWildEncounters();
|
82 |
+
console.log('Wild encounters generated:', wildEncounters.length);
|
83 |
+
encounters.push(...wildEncounters);
|
84 |
+
|
85 |
+
// Always add shop and health center
|
86 |
encounters.push({
|
87 |
type: EncounterType.SHOP,
|
88 |
title: 'Piclet Shop',
|
|
|
96 |
description: 'Heal your piclets back to full health',
|
97 |
createdAt: new Date()
|
98 |
});
|
|
|
|
|
|
|
|
|
99 |
|
100 |
// Clear existing encounters and add new ones
|
101 |
await db.encounters.clear();
|
|
|
130 |
|
131 |
// Get all discovered monsters
|
132 |
const discoveredMonsters = await db.monsters.toArray();
|
133 |
+
console.log('Discovered monsters for wild encounters:', discoveredMonsters.length);
|
134 |
|
135 |
+
if (discoveredMonsters.length === 0) {
|
136 |
+
console.log('No discovered monsters - returning empty wild encounters');
|
137 |
+
return encounters;
|
138 |
+
}
|
139 |
|
140 |
+
// Always allow catching duplicates for more encounters
|
141 |
+
const availableMonsters = discoveredMonsters;
|
142 |
+
console.log('Available monsters for encounters:', availableMonsters.map(m => m.name));
|
143 |
|
144 |
const encounterCount = MIN_WILD_ENCOUNTERS + Math.floor(Math.random() * (MAX_WILD_ENCOUNTERS - MIN_WILD_ENCOUNTERS + 1));
|
145 |
+
console.log('Generating', encounterCount, 'wild encounters');
|
146 |
|
147 |
for (let i = 0; i < encounterCount; i++) {
|
148 |
// Pick a random monster from discovered ones
|
|
|
151 |
const levelVariance = Math.floor(Math.random() * (LEVEL_VARIANCE * 2 + 1)) - LEVEL_VARIANCE;
|
152 |
const enemyLevel = Math.max(1, avgLevel + levelVariance);
|
153 |
|
154 |
+
const wildEncounter = {
|
155 |
type: EncounterType.WILD_PICLET,
|
156 |
title: `Wild ${monster.name} Appeared!`,
|
157 |
description: `A level ${enemyLevel} ${monster.name} blocks your path!`,
|
158 |
picletTypeId: monster.name.toLowerCase().replace(/\s+/g, '-'),
|
159 |
enemyLevel,
|
160 |
createdAt: new Date()
|
161 |
+
};
|
162 |
+
|
163 |
+
console.log('Created wild encounter:', wildEncounter.title, 'with typeId:', wildEncounter.picletTypeId);
|
164 |
+
encounters.push(wildEncounter);
|
165 |
}
|
166 |
|
167 |
+
console.log('Generated', encounters.length, 'wild encounters');
|
168 |
return encounters;
|
169 |
}
|
170 |
|