Jump to content

Autostacking for warp scrolls with the same coords


Go to solution Solved by CORKY,

Recommended Posts

  • Gold

Hello guys,

can someone help me to make the warp scrolls to be automatically stacked, when they have the same coordinates? I mean, when you create a warp scroll with some position and another warp scroll with the same position will be found in inventory, it will be automatically stacked, otherwise the new warp scroll will be created.

Spoiler
bool CHARACTER::GiveRecallItem(LPITEM item)
{
	int idx = GetMapIndex();
	int iEmpireByMapIndex = -1;

	if (idx < 20)
		iEmpireByMapIndex = 1;
	else if (idx < 40)
		iEmpireByMapIndex = 2;
	else if (idx < 60)
		iEmpireByMapIndex = 3;
	else if (idx < 10000)
		iEmpireByMapIndex = 0;

	switch (idx)
	{
		case 66:
		case 216:
			iEmpireByMapIndex = -1;
			break;
	}

	if (iEmpireByMapIndex && GetEmpire() != iEmpireByMapIndex)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("기억해 둘 수 없는 위치 입니다."));
		return false;
	}

	int pos;

	if (item->GetCount() == 1)
	{
		item->SetSocket(0, GetX());
		item->SetSocket(1, GetY());
	}
	else if ((pos = GetEmptyInventory(item->GetSize())) != -1)
	{
		LPITEM item2 = ITEM_MANAGER::instance().CreateItem(item->GetVnum(), 1);

		if (NULL != item2)
		{
			item2->SetSocket(0, GetX());
			item2->SetSocket(1, GetY());
			item2->AddToCharacter(this, TItemPos(INVENTORY, pos));

			item->SetCount(item->GetCount() - 1);
		}
	}
	else
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("소지품에 빈 공간이 없습니다."));
		return false;
	}

	return true;
}

 

Thanks for possible answers!

Sincerely,

ReFresh

Edited by ReFresh
  • Love 1

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • 8 months later...
  • Solution

Please excuse the messy code, but this should do the trick.

 

char_item.cpp

Replace the function bool CHARACTER::GiveRecallItem(LPITEM item) with:

bool CHARACTER::GiveRecallItem(LPITEM item)
{
	int idx = GetMapIndex();
	int iEmpireByMapIndex = -1;

	if (idx < 20)
		iEmpireByMapIndex = 1;
	else if (idx < 40)
		iEmpireByMapIndex = 2;
	else if (idx < 60)
		iEmpireByMapIndex = 3;
	else if (idx < 10000)
		iEmpireByMapIndex = 0;

	switch (idx)
	{
		case 66:
		case 216:
			iEmpireByMapIndex = -1;
			break;
	}

	if (iEmpireByMapIndex && GetEmpire() != iEmpireByMapIndex)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("기억해 둘 수 없는 위치 입니다."));
		return false;
	}

	int pos;

	if (item->GetCount() == 1)	// 아이템이 하나라면 그냥 셋팅.
	{
		item->SetSocket(0, GetX());
		item->SetSocket(1, GetY());
	}
	else if ((pos = GetEmptyInventory(item->GetSize())) != -1) // 그렇지 않다면 다른 인벤토리 슬롯을 찾는다.
	{
		LPITEM item2 = ITEM_MANAGER::instance().CreateItem(item->GetVnum(), 1);

		if (NULL != item2)
		{
			item2->SetSocket(0, GetX());
			item2->SetSocket(1, GetY());
		
			WORD bCount = item2->GetCount();

			if (IS_SET(item2->GetFlag(), ITEM_FLAG_STACKABLE))
			{
				for (WORD i = 0; i < INVENTORY_MAX_NUM; ++i)
				{
					LPITEM item3 = GetInventoryItem(i);

					if (!item3)
						continue;

					if (item3->GetVnum() == item2->GetVnum())
					{
						int j;

						for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
							if (item3->GetSocket(j) != item2->GetSocket(j))
								break;

						if (j != ITEM_SOCKET_MAX_NUM)
							continue;

						WORD bCount2 = MIN(ITEM_MAX_COUNT - item3->GetCount(), bCount);
						bCount -= bCount2;
						item3->SetCount(item3->GetCount() + bCount2);

						if (bCount == 0)
							break;
					}
				}
				item2->SetCount(bCount);
			}


			if (bCount > 0)
				item2->AddToCharacter(this, TItemPos(INVENTORY, pos));
			else
				M2_DESTROY_ITEM(item2);

			item->SetCount(item->GetCount() - 1);
		}
	}
	else
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("소지품에 빈 공간이 없습니다."));
		return false;
	}

	return true;
}

Should work like this:
https://metin2.download/picture/C8i7Pr0Y2pKQDiiviz4mn6zxiZU7taOH/.gif

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • 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.