- Oct 25, 2018
- 22
- 25
there are many problems with this code, but the main one I'm trying to solve is that it creates blank spaces where the code is that are visible to the player, I use the silently macro but in loops I cant seem to figure it out, and links cant be within silently or they wont show up is there a better way?
HTML:
:: CombatRound
<<silently>>
<!-- Debug: Check attackTarget at the start -->
<<print "Debug (start): attackTarget is set to: " + $attackTarget>><br>
<!-- Identify the target creature based on attackTarget -->
<<set _targetCreature = $creaturesEncountered.find(c => c.id == $attackTarget)>>
<!-- Debug: Confirm target creature -->
<<if _targetCreature>>
<<print "Targeting creature: " + _targetCreature.name + " with ID: " + _targetCreature.id + " and HP: " + _targetCreature.currentHP>><br>
<</if>>
<!-- Assign ID variables to use for combat -->
<<set _targetID1 = $creaturesEncountered[0] ? $creaturesEncountered[0].id : null>>
<<set _targetID2 = $creaturesEncountered[1] ? $creaturesEncountered[1].id : null>>
<!-- Set up the video pool for each creature -->
<<set _vid1 = null>>
<<set _vid2 = null>>
<<if _targetID1>>
<<if $creaturesEncountered[0].name == "Hinata">>
<<set _vid1 = [
"Videos/Hinata/Fight/Hinatafight1.mp4",
"Videos/Hinata/Fight/Hinatafight2.mp4",
"Videos/Hinata/Fight/Hinatafight3.mp4",
"Videos/Hinata/Fight/Hinatafight4.mp4",
"Videos/Hinata/Fight/Hinatafight5.mp4"
].random()>>
<</if>>
<</if>>
<<if _targetID2>>
<<if $creaturesEncountered[1].name == "Hinata">>
<<set _vid2 = [
"Videos/Hinata/Fight/Hinatafight1.mp4",
"Videos/Hinata/Fight/Hinatafight2.mp4",
"Videos/Hinata/Fight/Hinatafight3.mp4",
"Videos/Hinata/Fight/Hinatafight4.mp4",
"Videos/Hinata/Fight/Hinatafight5.mp4"
].random()>>
<</if>>
<</if>>
<!-- Handle Equipped Creature -->
<<set $equippedCreature = $creatures.find(c => c.equipped)>>
<<if $equippedCreature>>
<<if $equippedCreature.name == "Hinata">>
<<set _equippedCreatureVid = [
"Videos/Hinata/Fight/Hinatafight1.mp4",
"Videos/Hinata/Fight/Hinatafight2.mp4",
"Videos/Hinata/Fight/Hinatafight3.mp4",
"Videos/Hinata/Fight/Hinatafight4.mp4",
"Videos/Hinata/Fight/Hinatafight5.mp4"
].random()>>
<<elseif $equippedCreature.name == "Krystal">>
<<set _equippedCreatureVid = [
"Videos/Krystal/Fight/Krystalfight1.mp4",
"Videos/Krystal/Fight/Krystalfight2.mp4",
"Videos/Krystal/Fight/Krystalfight3.mp4",
"Videos/Krystal/Fight/Krystalfight4.mp4",
"Videos/Krystal/Fight/Krystalfight5.mp4",
"Videos/Krystal/Fight/Krystalfight6.mp4"
].random()>>
<<elseif $equippedCreature.name == "Marceline">>
<<set _equippedCreatureVid = [
"Videos/Marceline/Fight/Marcelinefight1.mp4",
"Videos/Marceline/Fight/Marcelinefight2.mp4",
"Videos/Marceline/Fight/Marcelinefight3.mp4",
"Videos/Marceline/Fight/Marcelinefight4.mp4",
"Videos/Marceline/Fight/Marcelinefight5.mp4"
].random()>>
<<elseif $equippedCreature.name == "Raven">>
<<set _equippedCreatureVid = [
"Videos/Raven/Fight/Ravenfight1.mp4",
"Videos/Raven/Fight/Ravenfight2.mp4",
"Videos/Raven/Fight/Ravenfight3.mp4",
"Videos/Raven/Fight/Ravenfight4.mp4",
"Videos/Raven/Fight/Ravenfight5.mp4",
"Videos/Raven/Fight/Ravenfight6.mp4"
].random()>>
<</if>>
<</if>>
<!-- Apply the damage to the selected creature -->
<<if _targetCreature>> <!-- Only apply player damage if no potion was used -->
<!-- Player's attack -->
<<if $playerUsedPotion == false>>
<<set _targetCreature.currentHP -= 10>>
<<print "After player's attack: " + _targetCreature.name + " HP: " + _targetCreature.currentHP>><br>
<</if>>
<<set $playerUsedPotion = false>> <!-- Set flag to indicate the player used a potion -->
<!-- If the equipped creature is helping, deal additional damage -->
<<if $equippedCreature and $equippedCreature.currentHP > 0>>
<<print "Equipped creature " + $equippedCreature.name + " assists with " + $equippedCreature.damage + " damage">><br>
<<set _targetCreature.currentHP -= $equippedCreature.damage>>
<<print "After assist: " + _targetCreature.name + " HP: " + _targetCreature.currentHP>><br>
<</if>>
<</if>>
<</silently>>
<<if $potion25hp > 0>>
<<if $playerHP < $playerMaxHP>>
<<link "Use 25 HP Healing Potion on Yourself">>
<<set $potion25hp -= 1>>
<<if $playerHP + 25 > $playerMaxHP>>
<<set $playerHP = $playerMaxHP>>
<<set $playerUsedPotion = true>> <!-- Set flag to indicate the player used a potion -->
<<else>>
<<set $playerHP += 25>>
<<set $playerUsedPotion = true>> <!-- Set flag to indicate the player used a potion -->
<</if>>
You use a 25 HP Healing Potion and heal yourself.<br>
<<goto "CombatRound">> <!-- Use goto to reload the combat round -->
<</link>>
<</if>>
<!-- Heal the equipped creature if they exist and their HP is not full -->
<<if $equippedCreature and $equippedCreature.currentHP > 0 and $equippedCreature.currentHP < $equippedCreature.maxHP>>
<<link "Use 25 HP Healing Potion on <<print $equippedCreature.name>>">>
<<set $potion25hp -= 1>> <!-- Decrease the potion count -->
<<if $equippedCreature.currentHP + 25 > $equippedCreature.maxHP>>
<<set $equippedCreature.currentHP = $equippedCreature.maxHP>>
<<else>>
<<set $equippedCreature.currentHP += 25>>
<</if>>
You use a 25 HP Healing Potion on <<print $equippedCreature.name>>.<br>
<<goto "CombatRound">> <!-- Use goto to reload the combat round -->
<</link>>
<</if>>
<</if>>
<!-- Continue rest of the combat logic below -->
<!-- Check if the player or all enemies are defeated -->
<<if $playerHP <= 0>>
<<goto "GameOver">>
<<elseif $creaturesEncountered.every(c => c.currentHP <= 0)>>
<<goto "PostBattle">>
<</if>>
<!-- Display the enemy creatures' status and their HP -->
<div style="display: flex; justify-content: center; gap: 20px;">
<<if _targetID1 and $creaturesEncountered[0].currentHP > 0>>
<div style="flex: 1; display: flex; flex-direction: column; align-items: center;">
<<= '<video src="' + _vid1 + '" autoplay loop muted controls style="width: 100%; height: auto; max-width: 800px;"></video>'>>
The <<print $creaturesEncountered[0].name>> has <<print $creaturesEncountered[0].currentHP>> HP and can deal <<print $creaturesEncountered[0].damage>> damage.<br>
<!-- Attack this creature specifically -->
<<link "Attack with Fist (10 damage)">>
<<set $attackTarget = _targetID1>>
<<goto "CombatRound">>
<</link>>
<<if $inventory["shovel"] is not null>>
<<link "Hit with Shovel (20 damage)">>
<<set $attackTarget = _targetID1>>
<<goto "CombatRound">>
<</link>>
<</if>>
</div>
<</if>>
<<if _targetID2 and $creaturesEncountered[1].currentHP > 0>>
<div style="flex: 1; display: flex; flex-direction: column; align-items: center;">
<<= '<video src="' + _vid2 + '" autoplay loop muted controls style="width: 100%; height: auto; max-width: 800px;"></video>'>>
The <<print $creaturesEncountered[1].name>> has <<print $creaturesEncountered[1].currentHP>> HP and can deal <<print $creaturesEncountered[1].damage>> damage.<br>
<!-- Attack this creature specifically -->
<<link "Attack with Fist (10 damage)">>
<<set $attackTarget = _targetID2>>
<<goto "CombatRound">>
<</link>>
<<if $inventory["shovel"] is not null>>
<<link "Hit with Shovel (20 damage)">>
<<set $attackTarget = _targetID2>>
<<goto "CombatRound">>
<</link>>
<</if>>
</div>
<</if>>
</div>
<!-- Display the equipped creature's video, HP, and damage if applicable -->
<<if $equippedCreature and $equippedCreature.currentHP > 0>>
<<= '<video src="' + _equippedCreatureVid + '" autoplay loop muted controls style="position: fixed; bottom: 20px; right: 20px; width: 250px; height: auto;"></video>'>>
Your equipped creature <<print $equippedCreature.name>> has <<print $equippedCreature.currentHP>> HP and can deal <<print $equippedCreature.damage>> damage.<br>
<</if>>
<!-- Creature attacks the player or pet -->
<<for _creature range $creaturesEncountered>>
<<if _creature.currentHP > 0>>
<<if not $equippedCreature or $equippedCreature.currentHP <= 0>>
<<set $playerHP -= _creature.damage>>
The <<print _creature.name>> attacks you, dealing <<print _creature.damage>> damage!<br>
<<else>>
<<set _target = random(1, 2)>>
<<if _target == 1>>
<<set $playerHP -= _creature.damage>>
The <<print _creature.name>> attacks you, dealing <<print _creature.damage>> damage!<br>
<<else>>
<<set $equippedCreature.currentHP -= _creature.damage>>
The <<print _creature.name>> attacks <<print $equippedCreature.name>>, dealing <<print _creature.damage>> damage!<br>
<!-- Check if the pet's HP is reduced to 0 or below -->
<<if $equippedCreature.currentHP <= 0>>
<<print $equippedCreature.name>> is too injured to continue fighting.<br>
<</if>>
<</if>>
<</if>>
<</if>>
<</for>>
<!-- Check if the player is defeated -->
<<if $playerHP <= 0>>
<<goto "GameOver">>
<</if>>
<!-- Check if all enemies are defeated -->
<<if $creaturesEncountered.every(c => c.currentHP <= 0)>>
<<goto "PostBattle">>
<</if>>
<<nobr>>
You attack with your Fist, dealing 10 damage!<br>
<<if $equippedCreature and $equippedCreature.currentHP > 0>>
<<print $equippedCreature.name>> assists in the attack, dealing <<print $equippedCreature.damage>> damage!<br>
<</if>>
<!-- Display each creature's status after the round -->
<<for _creature range $creaturesEncountered>>
<<if _creature.currentHP > 0>>
The <<print _creature.name>> has <<print _creature.currentHP>> HP left.<br>
<</if>>
<</for>>
You have <<print $playerHP>> HP left.<br>
<<if $equippedCreature and $equippedCreature.currentHP > 0>>
<<print $equippedCreature.name>> has <<print $equippedCreature.currentHP>> HP left.<br>
<</if>>
<</nobr>>
Last edited: