patch-dressedcheck #57

Merged
lopar merged 4 commits from patch-dressedcheck into master 2022-06-11 00:18:38 +00:00
3 changed files with 43 additions and 63 deletions
Showing only changes of commit 4b65e0d372 - Show all commits

View File

@ -12,9 +12,10 @@ use stdClass;
class DressedItems class DressedItems
{ {
private $USERID; private int $USERID;
private $dressedItem; private stdClass $dressedItem;
private static $db; private static Db $db;
private object $dressed;
/** /**
* DressedItems constructor. * DressedItems constructor.
@ -24,6 +25,7 @@ class DressedItems
{ {
self::$db = Db::getInstance(); self::$db = Db::getInstance();
$this->USERID = $user_id; $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) public static function getDressedItemBySlot($itemSlot, $ownerId)
@ -33,9 +35,8 @@ class DressedItems
public function getItemsInSlots(): stdClass public function getItemsInSlots(): stdClass
{ {
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
$this->dressedItem = new stdClass(); $this->dressedItem = new stdClass();
foreach ($items as $item) { foreach ($this->dressed as $item) {
$i = $item->dressed_slot; $i = $item->dressed_slot;
$this->dressedItem->$i = $item; $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]); 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) 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); 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 <?php
use Battles\DressedItems;
use Battles\Template;
use Battles\User;
if (isset($_POST['end'])) { if (isset($_POST['end'])) {
header("Location: main.php"); header("Location: main.php");
exit; exit;
@ -15,7 +20,7 @@ if (isset($user['id'])) {
include('./classes/battle_new.class.php'); include('./classes/battle_new.class.php');
$fbattle = new fbattle($user['battle']); $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/sl2.js"></script>
<script type="text/javascript" src="js/ch.js"></script> <script type="text/javascript" src="js/ch.js"></script>
@ -133,7 +138,7 @@ $fbattle = new fbattle($user['battle']);
<tr> <tr>
<td valign=top width=250 nowrap> <td valign=top width=250 nowrap>
<?php <?php
$myinfo = new \Battles\User($_SESSION['uid']); $myinfo = new User($_SESSION['uid']);
$myinfo->showUserDoll(1); $myinfo->showUserDoll(1);
?> ?>
</td> </td>
@ -290,7 +295,7 @@ $fbattle = new fbattle($user['battle']);
if (($user['hp'] > 0) && $fbattle->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>'; 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) { } 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>'; echo '<center><FONT COLOR=red><b>Ожидаем, пока бой закончат другие игроки...</b></FONT><BR><INPUT TYPE=submit value="Обновить" name=' . (($user['battle'] > 0) ? "battle" : "end") . '><BR></CENTER>';
} }
break; break;
@ -468,7 +473,7 @@ $fbattle = new fbattle($user['battle']);
<?php <?php
if ($fbattle->return == 1) { if ($fbattle->return == 1) {
$enemyInfo = new \Battles\User($fbattle->enemy); $enemyInfo = new User($fbattle->enemy);
$enemyInfo->showUserDoll(1); $enemyInfo->showUserDoll(1);
} else { } else {
if ($fbattle->battle_data['type'] == 4 || $fbattle->battle_data['type'] == 5) { 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; 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) function usemagic($id, $target)
{ {