2017-02-05 11:51:02 -06:00
< ? php // town.php :: All town functions.
// Before allowing anything else, we make sure the person is actually in town.
global $townrow ;
if ( $townrow == false ) { die ( header ( " Location: index.php " )); }
function dotown () { // Default town screen.
global $userrow ;
$newpm = doquery ( " SELECT * FROM { { table}} WHERE recipientid=' " . $userrow [ " id " ] . " ' AND status='0' " , " messages " );
if ( mysql_num_rows ( $newpm ) > 0 ) {
$row [ " unread " ] = " <b>( " . mysql_num_rows ( $newpm ) . " new)</b> " ;
} else {
$row [ " unread " ] = " " ;
}
display ( " In Town " , parsetemplate ( gettemplate ( " town " ), $row ));
}
function inn () { // Resting at the inn restores hp/mp/tp.
global $userrow , $townrow ;
// Errors.
if ( $userrow [ " gold " ] < $townrow [ " innprice " ]) { err ( " You do not have enough gold to stay at the inn. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $userrow [ " currenthp " ] == $userrow [ " maxhp " ] && $userrow [ " currentmp " ] == $userrow [ " maxmp " ] && $userrow [ " currenttp " ] == $userrow [ " maxtp " ]) { err ( " Your HP, MP and TP are already at their maximum levels. You do not need to stay at the Inn tonight.<br /><br /><a href= \" index.php \" >Click here</a> to return to the main town screen. " ); }
if ( isset ( $_POST [ " submit " ])) {
// Fill 'er up, my man!
$userrow [ " currenthp " ] = $userrow [ " maxhp " ];
$userrow [ " currentmp " ] = $userrow [ " maxmp " ];
$userrow [ " currenttp " ] = $userrow [ " maxtp " ];
$userrow [ " gold " ] -= $townrow [ " innprice " ];
$query = doquery ( " UPDATE { { table}} SET currenthp=' " . $userrow [ " maxhp " ] . " ', currentmp=' " . $userrow [ " maxmp " ] . " ', currenttp=' " . $userrow [ " maxtp " ] . " ', gold=' " . $userrow [ " gold " ] . " ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
display ( " Rest at the Inn " , gettemplate ( " town_inn2 " ));
} elseif ( isset ( $_POST [ " abortmission " ])) { die ( header ( " Location: index.php " )); }
display ( " Rest at the Inn " , parsetemplate ( gettemplate ( " town_inn1 " ), $townrow ));
}
function map () { // Buy maps to towns for the Travel To menu.
global $userrow ;
if ( isset ( $_POST [ " three " ])) {
$townquery = doquery ( " SELECT * FROM { { table}} WHERE id=' " . $_POST [ " id " ] . " ' LIMIT 1 " , " towns " );
$townrow = dorow ( $townquery );
if ( $userrow [ " gold " ] < $townrow [ " mapprice " ]) { err ( " You do not have enough gold to buy this map. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $townrow != false ) {
$userrow [ " townslist " ] .= " , " . $townrow [ " id " ];
$userrow [ " gold " ] -= $townrow [ " mapprice " ];
$query = doquery ( " UPDATE { { table}} SET townslist=' " . $userrow [ " townslist " ] . " ', gold=' " . $userrow [ " gold " ] . " ' WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
display ( " Buy Maps " , gettemplate ( " town_map3 " ));
} else {
err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " );
}
} elseif ( isset ( $_POST [ " two " ])) {
$townquery = doquery ( " SELECT * FROM { { table}} WHERE name=' " . $_POST [ " two " ] . " ' LIMIT 1 " , " towns " );
$townrow = dorow ( $townquery );
if ( $userrow [ " gold " ] < $townrow [ " mapprice " ]) { err ( " You do not have enough gold to buy this map. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $townrow != false ) {
display ( " Buy Maps " , parsetemplate ( gettemplate ( " town_map2 " ), $townrow ));
} else {
err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " );
}
} else {
2017-02-05 11:52:51 -06:00
$townquery = doquery ( " SELECT * FROM { { table}} WHERE world=' " . $userrow [ " world " ] . " ' ORDER BY id " , " towns " );
2017-02-05 11:51:02 -06:00
$townrow = dorow ( $townquery );
$townslist = explode ( " , " , $userrow [ " townslist " ]);
$row [ " maptable " ] = " <form action= \" index.php?do=maps \" method= \" post \" ><table width= \ 95% \" > \n " ;
foreach ( $townrow as $a => $b ) {
if ( in_array ( $b [ " id " ], $townslist )) {
if ( $b [ " latitude " ] < 0 ) { $latitude = ( $b [ " latitude " ] * - 1 ) . " S " ; } else { $latitude = $b [ " latitude " ] . " N " ; }
if ( $b [ " longitude " ] < 0 ) { $longitude = ( $b [ " longitude " ] * - 1 ) . " W " ; } else { $longitude = $b [ " longitude " ] . " E " ; }
$row [ " maptable " ] .= " <tr><td width= \" 20% \" ><input type= \" submit \" name= \" two \" value= \" " . $b [ " name " ] . " \" style= \" width: 100px; \" disabled= \" disabled \" /></td><td width= \" 30% \" style= \" vertical-align: middle; \" ><span class= \" grey \" >Already Purchased</span></td><td width= \" 30% \" style= \" vertical-align: middle; \" ><span class= \" grey \" >Location: <b> $latitude , $longitude </b></span></td><td width= \" 20% \" style= \" vertical-align: middle; \" ><span class= \" grey \" >TP: <b> " . $b [ " travelpoints " ] . " </b></span></td></tr> \n " ;
} else {
$row [ " maptable " ] .= " <tr><td width= \" 20% \" ><input type= \" submit \" name= \" two \" value= \" " . $b [ " name " ] . " \" style= \" width: 100px; \" /></td><td width= \" 30% \" style= \" vertical-align: middle; \" >Price: <b> " . $b [ " mapprice " ] . " Gold</b></td><td colspan= \" 2 \" style= \" vertical-align: middle; \" >Buy map to reveal details.</td></tr> \n " ;
}
}
$row [ " maptable " ] .= " </table></form> \n " ;
display ( " Buy Maps " , parsetemplate ( gettemplate ( " town_map1 " ), $row ));
}
}
function buy () { // Buy items from merchants.
/*
1 : Weapon
2 : Armor
3 : Shield
4 : Helmet
5 : Jewel
6 : Stone
*/
global $userrow , $townrow ;
if ( isset ( $_POST [ " three " ])) {
$idstring = explode ( " , " , $_POST [ " idstring " ]);
foreach ( $idstring as $a => $b ) { if ( ! is_numeric ( $b )) { err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " ); } }
// Get database info on new item.
$newbaseitem = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[1] ' LIMIT 1 " , " itembase " ));
$newprefix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[0] ' LIMIT 1 " , " itemprefixes " ));
$newsuffix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[2] ' LIMIT 1 " , " itemsuffixes " ));
$premodrow = dorow ( doquery ( " SELECT * FROM { { table}} ORDER BY id " , " itemmodnames " ));
// Format the mod name row.
foreach ( $premodrow as $a => $b ) {
$modrow [ $b [ " fieldname " ]] = $b ;
}
$newfullitem = builditem ( $newprefix , $newbaseitem , $newsuffix , $modrow );
// Get database info on old item, if applicable.
if ( $userrow [ " item " . $newbaseitem [ " slotnumber " ] . " idstring " ] != " 0 " ) {
$oldidstring = explode ( " , " , $userrow [ " item " . $newbaseitem [ " slotnumber " ] . " idstring " ]);
$oldbaseitem = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[1] ' LIMIT 1 " , " itembase " ));
$oldprefix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[0] ' LIMIT 1 " , " itemprefixes " ));
$oldsuffix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[2] ' LIMIT 1 " , " itemsuffixes " ));
$oldfullitem = builditem ( $oldprefix , $oldbaseitem , $oldsuffix , $modrow );
} else { $oldfullitem = false ; $oldprefix = false ; $oldsuffix = false ; }
// Requirements check.
if ( $newfullitem [ " requirements " ] == false ) { err ( " You do not meet one or more of the requirements for this item. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $userrow [ " gold " ] < $newfullitem [ " buycost " ]) { err ( " You do not have enough gold in your pocket to buy this item. " ); }
// Now do stuff to userrow (new item only).
$userrow [ " item " . $newfullitem [ " slotnumber " ] . " idstring " ] = $newfullitem [ " fullid " ];
$userrow [ " item " . $newfullitem [ " slotnumber " ] . " name " ] = $newfullitem [ " name " ];
$userrow [ " gold " ] -= $newfullitem [ " buycost " ];
$userrow [ $newfullitem [ " basename " ]] += $newfullitem [ " baseattr " ];
for ( $j = 1 ; $j < 7 ; $j ++ ) {
if ( $newfullitem [ " mod " . $j . " name " ] != " " ) {
$userrow [ $newfullitem [ " mod " . $j . " name " ]] += $newfullitem [ " mod " . $j . " attr " ];
}
}
if ( $newprefix != false ) {
$userrow [ $newprefix [ " basename " ]] += $newprefix [ " baseattr " ];
}
if ( $newsuffix != false ) {
$userrow [ $newsuffix [ " basename " ]] += $newsuffix [ " baseattr " ];
}
// Do more stuff to userrow (old item only).
if ( $oldfullitem != false ) {
$userrow [ " gold " ] += $oldfullitem [ " sellcost " ];
$userrow [ $oldfullitem [ " basename " ]] -= $oldfullitem [ " baseattr " ];
for ( $j = 1 ; $j < 7 ; $j ++ ) {
if ( $oldfullitem [ " mod " . $j . " name " ] != " " ) {
$userrow [ $oldfullitem [ " mod " . $j . " name " ]] -= $oldfullitem [ " mod " . $j . " attr " ];
}
}
if ( $oldprefix != false ) {
$userrow [ $oldprefix [ " basename " ]] -= $oldprefix [ " baseattr " ];
}
if ( $oldsuffix != false ) {
$userrow [ $oldsuffix [ " basename " ]] -= $oldsuffix [ " baseattr " ];
}
}
// And we're done.
updateuserrow ();
display ( " Buy Weapons & Armor " , gettemplate ( " town_buy3 " ));
} elseif ( isset ( $_POST [ " two " ])) {
$idstring = explode ( " , " , $_POST [ " idstring " ]);
foreach ( $idstring as $a => $b ) { if ( ! is_numeric ( $b )) { err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " ); } }
// Get database info on new item.
$newbaseitem = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[1] ' LIMIT 1 " , " itembase " ));
$newprefix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[0] ' LIMIT 1 " , " itemprefixes " ));
$newsuffix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $idstring[2] ' LIMIT 1 " , " itemsuffixes " ));
$premodrow = dorow ( doquery ( " SELECT * FROM { { table}} ORDER BY id " , " itemmodnames " ));
// Format the mod name row.
foreach ( $premodrow as $a => $b ) {
$modrow [ $b [ " fieldname " ]] = $b ;
}
$newfullitem = builditem ( $newprefix , $newbaseitem , $newsuffix , $modrow );
// Get database info on old item, if applicable.
if ( $userrow [ " item " . $newbaseitem [ " slotnumber " ] . " idstring " ] != " 0 " ) {
$oldidstring = explode ( " , " , $userrow [ " item " . $newbaseitem [ " slotnumber " ] . " idstring " ]);
$oldbaseitem = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[1] ' LIMIT 1 " , " itembase " ));
$oldprefix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[0] ' LIMIT 1 " , " itemprefixes " ));
$oldsuffix = dorow ( doquery ( " SELECT * FROM { { table}} WHERE id=' $oldidstring[2] ' LIMIT 1 " , " itemsuffixes " ));
$oldfullitem = builditem ( $oldprefix , $oldbaseitem , $oldsuffix , $modrow );
} else { $oldfullitem = false ; }
// Requirements check.
if ( $newfullitem [ " requirements " ] == false ) { err ( " You do not meet one or more of the requirements for this item. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $userrow [ " gold " ] < $newfullitem [ " buycost " ]) { err ( " You do not have enough gold in your pocket to buy this item. " ); }
// Now make a new array to send to the template.
$full = " _empty " ;
$row [ " newname " ] = $newfullitem [ " name " ];
if ( $oldfullitem != false ) {
$row [ " oldname " ] = $oldfullitem [ " name " ];
$row [ " oldsell " ] = $oldfullitem [ " sellcost " ];
$full = " _full " ;
}
$row [ " newidstring " ] = $newfullitem [ " fullid " ];
// And we're done.
display ( " Buy Weapons & Armor " , parsetemplate ( gettemplate ( " town_buy2 " . $full ), $row ));
} else {
// Grab lots of stuff from the DB.
2017-02-05 11:52:51 -06:00
$preitemsrow = dorow ( doquery ( " SELECT * FROM { { table}} WHERE reqlevel>=' " . $townrow [ " itemminlvl " ] . " ' AND reqlevel<=' " . $townrow [ " itemmaxlvl " ] . " ' ORDER BY RAND() LIMIT 10 " , " itembase " ));
$preprefixrow = dorow ( doquery ( " SELECT * FROM { { table}} WHERE reqlevel<=' " . $userrow [ " level " ] . " ' " , " itemprefixes " ));
$presuffixrow = dorow ( doquery ( " SELECT * FROM { { table}} WHERE reqlevel<=' " . $userrow [ " level " ] . " ' " , " itemsuffixes " ));
$allitemsrow = dorow ( doquery ( " SELECT * FROM { { table}} " , " itembase " ));
$allprefixrow = dorow ( doquery ( " SELECT * FROM { { table}} " , " itemprefixes " ));
$allsuffixrow = dorow ( doquery ( " SELECT * FROM { { table}} " , " itemsuffixes " ));
2017-02-05 11:51:02 -06:00
$premodrow = dorow ( doquery ( " SELECT * FROM { { table}} ORDER BY id " , " itemmodnames " ));
2017-02-05 11:52:51 -06:00
// Format the rows.
foreach ( $allitemsrow as $a => $b ) {
$itemsrow [ $b [ " id " ]] = $b ;
}
foreach ( $allprefixrow as $a => $b ) {
$prefixrow [ $b [ " id " ]] = $b ;
}
foreach ( $allsuffixrow as $a => $b ) {
$suffixrow [ $b [ " id " ]] = $b ;
}
2017-02-05 11:51:02 -06:00
foreach ( $premodrow as $a => $b ) {
$modrow [ $b [ " fieldname " ]] = $b ;
}
2017-02-05 11:52:51 -06:00
// Build old item table.
$row [ " olditems " ] = " " ;
for ( $i = 1 ; $i < 7 ; $i ++ ) {
if ( $userrow [ " item " . $i . " idstring " ] != " 0 " ) {
$ids = explode ( " , " , $userrow [ " item " . $i . " idstring " ]);
$baseitem = $itemsrow [ $ids [ 1 ]];
if ( $ids [ 0 ] != 0 ) { $prefix = $prefixrow [ $ids [ 0 ]]; } else { $prefix = false ; }
if ( $ids [ 2 ] != 0 ) { $suffix = $suffixrow [ $ids [ 2 ]]; } else { $suffix = false ; }
$fullitem = builditem ( $prefix , $baseitem , $suffix , $modrow );
$row [ " olditems " ] .= parsetemplate ( gettemplate ( " town_buy_olditemrow " ), $fullitem );
}
}
// Now build the new item table.
2017-02-05 11:51:02 -06:00
$row [ " itemtable " ] = " " ;
for ( $i = 0 ; $i < 10 ; $i ++ ) {
2017-02-05 11:52:51 -06:00
$baseitem = $preitemsrow [ rand ( 0 ,( sizeof ( $preitemsrow ) - 1 ))];
if ( rand ( 0 , 4 ) == 1 ) { $prefix = $preprefixrow [ rand ( 0 ,( sizeof ( $preprefixrow ) - 1 ))]; } else { $prefix = false ; }
if ( rand ( 0 , 4 ) == 1 ) { $suffix = $presuffixrow [ rand ( 0 ,( sizeof ( $presuffixrow ) - 1 ))]; } else { $suffix = false ; }
2017-02-05 11:51:02 -06:00
$fullitem = builditem ( $prefix , $baseitem , $suffix , $modrow );
$row [ " itemtable " ] .= parsetemplate ( gettemplate ( " town_buy_itemrow " ), $fullitem );
}
// And we're done.
display ( " Buy Weapons & Armor " , parsetemplate ( gettemplate ( " town_buy1 " ), $row ));
}
}
function gamble () {
2017-02-05 11:55:49 -06:00
global $userrow ;
$mode = " easy " ;
if ( isset ( $_GET [ " mode " ])) { $mode = $_GET [ " mode " ]; }
2017-02-05 11:51:02 -06:00
2017-02-05 11:55:49 -06:00
if ( isset ( $_POST [ " submit " ])) {
$amount = $_POST [ " amount " ];
// Cup errors.
if ( ! isset ( $_POST [ " cup " ])) { err ( " You didn't pick any cup to bet on. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
if ( ! is_numeric ( $_POST [ " cup " ])) { err ( " You didn't pick any cup to bet on. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
// Bet amount errors.
if ( trim ( $amount ) == " " ) { err ( " Invalid bet amount. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
if ( ! is_numeric ( $amount )) { err ( " Invalid bet amount. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
if ( $amount < 0 ) { err ( " Invalid bet amount. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
if ( $userrow [ " gold " ] < $amount ) { err ( " Invalid bet amount. Please <a href= \" index.php?do=gamble \" >go back</a> and try again. " ); }
if ( $mode == " hard " ) {
$thecup = $_POST [ " cup " ];
$thewin = rand ( 1 , 9 );
if ( $thecup == $thewin ) {
$userrow [ " gold " ] += ( $amount * 10 );
doquery ( " UPDATE { { table}} SET gold=gold+( $amount * 10) WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2017-02-05 11:56:42 -06:00
display ( " Gamble " , " You won!<br /><br />You just picked up <b> " . ( $amount * 10 ) . " Gold</b>.<br /><br />Care to <a href= \" index.php?do=gamble&mode=hard \" >try again</a> or would you rather go back to <a href= \" index.php \" >town</a>? " );
2017-02-05 11:55:49 -06:00
} else {
$userrow [ " gold " ] -= $amount ;
doquery ( " UPDATE { { table}} SET gold=gold- $amount WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2017-02-05 11:56:42 -06:00
display ( " Gamble " , " You lost!<br /><br />Sorry buddy, but we're gonna have to take your <b> " . $amount . " Gold</b>.<br /><br />Care to <a href= \" index.php?do=gamble&mode=hard \" >try again</a> or would you rather go back to <a href= \" index.php \" >town</a>? " );
2017-02-05 11:55:49 -06:00
}
}
if ( $mode == " easy " ) {
$thecup = $_POST [ " cup " ];
$thewin = rand ( 1 , 3 );
if ( $thecup == $thewin ) {
$userrow [ " gold " ] += ( $amount * 2 );
doquery ( " UPDATE { { table}} SET gold=gold+( $amount * 2) WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2017-02-05 11:56:42 -06:00
display ( " Gamble " , " You won!<br /><br />You just picked up <b> " . ( $amount * 2 ) . " Gold</b>.<br /><br />Care to <a href= \" index.php?do=gamble \" >try again</a> or would you rather go back to <a href= \" index.php \" >town</a>? " );
2017-02-05 11:55:49 -06:00
} else {
$userrow [ " gold " ] -= $amount ;
doquery ( " UPDATE { { table}} SET gold=gold- $amount WHERE id=' " . $userrow [ " id " ] . " ' LIMIT 1 " , " users " );
2017-02-05 11:56:42 -06:00
display ( " Gamble " , " You lost!<br /><br />Sorry buddy, but we're gonna have to take your <b> " . $amount . " Gold</b>.<br /><br />Care to <a href= \" index.php?do=gamble \" >try again</a> or would you rather go back to <a href= \" index.php \" >town</a>? " );
2017-02-05 11:55:49 -06:00
}
}
} else {
if ( $mode == " hard " ) {
$row [ " mode " ] = " hard " ;
$row [ " form " ] = " <table width= \" 200 \" ><tr> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 1 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 1 \" id= \" 1 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 34% \" style= \" text-align: center; \" ><label for= \" 2 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 2 \" id= \" 2 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 3 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 3 \" id= \" 3 \" /></label></td> " ;
$row [ " form " ] .= " </tr><tr> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 4 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 4 \" id= \" 4 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 34% \" style= \" text-align: center; \" ><label for= \" 5 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 5 \" id= \" 5 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 6 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 6 \" id= \" 6 \" /></label></td> " ;
$row [ " form " ] .= " </tr><tr> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 7 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 7 \" id= \" 7 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 34% \" style= \" text-align: center; \" ><label for= \" 8 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 8 \" id= \" 8 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 9 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 9 \" id= \" 9 \" /></label></td> " ;
$row [ " form " ] .= " </tr></table> " ;
}
if ( $mode == " easy " ) {
$row [ " mode " ] = " easy " ;
$row [ " form " ] = " <table width= \" 200 \" ><tr> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 1 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 1 \" id= \" 1 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 34% \" style= \" text-align: center; \" ><label for= \" 2 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 2 \" id= \" 2 \" /></label></td> " ;
$row [ " form " ] .= " <td width= \" 33% \" style= \" text-align: center; \" ><label for= \" 3 \" ><img src= \" images/cup.gif \" alt= \" cup \" /><br /><input type= \" radio \" name= \" cup \" value= \" 3 \" id= \" 3 \" /></label></td> " ;
$row [ " form " ] .= " </tr></table> " ;
}
display ( " Gamble " , parsetemplate ( gettemplate ( " town_gamble1 " ), $row ));
}
2017-02-05 11:51:02 -06:00
}
function bank () {
global $userrow ;
if ( isset ( $_POST [ " withdraw " ])) {
if ( ! is_numeric ( $_POST [ " amount " ])) { err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $_POST [ " amount " ] < 1 ) { err ( " Withdrawal amount must be greater than 0. " ); }
if ( $_POST [ " amount " ] > $userrow [ " bank " ]) { err ( " You do not have that much money in the bank. " ); }
$userrow [ " gold " ] += $_POST [ " amount " ];
$userrow [ " bank " ] -= $_POST [ " amount " ];
updateuserrow ();
$row [ " formatbank " ] = number_format ( $userrow [ " bank " ]);
$row [ " formatgold " ] = number_format ( $userrow [ " gold " ]);
display ( " Deposit/Withdraw Gold at the Bank " , parsetemplate ( gettemplate ( " town_bank2 " ), $row ));
} elseif ( isset ( $_POST [ " deposit " ])) {
if ( ! is_numeric ( $_POST [ " amount " ])) { err ( " Invalid action. Please <a href= \" index.php \" >go back</a> and try again. " ); }
if ( $_POST [ " amount " ] < 1 ) { err ( " Deposit amount must be greater than 0. " ); }
if ( $_POST [ " amount " ] > $userrow [ " gold " ]) { err ( " You do not have that much money in your pocket. " ); }
$userrow [ " gold " ] -= $_POST [ " amount " ];
$userrow [ " bank " ] += $_POST [ " amount " ];
updateuserrow ();
$row [ " formatbank " ] = number_format ( $userrow [ " bank " ]);
$row [ " formatgold " ] = number_format ( $userrow [ " gold " ]);
display ( " Deposit/Withdraw Gold at the Bank " , parsetemplate ( gettemplate ( " town_bank2 " ), $row ));
} else {
$row [ " formatbank " ] = number_format ( $userrow [ " bank " ]);
$row [ " formatgold " ] = number_format ( $userrow [ " gold " ]);
display ( " Deposit/Withdraw Gold at the Bank " , parsetemplate ( gettemplate ( " town_bank1 " ), $row ));
}
}
function halloffame () {
2017-02-05 11:54:46 -06:00
$top = dorow ( doquery ( " SELECT *, DATE_FORMAT(birthdate, '%m.%d.%Y') AS fregdate FROM { { table}} ORDER BY experience DESC LIMIT 25 " , " users " ), " id " );
2017-02-05 11:51:02 -06:00
$row [ " halltable " ] = " " ;
$i = 1 ;
2017-02-05 11:54:46 -06:00
foreach ( $top as $a => $b ) {
2017-02-05 11:52:51 -06:00
if ( $b [ " charpicture " ] != " " ) {
$b [ " avatar " ] = " <img src= \" " . $b [ " charpicture " ] . " \" alt= \" " . $b [ " charname " ] . " \" /> " ;
2017-02-05 11:51:02 -06:00
} else {
2017-02-05 11:52:51 -06:00
$b [ " avatar " ] = " <img src= \" images/users/nopicture.gif \" alt= \" " . $b [ " charname " ] . " \" /> " ;
2017-02-05 11:51:02 -06:00
}
2017-02-05 11:52:51 -06:00
$b [ " experience " ] = number_format ( $b [ " experience " ]);
$b [ " number " ] = $i ;
if ( $b [ " guild " ] != 0 ) {
$charname = " [<span style= \" color: " . $b [ " tagcolor " ] . " ; \" > " . $b [ " guildtag " ] . " </span>]<span style= \" color: " . $b [ " namecolor " ] . " ; \" > " . $b [ " charname " ] . " </span> " ;
2017-02-05 11:51:02 -06:00
} else {
2017-02-05 11:52:51 -06:00
$charname = $b [ " charname " ];
2017-02-05 11:51:02 -06:00
}
2017-02-05 11:52:51 -06:00
$b [ " newcharname " ] = $charname ;
$row [ " halltable " ] .= parsetemplate ( gettemplate ( " town_halloffamerow " ), $b );
2017-02-05 11:51:02 -06:00
$i ++ ;
}
$row [ " halltable " ] .= " <br /> \n " ;
display ( " Hall of Fame " , parsetemplate ( gettemplate ( " town_halloffame " ), $row ));
}
function duel () {
global $userrow ;
2017-02-05 11:54:46 -06:00
$row = dorow ( doquery ( " SELECT * FROM { { table}} WHERE UNIX_TIMESTAMP(onlinetime) >= ' " . ( time () - 600 ) . " ' AND world=' " . $userrow [ " world " ] . " ' AND latitude=' " . $userrow [ " latitude " ] . " ' AND longitude=' " . $userrow [ " longitude " ] . " ' AND id !=' " . $userrow [ " id " ] . " ' ORDER BY id " , " users " ), " id " );
2017-02-05 11:51:02 -06:00
$list = " " ;
2017-02-05 11:54:46 -06:00
if ( $row == false ) {
2017-02-05 11:51:02 -06:00
$list .= " There is nobody available to challenge at this time.<br /> " ;
} else {
foreach ( $row as $a => $b ) {
2017-02-05 11:54:46 -06:00
if ( $b [ " guild " ] != 0 ) {
$charname = " [<span style= \" color: " . $b [ " tagcolor " ] . " ; \" > " . $b [ " guildtag " ] . " </span>]<span style= \" color: " . $b [ " namecolor " ] . " ; \" > " . $b [ " charname " ] . " </span> " ;
2017-02-05 11:51:02 -06:00
} else {
2017-02-05 11:54:46 -06:00
$charname = $b [ " charname " ];
2017-02-05 11:51:02 -06:00
}
$list .= " <a href= \" index.php?do=challenge&uid= " . $b [ " id " ] . " \" > " . $b [ " charname " ] . " (Level " . $b [ " level " ] . " )</a><br /> " ;
}
}
$pagerow [ " list " ] = $list ;
display ( " Duel Challenge " , parsetemplate ( gettemplate ( " town_pvplist " ), $pagerow ));
}
function duelchallenge () {
global $userrow , $acctrow ;
if ( isset ( $_GET [ " uid " ])) {
if ( ! is_numeric ( $_GET [ " uid " ])) { err ( " Invalid UID. " ); }
if ( $_GET [ " uid " ] == $userrow [ " id " ]) { err ( " You cannot duel yourself. " ); }
$newuserrow = dorow ( doquery ( " SELECT *,UNIX_TIMESTAMP(onlinetime) as fonlinetime FROM { { table}} WHERE id=' " . $_GET [ " uid " ] . " ' LIMIT 1 " , " users " ));
if ( $newuserrow == false ) { err ( " That user doesn't exist. " ); }
if ( $newuserrow [ " account " ] == $userrow [ " account " ]) { err ( " You cannot duel another character on your own account. " ); }
if ( $newuserrow [ " fonlinetime " ] <= ( time () - 600 )) { err ( " That user is not online. " ); }
if ( $newuserrow [ " currentaction " ] != " In Town " ) { err ( " That user is busy. " ); }
if ( $newuserrow [ " latitude " ] != $userrow [ " latitude " ] || $newuserrow [ " longitude " ] != $userrow [ " longitude " ]) { err ( " That user is not in this town. " ); }
} else { err ( " Invalid UID. " ); }
// No errors, so create the PVP record and update everyone's userrow.
$query = doquery ( " INSERT INTO { { table}} SET id='',player1id=' " . $userrow [ " id " ] . " ',player2id=' " . $newuserrow [ " id " ] . " ',player1name=' " . $userrow [ " charname " ] . " ',player2name=' " . $newuserrow [ " charname " ] . " ',playerturn=' " . $newuserrow [ " id " ] . " ',turntime=NOW(),fightrow='' " , " pvp " );
$query2 = doquery ( " UPDATE { { table}} SET currentpvp=' " . mysql_insert_id () . " ' WHERE id=' " . $newuserrow [ " id " ] . " ' OR id=' " . $userrow [ " id " ] . " ' LIMIT 2 " , " users " );
display ( " Duel Challenge " , parsetemplate ( gettemplate ( " pvp_challenge " ), $newuserrow ));
}
?>