This commit is contained in:
Ivor Barhansky 2022-06-11 02:57:27 +03:00
parent b8f837b6cf
commit 4b65e0d372
3 changed files with 43 additions and 63 deletions

View File

@ -12,9 +12,10 @@ use stdClass;
class DressedItems
{
private $USERID;
private $dressedItem;
private static $db;
private int $USERID;
private stdClass $dressedItem;
private static Db $db;
private object $dressed;
/**
* DressedItems constructor.
@ -24,6 +25,7 @@ class DressedItems
{
self::$db = Db::getInstance();
$this->USERID = $user_id;
$this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->USERID);
}
public static function getDressedItemBySlot($itemSlot, $ownerId)
@ -33,9 +35,8 @@ class DressedItems
public function getItemsInSlots(): stdClass
{
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$this->dressedItem = new stdClass();
foreach ($items as $item) {
foreach ($this->dressed as $item) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;
}
@ -54,8 +55,35 @@ class DressedItems
self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]);
}
}
public static function undressAllItems($user_id)
{
return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $user_id);
}
public function checkRequirements()
{
$stats = (new UserStats($this->USERID))->getFullStats();
$q = 'select count(*) from inventory where
dressed_slot > 0 and
need_strength > ? and
need_dexterity > ? and
need_intuition > ? and
need_endurance > ? and
need_intelligence > ? and
need_wisdom > ? and
owner_id = ?';
$args = [
$stats->strength,
$stats->dexterity,
$stats->intuition,
$stats->endurance,
$stats->intelligence,
$stats->wisdom,
$this->USERID
];
if (self::$db->fetchColumn($q, $args) > 0) {
self::undressAllItems($this->USERID);
}
}
}

View File

@ -1,4 +1,9 @@
<?php
use Battles\DressedItems;
use Battles\Template;
use Battles\User;
if (isset($_POST['end'])) {
header("Location: main.php");
exit;
@ -15,7 +20,7 @@ if (isset($user['id'])) {
include('./classes/battle_new.class.php');
$fbattle = new fbattle($user['battle']);
\Battles\Template::header('fbattle');
Template::header('fbattle');
?>
<script type="text/javascript" src="js/sl2.js"></script>
<script type="text/javascript" src="js/ch.js"></script>
@ -133,7 +138,7 @@ $fbattle = new fbattle($user['battle']);
<tr>
<td valign=top width=250 nowrap>
<?php
$myinfo = new \Battles\User($_SESSION['uid']);
$myinfo = new User($_SESSION['uid']);
$myinfo->showUserDoll(1);
?>
</td>
@ -290,7 +295,7 @@ $fbattle = new fbattle($user['battle']);
if (($user['hp'] > 0) && $fbattle->battle) {
echo '<center><FONT COLOR=red><b>Ожидаем хода противника...</b></FONT><BR><INPUT TYPE=submit value="Обновить" name=' . (($user['battle'] > 0) ? "battle" : "end") . '><BR></CENTER>';
} elseif ($user['hp'] <= 0 && $fbattle->battle) {
ref_drop();
(new DressedItems(User::getInstance()->getId()))->checkRequirements();
echo '<center><FONT COLOR=red><b>Ожидаем, пока бой закончат другие игроки...</b></FONT><BR><INPUT TYPE=submit value="Обновить" name=' . (($user['battle'] > 0) ? "battle" : "end") . '><BR></CENTER>';
}
break;
@ -468,7 +473,7 @@ $fbattle = new fbattle($user['battle']);
<?php
if ($fbattle->return == 1) {
$enemyInfo = new \Battles\User($fbattle->enemy);
$enemyInfo = new User($fbattle->enemy);
$enemyInfo->showUserDoll(1);
} else {
if ($fbattle->battle_data['type'] == 4 || $fbattle->battle_data['type'] == 5) {

View File

@ -281,59 +281,6 @@ function addActions($time, $vars, $vls, $uid)
return $ins;
}
#15
function ref_drop()
{
//сможет держать
function derj($id)
{
$user = db::c()->query('SELECT `id`, `align` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
$ts = db::c()->query('SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i', $id)->fetch_assoc();
$al = '(1 = 1)';
if ($ts['nalign'] == 1.1) {
$al = '(1 = 2)';
}
$dd = db::c()->query('SELECT `i`.`id` FROM `users` AS `u`, `inventory` AS `i`
WHERE
`i`.`needident` = 0 AND
`i`.`id` = ?i AND
`i`.`duration` < `i`.`maxdur` AND
`i`.`owner` = ?i AND
`u`.`sila` >= `i`.`nsila` AND
`u`.`lovk` >= `i`.`nlovk` AND
`u`.`inta` >= `i`.`ninta` AND
`u`.`vinos` >= `i`.`nvinos` AND
`u`.`intel` >= `i`.`nintel` AND
`u`.`mudra` >= `i`.`nmudra` AND
`u`.`level` >= `i`.`nlevel` AND
("?s" OR (?i = `i`.`nalign`) or (`i`.`nalign` = 0)) AND
`u`.`noj` >= `i`.`nnoj` AND
`u`.`topor` >= `i`.`ntopor` AND
`u`.`dubina` >= `i`.`ndubina` AND
`u`.`mec` >= `i`.`nmech` AND
`u`.`mfire` >= `i`.`nfire` AND
`u`.`mwater` >= `i`.`nwater` AND
`u`.`mair` >= `i`.`nair` AND
`u`.`mearth` >= `i`.`nearth` AND
`u`.`mlight` >= `i`.`nlight` AND
`u`.`mgray` >= `i`.`ngray` AND
`u`.`mdark` >= `i`.`ndark` AND
`i`.`setsale` = 0 AND
`u`.`id` = ?i', $id, $user['id'], $al, $user['align'], $user['id']);
return $dd->getNumRows() > 0;
}
$slot = ['sergi', 'kulon', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'perchi', 'shit', 'boots', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'];
$user = db::c()->query('SELECT `sergi`,`kulon`,`weap`,`bron`,`r1`,`r2`,`r3`,`helm`,`perchi`,`shit`,`boots`,`m1`,`m2`,`m3`,`m4`,`m5`,`m6`,`m7`,`m8`,`m9`,`m10` FROM `users` WHERE id = ?i', $_SESSION['uid'])->fetch_assoc();
for ($i = 0; $i <= 20; $i++) {
if ($user[$slot[$i]] && !derj($user[$slot[$i]])) {
$item = new DressedItems($_SESSION['uid']);
$item->undressItem($i + 1);
$user[$slot[$i]] = null;
}
}
}
// использовать магию
function usemagic($id, $target)
{