mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-04-30 03:09:22 +02:00
TFS 1.0: House auction system
Would be great if somebody could test it out properly for me. :)
This commit is contained in:
parent
d57f835c91
commit
6001abae5d
11
config.php
11
config.php
@ -36,7 +36,7 @@
|
||||
if (!$time) $time = time();
|
||||
// Date string representation
|
||||
$date = "d F Y (H:i)"; // 15 July 2013 (13:50)
|
||||
if ($adjust) $adjust = (2 * 3600); // Adjust to fit your timezone.
|
||||
if ($adjust) $adjust = (1 * 3600); // Adjust to fit your timezone.
|
||||
else $adjust = 0;
|
||||
if ($format) return date($date, $time+$adjust);
|
||||
else return $time+$adjust;
|
||||
@ -65,8 +65,13 @@
|
||||
2 => 'Thyrfing',
|
||||
3 => 'Town 3',
|
||||
);
|
||||
// Default town id to display when visting house list page page. (TFS 1.0+).
|
||||
$config['HouseListDefaultTown'] = 1;
|
||||
|
||||
// - TFS 1.0 ONLY -- HOUSE AUCTION SYSTEM!
|
||||
$config['houseConfig'] = array(
|
||||
'HouseListDefaultTown' => 1, // Default town id to display when visting house list page page.
|
||||
'minimumBidSQM' => 200, // minimum bid cost on auction (per SQM)
|
||||
'auctionPeriod' => 24 * 60 * 60, // 24 hours auction time.
|
||||
);
|
||||
|
||||
// Leave on black square in map and player should get teleported to their selected town.
|
||||
// If chars get buggy set this position to a beginner location to force players there.
|
||||
|
@ -1414,7 +1414,7 @@ function user_exist($username) {
|
||||
return (mysql_result(mysql_query("SELECT COUNT('id') FROM `accounts` WHERE `name`='$username';"), 0) == 1) ? true : false;
|
||||
}
|
||||
|
||||
function user_name($id) { //USERNAME FROM PLAYER ID (Hauni@otland.net)
|
||||
function user_name($id) { //USERNAME FROM PLAYER ID
|
||||
$id = (int)$id;
|
||||
$name = mysql_select_single("SELECT `name` FROM `players` WHERE `id`='$id';");
|
||||
if ($name !== false) return $name['name'];
|
||||
|
122
house.php
Normal file
122
house.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
|
||||
if ($config['log_ip']) {
|
||||
znote_visitor_insert_detailed_data(3);
|
||||
}
|
||||
|
||||
$house = getValue($_GET['id']);
|
||||
|
||||
if ($house !== false && $config['TFSVersion'] === 'TFS_10') {
|
||||
$house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='$house';");
|
||||
$minbid = $config['houseConfig']['minimumBidSQM'] * $house['size'];
|
||||
if ($house['owner'] > 0) $house['ownername'] = user_name($house['owner']);
|
||||
|
||||
//data_dump($house, false, "Data");
|
||||
|
||||
//////////////////////
|
||||
// Bid on house logic
|
||||
$bid_char = getValue($_POST['char']);
|
||||
$bid_amount = getValue($_POST['amount']);
|
||||
if ($bid_amount !== false && $bid_char !== false) {
|
||||
$bid_char = (int)$bid_char;
|
||||
$bid_amount = (int)$bid_amount;
|
||||
|
||||
$player = mysql_select_single("SELECT `id`, `name`, `balance` FROM `players` WHERE `id`='$bid_char' LIMIT 1;");
|
||||
// Can player afford this bid?
|
||||
if ($player['balance'] > $bid_amount) {
|
||||
// Is bid higher than previous bid?
|
||||
if ($bid_amount > $house['bid']) {
|
||||
// Is bid higher than lowest bid?
|
||||
if ($bid_amount > $minbid) {
|
||||
$lastbid = $house['bid'] + 1;
|
||||
|
||||
// Has bid already started?
|
||||
if ($house['bid_end'] > 0) {
|
||||
mysql_update("UPDATE `houses` SET `highest_bidder`='". $player['id'] ."', `bid`='$bid_amount', `last_bid`='$lastbid' WHERE `id`='". $house['id'] ."' LIMIT 1;");
|
||||
$house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
|
||||
} else {
|
||||
$lastbid = $minbid + 1;
|
||||
$bidend = time() + $config['houseConfig']['auctionPeriod'];
|
||||
mysql_update("UPDATE `houses` SET `highest_bidder`='". $player['id'] ."', `bid`='$bid_amount', `last_bid`='$lastbid', `bid_end`='$bidend' WHERE `id`='". $house['id'] ."' LIMIT 1;");
|
||||
$house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
|
||||
}
|
||||
echo "<b><font color='green'>You have the highest bid on this house!</font></b>";
|
||||
} else echo "<b><font color='red'>You need to place a bid that is higher or equal to {$minbid}gp.</font></b>";
|
||||
} else {
|
||||
// Check if current bid is higher than last_bid
|
||||
if ($bid_amount > $house['last_bid']) {
|
||||
$lastbid = $bid_amount + 1;
|
||||
mysql_update("UPDATE `houses` SET `last_bid`='$lastbid' WHERE `id`='". $house['id'] ."' LIMIT 1;");
|
||||
$house = mysql_select_single("SELECT `id`, `owner`, `paid`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` WHERE `id`='". $house['id'] ."';");
|
||||
echo "<b><font color='orange'>Unfortunately your bid was not higher than previous bidder.</font></b>";
|
||||
} else {
|
||||
echo "<b><font color='red'>Too low bid amount, someone else has a higher bid active.</font></b>";
|
||||
}
|
||||
}
|
||||
} else echo "<b><font color='red'>You don't have enough money to bid this high.</font></b>";
|
||||
}
|
||||
|
||||
// HTML structure and logic
|
||||
?>
|
||||
<h1>House: <?php echo $house['name']; ?></h1>
|
||||
<?php data_dump($house, false, "House SQL"); ?>
|
||||
<ul>
|
||||
<li><b>Town</b>: <?php echo "<a href='houses.php?id=". $house['town_id'] ."'>". $config['towns'][$house['town_id']] ."</a>"; ?></li>
|
||||
<li><b>Size</b>: <?php echo $house['size']; ?></li>
|
||||
<li><b>Beds</b>: <?php echo $house['beds']; ?></li>
|
||||
<li><b>owner</b>: <?php
|
||||
if ($house['owner'] > 0) echo "<a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a>";
|
||||
else echo "Available for auction.";
|
||||
?></li>
|
||||
<li><b>Rent</b>: <?php echo $house['rent']; ?></li>
|
||||
</ul>
|
||||
<?php
|
||||
// AUCTION MARKUP INIT
|
||||
if ($house['owner'] == 0) {
|
||||
?>
|
||||
<h2>This house is up on auction!</h2>
|
||||
<?php
|
||||
if ($house['highest_bidder'] == 0) echo "<b>This house don't have any bidders yet.</b>";
|
||||
else {
|
||||
$bidder = mysql_select_single("SELECT `name` FROM `players` WHERE `id`='". $house['highest_bidder'] ."' LIMIT 1;");
|
||||
echo "<b>This house have bidders! If you want this house, now is your chance!</b>";
|
||||
echo "<br><b>Active bid:</b> ". $house['last_bid'] ."gp";
|
||||
echo "<br><b>Active bid by:</b> <a href='characterprofile.php?name=". $bidder['name'] ."' target='_BLANK'>". $bidder['name'] ."</a>";
|
||||
echo "<br><b>Bid will end on:</b> ". getClock($house['bid_end'], true);
|
||||
}
|
||||
|
||||
if (user_logged_in()) {
|
||||
// Your characters, indexed by char_id
|
||||
$yourChars = mysql_select_multi("SELECT `id`, `name`, `balance` FROM `players` WHERE `account_id`='". $user_data['id'] ."';");
|
||||
if ($yourChars !== false) {
|
||||
$charData = array();
|
||||
foreach ($yourChars as $char) {
|
||||
$charData[$char['id']] = $char;
|
||||
if (get_character_guild_rank($char['id']) > 0) {
|
||||
$guild = get_player_guild_data($char['id']);
|
||||
$charData[$char['id']]['guild'] = $guild['guild_id'];
|
||||
$charData[$char['id']]['guild_rank'] = $guild['rank_level'];
|
||||
} else $charData[$char['id']]['guild'] = '0';
|
||||
}
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<select name="char">
|
||||
<?php
|
||||
foreach ($charData as $id => $char) {
|
||||
echo "<option value='$id'>". $char['name'] ." [". $char['balance'] ."]</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<input type="text" name="amount" placeholder="Min bid: <?php echo $minbid + 1; ?>">
|
||||
<input type="submit" value="Bid on this house">
|
||||
</form>
|
||||
<?php
|
||||
} else echo "<br>You need a character to bid on this house.";
|
||||
} else echo "<br>You need to login before you can bid on houses.";
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<h1>No house selected.</h1>
|
||||
<p>Go back to the <a href="houses.php">house list</a> and select a house for further details.</p>
|
||||
<?php
|
||||
}
|
||||
include 'layout/overall/footer.php'; ?>
|
16
houses.php
16
houses.php
@ -142,14 +142,14 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
||||
} else echo '<p><font color="red">Something is wrong with the cache.</font></p>';
|
||||
} else if ($config['TFSVersion'] === 'TFS_10') {
|
||||
// Fetch values
|
||||
$townid = (getValue($_POST['selected']) !== false) ? (int)$_POST['selected'] : $config['HouseListDefaultTown'];
|
||||
$townid = (getValue($_GET['id']) !== false) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
|
||||
$towns = $config['towns'];
|
||||
|
||||
// Create Search house box
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<form action="" method="get">
|
||||
<b>Select town:</b>
|
||||
<select name="selected">
|
||||
<select name="id">
|
||||
<?php
|
||||
foreach ($towns as $id => $name) {
|
||||
if ($id != $townid) echo '<option value="'. $id .'">'. $name .'</option>';
|
||||
@ -157,10 +157,6 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
/* Form file */
|
||||
Token::create();
|
||||
?>
|
||||
<input type="submit" value="Fetch houses">
|
||||
</form>
|
||||
<?php
|
||||
@ -210,7 +206,7 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
||||
if ($house['town_id'] == $townid) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $house['name']; ?></td>
|
||||
<td><?php echo "<a href='house.php?id=". $house['id'] ."'>". $house['name'] ."</a>"; ?></td>
|
||||
<td><?php echo $house['size']; ?></td>
|
||||
<td><?php echo $house['beds']; ?></td>
|
||||
<td><?php echo $house['rent']; ?></td>
|
||||
@ -219,7 +215,11 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
||||
if ($house['owner'] != 0) {
|
||||
echo "<td><a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a></td>";
|
||||
} else {
|
||||
if ($house['highest_bidder'] == 0) {
|
||||
echo "<td>None</td>";
|
||||
} else {
|
||||
echo "<td><b>Selling</b></td>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<td><?php echo $towns[$house['town_id']]; ?></td>
|
||||
|
@ -1,17 +1,17 @@
|
||||
<div class="sidebar">
|
||||
<h2>Search town list</h2>
|
||||
<div class="inner">
|
||||
<form action="houses.php" method="post">
|
||||
<form action="houses.php" method="<?php if ($config['TFSVersion'] !== 'TFS_10') echo "post"; else echo "get" ;?>">
|
||||
|
||||
Select town:<br>
|
||||
<select name="selected">
|
||||
<select name="<?php if ($config['TFSVersion'] !== 'TFS_10') echo "selected"; else echo "id" ;?>">
|
||||
<?php
|
||||
foreach ($config['towns'] as $id => $name) echo '<option value="'. $id .'">'. $name .'</option>';
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
/* Form file */
|
||||
Token::create();
|
||||
if ($config['TFSVersion'] !== 'TFS_10') Token::create();
|
||||
?>
|
||||
<input type="submit" value="Fetch houses">
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user