Перенос и унификация функции снятия предметов в класс DressedItems.

This commit is contained in:
lopar 2021-03-11 20:42:36 +02:00
parent 1d2128830f
commit a5d13d7e74
6 changed files with 19 additions and 277 deletions

View File

@ -37,10 +37,11 @@ if (isset($_SESSION['player_id'])) {
if ($del) {
$itemdel = db::c()->query('SELECT item_type, dressed_slot FROM inventory WHERE id=?i', $del)->fetch_assoc();
if ($itemdel['dressed_slot'] == 1) {
dropitem($itemdel['item_type']);
$item = new \Battles\DressedItems($del);
$item->undressItem($itemdel['item_type']);
if ($itemdel['item_type'] == 5) {
dropitem(6);
dropitem(7);
$item->undressItem(6);
$item->undressItem(7);
}
}
db::c()->query('DELETE FROM `inventory` WHERE `id` = ?i', $del);

View File

@ -487,7 +487,8 @@ if (@$_GET['kill'] && $user['id'] == $user['caveleader'] && $_GET['kill'] != $us
while ($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id'], $usr);
if ($slot) {
dropitemid(0, $v['user'], $slot);
$item = new \Battles\DressedItems($v['user']);
$item->undressItem($slot);
}
}
mysql_query("DELETE FROM `inventory` WHERE `owner` = '$v[user]' AND `foronetrip` = 1");
@ -898,7 +899,8 @@ if (@$_GET['exit']) {
while ($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id']);
if ($slot) {
dropitemid(0, $user['id'], $slot);
$item = new \Battles\DressedItems($user['id']);
$item->undressItem($slot);
}
}
mysql_query("DELETE FROM `inventory` WHERE `owner` = '$user[id]' AND `foronetrip` = 1");

View File

@ -8,6 +8,7 @@
namespace Battles;
use Battles\Database\DBPDO;
use stdClass;
class DressedItems
{
@ -30,10 +31,10 @@ class DressedItems
return self::$db->fetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
}
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) {
$i = $item->dressed_slot;
$this->dressedItem->$i = $item;

View File

@ -486,7 +486,8 @@ class fbattle
$inv_broken = mysql_query("SELECT * FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'");
while ($br = mysql_fetch_array($inv_broken)) {
dropitemid($br['type'], $v);
$item = new \Battles\DressedItems($v);
$item->undressItem($br['type']);
}
$its = mysql_query("SELECT `id` FROM `inventory` WHERE `dressed` = 0 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'");
@ -573,7 +574,8 @@ class fbattle
$this->AddToLog('<span class=date>' . date("H:i") . '</span> <b>' . Nick::id($v)->short() . '</b> получил повреждение: <font color=red>' . $tr . '</font><BR>');
$inv_broken = mysql_query("SELECT `id`, `type`, `dressed`, `duration`, `maxdur`, `dategoden`, `owner` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'");
while ($br = mysql_fetch_array($inv_broken)) {
dropitemid($br['type'], $v);
$item = new \Battles\DressedItems($v);
$item->undressItem($br['type']);
}
}
}

View File

@ -454,272 +454,6 @@ function undressall($user_id)
db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?i', $user_id);
}
function dropitemid($slot, $id)
{
global $user;
switch ($slot) {
case 1:
$slot1 = 'sergi';
break;
case 2:
$slot1 = 'kulon';
break;
case 3:
$slot1 = 'weap';
break;
case 4:
$slot1 = 'bron';
break;
case 5:
$slot1 = 'r1';
break;
case 6:
$slot1 = 'r2';
break;
case 7:
$slot1 = 'r3';
break;
case 8:
$slot1 = 'helm';
break;
case 9:
$slot1 = 'perchi';
break;
case 10:
$slot1 = 'shit';
break;
case 11:
$slot1 = 'boots';
break;
case 12:
$slot1 = 'm1';
break;
case 13:
$slot1 = 'm2';
break;
case 14:
$slot1 = 'm3';
break;
case 15:
$slot1 = 'm4';
break;
case 16:
$slot1 = 'm5';
break;
case 17:
$slot1 = 'm6';
break;
case 18:
$slot1 = 'm7';
break;
case 19:
$slot1 = 'm8';
break;
case 20:
$slot1 = 'm9';
break;
case 21:
$slot1 = 'm10';
break;
case 22:
$slot1 = 'rybax';
break;
case 23:
$slot1 = 'plaw';
break;
default:
$slot1 = '';
break;
}
$checkid = db::c()->query('SELECT 1 FROM `users` WHERE `id` = ?i', $id);
if ($checkid->getNumRows()) {
if (mysql_query('UPDATE `users`, `inventory` SET `users`.`' . $slot1 . '` = 0, `inventory`.`dressed` = 0, `users`.`sila` = `users`.`sila` - `inventory`.`gsila`, `users`.`lovk` = `users`.`lovk` - `inventory`.`glovk`, `users`.`inta` = `users`.`inta` - `inventory`.`ginta`, `users`.`intel` = `users`.`intel` - `inventory`.`gintel`, `users`.`maxhp` = `users`.`maxhp` - `inventory`.`ghp`, `users`.`noj` = `users`.`noj` - `inventory`.`gnoj`, `users`.`topor` = `users`.`topor` - `inventory`.`gtopor`, `users`.`dubina` = `users`.`dubina` - `inventory`.`gdubina`, `users`.`mec` = `users`.`mec` - `inventory`.`gmech`, `users`.`mfire` = `users`.`mfire` - `inventory`.`gfire`, `users`.`mwater` = `users`.`mwater` - `inventory`.`gwater`, `users`.`mair` = `users`.`mair` - `inventory`.`gair`, `users`.`mearth` = `users`.`mearth` - `inventory`.`gearth`, `users`.`mlight` = `users`.`mlight` - `inventory`.`glight`, `users`.`mgray` = `users`.`mgray` - `inventory`.`ggray`, `users`.`mdark` = `users`.`mdark` - `inventory`.`gdark`, `users`.`fkrit` = `users`.`fkrit` - `inventory`.`mfkrit`, `users`.`fakrit` = `users`.`fakrit` - `inventory`.`mfakrit`, `users`.`fuvorot` = `users`.`fuvorot` - `inventory`.`mfuvorot`, `users`.`fauvorot` = `users`.`fauvorot` - `inventory`.`mfauvorot`, `users`.`ubron1` = `users`.`ubron1` - `inventory`.`bron1`, `users`.`ubron2` = `users`.`ubron2` - `inventory`.`bron2`, `users`.`ubron3` = `users`.`ubron3` - `inventory`.`bron3`, `users`.`ubron4` = `users`.`ubron4` - `inventory`.`bron4`, `users`.`uminu` = `users`.`uminu` - `inventory`.`minu`, `users`.`umaxu` = `users`.`umaxu` - `inventory`.`maxu` WHERE `inventory`.`id` = `users`.`' . $slot1 . '` AND `inventory`.`dressed` = 1 AND `inventory`.`owner` = "' . $id . '" AND `users`.`id` = "' . $id . '"')) {
db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $id);
$user->$slot1 = 0;
}
return true;
} else {
return false;
}
}
// снять предмет
function dropitem($slot)
{
global $user;
$wear_arr = [];
switch ($slot) {
case 1:
$slot1 = 'sergi';
break;
case 2:
$slot1 = 'kulon';
break;
case 3:
$slot1 = 'weap';
break;
case 4:
$slot1 = 'bron';
break;
case 5:
$slot1 = 'r1';
break;
case 6:
$slot1 = 'r2';
break;
case 7:
$slot1 = 'r3';
break;
case 8:
$slot1 = 'helm';
break;
case 9:
$slot1 = 'perchi';
break;
case 10:
$slot1 = 'shit';
break;
case 11:
$slot1 = 'boots';
break;
case 12:
$slot1 = 'm1';
break;
case 13:
$slot1 = 'm2';
break;
case 14:
$slot1 = 'm3';
break;
case 15:
$slot1 = 'm4';
break;
case 16:
$slot1 = 'm5';
break;
case 17:
$slot1 = 'm6';
break;
case 18:
$slot1 = 'm7';
break;
case 19:
$slot1 = 'm8';
break;
case 20:
$slot1 = 'm9';
break;
case 21:
$slot1 = 'm10';
break;
case 22:
$slot1 = 'rybax';
break;
case 23:
$slot1 = 'plaw';
break;
default:
$slot1 = '';
break;
}
if (db::c()->query('UPDATE `users` as `u`, `inventory` as `i` SET `u`.?f = 0, `i`.`dressed` = 0,
`u`.`sila` = `u`.`sila` - `i`.`gsila`,
`u`.`lovk` = `u`.`lovk` - `i`.`glovk`,
`u`.`inta` = `u`.`inta` - `i`.`ginta`,
`u`.`intel` = `u`.`intel` - `i`.`gintel`,
`u`.`maxhp` = `u`.`maxhp` - `i`.`ghp`,
`u`.`noj` = `u`.`noj` - `i`.`gnoj`,
`u`.`topor` = `u`.`topor` - `i`.`gtopor`,
`u`.`dubina` = `u`.`dubina` - `i`.`gdubina`,
`u`.`mec` = `u`.`mec` - `i`.`gmech`,
`u`.`mfire` = `u`.`mfire` - `i`.`gfire`,
`u`.`mwater` = `u`.`mwater` - `i`.`gwater`,
`u`.`mair` = `u`.`mair` - `i`.`gair`,
`u`.`mearth` = `u`.`mearth` - `i`.`gearth`,
`u`.`mlight` = `u`.`mlight` - `i`.`glight`,
`u`.`mgray` = `u`.`mgray` - `i`.`ggray`,
`u`.`mdark` = `u`.`mdark` - `i`.`gdark`,
`u`.`ubron1` = `u`.`ubron1` - `i`.`bron1`,
`u`.`ubron2` = `u`.`ubron2` - `i`.`bron2`,
`u`.`ubron3` = `u`.`ubron3` - `i`.`bron3`,
`u`.`ubron4` = `u`.`ubron4` - `i`.`bron4`,
`u`.`fkrit` = `u`.`fkrit` - `i`.`mfkrit`,
`u`.`fakrit` = `u`.`fakrit` - `i`.`mfakrit`,
`u`.`fuvorot` = `u`.`fuvorot` - `i`.`mfuvorot`,
`u`.`fauvorot` = `u`.`fauvorot` - `i`.`mfauvorot`,
`u`.`uminu` = `u`.`uminu` - `i`.`minu`,
`u`.`umaxu` = `u`.`umaxu` - `i`.`maxu`
WHERE `i`.`id` = `u`.?f AND `i`.`dressed` = 1 AND `i`.`owner` = ?i AND u.id = ?i', $slot1, $slot1, $user->getId(), $user->getId())) {
db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $user->getId());
}
$wear_raw = db::c()->query('SELECT * FROM `inventory` where `owner` = ?i AND `dressed` = 1', $user->getId());
while ($wear_list = $wear_raw->fetch_assoc()) {
$wear_arr[] = $wear_list['prototype'];
}
$item['id'] = $user->$slot1;
$get_pro = db::c()->query('SELECT * FROM `inventory` where `id` = ?i', $item['id'])->fetch_assoc();
/////////////////////
$sets_items = db::c()->query('SELECT * FROM `item_sets`');
//для каждого комплекта
while ($items_in_set = $sets_items->fetch_assoc()) {
$checker = 0;
$temp_is = explode(",", $items_in_set['prot_id']);
$set_id = $items_in_set['set_id'];
//если прото в комплекте и не одет
if (in_array($get_pro['prototype'], $temp_is) && (!in_array($get_pro['prototype'], $wear_arr))) {
$checker = 1;
//для каждого одетого предмета
foreach ($temp_is as $check_proto) {
if ($check_proto != $get_pro['prototype'] && !in_array($check_proto, $wear_arr)) {
$checker = 0;
}
}
}
//
if (($checker == 1) && (!in_array($get_pro['prototype'], $wear_arr))) {
db::c()->query('UPDATE `users` as `u`, `item_sets` as `s` SET
`u`.`uminu` = `u`.`uminu` - `s`.`minu`,
`u`.`umaxu` = `u`.`umaxu` - `s`.`maxu`,
`u`.`sila = `u`.`sila - `s`.`gsila`,
`u`.`lovk = `u`.`lovk - `s`.`glovk`,
`u`.`inta = `u`.`inta - `s`.`ginta`,
`u`.`intel = `u`.`intel - `s`.`gintel`,
`u`.`maxhp = `u`.`maxhp - `s`.`ghp`,
`u`.`maxmana = `u`.`maxmana - `s`.`gmana`,
`u`.`fkrit = `u`.`fkrit - `s`.`mfkrit`,
`u`.`fakrit = `u`.`fakrit - `s`.`mfakrit`,
`u`.`fuvorot = `u`.`fuvorot - `s`.`mfuvorot`,
`u`.`fauvorot = `u`.`fauvorot - `s`.`mfauvorot`,
`u`.`noj = `u`.`noj - `s`.`gnoj`,
`u`.`topor = `u`.`topor - `s`.`gtopor`,
`u`.`dubina = `u`.`dubina - `s`.`gdubina`,
`u`.`mec = `u`.`mec - `s`.`gmech`,
`u`.`ubron1 = `u`.`ubron1 - `s`.`bron1`,
`u`.`ubron2 = `u`.`ubron2 - `s`.`bron2`,
`u`.`ubron3 = `u`.`ubron3 - `s`.`bron3`,
`u`.`ubron4 = `u`.`ubron4 - `s`.`bron4`,
`u`.`mfire = `u`.`mfire - `s`.`gfire`,
`u`.`mwater = `u`.`mwater - `s`.`gwater`,
`u`.`mair = `u`.`mair - `s`.`gair`,
`u`.`mearth = `u`.`mearth - `s`.`gearth`,
`u`.`mlight = `u`.`mlight - `s`.`glight`,
`u`.`mgray = `u`.`mgray - `s`.`ggray`
WHERE
`u`.`id` = ?i AND `s`.`set_id`= ?i', $user->getId(), $set_id);
}
}
return true;
}
#15
function ref_drop()
{

View File

@ -142,7 +142,8 @@ if (isset($_POST['exit'])) {
}
$dresed = mysql_query('SELECT `id`, `type` FROM `inventory` WHERE `dressed` = 1 AND `laba` = 2 AND `owner` = "' . $user['id'] . '"');
while ($pl = mysql_fetch_array($dresed)) {
dropitemid($pl['type'], $user['id']);
$item = new \Battles\DressedItems($user['id']);
$item->undressItem($pl['type']);
}
mysql_query('DELETE FROM `inventory` WHERE `laba` > 0 AND `owner` = "' . $user['id'] . '"');
mysql_query("UPDATE `users`, `online` SET `users`.`room` = '1051', `online`.`room` = '1051', `users`.`x` = '0', `users`.`y` = '0', `users`.`laba` = '0' WHERE `online`.`id` = `users`.`id` AND `online`.`id` = '" . $user['id'] . "'");
@ -291,7 +292,8 @@ if ($user['y'] >= count($map_d) - 2) {
}
$dresed = mysql_query('SELECT `id`, `type` FROM `inventory` WHERE `dressed` = 1 AND `laba` = 2 AND `owner` = "' . $user['id'] . '"');
while ($pl = mysql_fetch_array($dresed)) {
dropitemid($pl['type'], $user['id']);
$item = new \Battles\DressedItems($user['id']);
$item->undressItem($pl['type']);
}
mysql_query('UPDATE `inventory` SET `laba` = 0 WHERE `laba` = 1 AND `owner` = "' . $user['id'] . '"');
mysql_query('DELETE FROM `inventory` WHERE `laba` = 2 AND `owner` = "' . $user['id'] . '"');