WIP: перед введенимем класса Fighter.php

This commit is contained in:
2024-01-06 00:14:35 +02:00
parent 07f905ef64
commit a2c658166d
67 changed files with 5555 additions and 7135 deletions
+23 -2
View File
@@ -14,7 +14,7 @@ class ActionModel
$this->uid = $uid;
}
public static function new(array $user, string $vals, string $vars, int $time = 0)
public static function new(array $user, string $vals, string $vars, int $time = 0): void
{
if (!$time) {
$time = time();
@@ -60,7 +60,7 @@ class ActionModel
);
}
public function deleteByVals(string $vals)
public function deleteByVals(string $vals): void
{
Db::sql('delete from actions where uid = ? and vals = ?', [$this->uid, $vals]);
}
@@ -83,4 +83,25 @@ class ActionModel
return !empty($arr) ? $arr : [];
}*/
public function getDailyQuest(): array|false
{
return Db::getRow("select * from actions where uid = ? and vars = 'day_quest' limit 1", [$this->uid]);
}
public function getFinishedDailyQuestTasks(int $timeout): array
{
$arr = [];
$counter = Db::getRows(
"select count(*) as c, vars
from actions
where vars in ('end_trup', 'end_xaot', 'psh0', 'trup_sun', 'izlom', 'win') and time > ? and uid = ?
group by vars",
[$timeout, $this->uid]
);
foreach ($counter as $c) {
$arr[$c['vars']] = $c['c'];
}
return $arr;
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace Model;
use Core\Db;
use stdClass;
readonly class BattleModel
{
public stdClass $battle;
public array $battleArray;
private array $all;
public function __construct(int $id) {
$this->all = Db::getRows('select * from battle');
if (empty($id)) {
$this->battle = new stdClass();
$this->battleArray = [];
} else {
foreach ($this->all as $b) {
if ($b['id'] != $id) {
continue;
}
$this->battle = (object)$b;
$this->battleArray = get_object_vars($this->battle);
return;
}
}
}
public static function countClanWars(int $clanid): array
{
$today = (new \DateTimeImmutable('now 00:00:00'))->getTimestamp();
$sql = "select count(id) from battle where
type = 250 and
time_over > ? and
(team_win = ? and clan1 = ?) or (team_win = ? and clan2 = ?)";
$count1 = Db::getValue($sql, [$today, 1, $clanid, 2, $clanid]);
$count2 = Db::getValue($sql, [$today, 2, $clanid, 1, $clanid]);
return [
$count1 ?? 0,
$count2 ?? 0,
];
}
}