170 lines
7.6 KiB
PHP
170 lines
7.6 KiB
PHP
<?php
|
|
|
|
namespace Location;
|
|
|
|
use Chat;
|
|
use ChatMessage;
|
|
use User;
|
|
|
|
class DeathTower
|
|
{
|
|
public static function finish($id, $bu, $di)
|
|
{
|
|
$user = User::start();
|
|
if ($bu) {
|
|
/* â ýòîì áîþ ïðîâåðÿåì þçåðîâ */
|
|
$i = 0;
|
|
while ($i < count($bu[$i])) {
|
|
if ($bu[$i]['lose'] > 0 || $bu[$i]['nich']) {
|
|
mysql_query(
|
|
'UPDATE `users` SET `lose` = "' . $bu[$i]['lose'] . '", `nick` = "' . $bu[$i]['nich'] . '" WHERE `id` = "' . $bu[$i]['id'] . '" LIMIT 1'
|
|
);
|
|
mysql_query(
|
|
'UPDATE `bs_turnirs` SET `users_finish` = `users_finish` + 1 WHERE `id` = "' . $id['id'] . '" LIMIT 1'
|
|
);
|
|
/* óäàëÿåì þçåðà */
|
|
if ($bu['inBot'] == 0) {
|
|
$pls1 = mysql_fetch_array(
|
|
mysql_query(
|
|
'SELECT `id`, `bsid`, `money`, `finish`, `time`, `inBot`, `uid` FROM `bs_zv` WHERE `bsid` = "' . $id['id'] . '" AND `finish` = 0 AND `time` = "' . $id['time_start'] . '" AND `inBot` = "' . $bu[$i]['id'] . '" LIMIT 1'
|
|
)
|
|
);
|
|
if (isset($pls1['id'])) {
|
|
mysql_query('DELETE FROM `users` WHERE `id` = "' . $bu[$i]['id'] . '" LIMIT 1');
|
|
mysql_query('DELETE FROM `stats` WHERE `id` = "' . $bu[$i]['id'] . '" LIMIT 1');
|
|
|
|
//âûêèäûâàåì ïðåäìåòû íà çåìëþ
|
|
$spi = mysql_query(
|
|
'SELECT `id`,`item_id` FROM `items_users` WHERE `uid` = "' . $bu[$i]['id'] . '" LIMIT 500'
|
|
);
|
|
$ins = '';
|
|
while ($pli = mysql_fetch_array($spi)) {
|
|
$ins .= '("' . $di['dn_id'] . '","' . $pli['item_id'] . '","' . time(
|
|
) . '","' . $di['x'] . '","' . $di['y'] . '"),';
|
|
}
|
|
|
|
$ins = rtrim($ins, ',');
|
|
mysql_query(
|
|
'INSERT INTO `dungeon_items` (`dn`,`item_id`,`time`,`x`,`y`) VALUES ' . $ins . ''
|
|
);
|
|
mysql_query('DELETE FROM `items_users` WHERE `uid` = "' . $pls1['inBot'] . '" LIMIT 1');
|
|
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $pls1['inBot'] . '" LIMIT 1');
|
|
mysql_query(
|
|
'UPDATE `bs_zv` SET `finish` = "' . time(
|
|
) . '" WHERE `id` = "' . $pls1['id'] . '" LIMIT 1'
|
|
);
|
|
mysql_query('UPDATE `users` SET `inUser` = 0 WHERE `id` = "' . $pls1['uid'] . '" LIMIT 1');
|
|
}
|
|
}
|
|
$id['users_finish']++;
|
|
}
|
|
$i++;
|
|
}
|
|
}
|
|
if ($id['users'] - $id['users_finish'] >= 2) {
|
|
return;
|
|
}
|
|
$win = [];
|
|
$sp = mysql_query(
|
|
'SELECT `id`,`bsid`,`money`,`finish`,`time`,`inBot`,`uid` FROM `bs_zv` WHERE `bsid` = "' . $id['id'] . '" AND `finish` = "0" AND `time` = "' . $id['time_start'] . '" ORDER BY `money` DESC LIMIT 100'
|
|
);
|
|
while ($pl = mysql_fetch_array($sp)) {
|
|
$ur = mysql_fetch_array(
|
|
mysql_query(
|
|
'SELECT `id`,`login`,`room`,`name`,`sex`,`inUser`,`twink`,`lose`,`nich`,`win` FROM `users` WHERE `id` = "' . $pl['uid'] . '" LIMIT 1'
|
|
)
|
|
);
|
|
$ub = mysql_fetch_array(
|
|
mysql_query(
|
|
'SELECT `id`,`login`,`room`,`name`,`sex`,`inUser`,`twink`,`lose`,`nich`,`win` FROM `users` WHERE `id` = "' . $ur['inUser'] . '" LIMIT 1'
|
|
)
|
|
);
|
|
if (isset($ur['id']) && isset($ub['id']) && $ub['lose'] <= 0 && $ub['nich'] <= 0) {
|
|
$win = $ub;
|
|
$winr = $ur;
|
|
}
|
|
}
|
|
|
|
$chat = new Chat();
|
|
$cmsg = new ChatMessage();
|
|
|
|
/* çàâåðøàåì ÁÑ */
|
|
if (isset($win['id']) && $win['lose'] == 0 && $win['nich'] == 0 && $win['id'] > 0) {
|
|
//åñòü ïîáåäèòåëü
|
|
$bsep = 0;
|
|
if ($winr['level'] < 6) {
|
|
$bsep = 2500;
|
|
} elseif ($winr['level'] < 7) {
|
|
$bsep = 5000;
|
|
} elseif ($winr['level'] < 8) {
|
|
$bsep = 15000;
|
|
} elseif ($winr['level'] < 9) {
|
|
$bsep = 25000;
|
|
} else {
|
|
$bsep = 50000;
|
|
}
|
|
/* Âûäàåì ïðèç */
|
|
$mn = (round($id['money'] / 100 * 85));
|
|
mysql_query(
|
|
'UPDATE `users` SET `money` = `money` + "' . $mn . '" WHERE `id` = "' . $winr['id'] . '" LIMIT 1'
|
|
);
|
|
mysql_query(
|
|
'UPDATE `stats` SET `exp` = `exp` + "' . $bsep . '" WHERE `id` = "' . $winr['id'] . '" LIMIT 1'
|
|
);
|
|
/* ÷àò */
|
|
$cmsg->setTo($winr['login']);
|
|
$cmsg->setText(
|
|
"Ïîçäðàâëÿåì! Âû ïîáåäèëè â òóðíèðå "Áàøíÿ Ñìåðòè"! Ïîëó÷åíî îïûòà: $bsep, äåíüãè: $mn êð."
|
|
);
|
|
$cmsg->setType(6);
|
|
$chat->sendMsg($cmsg);
|
|
|
|
$cmsg->setTo('');
|
|
$cmsg->setIsAlert(true);
|
|
$cmsg->setText(
|
|
"Çàâåðøèëñÿ òóðíèð "Áàøíÿ Ñìåðòè", ïîáåäèòåëü òóðíèðà: <strong>{$winr['login']}</strong>! Ïîçäðàâëÿåì!"
|
|
);
|
|
$cmsg->setType(5);
|
|
$chat->sendMsg($cmsg);
|
|
|
|
$user->addDelo(
|
|
1, $uid,
|
|
'"<span style="color: #C65F00; ">WinTournament.' . $user->info['city'] . '</span>" (Áàøíÿ Ñìåðòè): Ïîëó÷åíî "<strong>' . $mn . '</strong> êð."',
|
|
time(), $user->info['city'], 'WinTournament.' . $user->info['city'], 0, 0
|
|
);
|
|
} else {
|
|
/* ÷àò */
|
|
$cmsg->setIsAlert(true);
|
|
$cmsg->setType(5);
|
|
$cmsg->setText('Çàâåðøèëñÿ òóðíèð «Áàøíÿ Ñìåðòè», ïîáåäèòåëü òóðíèðà: îòñóòñòâóåò.');
|
|
}
|
|
|
|
$sp = mysql_query(
|
|
'SELECT `id`,`bsid`,`money`,`finish`,`time`,`inBot`,`uid` FROM `bs_zv` WHERE `bsid` = "' . $id['id'] . '" AND `time` = "' . $id['time_start'] . '" ORDER BY `money` DESC LIMIT 100'
|
|
);
|
|
while ($pl = mysql_fetch_array($sp)) {
|
|
$ur = mysql_fetch_array(
|
|
mysql_query(
|
|
'SELECT `id`,`login`,`room`,`name`,`sex`,`inUser`,`lose`,`nich`,`win` FROM `users` WHERE `id` = "' . $pl['uid'] . '" LIMIT 1'
|
|
)
|
|
);
|
|
$ub = mysql_fetch_array(
|
|
mysql_query(
|
|
'SELECT `id`,`login`,`room`,`name`,`sex`,`inUser`,`lose`,`nich`,`win` FROM `users` WHERE `id` = "' . $ur['inUser'] . '" LIMIT 1'
|
|
)
|
|
);
|
|
if (isset($ub['id'])) {
|
|
//del
|
|
mysql_query('DELETE FROM `users` WHERE `id` = "' . $ub['id'] . '" LIMIT 1');
|
|
mysql_query('DELETE FROM `stats` WHERE `id` = "' . $ub['id'] . '" LIMIT 1');
|
|
mysql_query('DELETE FROM `items_users` WHERE `uid` = "' . $ub['id'] . '" LIMIT 500');
|
|
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $ub['id'] . '" LIMIT 500');
|
|
//upd
|
|
mysql_query(
|
|
'UPDATE `bs_zv` SET `finish` = "' . time() . '" WHERE `id` = "' . $pl['id'] . '" LIMIT 1'
|
|
);
|
|
mysql_query('UPDATE `users` SET `inUser` = 0 WHERE `id` = "' . $pl['uid'] . '" LIMIT 1');
|
|
}
|
|
}
|
|
}
|
|
} |