Fraser commited on
Commit
f6bbd39
·
1 Parent(s): 007132e
src/lib/components/Pages/Battle.svelte CHANGED
@@ -153,18 +153,23 @@
153
  battleEngine.executeActions(captureAction, enemyAction);
154
  battleState = battleEngine.getState();
155
 
 
 
 
156
  // Get capture result and new log entries
157
  const captureResult = battleState.captureResult;
158
  const logAfter = battleEngine.getLog();
159
  const newLogEntries = logAfter.slice(logBefore.length);
160
 
161
- // Show log messages with proper timing
162
  if (newLogEntries.length > 0) {
163
  let messageIndex = 0;
164
 
165
  const showNextMessage = () => {
166
  if (messageIndex < newLogEntries.length) {
167
  currentMessage = newLogEntries[messageIndex];
 
 
168
  messageIndex++;
169
  setTimeout(showNextMessage, 1500); // 1.5s between messages
170
  } else {
@@ -175,6 +180,25 @@
175
  battleEnded = true;
176
  onBattleEnd(currentEnemyPiclet); // Pass captured Piclet to add to roster
177
  }, 1000);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  } else {
179
  // Capture failed - continue battle
180
  setTimeout(() => {
 
153
  battleEngine.executeActions(captureAction, enemyAction);
154
  battleState = battleEngine.getState();
155
 
156
+ // Update UI state (HP bars, etc.) after the actions
157
+ updateUIFromBattleState();
158
+
159
  // Get capture result and new log entries
160
  const captureResult = battleState.captureResult;
161
  const logAfter = battleEngine.getLog();
162
  const newLogEntries = logAfter.slice(logBefore.length);
163
 
164
+ // Show log messages with proper timing and visual effects
165
  if (newLogEntries.length > 0) {
166
  let messageIndex = 0;
167
 
168
  const showNextMessage = () => {
169
  if (messageIndex < newLogEntries.length) {
170
  currentMessage = newLogEntries[messageIndex];
171
+ // Trigger visual effects for this message
172
+ triggerVisualEffectsFromMessage(newLogEntries[messageIndex]);
173
  messageIndex++;
174
  setTimeout(showNextMessage, 1500); // 1.5s between messages
175
  } else {
 
180
  battleEnded = true;
181
  onBattleEnd(currentEnemyPiclet); // Pass captured Piclet to add to roster
182
  }, 1000);
183
+ } else if (battleState.winner) {
184
+ // Battle ended (player probably fainted from enemy attack)
185
+ battleEnded = true;
186
+ const defeatedPiclet = battleState.winner === 'player' ? currentEnemyPiclet : currentPlayerPiclet;
187
+
188
+ // Show the faint message and trigger animation
189
+ currentMessage = `${defeatedPiclet.nickname} fainted!`;
190
+
191
+ // Trigger faint animation for the defeated Piclet
192
+ if (battleState.winner === 'player') {
193
+ enemyFaint = true;
194
+ } else {
195
+ playerFaint = true;
196
+ }
197
+
198
+ // Wait for faint message, then process battle results
199
+ setTimeout(async () => {
200
+ await handleBattleResults(battleState.winner === 'player');
201
+ }, 2500); // Wait time for faint message and animation
202
  } else {
203
  // Capture failed - continue battle
204
  setTimeout(() => {