2017-02-05 10:49:37 -06:00
< ? php // fight.php :: Handles all fighting action.
function fight () { // One big long function that determines the outcome of the fight.
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
global $userrow , $controlrow ;
2024-12-12 11:28:19 -06:00
if ( $userrow [ " currentaction " ] != " Fighting " ) { display ( " Cheat attempt detected.<br><br>Get a life, loser. " , " Error " ); }
2017-02-05 10:49:37 -06:00
$pagearray = array ();
$playerisdead = 0 ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$pagearray [ " magiclist " ] = " " ;
$userspells = explode ( " , " , $userrow [ " spells " ]);
$spellquery = doquery ( " SELECT id,name FROM { { table}} " , " spells " );
while ( $spellrow = mysql_fetch_array ( $spellquery )) {
2017-02-05 10:58:20 -06:00
$spell = false ;
foreach ( $userspells as $a => $b ) {
if ( $b == $spellrow [ " id " ]) { $spell = true ; }
}
if ( $spell == true ) {
2017-02-05 10:49:37 -06:00
$pagearray [ " magiclist " ] .= " <option value= \" " . $spellrow [ " id " ] . " \" > " . $spellrow [ " name " ] . " </option> \n " ;
}
2017-02-05 10:58:20 -06:00
unset ( $spell );
2017-02-05 10:49:37 -06:00
}
if ( $pagearray [ " magiclist " ] == " " ) { $pagearray [ " magiclist " ] = " <option value= \" 0 \" >None</option> \n " ; }
$magiclist = $pagearray [ " magiclist " ];
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$chancetoswingfirst = 1 ;
// First, check to see if we need to pick a monster.
if ( $userrow [ " currentfight " ] == 1 ) {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " latitude " ] < 0 ) { $userrow [ " latitude " ] *= - 1 ; } // Equalize negatives.
if ( $userrow [ " longitude " ] < 0 ) { $userrow [ " longitude " ] *= - 1 ; } // Ditto.
$maxlevel = floor ( max ( $userrow [ " latitude " ] + 5 , $userrow [ " longitude " ] + 5 ) / 5 ); // One mlevel per five spaces.
if ( $maxlevel < 1 ) { $maxlevel = 1 ; }
$minlevel = $maxlevel - 2 ;
if ( $minlevel < 1 ) { $minlevel = 1 ; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Pick a monster.
$monsterquery = doquery ( " SELECT * FROM { { table}} WHERE level>=' $minlevel ' AND level<=' $maxlevel ' ORDER BY RAND() LIMIT 1 " , " monsters " );
$monsterrow = mysql_fetch_array ( $monsterquery );
$userrow [ " currentmonster " ] = $monsterrow [ " id " ];
$userrow [ " currentmonsterhp " ] = rand ((( $monsterrow [ " maxhp " ] / 5 ) * 4 ), $monsterrow [ " maxhp " ]);
$userrow [ " currentmonstersleep " ] = 0 ;
$userrow [ " currentmonsterimmune " ] = $monsterrow [ " immune " ];
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$chancetoswingfirst = rand ( 1 , 10 ) + ceil ( sqrt ( $userrow [ " dexterity " ]));
if ( $chancetoswingfirst > ( rand ( 1 , 7 ) + ceil ( sqrt ( $monsterrow [ " maxdam " ])))) { $chancetoswingfirst = 1 ; } else { $chancetoswingfirst = 0 ; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
unset ( $monsterquery );
unset ( $monsterrow );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Next, get the monster statistics.
$monsterquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . $userrow [ " currentmonster " ] . " ' LIMIT 1 " , " monsters " );
$monsterrow = mysql_fetch_array ( $monsterquery );
$pagearray [ " monstername " ] = $monsterrow [ " name " ];
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Do run stuff.
if ( isset ( $_POST [ " run " ])) {
$chancetorun = rand ( 4 , 10 ) + ceil ( sqrt ( $userrow [ " dexterity " ]));
if ( $chancetorun > ( rand ( 1 , 5 ) + ceil ( sqrt ( $monsterrow [ " maxdam " ])))) { $chancetorun = 1 ; } else { $chancetorun = 0 ; }
2024-12-12 09:33:17 -06:00
if ( $chancetorun == 0 ) {
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You tried to run away, but were blocked in front!<br><br> " ;
$pagearray [ " monsterhp " ] = " Monster's HP: " . $userrow [ " currentmonsterhp " ] . " <br><br> " ;
2017-02-05 10:49:37 -06:00
$pagearray [ " monsterturn " ] = " " ;
if ( $userrow [ " currentmonstersleep " ] != 0 ) { // Check to wake up.
$chancetowake = rand ( 1 , 15 );
if ( $chancetowake > $userrow [ " currentmonstersleep " ]) {
$userrow [ " currentmonstersleep " ] = 0 ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster has woken up.<br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster is still asleep.<br> " ;
2017-02-05 10:49:37 -06:00
}
}
if ( $userrow [ " currentmonstersleep " ] == 0 ) { // Only do this if the monster is awake.
2017-02-05 10:55:54 -06:00
$tohit = ceil ( rand ( $monsterrow [ " maxdam " ] *. 5 , $monsterrow [ " maxdam " ]));
2017-02-05 10:54:09 -06:00
$toblock = ceil ( rand ( $userrow [ " defensepower " ] *. 75 , $userrow [ " defensepower " ]) / 4 );
2017-02-05 10:49:37 -06:00
$tododge = rand ( 1 , 150 );
if ( $tododge <= sqrt ( $userrow [ " dexterity " ])) {
2024-12-12 11:28:19 -06:00
$tohit = 0 ; $pagearray [ " monsterturn " ] .= " You dodge the monster's attack. No damage has been scored.<br> " ;
2017-02-05 10:49:37 -06:00
$persondamage = 0 ;
} else {
$persondamage = $tohit - $toblock ;
if ( $persondamage < 1 ) { $persondamage = 1 ; }
if ( $userrow [ " currentuberdefense " ] != 0 ) {
$persondamage -= ceil ( $persondamage * ( $userrow [ " currentuberdefense " ] / 100 ));
}
if ( $persondamage < 1 ) { $persondamage = 1 ; }
}
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster attacks you for $persondamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
$userrow [ " currenthp " ] -= $persondamage ;
if ( $userrow [ " currenthp " ] <= 0 ) {
$newgold = ceil ( $userrow [ " gold " ] / 2 );
$newhp = ceil ( $userrow [ " maxhp " ] / 4 );
$updatequery = doquery ( " UPDATE { { table}} SET currenthp=' $newhp ',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold=' $newgold ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
$playerisdead = 1 ;
}
}
}
$updatequery = doquery ( " UPDATE { { table}} SET currentaction='Exploring' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
header ( " Location: index.php " );
die ();
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Do fight stuff.
} elseif ( isset ( $_POST [ " fight " ])) {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Your turn.
$pagearray [ " yourturn " ] = " " ;
$tohit = ceil ( rand ( $userrow [ " attackpower " ] *. 75 , $userrow [ " attackpower " ]) / 3 );
$toexcellent = rand ( 1 , 150 );
2024-12-12 11:28:19 -06:00
if ( $toexcellent <= sqrt ( $userrow [ " strength " ])) { $tohit *= 2 ; $pagearray [ " yourturn " ] .= " Excellent hit!<br> " ; }
2024-12-12 09:33:17 -06:00
$toblock = ceil ( rand ( $monsterrow [ " armor " ] *. 75 , $monsterrow [ " armor " ]) / 3 );
2017-02-05 10:49:37 -06:00
$tododge = rand ( 1 , 200 );
2024-12-12 09:33:17 -06:00
if ( $tododge <= sqrt ( $monsterrow [ " armor " ])) {
2024-12-12 11:28:19 -06:00
$tohit = 0 ; $pagearray [ " yourturn " ] .= " The monster is dodging. No damage has been scored.<br> " ;
2017-02-05 10:49:37 -06:00
$monsterdamage = 0 ;
} else {
$monsterdamage = $tohit - $toblock ;
if ( $monsterdamage < 1 ) { $monsterdamage = 1 ; }
if ( $userrow [ " currentuberdamage " ] != 0 ) {
$monsterdamage += ceil ( $monsterdamage * ( $userrow [ " currentuberdamage " ] / 100 ));
}
}
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] .= " You attack the monster for $monsterdamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
$userrow [ " currentmonsterhp " ] -= $monsterdamage ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterhp " ] = " Monster's HP: " . $userrow [ " currentmonsterhp " ] . " <br><br> " ;
2017-02-05 10:49:37 -06:00
if ( $userrow [ " currentmonsterhp " ] <= 0 ) {
$updatequery = doquery ( " UPDATE { { table}} SET currentmonsterhp='0' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
header ( " Location: index.php?do=victory " );
die ();
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Monster's turn.
$pagearray [ " monsterturn " ] = " " ;
if ( $userrow [ " currentmonstersleep " ] != 0 ) { // Check to wake up.
$chancetowake = rand ( 1 , 15 );
if ( $chancetowake > $userrow [ " currentmonstersleep " ]) {
$userrow [ " currentmonstersleep " ] = 0 ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster has woken up.<br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster is still asleep.<br> " ;
2017-02-05 10:49:37 -06:00
}
}
if ( $userrow [ " currentmonstersleep " ] == 0 ) { // Only do this if the monster is awake.
2017-02-05 10:55:54 -06:00
$tohit = ceil ( rand ( $monsterrow [ " maxdam " ] *. 5 , $monsterrow [ " maxdam " ]));
2017-02-05 10:49:37 -06:00
$toblock = ceil ( rand ( $userrow [ " defensepower " ] *. 75 , $userrow [ " defensepower " ]) / 4 );
$tododge = rand ( 1 , 150 );
if ( $tododge <= sqrt ( $userrow [ " dexterity " ])) {
2024-12-12 11:28:19 -06:00
$tohit = 0 ; $pagearray [ " monsterturn " ] .= " You dodge the monster's attack. No damage has been scored.<br> " ;
2017-02-05 10:49:37 -06:00
$persondamage = 0 ;
} else {
$persondamage = $tohit - $toblock ;
if ( $persondamage < 1 ) { $persondamage = 1 ; }
if ( $userrow [ " currentuberdefense " ] != 0 ) {
$persondamage -= ceil ( $persondamage * ( $userrow [ " currentuberdefense " ] / 100 ));
}
if ( $persondamage < 1 ) { $persondamage = 1 ; }
}
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster attacks you for $persondamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
$userrow [ " currenthp " ] -= $persondamage ;
if ( $userrow [ " currenthp " ] <= 0 ) {
$newgold = ceil ( $userrow [ " gold " ] / 2 );
$newhp = ceil ( $userrow [ " maxhp " ] / 4 );
$updatequery = doquery ( " UPDATE { { table}} SET currenthp=' $newhp ',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold=' $newgold ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
$playerisdead = 1 ;
}
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Do spell stuff.
} elseif ( isset ( $_POST [ " spell " ])) {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Your turn.
$pickedspell = $_POST [ " userspell " ];
if ( $pickedspell == 0 ) { display ( " You must select a spell first. Please go back and try again. " , " Error " ); die (); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$newspellquery = doquery ( " SELECT * FROM { { table}} WHERE id=' $pickedspell ' LIMIT 1 " , " spells " );
$newspellrow = mysql_fetch_array ( $newspellquery );
2017-02-05 10:58:20 -06:00
$spell = false ;
foreach ( $userspells as $a => $b ) {
if ( $b == $pickedspell ) { $spell = true ; }
}
2017-02-05 11:05:09 -06:00
if ( $spell != true ) { display ( " You have not yet learned this spell. Please go back and try again. " , " Error " ); die (); }
2017-02-05 10:49:37 -06:00
if ( $userrow [ " currentmp " ] < $newspellrow [ " mp " ]) { display ( " You do not have enough Magic Points to cast this spell. Please go back and try again. " , " Error " ); die (); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $newspellrow [ " type " ] == 1 ) { // Heal spell.
$newhp = $userrow [ " currenthp " ] + $newspellrow [ " attribute " ];
if ( $userrow [ " maxhp " ] < $newhp ) { $newspellrow [ " attribute " ] = $userrow [ " maxhp " ] - $userrow [ " currenthp " ]; $newhp = $userrow [ " currenthp " ] + $newspellrow [ " attribute " ]; }
$userrow [ " currenthp " ] = $newhp ;
$userrow [ " currentmp " ] -= $newspellrow [ " mp " ];
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell, and gained " . $newspellrow [ " attribute " ] . " Hit Points.<br><br> " ;
2017-02-05 10:49:37 -06:00
} elseif ( $newspellrow [ " type " ] == 2 ) { // Hurt spell.
if ( $userrow [ " currentmonsterimmune " ] == 0 ) {
$monsterdamage = rand ((( $newspellrow [ " attribute " ] / 6 ) * 5 ), $newspellrow [ " attribute " ]);
$userrow [ " currentmonsterhp " ] -= $monsterdamage ;
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell for $monsterdamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell, but the monster is immune to it.<br><br> " ;
2017-02-05 10:49:37 -06:00
}
$userrow [ " currentmp " ] -= $newspellrow [ " mp " ];
} elseif ( $newspellrow [ " type " ] == 3 ) { // Sleep spell.
if ( $userrow [ " currentmonsterimmune " ] != 2 ) {
$userrow [ " currentmonstersleep " ] = $newspellrow [ " attribute " ];
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell. The monster is asleep.<br><br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell, but the monster is immune to it.<br><br> " ;
2017-02-05 10:49:37 -06:00
}
$userrow [ " currentmp " ] -= $newspellrow [ " mp " ];
} elseif ( $newspellrow [ " type " ] == 4 ) { // +Damage spell.
$userrow [ " currentuberdamage " ] = $newspellrow [ " attribute " ];
$userrow [ " currentmp " ] -= $newspellrow [ " mp " ];
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell, and will gain " . $newspellrow [ " attribute " ] . " % damage until the end of this fight.<br><br> " ;
2017-02-05 10:49:37 -06:00
} elseif ( $newspellrow [ " type " ] == 5 ) { // +Defense spell.
$userrow [ " currentuberdefense " ] = $newspellrow [ " attribute " ];
$userrow [ " currentmp " ] -= $newspellrow [ " mp " ];
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " You have cast the " . $newspellrow [ " name " ] . " spell, and will gain " . $newspellrow [ " attribute " ] . " % defense until the end of this fight.<br><br> " ;
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterhp " ] = " Monster's HP: " . $userrow [ " currentmonsterhp " ] . " <br><br> " ;
2017-02-05 10:49:37 -06:00
if ( $userrow [ " currentmonsterhp " ] <= 0 ) {
$updatequery = doquery ( " UPDATE { { table}} SET currentmonsterhp='0',currenthp=' " . $userrow [ " currenthp " ] . " ',currentmp=' " . $userrow [ " currentmp " ] . " ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
header ( " Location: index.php?do=victory " );
die ();
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Monster's turn.
$pagearray [ " monsterturn " ] = " " ;
if ( $userrow [ " currentmonstersleep " ] != 0 ) { // Check to wake up.
$chancetowake = rand ( 1 , 15 );
if ( $chancetowake > $userrow [ " currentmonstersleep " ]) {
$userrow [ " currentmonstersleep " ] = 0 ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster has woken up.<br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster is still asleep.<br> " ;
2017-02-05 10:49:37 -06:00
}
}
if ( $userrow [ " currentmonstersleep " ] == 0 ) { // Only do this if the monster is awake.
2017-02-05 10:55:54 -06:00
$tohit = ceil ( rand ( $monsterrow [ " maxdam " ] *. 5 , $monsterrow [ " maxdam " ]));
2017-02-05 10:54:09 -06:00
$toblock = ceil ( rand ( $userrow [ " defensepower " ] *. 75 , $userrow [ " defensepower " ]) / 4 );
2017-02-05 10:49:37 -06:00
$tododge = rand ( 1 , 150 );
if ( $tododge <= sqrt ( $userrow [ " dexterity " ])) {
2024-12-12 11:28:19 -06:00
$tohit = 0 ; $pagearray [ " monsterturn " ] .= " You dodge the monster's attack. No damage has been scored.<br> " ;
2017-02-05 10:49:37 -06:00
$persondamage = 0 ;
} else {
if ( $tohit <= $toblock ) { $tohit = $toblock + 1 ; }
$persondamage = $tohit - $toblock ;
if ( $userrow [ " currentuberdefense " ] != 0 ) {
$persondamage -= ceil ( $persondamage * ( $userrow [ " currentuberdefense " ] / 100 ));
}
if ( $persondamage < 1 ) { $persondamage = 1 ; }
}
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster attacks you for $persondamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
$userrow [ " currenthp " ] -= $persondamage ;
if ( $userrow [ " currenthp " ] <= 0 ) {
$newgold = ceil ( $userrow [ " gold " ] / 2 );
$newhp = ceil ( $userrow [ " maxhp " ] / 4 );
$updatequery = doquery ( " UPDATE { { table}} SET currenthp=' $newhp ',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold=' $newgold ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
$playerisdead = 1 ;
}
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Do a monster's turn if person lost the chance to swing first. Serves him right!
} elseif ( $chancetoswingfirst == 0 ) {
2024-12-12 11:28:19 -06:00
$pagearray [ " yourturn " ] = " The monster attacks before you are ready!<br><br> " ;
$pagearray [ " monsterhp " ] = " Monster's HP: " . $userrow [ " currentmonsterhp " ] . " <br><br> " ;
2017-02-05 10:49:37 -06:00
$pagearray [ " monsterturn " ] = " " ;
if ( $userrow [ " currentmonstersleep " ] != 0 ) { // Check to wake up.
$chancetowake = rand ( 1 , 15 );
if ( $chancetowake > $userrow [ " currentmonstersleep " ]) {
$userrow [ " currentmonstersleep " ] = 0 ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster has woken up.<br> " ;
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster is still asleep.<br> " ;
2017-02-05 10:49:37 -06:00
}
}
if ( $userrow [ " currentmonstersleep " ] == 0 ) { // Only do this if the monster is awake.
2017-02-05 10:55:54 -06:00
$tohit = ceil ( rand ( $monsterrow [ " maxdam " ] *. 5 , $monsterrow [ " maxdam " ]));
2017-02-05 10:49:37 -06:00
$toblock = ceil ( rand ( $userrow [ " defensepower " ] *. 75 , $userrow [ " defensepower " ]) / 4 );
$tododge = rand ( 1 , 150 );
if ( $tododge <= sqrt ( $userrow [ " dexterity " ])) {
2024-12-12 11:28:19 -06:00
$tohit = 0 ; $pagearray [ " monsterturn " ] .= " You dodge the monster's attack. No damage has been scored.<br> " ;
2017-02-05 10:49:37 -06:00
$persondamage = 0 ;
} else {
$persondamage = $tohit - $toblock ;
if ( $persondamage < 1 ) { $persondamage = 1 ; }
if ( $userrow [ " currentuberdefense " ] != 0 ) {
$persondamage -= ceil ( $persondamage * ( $userrow [ " currentuberdefense " ] / 100 ));
}
if ( $persondamage < 1 ) { $persondamage = 1 ; }
}
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterturn " ] .= " The monster attacks you for $persondamage damage.<br><br> " ;
2017-02-05 10:49:37 -06:00
$userrow [ " currenthp " ] -= $persondamage ;
if ( $userrow [ " currenthp " ] <= 0 ) {
$newgold = ceil ( $userrow [ " gold " ] / 2 );
$newhp = ceil ( $userrow [ " maxhp " ] / 4 );
$updatequery = doquery ( " UPDATE { { table}} SET currenthp=' $newhp ',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold=' $newgold ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
$playerisdead = 1 ;
}
}
} else {
$pagearray [ " yourturn " ] = " " ;
2024-12-12 11:28:19 -06:00
$pagearray [ " monsterhp " ] = " Monster's HP: " . $userrow [ " currentmonsterhp " ] . " <br><br> " ;
2017-02-05 10:49:37 -06:00
$pagearray [ " monsterturn " ] = " " ;
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$newmonster = $userrow [ " currentmonster " ];
$newmonsterhp = $userrow [ " currentmonsterhp " ];
$newmonstersleep = $userrow [ " currentmonstersleep " ];
$newmonsterimmune = $userrow [ " currentmonsterimmune " ];
$newuberdamage = $userrow [ " currentuberdamage " ];
$newuberdefense = $userrow [ " currentuberdefense " ];
$newfight = $userrow [ " currentfight " ] + 1 ;
$newhp = $userrow [ " currenthp " ];
2024-12-12 09:33:17 -06:00
$newmp = $userrow [ " currentmp " ];
if ( $playerisdead != 1 ) {
2017-02-05 10:49:37 -06:00
$pagearray [ " command " ] = <<< END
2024-12-12 11:28:19 -06:00
Command ? < br >< br >
2017-02-05 10:49:37 -06:00
< form action = " index.php?do=fight " method = " post " >
2024-12-12 11:28:19 -06:00
< input type = " submit " name = " fight " value = " Fight " />< br >< br >
< select name = " userspell " >< option value = " 0 " > Choose One </ option > $magiclist </ select > < input type = " submit " name = " spell " value = " Spell " />< br >< br >
< input type = " submit " name = " run " value = " Run " />< br >< br >
2017-02-05 10:49:37 -06:00
</ form >
END ;
$updatequery = doquery ( " UPDATE { { table}} SET currentaction='Fighting',currenthp=' $newhp ',currentmp=' $newmp ',currentfight=' $newfight ',currentmonster=' $newmonster ',currentmonsterhp=' $newmonsterhp ',currentmonstersleep=' $newmonstersleep ',currentmonsterimmune=' $newmonsterimmune ',currentuberdamage=' $newuberdamage ',currentuberdefense=' $newuberdefense ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
} else {
2024-12-12 11:28:19 -06:00
$pagearray [ " command " ] = " <b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href= \" index.php \" >town</a>, and we hope you fair better next time. " ;
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
// Finalize page and display it.
$template = gettemplate ( " fight " );
$page = parsetemplate ( $template , $pagearray );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
display ( $page , " Fighting " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
function victory () {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
global $userrow , $controlrow ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " currentmonsterhp " ] != 0 ) { header ( " Location: index.php?do=fight " ); die (); }
if ( $userrow [ " currentfight " ] == 0 ) { header ( " Location: index.php " ); die (); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$monsterquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . $userrow [ " currentmonster " ] . " ' LIMIT 1 " , " monsters " );
$monsterrow = mysql_fetch_array ( $monsterquery );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$exp = rand ((( $monsterrow [ " maxexp " ] / 6 ) * 5 ), $monsterrow [ " maxexp " ]);
if ( $exp < 1 ) { $exp = 1 ; }
if ( $userrow [ " expbonus " ] != 0 ) { $exp += ceil (( $userrow [ " expbonus " ] / 100 ) * $exp ); }
$gold = rand ((( $monsterrow [ " maxgold " ] / 6 ) * 5 ), $monsterrow [ " maxgold " ]);
if ( $gold < 1 ) { $gold = 1 ; }
if ( $userrow [ " goldbonus " ] != 0 ) { $gold += ceil (( $userrow [ " goldbonus " ] / 100 ) * $exp ); }
2017-02-05 10:57:01 -06:00
if ( $userrow [ " experience " ] + $exp < 16777215 ) { $newexp = $userrow [ " experience " ] + $exp ; $warnexp = " " ; } else { $newexp = $userrow [ " experience " ]; $exp = 0 ; $warnexp = " You have maxed out your experience points. " ; }
if ( $userrow [ " gold " ] + $gold < 16777215 ) { $newgold = $userrow [ " gold " ] + $gold ; $warngold = " " ; } else { $newgold = $userrow [ " gold " ]; $gold = 0 ; $warngold = " You have maxed out your experience points. " ; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$levelquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . ( $userrow [ " level " ] + 1 ) . " ' LIMIT 1 " , " levels " );
if ( mysql_num_rows ( $levelquery ) == 1 ) { $levelrow = mysql_fetch_array ( $levelquery ); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " level " ] < 100 ) {
if ( $newexp >= $levelrow [ $userrow [ " charclass " ] . " _exp " ]) {
$newhp = $userrow [ " maxhp " ] + $levelrow [ $userrow [ " charclass " ] . " _hp " ];
$newmp = $userrow [ " maxmp " ] + $levelrow [ $userrow [ " charclass " ] . " _mp " ];
$newtp = $userrow [ " maxtp " ] + $levelrow [ $userrow [ " charclass " ] . " _tp " ];
$newstrength = $userrow [ " strength " ] + $levelrow [ $userrow [ " charclass " ] . " _strength " ];
$newdexterity = $userrow [ " dexterity " ] + $levelrow [ $userrow [ " charclass " ] . " _dexterity " ];
$newattack = $userrow [ " attackpower " ] + $levelrow [ $userrow [ " charclass " ] . " _strength " ];
$newdefense = $userrow [ " defensepower " ] + $levelrow [ $userrow [ " charclass " ] . " _dexterity " ];
$newlevel = $levelrow [ " id " ];
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $levelrow [ $userrow [ " charclass " ] . " _spells " ] != 0 ) {
2017-02-05 11:00:00 -06:00
$userspells = $userrow [ " spells " ] . " , " . $levelrow [ $userrow [ " charclass " ] . " _spells " ];
2017-02-05 10:49:37 -06:00
$newspell = " spells=' $userspells ', " ;
2024-12-12 11:28:19 -06:00
$spelltext = " You have learned a new spell.<br> " ;
2017-02-05 10:49:37 -06:00
} else { $spelltext = " " ; $newspell = " " ; }
2024-12-12 09:33:17 -06:00
2024-12-12 11:28:19 -06:00
$page = " Congratulations. You have defeated the " . $monsterrow [ " name " ] . " .<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain " . $levelrow [ $userrow [ " charclass " ] . " _hp " ] . " hit points.<br>You gain " . $levelrow [ $userrow [ " charclass " ] . " _mp " ] . " magic points.<br>You gain " . $levelrow [ $userrow [ " charclass " ] . " _tp " ] . " travel points.<br>You gain " . $levelrow [ $userrow [ " charclass " ] . " _strength " ] . " strength.<br>You gain " . $levelrow [ $userrow [ " charclass " ] . " _dexterity " ] . " dexterity.<br> $spelltext <br>You can now continue <a href= \" index.php \" >exploring</a>. " ;
2017-02-05 10:49:37 -06:00
$title = " Courage and Wit have served thee well! " ;
2017-02-05 10:57:01 -06:00
$dropcode = " " ;
2017-02-05 10:49:37 -06:00
} else {
$newhp = $userrow [ " maxhp " ];
$newmp = $userrow [ " maxmp " ];
$newtp = $userrow [ " maxtp " ];
$newstrength = $userrow [ " strength " ];
$newdexterity = $userrow [ " dexterity " ];
$newattack = $userrow [ " attackpower " ];
$newdefense = $userrow [ " defensepower " ];
$newlevel = $userrow [ " level " ];
$newspell = " " ;
2024-12-12 11:28:19 -06:00
$page = " Congratulations. You have defeated the " . $monsterrow [ " name " ] . " .<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br> " ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( rand ( 1 , 30 ) == 1 ) {
$dropquery = doquery ( " SELECT * FROM { { table}} WHERE mlevel <= ' " . $monsterrow [ " level " ] . " ' ORDER BY RAND() LIMIT 1 " , " drops " );
$droprow = mysql_fetch_array ( $dropquery );
$dropcode = " dropcode=' " . $droprow [ " id " ] . " ', " ;
$page .= " This monster has dropped an item. <a href= \" index.php?do=drop \" >Click here</a> to reveal and equip the item, or you may also move on and continue <a href= \" index.php \" >exploring</a>. " ;
2024-12-12 09:33:17 -06:00
} else {
2017-02-05 10:49:37 -06:00
$dropcode = " " ;
$page .= " You can now continue <a href= \" index.php \" >exploring</a>. " ;
}
$title = " Victory! " ;
}
}
$updatequery = doquery ( " UPDATE { { table}} SET currentaction='Exploring',level=' $newlevel ',maxhp=' $newhp ',maxmp=' $newmp ',maxtp=' $newtp ',strength=' $newstrength ',dexterity=' $newdexterity ',attackpower=' $newattack ',defensepower=' $newdefense ', $newspell currentfight='0',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentuberdamage='0',currentuberdefense='0', $dropcode experience=' $newexp ',gold=' $newgold ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
display ( $page , $title );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
function drop () {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
global $userrow ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " dropcode " ] == 0 ) { header ( " Location: index.php " ); die (); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$dropquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . $userrow [ " dropcode " ] . " ' LIMIT 1 " , " drops " );
$droprow = mysql_fetch_array ( $dropquery );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( isset ( $_POST [ " submit " ])) {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$slot = $_POST [ " slot " ];
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $slot == 0 ) { display ( " Please go back and select an inventory slot to continue. " , " Error " ); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " slot " . $slot . " id " ] != 0 ) {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$slotquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . $userrow [ " slot " . $slot . " id " ] . " ' LIMIT 1 " , " drops " );
$slotrow = mysql_fetch_array ( $slotquery );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$old1 = explode ( " , " , $slotrow [ " attribute1 " ]);
if ( $slotrow [ " attribute2 " ] != " X " ) { $old2 = explode ( " , " , $slotrow [ " attribute2 " ]); } else { $old2 = array ( 0 => " maxhp " , 1 => 0 ); }
$new1 = explode ( " , " , $droprow [ " attribute1 " ]);
if ( $droprow [ " attribute2 " ] != " X " ) { $new2 = explode ( " , " , $droprow [ " attribute2 " ]); } else { $new2 = array ( 0 => " maxhp " , 1 => 0 ); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$userrow [ $old1 [ 0 ]] -= $old1 [ 1 ];
$userrow [ $old2 [ 0 ]] -= $old2 [ 1 ];
if ( $old1 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] -= $old1 [ 1 ]; }
if ( $old1 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] -= $old1 [ 1 ]; }
if ( $old2 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] -= $old2 [ 1 ]; }
if ( $old2 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] -= $old2 [ 1 ]; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$userrow [ $new1 [ 0 ]] += $new1 [ 1 ];
$userrow [ $new2 [ 0 ]] += $new2 [ 1 ];
if ( $new1 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] += $new1 [ 1 ]; }
if ( $new1 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] += $new1 [ 1 ]; }
if ( $new2 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] += $new2 [ 1 ]; }
if ( $new2 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] += $new2 [ 1 ]; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
if ( $userrow [ " currenthp " ] > $userrow [ " maxhp " ]) { $userrow [ " currenthp " ] = $userrow [ " maxhp " ]; }
if ( $userrow [ " currentmp " ] > $userrow [ " maxmp " ]) { $userrow [ " currentmp " ] = $userrow [ " maxmp " ]; }
if ( $userrow [ " currenttp " ] > $userrow [ " maxtp " ]) { $userrow [ " currenttp " ] = $userrow [ " maxtp " ]; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$newname = addslashes ( $droprow [ " name " ]);
$query = doquery ( " UPDATE { { table}} SET slot " . $_POST [ " slot " ] . " name=' $newname ',slot " . $_POST [ " slot " ] . " id=' " . $droprow [ " id " ] . " ', $old1[0] =' " . $userrow [ $old1 [ 0 ]] . " ', $old2[0] =' " . $userrow [ $old2 [ 0 ]] . " ', $new1[0] =' " . $userrow [ $new1 [ 0 ]] . " ', $new2[0] =' " . $userrow [ $new2 [ 0 ]] . " ',attackpower=' " . $userrow [ " attackpower " ] . " ',defensepower=' " . $userrow [ " defensepower " ] . " ',currenthp=' " . $userrow [ " currenthp " ] . " ',currentmp=' " . $userrow [ " currentmp " ] . " ',currenttp=' " . $userrow [ " currenttp " ] . " ',dropcode='0' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
} else {
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$new1 = explode ( " , " , $droprow [ " attribute1 " ]);
if ( $droprow [ " attribute2 " ] != " X " ) { $new2 = explode ( " , " , $droprow [ " attribute2 " ]); } else { $new2 = array ( 0 => " maxhp " , 1 => 0 ); }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$userrow [ $new1 [ 0 ]] += $new1 [ 1 ];
$userrow [ $new2 [ 0 ]] += $new2 [ 1 ];
if ( $new1 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] += $new1 [ 1 ]; }
if ( $new1 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] += $new1 [ 1 ]; }
if ( $new2 [ 0 ] == " strength " ) { $userrow [ " attackpower " ] += $new2 [ 1 ]; }
if ( $new2 [ 0 ] == " dexterity " ) { $userrow [ " defensepower " ] += $new2 [ 1 ]; }
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$newname = addslashes ( $droprow [ " name " ]);
$query = doquery ( " UPDATE { { table}} SET slot " . $_POST [ " slot " ] . " name=' $newname ',slot " . $_POST [ " slot " ] . " id=' " . $droprow [ " id " ] . " ', $new1[0] =' " . $userrow [ $new1 [ 0 ]] . " ', $new2[0] =' " . $userrow [ $new2 [ 0 ]] . " ',attackpower=' " . $userrow [ " attackpower " ] . " ',defensepower=' " . $userrow [ " defensepower " ] . " ',dropcode='0' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
$page = " The item has been equipped. You can now continue <a href= \" index.php \" >exploring</a>. " ;
display ( $page , " Item Drop " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$attributearray = array ( " maxhp " => " Max HP " ,
" maxmp " => " Max MP " ,
" maxtp " => " Max TP " ,
" defensepower " => " Defense Power " ,
" attackpower " => " Attack Power " ,
" strength " => " Strength " ,
" dexterity " => " Dexterity " ,
" expbonus " => " Experience Bonus " ,
" goldbonus " => " Gold Bonus " );
2024-12-12 09:33:17 -06:00
2024-12-12 11:28:19 -06:00
$page = " The monster dropped the following item: <b> " . $droprow [ " name " ] . " </b><br><br> " ;
$page .= " This item has the following attribute(s):<br> " ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
$attribute1 = explode ( " , " , $droprow [ " attribute1 " ]);
$page .= $attributearray [ $attribute1 [ 0 ]];
2024-12-12 11:28:19 -06:00
if ( $attribute1 [ 1 ] > 0 ) { $page .= " + " . $attribute1 [ 1 ] . " <br> " ; } else { $page .= $attribute1 [ 1 ] . " <br> " ; }
2024-12-12 09:33:17 -06:00
if ( $droprow [ " attribute2 " ] != " X " ) {
2017-02-05 10:49:37 -06:00
$attribute2 = explode ( " , " , $droprow [ " attribute2 " ]);
$page .= $attributearray [ $attribute2 [ 0 ]];
2024-12-12 11:28:19 -06:00
if ( $attribute2 [ 1 ] > 0 ) { $page .= " + " . $attribute2 [ 1 ] . " <br> " ; } else { $page .= $attribute2 [ 1 ] . " <br> " ; }
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2024-12-12 11:28:19 -06:00
$page .= " <br>Select an inventory slot from the list below to equip this item. If the inventory slot is already full, the old item will be discarded. " ;
2017-02-05 10:49:37 -06:00
$page .= " <form action= \" index.php?do=drop \" method= \" post \" ><select name= \" slot \" ><option value= \" 0 \" >Choose One</option><option value= \" 1 \" >Slot 1: " . $userrow [ " slot1name " ] . " </option><option value= \" 2 \" >Slot 2: " . $userrow [ " slot2name " ] . " </option><option value= \" 3 \" >Slot 3: " . $userrow [ " slot3name " ] . " </option></select> <input type= \" submit \" name= \" submit \" value= \" Submit \" /></form> " ;
$page .= " You may also choose to just continue <a href= \" index.php \" >exploring</a> and give up this item. " ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
display ( $page , " Item Drop " );
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
function dead () {
2024-12-12 09:33:17 -06:00
2024-12-12 11:28:19 -06:00
$page = " <b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href= \" index.php \" >town</a>, and we hope you fair better next time. " ;
2024-12-12 09:33:17 -06:00
2017-02-05 10:49:37 -06:00
}
2024-12-12 09:33:17 -06:00
?>