226 lines
9.5 KiB
PHP
226 lines
9.5 KiB
PHP
|
<?php
|
|||
|
|
|||
|
use Insallah\Db;
|
|||
|
use Insallah\Math;
|
|||
|
use Insallah\Table;
|
|||
|
|
|||
|
class Achievements
|
|||
|
{
|
|||
|
private $user;
|
|||
|
private $info;
|
|||
|
private $data = [
|
|||
|
'zb' => [
|
|||
|
'questname' => 'Ежедн.Задания',
|
|||
|
'quest' => 'Выполнить задания бабки.',
|
|||
|
'check' => ['Заданий', 5, 25, 50, 100, 250],
|
|||
|
'prize' => ['Жетон <br>успеха <br>', 5, 20, 40, 60, 100],
|
|||
|
'startlink' => 11
|
|||
|
],
|
|||
|
'vx' => [
|
|||
|
'questname' => 'Хаотические бои',
|
|||
|
'quest' => 'Победить в хаотических боях.',
|
|||
|
'check' => ['Побед', 50, 300, 400, 500, 1000],
|
|||
|
'prize' => ['екр.', 25, 50, 75, 100, 200],
|
|||
|
'startlink' => 21
|
|||
|
],
|
|||
|
'snt' => [
|
|||
|
'questname' => 'Сундук трупожора',
|
|||
|
'quest' => 'Открыть сундук трупожора.',
|
|||
|
'check' => ['Открытий', 5, 25, 50, 100, 250],
|
|||
|
'prize' => ['екр.', 10, 25, 50, 75, 200],
|
|||
|
'startlink' => 31
|
|||
|
],
|
|||
|
'rp' => [
|
|||
|
'questname' => 'Руны 8 лвл.',
|
|||
|
'quest' => 'Получить руну при плавке плохих заготовок. [S]',
|
|||
|
'check' => ['Рун', 5, 10, 25, 50, 100],
|
|||
|
'prize' => ['Плохие <br> заготовки <br>', 5, 7, 10, 12, 15],
|
|||
|
'startlink' => 41
|
|||
|
],
|
|||
|
'rn' => [
|
|||
|
'questname' => 'Руны 9 лвл.',
|
|||
|
'quest' => 'Получить руну при плавке нормальных заготовок. [M]',
|
|||
|
'check' => ['Рун', 5, 10, 15, 25, 50],
|
|||
|
'prize' => ['Нормальные <br> заготовки <br>', 5, 7, 9, 12, 15],
|
|||
|
'startlink' => 51
|
|||
|
],
|
|||
|
'rb' => [
|
|||
|
'questname' => 'Руны 10 лвл.',
|
|||
|
'quest' => 'Получить руну при плавке идеальных заготовок. [L]',
|
|||
|
'check' => ['Рун', 2, 5, 8, 11, 15],
|
|||
|
'prize' => ['Идеальные <br> заготовки <br>', 2, 4, 6, 10, 15],
|
|||
|
'startlink' => 61
|
|||
|
],
|
|||
|
'pg' => [
|
|||
|
'questname' => 'Героич. Сражения',
|
|||
|
'quest' => 'Поучаствовать в героическом сражении.',
|
|||
|
'check' => ['Участий', 100, 200, 400, 600, 1000],
|
|||
|
'prize' => ['Жетон <br>успеха <br>', 10, 20, 40, 60, 80],
|
|||
|
'startlink' => 71
|
|||
|
],
|
|||
|
'bv' => [
|
|||
|
'questname' => 'Продажи Бабушке',
|
|||
|
'quest' => 'Продать бабушке найденные вещи в пещере.',
|
|||
|
'check' => ['Продаж', 5, 25, 50, 100, 250],
|
|||
|
'prize' => ['кр.', 500, 1000, 2000, 4000, 5000],
|
|||
|
'startlink' => 81
|
|||
|
],
|
|||
|
'kw' => [
|
|||
|
'questname' => 'Клан Поединки',
|
|||
|
'quest' => 'Победить в клановой войне.',
|
|||
|
'check' => ['Побед', 5, 10, 15, 20, 25],
|
|||
|
'prize' => ['Свиток <br> кланового<br> опыта ', 1, 2, 5, 10, 15],
|
|||
|
'startlink' => 91
|
|||
|
],
|
|||
|
'pa' => [ # not implemented!
|
|||
|
'questname' => 'Покровительство',
|
|||
|
'quest' => 'Получить покровительство Ангела.',
|
|||
|
'check' => ['Получено', 5, 25, 50, 100, 250],
|
|||
|
'prize' => null,
|
|||
|
'startlink' => null
|
|||
|
],
|
|||
|
'bs' => [
|
|||
|
'questname' => 'Башня смерти',
|
|||
|
'quest' => 'Победы в башне смерти.',
|
|||
|
'check' => ['Побед', 1, 5, 10, 50, 500],
|
|||
|
'prize' => ['екр.', 1, 5, 10, 50, 200],
|
|||
|
'startlink' => 101
|
|||
|
],
|
|||
|
'trn' => [ # not implemented!
|
|||
|
'questname' => null,
|
|||
|
'quest' => 'Победы в турнирах.',
|
|||
|
'check' => ['Побед', 25, 50, 100, 200, 500],
|
|||
|
'prize' => ['екр.', 25, 25, 25, 25, 50],
|
|||
|
'startlink' => 111
|
|||
|
],
|
|||
|
];
|
|||
|
|
|||
|
public function __construct(user $user)
|
|||
|
{
|
|||
|
$this->user = $user;
|
|||
|
$this->info = Db::getRow('select * from users_achiv where id = ?', [$user->info['id']]);
|
|||
|
}
|
|||
|
|
|||
|
private function prizeName($int, $string)
|
|||
|
{
|
|||
|
return in_array($string, ['екр.', 'кр.']) ? $int . ' ' . $string : $string . ' ' . $int;
|
|||
|
}
|
|||
|
|
|||
|
private function drawSunduk($nagr, $whatInside, $tier)
|
|||
|
{
|
|||
|
return vsprintf('<img onclick="%s" onmouseover="%s" onmouseout="%s" onmousedown="%s" class="cp" src="%s" alt="Сундук">',
|
|||
|
[
|
|||
|
"location.href='\main.php?titul&nagr=$nagr'",
|
|||
|
"top.hi(this, '<b>Сундук $tier ранга<hr>Содержит:<hr> $whatInside</b>', event, 2, 0, 1, 1, 'max-width:307px')",
|
|||
|
"top.hic();",
|
|||
|
"top.hic();",
|
|||
|
"https://img.new-combats.com/i/titul/nagr$tier.gif"
|
|||
|
]);
|
|||
|
}
|
|||
|
|
|||
|
public function getList()
|
|||
|
{
|
|||
|
$string = '';
|
|||
|
$this->calculateCurrent(1);
|
|||
|
|
|||
|
foreach ($this->data as $key => $value) {
|
|||
|
//Бля, какую херню приходится городить!
|
|||
|
//Первое число = требование следующего тира минус требование текущего тира (надо набрать)
|
|||
|
//Второе число = количество достижений минус требование текущего тира (набрал)
|
|||
|
//Требования текущего тира отнимаются чтобы каждый тир начинал считать процент с 0.
|
|||
|
//Пизды дать тому, кто так уебански называет переменные, что нужно полдня въезжать что происходит.
|
|||
|
//И хер поменяешь - всё сломается. FFUUUUUUUUUUUUUU!!! Ins.
|
|||
|
$percentToSuccess = Math::get100Percentage(
|
|||
|
$value['check'][$this->info['klas' . $key] + 1] - $value['check'][$this->info['klas' . $key]],
|
|||
|
$this->info[$key] - $value['check'][$this->info['klas' . $key]]
|
|||
|
);
|
|||
|
//klas$name динамически рассчитыватся исходя из $name в базе
|
|||
|
$string .= '<h4>' . empty($value['questname']) ? $value['quest'] : $value['questname'] . '</h4>';
|
|||
|
$string .= '<strong>' . $value['quest'] . '</strong><br>';
|
|||
|
$string .= 'Текущий Ранг: <strong>' . $this->info['klas' . $key] . '</strong> ';
|
|||
|
$string .= 'Количество ' . mb_strtolower($value['check'][0]) . ': <strong>' . $this->info[$key] . ' =' . $percentToSuccess . '%</strong>';
|
|||
|
|
|||
|
$string .= Table::get([
|
|||
|
['Ранги', 1, 2, 3, 4, 5],
|
|||
|
$value['check'],
|
|||
|
[
|
|||
|
'Награда',
|
|||
|
$this->prizeName($value['prize'][1], $value['prize'][0]),
|
|||
|
$this->prizeName($value['prize'][2], $value['prize'][0]),
|
|||
|
$this->prizeName($value['prize'][3], $value['prize'][0]),
|
|||
|
$this->prizeName($value['prize'][4], $value['prize'][0]),
|
|||
|
$this->prizeName($value['prize'][5], $value['prize'][0])
|
|||
|
]
|
|||
|
], 'prizelist', true);
|
|||
|
# If has new tier, AND only first 5 tiers AND prize is set.
|
|||
|
if (
|
|||
|
$this->info['klas' . $key] > $this->info[$key . '_n'] &&
|
|||
|
in_array($this->info[$key . '_n'], [0, 1, 2, 3, 4]) &&
|
|||
|
!empty($value['prize']) &&
|
|||
|
!empty($value['startlink'])
|
|||
|
) {
|
|||
|
$string .= '<br>Награда:<br>';
|
|||
|
$string .= $this->drawSunduk(
|
|||
|
$this->info[$key . '_n'] + $value['startlink'],
|
|||
|
$this->prizeName($value['prize'][$this->info[$key . '_n'] + 1], $value['prize'][0]),
|
|||
|
$this->info[$key . '_n'] + 1
|
|||
|
);
|
|||
|
}
|
|||
|
$string .= '<hr>';
|
|||
|
}
|
|||
|
return $string;
|
|||
|
}
|
|||
|
|
|||
|
private function calculateCurrent($check = null)
|
|||
|
{
|
|||
|
$this->info['bs'] = $this->user->info['win_bs'];
|
|||
|
foreach ($this->info as $k => $v) {
|
|||
|
if (empty($this->info[$k]) && is_null($check)) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
$this->info["klas$k"] = 0;
|
|||
|
for ($i = 1; $i <= 5; $i++) {
|
|||
|
if ($this->info[$k] >= $this->data[$k]['check'][$i]) {
|
|||
|
$this->info["klas$k"] = $i;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public function getInfo()
|
|||
|
{
|
|||
|
$this->calculateCurrent();
|
|||
|
return $this->info;
|
|||
|
}
|
|||
|
|
|||
|
public function getCheckedInfo()
|
|||
|
{
|
|||
|
$this->calculateCurrent(1);
|
|||
|
return $this->info;
|
|||
|
}
|
|||
|
|
|||
|
public function updateTier($name)
|
|||
|
{
|
|||
|
Db::sql("update users_achiv set $name = $name + 1 where id = ?", [$this->user->info['id']]);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @return array[]
|
|||
|
*/
|
|||
|
public function getData()
|
|||
|
{
|
|||
|
return $this->data;
|
|||
|
}
|
|||
|
|
|||
|
public function hasNoTier4Access($nagr)
|
|||
|
{
|
|||
|
return $this->user->info['level'] < 9 && in_array($nagr, [14, 15, 24, 25, 34, 35, 44, 45, 54, 55, 64, 65, 74, 75, 84, 85, 94, 95, 104, 105]);
|
|||
|
}
|
|||
|
|
|||
|
public function givePrizeItems($itemId, $aType)
|
|||
|
{
|
|||
|
for ($i = 1; $i <= $this->data[$aType]['prize'][$this->info[$aType . '_n'] + 1]; $i++) {
|
|||
|
$this->user->addItem($itemId, $this->user->info['id']);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|