Изменил отображение приёмов

This commit is contained in:
2023-01-23 07:33:19 +01:00
parent d9ec810f7f
commit 1fbd8d6de2
6 changed files with 239 additions and 116 deletions
@@ -0,0 +1,14 @@
<?php
namespace DarksLight2\Battle\Techniques;
use DarksLight2\Entity;
use DarksLight2\Traits\Singleton;
class TechniqueCategoryEntity extends Entity
{
use Singleton;
public int $id;
public string $name;
}
@@ -0,0 +1,25 @@
<?php
namespace DarksLight2\Battle\Techniques;
use DarksLight2\Entity;
use DarksLight2\Traits\Singleton;
class TechniquesEntity extends Entity
{
use Singleton;
public int $id;
public string $name;
public string $description;
public string $image;
public int $category_id;
public int $delay;
public float $spirit_points;
public int $critical_points;
public int $parry_points;
public int $defense_points;
public int $damage_points;
public ?int $skip;
public int $level;
}
+122
View File
@@ -0,0 +1,122 @@
<?php
namespace DarksLight2;
use Core\Db;
use Exception;
use ReflectionClass;
use ReflectionException;
use ReflectionProperty;
abstract class Entity
{
protected string $table;
public function toSnakCase($string): string
{
return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $string));
}
protected function getTable(): string
{
if(!isset($this->table)) {
try {
$class = new ReflectionClass($this);
$table_name = preg_replace(
'/_entity/',
'',
$this->toSnakCase($class->getShortName())
);
if (!Db::getRow("SHOW TABLES LIKE '$table_name'")) {
throw new Exception(
'Undefined table ' . $table_name . ' in database'
);
}
$this->table = $table_name;
} catch (Exception $e) {
die;
}
}
return $this->table;
}
public function morph(array $object) {
$class = new ReflectionClass(get_called_class());
try {
$entity = $class->newInstance();
} catch (ReflectionException $e) {
die($e->getMessage());
}
foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
if (isset($object[$prop->getName()])) {
$prop->setValue($entity,$object[$prop->getName()]);
}
}
return $entity;
}
public function find(array $condition): ?Entity
{
$query = "SELECT * FROM {$this->getTable()} WHERE ";
$values = [];
foreach ($condition as $field => $value) {
$values[] = $value;
$query .= "$field = ?";
}
$request = Db::prepare("$query LIMIT 1");
$request->execute($values);
if($result = $request->fetch()) {
return self::morph($result);
}
return null;
}
/**
* @param array|null $condition
*
* @return Entity[]|null
*/
public function findAll(?array $condition = null): ?array
{
if(!isset($condition)) {
$query = "SELECT * FROM {$this->getTable()}";
} else {
$query = "SELECT * FROM {$this->getTable()} WHERE ";
$values = [];
foreach ($condition as $field => $value) {
$values[] = $value;
$query .= "$field = ?";
}
}
$request = Db::prepare("$query");
$request->execute($values ?? null);
if($rows = $request->fetchAll()) {
$result = [];
foreach ($rows as $row) {
$result[] = self::morph($row);
}
return $result;
}
return null;
}
public function save(): void
{
}
}
+33 -47
View File
@@ -2020,11 +2020,9 @@ class Priems
public function uns($id)
{
global $u, $c, $code;
$pl = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `priems` WHERE `level`<="' . $this->u->info['level'] . '" AND `activ` > "0" AND `id` = "' . $id . '" LIMIT 1'
)
);
$pl = $this->getTechniquesInfo($id);
if (!isset($pl['id']) || $this->testpriem($pl, 1) != 0) {
return;
}
@@ -2129,13 +2127,13 @@ class Priems
$cli2 = ' class="nopriemuse" ';
}
$pr .= '<a onMouseOver="top.hi(this,\'<b>' . $pl['name'] . '</b><Br>' . $lvar . '\',event,3,0,1,1,\'width:240px\');" onMouseOut="top.hic();" onMouseDown="top.hic();" ' . $cl . '><img ' . $cli2 . ' style="margin-top:3px; ' . $cl2 . ' margin-left:4px;" src="https://img.new-combats.com/i/eff/' . $pl['img'] . '.gif" width="40" height="25" /></a>';
$pr .= '<a onMouseOver="top.hi(this,\'<b>' . $pl['name'] . '</b><Br>' . $lvar . '\',event,3,0,1,1,\'width:240px\');" onMouseOut="top.hic();" onMouseDown="top.hic();" ' . $cl . '><img ' . $cli2 . ' style="margin-top:3px; ' . $cl2 . ' margin-left:4px;" src="https://img.new-combats.com/i/eff/' . $pl['img'] . '.gif" width="55" height="35" /></a>';
} else {
if (isset($_GET['inv'])) {
$pr .= '<a title="Перейти к настройкам приемов" href="javascript:void(0)" onclick="location.href=\'main.php?all=' . ((int)$_GET['all']) . '&skills=1&rz=4&p_raz=all\'"><img style="margin-top:4px; margin-left:4px;" src="https://img.new-combats.com/i/items/w/clearPriem.gif" width="40" height="25" /></a>';
$pr .= '<a title="Перейти к настройкам приемов" href="javascript:void(0)" onclick="location.href=\'main.php?all=' . ((int)$_GET['all']) . '&skills=1&rz=4&p_raz=all\'"><img style="margin-top:4px; margin-left:4px;" src="https://img.new-combats.com/i/items/w/clearPriem.gif" width="55" height="35" /></a>';
} else {
$pr .= '<img style="margin-top:4px; margin-left:4px;" src="https://img.new-combats.com/i/items/w/clearPriem.gif" width="40" height="25" />';
$pr .= '<img style="margin-top:4px; margin-left:4px;" src="https://img.new-combats.com/i/items/w/clearPriem.gif" width="55" height="35" />';
}
}
@@ -2516,50 +2514,38 @@ class Priems
return $r;
}
//выводим все доступные приемы игроку на его уровне - 1, выводим все доступные приемы только игроку - 2
public function seePriems($mt)
public function getTechniquesInfo(?int $id = null): array
{
global $code;
$t = $this->u->items['tr'];
$nm = [1 => 'hit', 2 => 'krit', 3 => 'counter', 4 => 'block', 5 => 'parry', 6 => 'hp', 7 => 'spirit'];
$lvlfe = $this->u->info['level'];
if (isset($_GET['all'])) {
$lvlfe = 21;
if(isset($id)) {
return Db::getRow('SELECT * FROM techniques_categories LEFT JOIN priems ON techniques_categories.technique_id = priems.id
WHERE priems.level <= ? AND priems.activ > 0 AND priems.id = ? ORDER BY priems.img,priems.level', [User::start()->info['level'], $id]);
}
$sp = mysql_query(
'SELECT * FROM `priems` WHERE `level`<="' . $lvlfe . '" AND `activ` > "0" ORDER BY `img`,`level` ASC'
);
$this->u->info['lvl'] = $this->u->info['level'];
$lvar = '';
while ($pl = mysql_fetch_assoc($sp)) {
$noaki = 0;
if ($pl['activ'] == 1 || $this->testActiv($pl['activ']) == 1) {
$lvar = $this->priemInfo($pl, 1);
$lvar = $lvar[0];
$cl = '';
$a1 = '<a href="javascript:void(0)" onclick="location.href=\'main.php?skills=1&all=' . ((int)$_GET['all']) . '&rz=4&use_priem=' . $pl['id'] . '&rnd=' . $code . '&p_raz=\' + p_raz;">';
$a2 = '</a>';
if ($this->pyes($pl['id']) || $this->testpriem($pl, 1) > 0) {
if ((isset($_GET['all']) && $_GET['all'] == 1) || $this->pyes($pl['id'])) {
$cl = 'filter: alpha(opacity=35); -moz-opacity: 0.35; -khtml-opacity: 0.35; opacity: 0.35;';
$a1 = '';
$a2 = '';
} else {
$noaki = 1;
}
}
if ($noaki == 0) {
$mtnu = explode('_', $pl['img']);
if ($mtnu[0] != 'wis') {
$mtnu = $mtnu[0];
} else {
$mtnu = 'wis_' . $mtnu[1];
}
echo $a1 . '<img class="pwq' . $mtnu . ' pwqall" onMouseOver="top.hi(this,\'(#' . $pl['id'] . ') <b>' . $pl['name'] . '</b><Br>' . $lvar . '\',event,3,0,1,1,\'width:240px\');" onMouseOut="top.hic();" onMouseDown="top.hic();" style="margin-top:2px; ' . $cl . ' margin-left:1px;" src="https://img.new-combats.com/i/eff/' . $pl['img'] . '.gif" width="40" height="25" />' . $a2;
}
return Db::getRows('SELECT * FROM techniques_categories LEFT JOIN priems ON techniques_categories.technique_id = priems.id
WHERE priems.level <= ? AND priems.activ > 0 ORDER BY priems.img,priems.level', [User::start()->info['level']]);
}
public function getByCategory(?int $category_id = null)
{
$priems = $this->getTechniquesInfo();
$cl = '';
foreach ($priems as $priem) {
if ($this->pyes($priem['id']) || $this->testpriem($priem, 1) > 0) {
$cl = 'filter: alpha(opacity=35); -moz-opacity: 0.35; -khtml-opacity: 0.35; opacity: 0.35;';
}
echo
<<< HTML
<a href="javascript:void(0)" onclick="location.href='main.php?skills=1&rz=4&use_priem=$priem[id]';">
<img class="pwq$priem[category_id] pwqall" onMouseOver="top.popup(this, '(#$priem[id]) <b>$priem[name]</b><Br>{$this->priemInfo($priem, 1)[0]}');" onMouseOut="top.hic();" onMouseDown="top.hic();" style="display:none;margin-top:2px; $cl margin-left:1px;" src="https://img.new-combats.com/i/eff/$priem[img].gif" width="40" height="25" />
</a>
HTML;
}
}
private function zeromax($num, $max)