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

This commit is contained in:
Maksym 2023-01-23 07:33:19 +01:00
parent d9ec810f7f
commit 1fbd8d6de2
6 changed files with 239 additions and 116 deletions

View File

@ -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;
}

View File

@ -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;
}

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
{
}
}

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)

View File

@ -60,6 +60,20 @@ function himove(e) {
$('#ttl').css({'top': `${y}px`, 'left': `${x}px`});
}
function popup(element, content, width = 230) {
let el_offset = $(element).offset()
let popup = $('#ttl');
popup.html(content);
popup.css({
'display': 'block',
'top': el_offset.top + 20 + 'px',
'left': el_offset.left + 40 + 'px',
'width': width + 'px'
});
}
function hi(el, txt, e, tp, st, sm, fm, css) {
if (!e) e = window.event;
top.xyfmn = [el, txt, e, tp, st, sm, fm, css];

View File

@ -1,4 +1,7 @@
<?php
use DarksLight2\Battle\Techniques\TechniqueCategoryEntity;
if (!defined('GAME')) {
die();
}
@ -1651,75 +1654,35 @@ $tma = '';
echo !$re ?: "<br> <b style='color:red;'>$re</b><br><br>";
}
?>
<B>Выбранные приемы:</B><BR>
<?php $priem->seeMy(1); ?><br>
<B>Приёмы для выбора:</B>
<div>
<?php $priem->seePriems(1); ?>
<div style="display: flex; width: 100%;text-align: center;">
<fieldset style="width: 100%">
<legend><b>Выбранные приемы</b></legend>
<input type="button" class="btn" value="Запомнить набор" onclick="top.savePriems(); return false;" >
<input type="button" class="btn" value="Очистить слоты" onclick="window.location.href = '/main.php?skills=1&rz=4&all=<?= $_GET[all] ?>&clear_abil=1'; return false;">
<?php $priem->seeMy(1); ?>
</fieldset>
</div>
</td>
<td valign="top" align=right width=1>
<FIELDSET>
<LEGEND>Категории</LEGEND>
<SMALL>
<NOBR>
<A href="#" onclick='show_div("all"); return(false)'>Все</A>
<BR>
<A href="#" onclick='show_div("hit"); return(false)'>Приемы атаки</A>
<BR>
<A href="#" onclick='show_div("block"); return(false)'>Приемы защиты</A>
<BR>
<A href="#" onclick='show_div("counter"); return(false)'>Приемы
контрударов</A>
<BR>
<A href="#" onclick='show_div("krit"); return(false)'>Приемы критических
ударов</A>
<BR>
<A href="#" onclick='show_div("parry"); return(false)'>Приемы
парирования</A>
<BR>
<A href="#" onclick='show_div("multi"); return(false)'>Комбо-приемы</A>
<BR>
<A href="#" onclick='show_div("hp"); return(false)'>Приемы крови</A>
<BR>
<A href="#" onclick='show_div("blood"); return(false)'>Приемы жертвы</A>
<BR>
<A href="#" onclick='show_div("spirit"); return(false)'>Приемы силы духа</A>
<BR>
<A href="#" onclick='show_div("wis_fire"); return(false)'>Заклинания
Огня</A>
<BR>
<A href="#" onclick='show_div("wis_water"); return(false)'>Заклинания
Воды</A>
<BR>
<A href="#" onclick='show_div("wis_air"); return(false)'>Заклинания
Воздуха</A>
<BR>
<A href="#" onclick='show_div("wis_earth"); return(false)'>Заклинания
Земли</A>
<BR>
<A href="#" onclick='show_div("wis_light"); return(false)'>Заклинания магии
Света</A>
<BR>
<A href="#" onclick='show_div("wis_gray"); return(false)'>Заклинания Серой
магии</A>
<BR>
<A href="#" onclick='show_div("wis_dark"); return(false)'>Заклинания магии
Тьмы</A><BR>
</NOBR>
</SMALL>
</FIELDSET>
<SCRIPT>show_div(p_raz);</SCRIPT>
</td>
<td valign="top" align="right">
<table width="200" align=right cellpadding=0 cellspacing=0>
<tr>
<form name=F1 action="?skills=1&rz=4" method="GET">
<input type="hidden" name="skills" value="1">
<input type="hidden" name="rz" value="4">
<td>
<FIELDSET>
<LEGEND>Показывать приёмы</LEGEND>
<div style="display: flex; width: 100%">
<fieldset style="width: 50%">
<legend><b>Категории</b></legend>
<div style="display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;">
<?php
$categories = TechniqueCategoryEntity::getInstance()->findAll();
foreach ($categories as $category) {
?>
<div style='margin-right: 10px;height: 20px'><a onclick='show_div("<?=$category->id?>")' href='#'><?=$category->name?></a></div>
<?php
}
?>
</div>
</fieldset>
&nbsp;<INPUT TYPE=radio ID=A1 NAME=all value=0 <?php
if ($_GET['all'] == 0) {
@ -1754,7 +1717,6 @@ $tma = '';
</tr>
</table>
</td>
<td>&nbsp;</td>
</tr>
</table>
</div>