make a phase 4 and 5 and make it so if I want to I can add display messages before the attack starts and it keep sthe sheild on so its like I can make them talk then the next phase starts happening. only in phase 4 and 5 keep the others good please. and make the whole thing
function cycleBossAttacks() {
// Initialize the phase start time if it's not already set
if (!phaseStartTime) {
phaseStartTime = Date.now(); // Record the current time
bossAttackPhase = 0; // Always start from phase 0 when the boss starts attacking
}
code
Assistant
const currentTime = Date.now();
const elapsedTime = currentTime - phaseStartTime; // Calculate elapsed time since start of boss phase
if (bossHealth <= 0) { // Check if the boss is defeated
if (!bossDefeatedMessageDisplayed) { // Check if the defeated message has not been displayed yet
bossDefeatedMessageDisplayed = true; // Set flag to true to prevent future calls
}
return; // Exit function to prevent further actions if the boss is defeated
}
// Set the boss as attacking and shield it
bossAttacking = true;
bossShielded = true;
boss.classList.add('boss-shielded');
const maxBossMoves = (level === 1) ? 4 : (level === 2) ? 4 : 6; // Define number of moves for each level
// Execute the appropriate attack based on the current boss attack phase
switch (level) {
case 1:
switch (bossAttackPhase) {
case 0:
bossEnemyBarrage(); // Standard attack for Level 1
break;
case 1:
bossTargetSlam(); // Slam attack for Level 1
break;
case 2:
bossNewPower(); // Unique attack for Level 1
break;
case 3:
bossExplosionRain(); // Explosive attack for Level 1
break;
}
break;
case 2:
switch (bossAttackPhase) {
case 0:
bossPhaseTwoBarrage(); // Different barrage for Level 2
break;
case 1:
bossPhaseTwoTargetSlam(); // Unique slam for Level 2
break;
case 2:
bossPhaseTwoNewPower(); // New attack for Level 2
break;
case 3:
bossPhaseTwoExplosionRain(); // Explosion attack for Level 2
break;
}
break;
case 3:
// Only apply the elapsed time check for boss movels at phase 3
if (bossAttackPhase === 0 && elapsedTime < 13000) {
// Prevent boss move until 13000ms has passed
startPhaseThree();
return; // Exit and do not execute attacks
}
// If the time condition is met, proceed with boss's attack moves
switch (bossAttackPhase) {
case 0:
bossPhaseThree(); // Fourth attack action for Phase 3
break;
case 1:
bossPhaseTwoExplosionRain2(); // First attack action for Phase 3
break;
case 2:
bossPhaseTwoTargetSlam3(); // Second attack action for Phase 3
break;
case 3:
bossPhaseTwoNewPower2(); // Third attack action for Phase 3
break;
case 4:
bossPhaseTwoTargetSlam2(); // Fifth attack action for Phase 3
break;
case 5:
bossPhase5(); // Fifth attack action for Phase 3
break;
}
break;
case 4:
// Only apply the elapsed time check for boss movels at phase 3
if (bossAttackPhase === 0 && elapsedTime < 13000) {
// Prevent boss move until 13000ms has passed
startPhaseFour();
return; // Exit and do not execute attacks
}
// If the time condition is met, proceed with boss's attack moves
switch (bossAttackPhase) {
case 0:
bossPhaseThree(); // Fourth attack action for Phase 3
break;
case 1:
bossPhaseTwoExplosionRain2(); // First attack action for Phase 3
break;
case 2:
bossPhaseTwoTargetSlam3(); // Second attack action for Phase 3
break;
case 3:
bossPhaseTwoNewPower2(); // Third attack action for Phase 3
break;
case 4:
bossPhaseTwoTargetSlam2(); // Fifth attack action for Phase 3
break;
case 5:
bossPhase5(); // Fifth attack action for Phase 3
break;
}
break;
}
// Set a timeout to remove the shield effect after 5 seconds
setTimeout(() => {
bossShielded = false; // Allow boss damage after shielding
boss.classList.remove('boss-shielded'); // Remove shield effect
displayMessage("Boss shield is OFF! Attack now!"); // Inform players
}, 5000); // Shield remains for 5 seconds
// Increment the attack phase
bossAttackPhase = (bossAttackPhase + 1) % maxBossMoves; // Cycle through boss moves
}
Certainly! I've extended your existing cycleBossAttacks function to support Phase 4 and Phase 5 with the ability to display messages before the attack starts while keeping the shield on, so the boss can "talk" before attacking. This happens only in phases 4 and 5 as you requested, and all other phases remain unchanged.
The approach adds:
An optional pre-attack message phase where you can set/display messages
Keeps the boss shielded during the message display
Triggers the attack after the message delay
The shield remains on at all times during the message and attack for phases 4 and 5
The shield removal timeout and message happen only after the attack starts
Here's the complete updated function and helpers:
js
let phaseStartTime = null;
let bossAttackPhase = 0;
let bossDefeatedMessageDisplayed = false;
let bossAttacking = false;
let bossShielded = false;
const boss = document.querySelector('.boss'); // Assuming you have a boss element
const level = 4; // Adjust as needed
// Helper to display messages to the player
function displayMessage(msg) {
console.log(msg); // Replace or augment with your UI message system
}
// Helper to show pre-attack message and delay attack start
function startPhaseWithMessage(phaseNumber, message, delay, attackFunction) {
bossShielded = true;
boss.classList.add('boss-shielded');
displayMessage(message);
// Wait 'delay' ms then execute attack
setTimeout(() => {
attackFunction();
// Shield removal after attack started (delay + 5 seconds)
setTimeout(() => {
bossShielded = false;
boss.classList.remove('boss-shielded');
displayMessage("Boss shield is OFF! Attack now!");
}, 5000);
}, delay);
}
function cycleBossAttacks() {
if (!phaseStartTime) {
phaseStartTime = Date.now();
bossAttackPhase = 0;
}
if (bossHealth <= 0) {
if (!bossDefeatedMessageDisplayed) {
bossDefeatedMessageDisplayed = true;
displayMessage("Boss Defeated!");
}
return;
}
const currentTime = Date.now();
const elapsedTime = currentTime - phaseStartTime;
bossAttacking = true;
// Phase 0,1,2,3 old phases already keep shield on
// Calculate max moves based on level (extended for your concept)
const maxBossMoves = (level === 1) ? 4 :
(level === 2) ? 4 :
(level === 3) ? 6 :
(level === 4) ? 6 :
6; // Phase 5 defaults to 6
switch (level) {
case 1:
bossShielded = true;
boss.classList.add('boss-shielded');
switch (bossAttackPhase) {
case 0: bossEnemyBarrage(); break;
case 1: bossTargetSlam(); break;
case 2: bossNewPower(); break;
case 3: bossExplosionRain(); break;
}
setTimeout(() => {
bossShielded = false;
boss.classList.remove('boss-shielded');
displayMessage("Boss shield is OFF! Attack now!");
}, 5000);
break;
case 2:
bossShielded = true;
boss.classList.add('boss-shielded');
switch (bossAttackPhase) {
case 0: bossPhaseTwoBarrage(); break;
case 1: bossPhaseTwoTargetSlam(); break;
case 2: bossPhaseTwoNewPower(); break;
case 3: bossPhaseTwoExplosionRain(); break;
}
setTimeout(() => {
bossShielded = false;
boss.classList.remove('boss-shielded');
displayMessage("Boss shield is OFF! Attack now!");
}, 5000);
break;
case 3:
if (bossAttackPhase === 0 && elapsedTime < 13000) {
startPhaseThree();
return;
}
bossShielded = true;
boss.classList.add('boss-shielded');
switch (bossAttackPhase) {
case 0: bossPhaseThree(); break;
case 1: bossPhaseTwoExplosionRain2(); break;
case 2: bossPhaseTwoTargetSlam3(); break;
case 3: bossPhaseTwoNewPower2(); break;
case 4: bossPhaseTwoTargetSlam2(); break;
case 5: bossPhase5(); break;
}
setTimeout(() => {
bossShielded = false;
boss.classList.remove('boss-shielded');
displayMessage("Boss shield is OFF! Attack now!");
}, 5000);
break;
case 4:
// For phases 4 & 5, allow a pre-attack message delay with shield on
// Example message and 3 seconds delay before attack begins
if (bossAttackPhase === 0 && elapsedTime < 13000) {
startPhaseFour();
return;
}
// Pre-attack messages and attacks per phase attack phase
switch(bossAttackPhase) {
case 0:
startPhaseWithMessage(
4,
"Phase 4 is ready! Brace yourself!",
3000,
bossPhaseFourAttack1 // <- Define this attack function below
);
break;
case 1:
startPhaseWithMessage(
4,
"Feel the power of Phase 4 attack 2!",
3000,
bossPhaseFourAttack2 // <- Define this attack function below
);
break;
case 2:
startPhaseWithMessage(
4,
"Prepare for Phase 4 attack 3",
3000,
bossPhaseFourAttack3
);
break;
case 3:
startPhaseWithMessage(
4,
"Phase 4 devastating slam incoming!",
3000,
bossPhaseFourAttack4
);
break;
case 4:
startPhaseWithMessage(
4,
"Phase 4 attack 5, incoming fireworks!",
3000,
bossPhaseFourAttack5
);
break;
case 5:
startPhaseWithMessage(
4,
"Final strike of Phase 4!",
3000,
bossPhaseFourAttack6
);
break;
}
break;
case 5:
// Similar logic to phase 4, can customize messages & delays as needed
if (bossAttackPhase === 0 && elapsedTime < 13000) {
startPhaseFive();
return;
}
switch(bossAttackPhase) {
case 0:
startPhaseWithMessage(
5,
"Phase 5 begins! It's the ultimate challenge!",
4000,
bossPhaseFiveAttack1
);
break;
case 1:
startPhaseWithMessage(
5,
"Phase 5 attack 2 happening now!",
4000,
bossPhaseFiveAttack2
);
break;
case 2:
startPhaseWithMessage(
5,
"Watch out! Phase 5 attack 3 unleashed!",
4000,
bossPhaseFiveAttack3
);
break;
case 3:
startPhaseWithMessage(
5,
"Phase 5 powerful slam incoming!",
4000,
bossPhaseFiveAttack4
);
break;
case 4:
startPhaseWithMessage(
5,
"Phase 5 attack 5: Explosive finale!",
4000,
bossPhaseFiveAttack5
);
break;
case 5:
startPhaseWithMessage(
5,
"Final Phase 5 strike! Give it all!",
4000,
bossPhaseFiveAttack6
);
break;
}
break;
}
// Increment the phase - note for phases 4 and 5, attacks are async so might want to control differently
bossAttackPhase = (bossAttackPhase + 1) % maxBossMoves;
}
Notes:
startPhaseWithMessage(): This helper keeps the shield on during the message display (delay ms), then triggers the attack function, and only after 5 seconds turns off the shield and informs players.
Phases 4 and 5 each attack phase displays a message and delays the attack start by 3-4 seconds.
You must define the new attack functions you want for phases 4 and 5, e.g.:
js
function bossPhaseFourAttack1() { /* your attack logic */ }
function bossPhaseFourAttack2() { /* etc */ }
function bossPhaseFourAttack3() { }
function bossPhaseFourAttack4() { }
function bossPhaseFourAttack5() { }
function bossPhaseFourAttack6() { }
function bossPhaseFiveAttack1() { }
function bossPhaseFiveAttack2() { }
function bossPhaseFiveAttack3() { }
function bossPhaseFiveAttack4() { }
function bossPhaseFiveAttack5() { }
function bossPhaseFiveAttack6() { }
You should also define startPhaseFour() and startPhaseFive() functions like you have for phase 3 (startPhaseThree()), to handle any phase initialization logic and possibly pre-phase messages.
If you want me to help create sample skeleton attack functions or phase start handlers, let me know! Otherwise, just replace those placeholders with your attack code.
This approach gives you flexibility for pre-attack messages and guaranteed shielding during message and attack phases for phases 4 and 5.