Jump to content

Proper 4th Inventory CExchange::CheckSpace function


Recommended Posts

  • Bot

Based on the github sourcecode this should be correct.
 

bool CExchange::CheckSpace()
{
	static CGrid s_grid1(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 1   9 Rows a 5 Columns
	static CGrid s_grid2(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 2   9 Rows a 5 Columns
	static CGrid s_grid3(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 3   9 Rows a 5 Columns
	static CGrid s_grid4(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 4   9 Rows a 5 Columns

	s_grid1.Clear();
	s_grid2.Clear();
	s_grid3.Clear();
	s_grid4.Clear();

	LPCHARACTER	victim = GetCompany()->GetOwner();
	LPITEM item;

	int i;

	const int perPageSlotCount = INVENTORY_MAX_NUM / 4;

	for (i = 0; i < INVENTORY_MAX_NUM; ++i) {
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		BYTE itemSize = item->GetSize();

		if (i < perPageSlotCount) // Notice: This is adjusted for 4 Pages only!
			s_grid1.Put(i, 1, itemSize);
		else if (i < perPageSlotCount * 2)
			s_grid2.Put(i - perPageSlotCount, 1, itemSize);
		else if (i < perPageSlotCount * 3)
			s_grid3.Put(i - perPageSlotCount * 2, 1, itemSize);
		else
			s_grid4.Put(i - perPageSlotCount * 3, 1, itemSize);
	}

	static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);

	bool bDSInitialized = false;

	for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
	{
		if (!(item = m_apItems[i]))
			continue;

		BYTE itemSize = item->GetSize();

		if (item->IsDragonSoul())
		{
			if (!victim->DragonSoul_IsQualified())
				return false;

			if (!bDSInitialized) {
				bDSInitialized = true;
				victim->CopyDragonSoulItemGrid(s_vDSGrid);
			}

			bool bExistEmptySpace = false;
			WORD wBasePos = DSManager::instance().GetBasePosition(item);
			if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
				return false;

			for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
			{
				WORD wPos = wBasePos + i;
				if (0 == s_vDSGrid[wBasePos])
				{
					bool bEmpty = true;
					for (int j = 1; j < item->GetSize(); j++)
					{
						if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
						{
							bEmpty = false;
							break;
						}
					}
					if (bEmpty)
					{
						for (int j = 0; j < item->GetSize(); j++)
						{
							s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
						}
						bExistEmptySpace = true;
						break;
					}
				}
				if (bExistEmptySpace)
					break;
			}
			if (!bExistEmptySpace)
				return false;
		}
		else
		{
			int iPos = s_grid1.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid1.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid2.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid2.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid3.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid3.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid4.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid4.Put(iPos, 1, itemSize);
				continue;
			}

			return false;  // No space left in inventory
		}
	}

	return true;
}

PS: If there are any errors please report them asap because i have no way to test this.
 
Kind regards
MartPwnS

english_banner.gif

  • Premium

Can someone maybe provide the clean source code for that function everyone is using this is a WoM custom function <.<

		if (!(item = m_apItems[i]))
			continue;

instead of

                if (!(item = GetCompany()->GetItemByPosition(i)))
                        continue;

EDIT: Nvm :D

Everyone is understand cbaran's function is not provide anything to you. I am only see one variable is defined in cpp file and any function or condition is not call this.

Actually one thing is too strange (Everyone thank to him)

 

Mostly people understand these codes doing nothing :)

 

Btw thanks for share to us.

 

Kind Regards

Ken

Edited by Ken

Do not be sorry, be better.

  • Premium

Ok fixed version up there thanks to Cataclisimo for the original function.

Ahahaha. People always write my name wrong xD

Also, in the clean code it's checked the victim (i think), not the owner:

LPCHARACTER	victim = GetCompany()->GetOwner();

Can you check that too? :D

Yeah, you are right @Cataclismo. WoM's logic is changed a bit, thus the difference. The problems of helping out after you change a few things xD

That's the reason for the GetCompany in

if (!(item = GetCompany()->GetItemByPosition(i)))

 

Where's your code ?

 

Anyway, I don't have this bug I think :o

If you don't use more than 2 inventories you don't. If you do, and you didn't patch it, you do.

 

 

I have 4 inventories and I've just tested twice and I don't have this.. all I did is copied the loop that was used for inventory 1 and 2 and change it a little bit so it works with 4 inventories.

  • Bot

Ofc you dont have it you fixed it with that xD

 

Mine is just a refined version of the one CBaran didnt provide in his first edit.

He now edited his post and provided the "ugly" version with the nested if / else conditions and multiple for loops which i wanted to avoid.

english_banner.gif

  • Premium

Ofc you dont have it you fixed it with that xD

 

Mine is just a refined version of the one CBaran didnt provide in his first edit.

He now edited his post and provided the "ugly" version with the nested if / else conditions and multiple for loops which i wanted to avoid.

 

Very ugly xD

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.