Пример #1
0
bool GuildBankManager::AllowedToWithdraw(uint32 GuildID, uint16 Area, uint16 SlotID, const char *Name)
{
	// Is a none-Guild Banker allowed to withdraw the item at this slot ?
	// This is really here for anti-hacking measures, as the client should not request an item it does not have permission to withdraw.
	//
	if(SlotID > (GUILD_BANK_MAIN_AREA_SIZE - 1))
		return false;

	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return false;

	if(Area != GuildBankMainArea)
		return false;

	uint8 Permissions = (*Iterator)->Items.MainArea[SlotID].Permissions;

	if(Permissions == GuildBankBankerOnly)
		return false;

	if(Permissions != GuildBankSingleMember)	// Public or Public-If-Useable (should really check if item is useable)
		return true;

	if(!strncmp((*Iterator)->Items.MainArea[SlotID].WhoFor, Name, sizeof((*Iterator)->Items.MainArea[SlotID].WhoFor)))
		return true;

	return false;
}
Пример #2
0
bool GuildBankManager::IsAreaFull(uint32 GuildID, uint16 Area)
{
	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return true;

	GuildBankItem* BankArea = nullptr;

	int AreaSize = 0;

	if(Area == GuildBankMainArea)
	{
		BankArea = &(*Iterator)->Items.MainArea[0];

		AreaSize = GUILD_BANK_MAIN_AREA_SIZE;
	}
	else
	{
		BankArea = &(*Iterator)->Items.DepositArea[0];

		AreaSize = GUILD_BANK_DEPOSIT_AREA_SIZE;
	}

	for(int i = 0; i < AreaSize; ++i)
		if(BankArea[i].ItemID == 0)
			return false;

	return true;
}
Пример #3
0
bool GuildBankManager::SplitStack(uint32 GuildID, uint16 SlotID, uint32 Quantity)
{
	if(SlotID > (GUILD_BANK_MAIN_AREA_SIZE - 1))
		return false;

	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return false;

	if(IsAreaFull(GuildID, GuildBankMainArea))
		return false;

	GuildBankItem* BankArea = &(*Iterator)->Items.MainArea[0];

	if(BankArea[SlotID].ItemID == 0)
		return false;

	if(BankArea[SlotID].Quantity <= Quantity || Quantity == 0)
		return false;

	const Item_Struct *Item = database.GetItem(BankArea[SlotID].ItemID);

	if(!Item->Stackable)
		return false;

	AddItem(GuildID, GuildBankMainArea, BankArea[SlotID].ItemID, Quantity, "", BankArea[SlotID].Permissions, BankArea[SlotID].WhoFor);

	DeleteItem(GuildID, GuildBankMainArea, SlotID, Quantity);

	return true;
}
Пример #4
0
void GuildBankManager::SetPermissions(uint32 guildID, uint16 slotID, uint32 permissions, const char *memberName)
{
	if((slotID > (GUILD_BANK_MAIN_AREA_SIZE - 1)))
		return;

	auto iter = GetGuildBank(guildID);

	if(iter == Banks.end())
		return;

	if((*iter)->Items.MainArea[slotID].ItemID == 0)
		return;

	std::string query = StringFormat("UPDATE `guild_bank` SET `permissions` = %i, `whofor` = '%s' "
                                "WHERE `guildid` = %i AND `area` = 1 AND `slot` = %i LIMIT 1",
                                permissions, memberName, guildID, slotID);
    auto results = database.QueryDatabase(query);
	if(!results.Success())
	{
		return;
	}

	(*iter)->Items.MainArea[slotID].Permissions = permissions;

	if(permissions == GuildBankSingleMember)
		strn0cpy((*iter)->Items.MainArea[slotID].WhoFor, memberName, sizeof((*iter)->Items.MainArea[slotID].WhoFor));
	else
		(*iter)->Items.MainArea[slotID].WhoFor[0] = '\0';

	const Item_Struct *Item = database.GetItem((*iter)->Items.MainArea[slotID].ItemID);

	GuildBankItemUpdate_Struct gbius;

	if(!Item->Stackable)
		gbius.Init(GuildBankItemUpdate, 1, slotID, GuildBankMainArea, 1, Item->ID, Item->Icon, 1, (*iter)->Items.MainArea[slotID].Permissions, 0, 0);
	else
	{
		if((*iter)->Items.MainArea[slotID].Quantity == Item->StackSize)
			gbius.Init(GuildBankItemUpdate, 1, slotID, GuildBankMainArea, 1, Item->ID, Item->Icon,
					(*iter)->Items.MainArea[slotID].Quantity, (*iter)->Items.MainArea[slotID].Permissions, 0, 0);
		else
			gbius.Init(GuildBankItemUpdate, 1, slotID, GuildBankMainArea, 1, Item->ID, Item->Icon,
					(*iter)->Items.MainArea[slotID].Quantity, (*iter)->Items.MainArea[slotID].Permissions, 1, 0);
	}


	strn0cpy(gbius.ItemName, Item->Name, sizeof(gbius.ItemName));

	strn0cpy(gbius.WhoFor, (*iter)->Items.MainArea[slotID].WhoFor, sizeof(gbius.WhoFor));

	entity_list.QueueClientsGuildBankItemUpdate(&gbius, guildID);
}
Пример #5
0
ItemInst* GuildBankManager::GetItem(uint32 GuildID, uint16 Area, uint16 SlotID, uint32 Quantity)
{
	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return nullptr;

	GuildBankItem* BankArea = nullptr;

	ItemInst* inst = nullptr;

	if(Area == GuildBankDepositArea)
	{
		if((SlotID > (GUILD_BANK_DEPOSIT_AREA_SIZE - 1)))
			return nullptr;

		inst = database.CreateItem((*Iterator)->Items.DepositArea[SlotID].ItemID);

		if(!inst)
			return nullptr;

		BankArea = &(*Iterator)->Items.DepositArea[0];
	}
	else
	{

		if((SlotID > (GUILD_BANK_MAIN_AREA_SIZE - 1)))
			return nullptr;

		inst = database.CreateItem((*Iterator)->Items.MainArea[SlotID].ItemID);

		if(!inst)
			return nullptr;

		BankArea = &(*Iterator)->Items.MainArea[0];
	}

	if(!inst->IsStackable())
		inst->SetCharges(BankArea[SlotID].Quantity);
	else
	{
		if(Quantity <= BankArea[SlotID].Quantity)
			inst->SetCharges(Quantity);
		else
			inst->SetCharges(BankArea[SlotID].Quantity);
	}

	return inst;
}
Пример #6
0
bool GuildBankManager::HasItem(uint32 GuildID, uint32 ItemID)
{
	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return false;

	for(int i = 0; i < GUILD_BANK_MAIN_AREA_SIZE; ++i)
		if((*Iterator)->Items.MainArea[i].ItemID == ItemID)
			return true;

	for(int i = 0; i < GUILD_BANK_DEPOSIT_AREA_SIZE; ++i)
		if((*Iterator)->Items.DepositArea[i].ItemID == ItemID)
			return true;

	return false;
}
Пример #7
0
BOOL CDbManager::ConvItemStart( void )
{
	int nCount	= 0;
	int nStarted	= 0;
	DWORD dwMaxConv	= 0;
	char* szSQL	= new char[40960];
	char lpString[300];
	char lpString1[300];

	CQuery* pQueryChar	= new CQuery;
	CQuery* pQuerySave	= new CQuery;
	if( ConvItemConnectDB( pQueryChar, pQuerySave ) == FALSE )
		return FALSE;

	InitConvItemDialog();
	
	AfxMessageBox( "ConvItemStart", MB_OK );
//////////////////////////////////////// Inventory Start ////////////////////////////////////////
	if( ( dwMaxConv = GetMaxInventory( szSQL, pQueryChar, pQuerySave ) ) == 0 )
		return FALSE;

	sprintf( lpString, "%d / %d", 0, dwMaxConv );
	UpdateConvItemDialog( "Inventory, Bank", lpString, "0 %%", 0 );
	if( CreateInvenBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;
	// Inven, Bank Item 가지고 오기
	if( GetInventoryBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;
	while( pQueryChar->Fetch() )
	{
		++nStarted;
		sprintf( lpString, "%d / %d", nStarted, dwMaxConv );
		sprintf( lpString1, "%d %", int( float( (float)nStarted / (float)dwMaxConv ) * 100.0f ) );
		UpdateConvItemDialog( "Inventory, Bank", lpString, lpString1, (int( float( (float)nStarted / (float)dwMaxConv ) * 100.0f )) );
		
		CMover* pMover	= new CMover;
		//GetUserInventoryBank( pMover, pQueryChar );
		// mirchang_100416 VERIFYSTRING use return value
		if( GetUserInventoryBank( pMover, pQueryChar ) == FALSE )
		{
			safe_delete( pMover );
			return FALSE;
		}
		// mirchang_100416

		if( InventoryBankConv( szSQL, pMover, pQueryChar, pQuerySave ) ) // SaveItem
		{
			if( SaveUserInventoryBank( szSQL, pMover, pQueryChar, pQuerySave ) == FALSE )
			{
				safe_delete( pMover );
				return FALSE;
			}
		}
		safe_delete( pMover );
	}
	if( DeleteInvenBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;

//////////////////////////////////////// GuildBank Start ////////////////////////////////////////
	nStarted = 0;
	if( ( dwMaxConv = GetMaxGuildBank( szSQL, pQueryChar, pQuerySave ) ) == 0 )
		return FALSE;
	
	sprintf( lpString, "%d / %d", 0, dwMaxConv );
	UpdateConvItemDialog( "GuildBank", lpString, "0 %%", 0 );
	if( CreateGuildBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;
	// Inven, Bank Item 가지고 오기
	if( GetGuildBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;
	
	while( pQueryChar->Fetch() )
	{
		++nStarted;

		sprintf( lpString, "%d / %d", nStarted, dwMaxConv );
		sprintf( lpString1, "%d %", int( float( (float)nStarted / (float)dwMaxConv ) * 100.0f ) );
		UpdateConvItemDialog( "GuildBank", lpString, lpString1, (int( float( (float)nStarted / (float)dwMaxConv ) * 100.0f )) );
			
		CItemContainer<CItemElem>	GuildBank;	// 길드 창고
		int							nGuildId	= 0;
	
		GuildBank.SetItemContainer( ITYPE_ITEM, MAX_GUILDBANK );
		nGuildId		= pQueryChar->GetInt( "m_idGuild" );
		GetGuildBank( &GuildBank, pQueryChar );
		
		if( GuildBankConv( szSQL, nGuildId, &GuildBank, pQueryChar, pQuerySave ) )
		{
			if( SaveConvGuildBank( szSQL, nGuildId, &GuildBank, pQueryChar, pQuerySave ) == FALSE )
				return FALSE;
		}
	}
	if( DeleteGuildBankView( szSQL, pQueryChar, pQuerySave ) == FALSE )
		return FALSE;
	
	SAFE_DELETE( pQueryChar ); SAFE_DELETE( pQuerySave );
	return TRUE;
}
Пример #8
0
int GuildBankManager::Promote(uint32 guildID, int slotID)
{
	if((slotID < 0) || (slotID > (GUILD_BANK_DEPOSIT_AREA_SIZE - 1)))
		return -1;

	auto iter = GetGuildBank(guildID);

	if(iter == Banks.end())
		return -1;

	if((*iter)->Items.DepositArea[slotID].ItemID == 0)
		return -1;

	int mainSlot = -1;

	for(int i = 0; i < GUILD_BANK_MAIN_AREA_SIZE; ++i)
		if((*iter)->Items.MainArea[i].ItemID == 0) {
			mainSlot = i;
			break;
		}

	if(mainSlot == -1)
		return -1;

	(*iter)->Items.MainArea[mainSlot].ItemID = (*iter)->Items.DepositArea[slotID].ItemID;
	(*iter)->Items.MainArea[mainSlot].Quantity = (*iter)->Items.DepositArea[slotID].Quantity;
    (*iter)->Items.MainArea[mainSlot].Permissions = (*iter)->Items.DepositArea[slotID].Permissions;

	strn0cpy((*iter)->Items.MainArea[mainSlot].Donator, (*iter)->Items.DepositArea[slotID].Donator, sizeof((*iter)->Items.MainArea[mainSlot].Donator));
	strn0cpy((*iter)->Items.MainArea[mainSlot].WhoFor, (*iter)->Items.DepositArea[slotID].WhoFor, sizeof((*iter)->Items.MainArea[mainSlot].WhoFor));

	std::string query = StringFormat("UPDATE `guild_bank` SET `area` = 1, `slot` = %i "
                                    "WHERE `guildid` = %i AND `area` = 0 AND `slot` = %i "
                                    "LIMIT 1", mainSlot, guildID, slotID);
    auto results = database.QueryDatabase(query);
    if (!results.Success()) {
		return -1;
	}

	(*iter)->Items.DepositArea[slotID].ItemID = 0;

	const Item_Struct *Item = database.GetItem((*iter)->Items.MainArea[mainSlot].ItemID);

	GuildBankItemUpdate_Struct gbius;

	if(!Item->Stackable)
		gbius.Init(GuildBankItemUpdate, 1, mainSlot, GuildBankMainArea, 1, Item->ID, Item->Icon, 1, 0, 0, 0);
	else
	{
		if((*iter)->Items.MainArea[mainSlot].Quantity == Item->StackSize)
			gbius.Init(GuildBankItemUpdate, 1, mainSlot, GuildBankMainArea, 1, Item->ID, Item->Icon,
					(*iter)->Items.MainArea[mainSlot].Quantity, 0, 0, 0);
		else
			gbius.Init(GuildBankItemUpdate, 1, mainSlot, GuildBankMainArea, 1, Item->ID, Item->Icon,
					(*iter)->Items.MainArea[mainSlot].Quantity, 0, 1, 0);
	}

	strn0cpy(gbius.ItemName, Item->Name, sizeof(gbius.ItemName));

	entity_list.QueueClientsGuildBankItemUpdate(&gbius, guildID);

	gbius.Init(GuildBankItemUpdate, 1, slotID, GuildBankDepositArea, 0, 0, 0, 0, 0, 0, 0);

	entity_list.QueueClientsGuildBankItemUpdate(&gbius, guildID);

	return mainSlot;
}
Пример #9
0
bool GuildBankManager::AddItem(uint32 GuildID, uint8 Area, uint32 ItemID, int32 QtyOrCharges, const char *Donator, uint8 Permissions, const char *WhoFor)
{
	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
	{
		Log.Out(Logs::General, Logs::Error, "Unable to find guild bank for guild ID %i", GuildID);

		return false;
	}

	GuildBankItem* BankArea = nullptr;

	int AreaSize = 0;

	if(Area == GuildBankMainArea)
	{
		BankArea = &(*Iterator)->Items.MainArea[0];

		AreaSize = GUILD_BANK_MAIN_AREA_SIZE;
	}
	else
	{
		BankArea = &(*Iterator)->Items.DepositArea[0];

		AreaSize = GUILD_BANK_DEPOSIT_AREA_SIZE;
	}

	int Slot = -1;

	for(int i = 0; i < AreaSize; ++i)
	{
		if(BankArea[i].ItemID == 0)
		{
			BankArea[i].ItemID = ItemID;

			BankArea[i].Quantity = QtyOrCharges;

			strn0cpy(BankArea[i].Donator, Donator, sizeof(BankArea[i].Donator));

			BankArea[i].Permissions = Permissions;

			strn0cpy(BankArea[i].WhoFor, WhoFor, sizeof(BankArea[i].WhoFor));

			Slot = i;

			break;
		}
	}

	if(Slot < 0)
	{
		Log.Out(Logs::General, Logs::Error, "No space to add item to the guild bank.");

		return false;
	}

	std::string query = StringFormat("INSERT INTO `guild_bank` "
                                    "(`guildid`, `area`, `slot`, `itemid`, `qty`, `donator`, `permissions`, `WhoFor`) "
                                    "VALUES (%i, %i, %i, %i, %i, '%s', %i, '%s')",
                                    GuildID, Area, Slot, ItemID, QtyOrCharges, Donator, Permissions, WhoFor);
    auto results = database.QueryDatabase(query);
	if(!results.Success()) {
		return false;
	}

	const Item_Struct *Item = database.GetItem(ItemID);

	GuildBankItemUpdate_Struct gbius;

	if(!Item->Stackable)
		gbius.Init(GuildBankItemUpdate, 1, Slot, Area, 1, ItemID, Item->Icon, Item->Stackable ? QtyOrCharges : 1, Permissions, 0, 0);
	else
	{
		if(QtyOrCharges == Item->StackSize)
			gbius.Init(GuildBankItemUpdate, 1, Slot, Area, 1, ItemID, Item->Icon, Item->Stackable ? QtyOrCharges : 1, Permissions, 0, 0);
		else
			gbius.Init(GuildBankItemUpdate, 1, Slot, Area, 1, ItemID, Item->Icon, Item->Stackable ? QtyOrCharges : 1, Permissions, 1, 0);
	}

	strn0cpy(gbius.ItemName, Item->Name, sizeof(gbius.ItemName));

	strn0cpy(gbius.Donator, Donator, sizeof(gbius.Donator));

	strn0cpy(gbius.WhoFor, WhoFor, sizeof(gbius.WhoFor));

	entity_list.QueueClientsGuildBankItemUpdate(&gbius, GuildID);

	return true;
}
Пример #10
0
void GuildBankManager::SendGuildBank(Client *c)
{
	if(!c || !c->IsInAGuild())
		return;

	if(!IsLoaded(c->GuildID()))
		Load(c->GuildID());

	std::list<GuildBank*>::iterator Iterator = GetGuildBank(c->GuildID());

	if(Iterator == Banks.end())
	{
		Log.Out(Logs::General, Logs::Error, "Unable to find guild bank for guild ID %i", c->GuildID());

		return;
	}

	for(int i = 0; i < GUILD_BANK_DEPOSIT_AREA_SIZE; ++i)
	{
		if((*Iterator)->Items.DepositArea[i].ItemID > 0)
		{
			const Item_Struct *Item = database.GetItem((*Iterator)->Items.DepositArea[i].ItemID);

			if(!Item)
				continue;

			EQApplicationPacket *outapp = new EQApplicationPacket(OP_GuildBank, sizeof(GuildBankItemUpdate_Struct));

			GuildBankItemUpdate_Struct *gbius = (GuildBankItemUpdate_Struct*)outapp->pBuffer;

			if(!Item->Stackable)
				gbius->Init(GuildBankItemUpdate, 1, i, GuildBankDepositArea, 1, Item->ID, Item->Icon, 1,
						(*Iterator)->Items.DepositArea[i].Permissions, 0, 0);
			else
			{
				if((*Iterator)->Items.DepositArea[i].Quantity == Item->StackSize)
					gbius->Init(GuildBankItemUpdate, 1, i, GuildBankDepositArea, 1, Item->ID, Item->Icon,
							(*Iterator)->Items.DepositArea[i].Quantity, (*Iterator)->Items.DepositArea[i].Permissions, 0, 0);
				else
					gbius->Init(GuildBankItemUpdate, 1, i, GuildBankDepositArea, 1, Item->ID, Item->Icon,
							(*Iterator)->Items.DepositArea[i].Quantity, (*Iterator)->Items.DepositArea[i].Permissions, 1, 0);
			}

			strn0cpy(gbius->ItemName, Item->Name, sizeof(gbius->ItemName));

			strn0cpy(gbius->Donator, (*Iterator)->Items.DepositArea[i].Donator, sizeof(gbius->Donator));

			strn0cpy(gbius->WhoFor, (*Iterator)->Items.DepositArea[i].WhoFor, sizeof(gbius->WhoFor));

			c->FastQueuePacket(&outapp);
		}
	}

	for(int i = 0; i < GUILD_BANK_MAIN_AREA_SIZE; ++i)
	{
		if((*Iterator)->Items.MainArea[i].ItemID > 0)
		{
			const Item_Struct *Item = database.GetItem((*Iterator)->Items.MainArea[i].ItemID);

			if(!Item)
				continue;

			bool Useable = Item->IsEquipable(c->GetBaseRace(), c->GetBaseClass());

			EQApplicationPacket *outapp = new EQApplicationPacket(OP_GuildBank, sizeof(GuildBankItemUpdate_Struct));

			GuildBankItemUpdate_Struct *gbius = (GuildBankItemUpdate_Struct*)outapp->pBuffer;

			if(!Item->Stackable)
				gbius->Init(GuildBankItemUpdate, 1, i, GuildBankMainArea, 1, Item->ID, Item->Icon, 1,
						(*Iterator)->Items.MainArea[i].Permissions, 0, Useable);
			else
			{
				if((*Iterator)->Items.MainArea[i].Quantity == Item->StackSize)
					gbius->Init(GuildBankItemUpdate, 1, i, GuildBankMainArea, 1, Item->ID, Item->Icon,
							(*Iterator)->Items.MainArea[i].Quantity, (*Iterator)->Items.MainArea[i].Permissions, 0, Useable);
				else
					gbius->Init(GuildBankItemUpdate, 1, i, GuildBankMainArea, 1, Item->ID, Item->Icon,
							(*Iterator)->Items.MainArea[i].Quantity, (*Iterator)->Items.MainArea[i].Permissions, 1, Useable);
			}

			strn0cpy(gbius->ItemName, Item->Name, sizeof(gbius->ItemName));

			strn0cpy(gbius->Donator, (*Iterator)->Items.MainArea[i].Donator, sizeof(gbius->Donator));

			strn0cpy(gbius->WhoFor, (*Iterator)->Items.MainArea[i].WhoFor, sizeof(gbius->WhoFor));

			c->FastQueuePacket(&outapp);
		}
	}
}
Пример #11
0
bool GuildBankManager::IsLoaded(uint32 GuildID)
{
	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	return (Iterator != Banks.end());
}
Пример #12
0
bool GuildBankManager::MergeStacks(uint32 GuildID, uint16 SlotID)
{
	if(SlotID > (GUILD_BANK_MAIN_AREA_SIZE - 1))
		return false;

	std::list<GuildBank*>::iterator Iterator = GetGuildBank(GuildID);

	if(Iterator == Banks.end())
		return false;

	GuildBankItem* BankArea = &(*Iterator)->Items.MainArea[0];

	if(BankArea[SlotID].ItemID == 0)
		return false;

	const Item_Struct *Item = database.GetItem(BankArea[SlotID].ItemID);

	if(!Item->Stackable)
		return false;

	uint32 ItemID = BankArea[SlotID].ItemID;

	for(int i = 0; i < GUILD_BANK_MAIN_AREA_SIZE - 1; ++i)
	{
		if(BankArea[i].ItemID != ItemID)
			continue;

		if(BankArea[i].Quantity == Item->StackSize)
			continue;

		bool Merged = false;

		for(int j = i + 1; j < GUILD_BANK_MAIN_AREA_SIZE; ++j)
		{
			if(BankArea[j].ItemID != ItemID)
				continue;

			if(BankArea[j].Permissions != BankArea[i].Permissions)
				continue;

			if(BankArea[i].Permissions == 1)
				if(strncmp(BankArea[i].WhoFor, BankArea[j].WhoFor, sizeof(BankArea[i].WhoFor)))
					continue;

			if((BankArea[i].Quantity + BankArea[j].Quantity) <= Item->StackSize)
			{
				BankArea[i].Quantity += BankArea[j].Quantity;

				DeleteItem(GuildID, GuildBankMainArea, j, BankArea[j].Quantity);

				Merged = true;

				if(BankArea[i].Quantity == Item->StackSize)
					break;
			}
			else
			{
				uint32 QuantityToMove = Item->StackSize - BankArea[i].Quantity;

				DeleteItem(GuildID, GuildBankMainArea, j, QuantityToMove);

				BankArea[i].Quantity = Item->StackSize;

				Merged = true;

				break;
			}
		}

		if(Merged)
		{
			UpdateItemQuantity(GuildID, GuildBankMainArea, i, BankArea[i].Quantity);

			GuildBankItemUpdate_Struct gbius;

			if(BankArea[i].Quantity == Item->StackSize)
				gbius.Init(GuildBankItemUpdate, 1, i, GuildBankMainArea, 1, ItemID, Item->Icon, BankArea[i].Quantity, BankArea[i].Permissions, 0, 0);
			else
				gbius.Init(GuildBankItemUpdate, 1, i, GuildBankMainArea, 1, ItemID, Item->Icon, BankArea[i].Quantity, BankArea[i].Permissions, 1, 0);

			strn0cpy(gbius.ItemName, Item->Name, sizeof(gbius.ItemName));

			strn0cpy(gbius.WhoFor, BankArea[i].WhoFor, sizeof(gbius.WhoFor));

			entity_list.QueueClientsGuildBankItemUpdate(&gbius, GuildID);
		}

	}

	return true;
}
Пример #13
0
bool GuildBankManager::DeleteItem(uint32 guildID, uint16 area, uint16 slotID, uint32 quantity)
{
	auto iter = GetGuildBank(guildID);

	if(iter == Banks.end())
		return false;

	GuildBankItem* BankArea = nullptr;

	if(area == GuildBankMainArea)
	{
		if(slotID > (GUILD_BANK_MAIN_AREA_SIZE - 1))
			return false;

		BankArea = &(*iter)->Items.MainArea[0];
	} else {
		if(slotID > (GUILD_BANK_DEPOSIT_AREA_SIZE - 1))
			return false;

		BankArea = &(*iter)->Items.DepositArea[0];
	}

	bool deleted = true;

	const Item_Struct *Item = database.GetItem(BankArea[slotID].ItemID);

	if(!Item->Stackable || (quantity >= BankArea[slotID].Quantity)) {
        std::string query = StringFormat("DELETE FROM `guild_bank` WHERE `guildid` = %i "
                                        "AND `area` = %i AND `slot` = %i LIMIT 1",
                                        guildID, area, slotID);
        auto results = database.QueryDatabase(query);
		if(!results.Success()) {
			return false;
		}

		BankArea[slotID].ItemID = 0;

	} else {
		std::string query = StringFormat("UPDATE `guild_bank` SET `qty` = %i WHERE `guildid` = %i "
                                        "AND `area` = %i AND `slot` = %i LIMIT 1",
                                        BankArea[slotID].Quantity - quantity, guildID, area, slotID);
        auto results = database.QueryDatabase(query);
		if(!results.Success()) {
			return false;
		}

		BankArea[slotID].Quantity -= quantity;

		deleted = false;
	}

	GuildBankItemUpdate_Struct gbius;

	if(!deleted)
	{
		gbius.Init(GuildBankItemUpdate, 1, slotID, area, 1, Item->ID, Item->Icon, BankArea[slotID].Quantity, BankArea[slotID].Permissions, 1, 0);

		strn0cpy(gbius.ItemName, Item->Name, sizeof(gbius.ItemName));

		strn0cpy(gbius.WhoFor, BankArea[slotID].WhoFor, sizeof(gbius.WhoFor));
	}
	else
		gbius.Init(GuildBankItemUpdate, 1, slotID, area, 0, 0, 0, 0, 0, 0, 0);

	entity_list.QueueClientsGuildBankItemUpdate(&gbius, guildID);

	return true;

}