Merge remote-tracking branch 'origin/dev' into dev-lopar
# Conflicts: # online.php
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Helpers;
|
||||
|
||||
class Str
|
||||
{
|
||||
public static function snakeCase($string): string
|
||||
{
|
||||
return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $string));
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,47 @@
|
||||
|
||||
namespace DarksLight2\Training;
|
||||
|
||||
use DarksLight2\Helpers\Str;
|
||||
use User;
|
||||
|
||||
abstract class StepFactory
|
||||
{
|
||||
|
||||
abstract public function getTitle(): string;
|
||||
abstract public function getMessage(): string;
|
||||
abstract public function getShortName(): string;
|
||||
abstract public function getRewards(): array;
|
||||
public function onLocations(): array
|
||||
{
|
||||
return ['all'];
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return Str::snakeCase(get_class($this));
|
||||
}
|
||||
public function getAnswer()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function allowedToMove(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function databaseRecord()
|
||||
{
|
||||
return [
|
||||
'completed' => false,
|
||||
'progress' => [
|
||||
'current' => 0,
|
||||
'need' => 1,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
+8
-4
@@ -4,17 +4,17 @@ namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class FirstStep extends StepFactory
|
||||
class ChatFirstQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Первое знакомство';
|
||||
return 'Начало.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'test';
|
||||
return 'Отправьте сообщение в общий чат.';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
@@ -24,7 +24,11 @@ class FirstStep extends StepFactory
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'first_step';
|
||||
return 'chat_first_quest';
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class ChatFirstStep extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Начало.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Помните, оскорблять, унижать, обсуждать политику, подстёгивать других игроков, как в общем чате так и в приватном приведет к временному ограничению возможности отправки сообщений в любой из чатов.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'chat_first_step';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class ChatSecondQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Начало.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Отправьте адресное сообщение в общий чат, нажав 1 раз по никнейму игрока либо в чате, либо со списка онлайна, который находится справа.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'chat_second_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class ChatThirdQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Начало.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Отправьте адресное личное сообщение в чат, нажав 2 раза по никнему игрока либо в чате, либо со списка онлайна, который находится справа.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'chat_third_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserFirstQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Сколько всего основных игровых Валют? Введите их число...';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_first_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAnswer(): string
|
||||
{
|
||||
return '2';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserFirstStep extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'В нашей игре, ваш персонаж расположен слева от экрана с игровыми локациями, там же, можно увидеть пустые слоты под предметы и параметры персонажа, ваш опыт, деньги, ежедневные задания...';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_first_step';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserFourthQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Войдите во вкладку " Умения ", в правой части экрана, сверху, а далее, перейдите во вкладку " Приёмы ", после чего, выберите нужные Вам приемы, но будьте внимательны, некоторые из приемов могут быть на разные классы, обязательно прочтите их описание или потестируйте в поединках.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_fourth_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserFourthStep extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return '"Параметры Персонажа"<br>
|
||||
Все игроки имеют свободные очки распределения параметров, что они дают игрокам конкретные модификаторы в зависимости от того, в какой из параметров распределяются очки распределения.<br>
|
||||
--- если можно, добавить скрин как выглядит эта кнопка ---
|
||||
Сила - Увеличивает мощность рубящего урона ( для Силачей )<br>
|
||||
Ловкость - Увеличивает мощность колющего урона ( для Критоуворотов и Уворотов )<br>
|
||||
Интуиция - Увеличивает мощность режущего урона ( для Критовиков )<br>
|
||||
Выносливость - Увеличивает защиту от урона и магии, а так же добавит немного жизней. ( для Танков )<br>
|
||||
Интелект - Увеличивает мощность магии. ( Для Любого Мага )<br>
|
||||
Мудрость - Увеличивает колличество маны. ( Для Любого Мага )<br>
|
||||
<br>
|
||||
Дополнительно, игроки имеют очки распределения Мастерства Оружия, это позволит воинам увеличить урон, а магам, открыть новые приемы.<br>
|
||||
Очки распределения Оружий распределяются точно так же, как и очки распределения параметров ( статов ).<br>
|
||||
<br>
|
||||
В случае, если вы распределили неверно любые доступные очки распределения, или хотите их изменить, вы можете это сделать, поднявшись на 2 этаж здания " Бойцовский Клуб ".';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_fourth_step';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAnswer(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserSecondQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Кого убивает игровой класс "Танк"?';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_second_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAnswer(): string
|
||||
{
|
||||
return 'Уворотов и Силачей';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserSecondStep extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Опыт - Получение опыта происходит после сыгранных поединков, в зависимости от выбитого урона с противников, нажав по своему опыту, откроется таблица опыта, в которой можно посмотреть, когда вы получите дополнительное очко распределение параметров персонажа/оружий, награду за взятие " апа " или " Уровня "<br>
|
||||
Текущий уровень - Отображает ваш текущий уровень персонажа.<br>
|
||||
Победы - Отображает сумму всех ваших побед, в любых поединках.<br>
|
||||
Поражения - Отображает сумму всех ваших поражений, в любых поединках.<br>
|
||||
Ничьих - Отображает сумму всех поединков, которые завершились в ничью.<br>
|
||||
Кредиты - Обычная игровая валюта - кредиты ( креды ), которые можно потратить в обычном магазине.<br>
|
||||
Еврокредиты - Покупная игровая валюта - еврокредиты ( екры ) , которые можно потратить в магазине " Берёзка ". <br>
|
||||
Воинственность - Дополнительная игровая валюта, потратить её можно в Подпольной Лавке.<br>
|
||||
Ежедневное задание - Отображает текущее ежедневное задание либо предоставляет возможность его взятия.<br>
|
||||
Бонус - Позволяет получить немного кредитов или еврокредитов.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_second_step';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserThirdQuest extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'Распределите свободные параметры распределения ( статы ) и параметры оружий ( умения ) в зависимости от выбранного вами при регистрации "Класса" игрока нажав по кнопке " + Способности ", а далее, после распределения параметров " Сохранить ".';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_third_quest';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function isInfo(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function allowedToMove(): array
|
||||
{
|
||||
return ['cp1'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace DarksLight2\Training\Steps;
|
||||
|
||||
use DarksLight2\Training\StepFactory;
|
||||
|
||||
class MyUserThirdStep extends StepFactory
|
||||
{
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Персонаж.';
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return 'В нашей игре, существует 5 Воинских и 4 Магических класса, такие как:<br>
|
||||
Критовик - Убивает Танков и Магов, основное оружие - Мечи<br>
|
||||
Уворот - Убивает Критовиков и Силачей, основное оружие - Кинжалы<br>
|
||||
Танк - Убивает Уворотов и Силачей, основное оружие - Дубина и щит.<br>
|
||||
Силач - Убивает Критовиков и Магов, основное оружие - Топоры<br>
|
||||
Критоуворот - Убивает Силачей и с небольшим шансом Критовиков и Уворотов, основное оружие - Кинжалы.<br>
|
||||
<br>
|
||||
Маг Огня - Атакующий маг, убивает Уворотов и Танков.<br>
|
||||
Маг Воздуха - Атакующий маг, убивает Уворотов и Танков.<br>
|
||||
Маг Земли - Защищающийся маг, слабый урон, хорошая защита.<br>
|
||||
Маг Воды - Защищающийся маг, слабый урон, хорошая защита.';
|
||||
}
|
||||
|
||||
public function getShortName(): string
|
||||
{
|
||||
return 'my_user_third_step';
|
||||
}
|
||||
|
||||
public function getRewards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function allowedToMove(): array
|
||||
{
|
||||
return ['cp1'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,24 +3,125 @@
|
||||
namespace DarksLight2\Training;
|
||||
|
||||
use Core\Db;
|
||||
use DarksLight2\Training\Steps\ChatFirstStep;
|
||||
use DarksLight2\Training\Steps\MyUserFirstQuest;
|
||||
use DarksLight2\Training\Steps\MyUserFirstStep;
|
||||
use DarksLight2\Training\Steps\MyUserFourthQuest;
|
||||
use DarksLight2\Training\Steps\MyUserFourthStep;
|
||||
use DarksLight2\Training\Steps\MyUserSecondQuest;
|
||||
use DarksLight2\Training\Steps\MyUserSecondStep;
|
||||
use DarksLight2\Training\Steps\MyUserThirdQuest;
|
||||
use DarksLight2\Training\Steps\MyUserThirdStep;
|
||||
use DarksLight2\Traits\Singleton;
|
||||
use PDO;
|
||||
use stdClass;
|
||||
use PassGen;
|
||||
use User;
|
||||
|
||||
class TrainingManager
|
||||
{
|
||||
|
||||
use Singleton;
|
||||
|
||||
private $database_records = false;
|
||||
private array $steps_data;
|
||||
private int $user_id;
|
||||
private array $steps;
|
||||
public string $current_step = '';
|
||||
private array $registered_steps;
|
||||
private array $completed_steps;
|
||||
private array $active_steps;
|
||||
|
||||
public function __construct(int $user_id)
|
||||
private $database;
|
||||
|
||||
public function __construct(int $user_id, $refresh_token = true)
|
||||
{
|
||||
try {
|
||||
$this->register([
|
||||
new ChatFirstStep(),
|
||||
new MyUserFirstStep(),
|
||||
new MyUserFirstQuest(),
|
||||
new MyUserSecondStep(),
|
||||
new MyUserSecondQuest(),
|
||||
new MyUserThirdStep(),
|
||||
new MyUserThirdQuest(),
|
||||
new MyUserFourthStep(),
|
||||
new MyUserFourthQuest(),
|
||||
]);
|
||||
} catch (TrainingException $e) {
|
||||
}
|
||||
|
||||
$this->user_id = $user_id;
|
||||
|
||||
if($refresh_token) {
|
||||
$this->generateToken();
|
||||
}
|
||||
|
||||
$this->database = Db::getRow('SELECT * FROM user_training WHERE user_id = ?', [$user_id]);
|
||||
|
||||
$this->createDatabaseRecord();
|
||||
|
||||
$this->database['data'] = json_decode($this->database['data'], true);
|
||||
|
||||
$this->selectActiveSteps();
|
||||
}
|
||||
|
||||
public function getCurrentStepName(): string
|
||||
{
|
||||
if(empty($this->current_step)) {
|
||||
$this->current_step = array_key_first($this->active_steps) ?? '';
|
||||
}
|
||||
|
||||
return $this->current_step;
|
||||
}
|
||||
public function getRegistered(): array
|
||||
{
|
||||
return $this->registered_steps;
|
||||
}
|
||||
|
||||
public function getDatabaseData()
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function addPoint($short_name, $closure = null)
|
||||
{
|
||||
if($short_name === $this->getCurrentStepName()) {
|
||||
$this->database['data'][$short_name]['progress']['current']++;
|
||||
if(isset($closure)) {
|
||||
$closure($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function nextStep()
|
||||
{
|
||||
|
||||
if($this->database['data'][$this->getCurrentStepName()]['progress']['need'] <= $this->database['data'][$this->getCurrentStepName()]['progress']['current']) {
|
||||
$this->database['data'][$this->getCurrentStepName()]['progress']['current'] = 0;
|
||||
$this->database['data'][$this->getCurrentStepName()]['completed'] = true;
|
||||
unset($this->active_steps[$this->getCurrentStepName()]);
|
||||
$this->current_step = array_key_first($this->active_steps) ?? '';
|
||||
$this->database['current'] = $this->getCurrentStepName();
|
||||
}
|
||||
}
|
||||
|
||||
public function previousStep()
|
||||
{
|
||||
$this->current_step = end($this->completed_steps) ?? '';
|
||||
$this->database['current'] = $this->current_step;
|
||||
$this->database['data'][$this->getCurrentStepName()]['completed'] = false;
|
||||
}
|
||||
|
||||
public function selectActiveSteps()
|
||||
{
|
||||
foreach ($this->database['data'] as $step_name => $data) {
|
||||
if($data['completed'] === false) {
|
||||
$this->active_steps[$step_name] = $data;
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->completed_steps[] = $step_name;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
Db::sql('UPDATE user_training SET data = ?, current = ? WHERE user_id = ?', [json_encode($this->database['data']), $this->database['current'], $this->user_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,104 +138,55 @@ class TrainingManager
|
||||
|
||||
foreach ($steps as $step) {
|
||||
if($step instanceof StepFactory) {
|
||||
$this->steps[$step->getShortName()] = new class (
|
||||
$step->getMessage(),
|
||||
$step->getTitle(),
|
||||
$step->getRewards(),
|
||||
$this->stepData($step->getShortName())->complete,
|
||||
$step->getShortName(),
|
||||
$this->stepData($step->getShortName())->progress
|
||||
) {
|
||||
public string $message;
|
||||
public string $title;
|
||||
public string $short_name;
|
||||
public array $rewards;
|
||||
public bool $isComplete;
|
||||
|
||||
public stdClass $progress;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
string $title,
|
||||
array $rewards,
|
||||
bool $isComplete,
|
||||
string $short_name,
|
||||
stdClass $progress
|
||||
) {
|
||||
$this->rewards = $rewards;
|
||||
$this->title = $title;
|
||||
$this->isComplete = $isComplete;
|
||||
$this->message = $message;
|
||||
$this->short_name = $short_name;
|
||||
$this->progress = $progress;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$path = $_SERVER['DOCUMENT_ROOT'] . '/modules_data/steps/' . $this->short_name . '.php';
|
||||
|
||||
if(file_exists($path)) {
|
||||
require $path;
|
||||
return;
|
||||
}
|
||||
|
||||
throw TrainingException::noRenderingFile();
|
||||
}
|
||||
};
|
||||
$this->registered_steps[$step->getShortName()] = $step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function stepData(string $short_name): object
|
||||
private function generateToken($length = 16)
|
||||
{
|
||||
return json_decode($this->getDatabaseRecords()->data)->$short_name;
|
||||
}
|
||||
|
||||
private function getDatabaseRecords()
|
||||
{
|
||||
if(!$this->database_records) {
|
||||
$this->database_records = Db::run('SELECT * FROM user_training WHERE user_id = ?', [$this->user_id])
|
||||
->fetch(PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
return $this->database_records;
|
||||
Db::run('UPDATE user_training SET api_token = ? WHERE user_id = ?', [
|
||||
PassGen::new($length),
|
||||
$this->user_id
|
||||
]);
|
||||
}
|
||||
|
||||
public function createDatabaseRecord()
|
||||
{
|
||||
if(!$this->getDatabaseRecords()) {
|
||||
Db::run('INSERT INTO user_training (user_id, data) VALUES (?, ?)', [
|
||||
if(!$this->database) {
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($this->registered_steps as $step) {
|
||||
$data[$step->getShortName()] = $step->databaseRecord();
|
||||
}
|
||||
|
||||
Db::sql('INSERT INTO user_training (user_id, data, current) VALUES (?, ?, ?)', [
|
||||
$this->user_id,
|
||||
json_encode($this->firstRecordData())
|
||||
json_encode($data, true),
|
||||
array_key_first($data)
|
||||
]);
|
||||
|
||||
$this->database = Db::getRow('SELECT * FROM user_training WHERE user_id = ?', [$this->user_id]);
|
||||
}
|
||||
}
|
||||
|
||||
private function firstRecordData(): array
|
||||
/**
|
||||
* @throws \DarksLight2\Training\TrainingException
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return [
|
||||
'first_step' => [
|
||||
'complete' => 0,
|
||||
'progress' => [
|
||||
'current' => 0,
|
||||
'need' => 0,
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
if(in_array(User::start()->room['file'], $this->registered_steps[$this->getCurrentStepName()]->onLocations()) || in_array('all', $this->registered_steps[$this->getCurrentStepName()]->onLocations())) {
|
||||
$path = $_SERVER['DOCUMENT_ROOT'] . '/modules_data/steps/step.php';
|
||||
|
||||
public function __get(string $name)
|
||||
{
|
||||
return $this->steps[$name];
|
||||
}
|
||||
|
||||
public function addPoint(string $short_name)
|
||||
{
|
||||
$this->$short_name->progress++;
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
$short_name = $this->getCurrentStepName();
|
||||
$answer = $this->registered_steps[$this->getCurrentStepName()]->getAnswer();
|
||||
require $path;
|
||||
return;
|
||||
}
|
||||
|
||||
throw TrainingException::noRenderingFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Core\Db;
|
||||
use DarksLight2\Training\TrainingManager;
|
||||
use Insallah\Math;
|
||||
|
||||
/*
|
||||
@@ -2054,6 +2055,10 @@ class Priems
|
||||
'UPDATE `stats` SET `priems` = "' . $p . '" WHERE `id` = "' . $this->u->info['id'] . '" LIMIT 1'
|
||||
);
|
||||
if ($upd) {
|
||||
TrainingManager::getInstance()
|
||||
->addPoint('my_user_fourth_quest', function (TrainingManager $manager) {
|
||||
$manager->store();
|
||||
});
|
||||
$this->u->info['priems'] = $p;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user