Loading...   

  • Created By Uleat On: 09:17 PM March 12, 2018
  • Link

void command_peekinv(Client *c, const Seperator *sep)
{
	// this can be cleaned up once inventory is cleaned up
	enum {
		peekEquip = 0x01,
		peekGen = 0x02,
		peekCursor = 0x04,
		peekLimbo = 0x08,
		peekTrib = 0x10,
		peekBank = 0x20,
		peekShBank = 0x40,
		peekTrade = 0x80,
		peekWorld = 0x100,
		peekOutOfScope = (peekWorld * 2) // less than
	} ;

	static char* scope_prefix[] = { "Equip", "Gen", "Cursor", "Limbo", "Trib", "Bank", "ShBank", "Trade", "World" };

	static int16 scope_range[][2] = {
		{ EQEmu::legacy::EQUIPMENT_BEGIN, EQEmu::legacy::EQUIPMENT_END },
		{ EQEmu::legacy::GENERAL_BEGIN, EQEmu::legacy::GENERAL_END },
		{ EQEmu::legacy::SLOT_CURSOR, EQEmu::legacy::SLOT_CURSOR },
		{ EQEmu::legacy::SLOT_INVALID, EQEmu::legacy::SLOT_INVALID },
		{ EQEmu::legacy::TRIBUTE_BEGIN, EQEmu::legacy::TRIBUTE_END },
		{ EQEmu::legacy::BANK_BEGIN, EQEmu::legacy::BANK_END },
		{ EQEmu::legacy::SHARED_BANK_BEGIN, EQEmu::legacy::SHARED_BANK_END },
		{ EQEmu::legacy::TRADE_BEGIN, EQEmu::legacy::TRADE_END },
		{ EQEmu::inventory::slotBegin, (EQEmu::legacy::WORLD_SIZE - 1) }
	};
	
	static bool scope_bag[] = { false, true, true, true, false, true, true, true, true };

	if (!c)
		return;

	if (c->GetTarget() && !c->GetTarget()->IsClient()) {
		c->Message(0, "You must target a PC for this command.");
		return;
	}

	int scopeMask = 0;

	if (strcasecmp(sep->arg[1], "all") == 0) { scopeMask = ~0; }
	else if (strcasecmp(sep->arg[1], "equip") == 0) { scopeMask |= peekEquip; }
	else if (strcasecmp(sep->arg[1], "gen") == 0) { scopeMask |= peekGen; }
	else if (strcasecmp(sep->arg[1], "cursor") == 0) { scopeMask |= peekCursor; }
	else if (strcasecmp(sep->arg[1], "poss") == 0) { scopeMask |= (peekEquip | peekGen | peekCursor); }
	else if (strcasecmp(sep->arg[1], "limbo") == 0) { scopeMask |= peekLimbo; }
	else if (strcasecmp(sep->arg[1], "trib") == 0) { scopeMask |= peekTrib; }
	else if (strcasecmp(sep->arg[1], "bank") == 0) { scopeMask |= peekBank; }
	else if (strcasecmp(sep->arg[1], "shbank") == 0) { scopeMask |= peekShBank; }
	else if (strcasecmp(sep->arg[1], "allbank") == 0) { scopeMask |= (peekBank | peekShBank); }
	else if (strcasecmp(sep->arg[1], "trade") == 0) { scopeMask |= peekTrade; }
	else if (strcasecmp(sep->arg[1], "world") == 0) { scopeMask |= peekWorld; }

	if (!scopeMask) {
		c->Message(0, "Usage: #peekinv [equip|gen|cursor|poss|limbo|trib|bank|shbank|allbank|trade|world|all]");
		c->Message(0, "- Displays a portion of the targeted user's inventory");
		c->Message(0, "- Caution: 'all' is a lot of information!");
		return;
	}

	Client* targetClient = c;
	if (c->GetTarget())
		targetClient = c->GetTarget()->CastToClient();

	const EQEmu::ItemInstance* inst_main = nullptr;
	const EQEmu::ItemInstance* inst_sub = nullptr;
	const EQEmu::ItemInstance* inst_aug = nullptr;
	const EQEmu::ItemData* item_data = nullptr;

	EQEmu::SayLinkEngine linker;
	linker.SetLinkType(EQEmu::saylink::SayLinkItemInst);

	c->Message(0, "Displaying inventory for %s...",  targetClient->GetName());

	Object* objectTradeskill = targetClient->GetTradeskillObject();

	bool itemsFound = false;

	for (int scopeIndex = 0, scopeBit = peekEquip; scopeBit < peekOutOfScope; ++scopeIndex, scopeBit <<= 1) {
		if (scopeBit & ~scopeMask)
			continue;

		if (scopeBit & peekWorld) {
			if (objectTradeskill == nullptr) {
				c->Message(1, "No world tradeskill object selected...");
				continue;
			}
			else {
				c->Message(0, "[WorldObject DBID: %i (entityid: %i)]", objectTradeskill->GetDBID(), objectTradeskill->GetID());
			}
		}

		for (int16 indexMain = scope_range[scopeIndex][0]; indexMain <= scope_range[scopeIndex][1]; ++indexMain) {
			if (indexMain == EQEmu::legacy::SLOT_INVALID)
				continue;

			inst_main = ((scopeBit & peekWorld) ? objectTradeskill->GetItem(indexMain) : targetClient->GetInv().GetItem(indexMain));
			if (inst_main) {
				itemsFound = true;
				item_data = inst_main->GetItem();
			}
			else {
				item_data = nullptr;
			}

			linker.SetItemInst(inst_main);

			c->Message(
				(item_data == nullptr),
				"%sSlot: %i, Item: %i (%s), Charges: %i",
				scope_prefix[scopeIndex],
				((scopeBit & peekWorld) ? (EQEmu::legacy::WORLD_BEGIN + indexMain) : indexMain),
				((item_data == nullptr) ? 0 : item_data->ID),
				linker.GenerateLink().c_str(),
				((inst_main == nullptr) ? 0 : inst_main->GetCharges())
			);

			if (inst_main && inst_main->IsClassCommon()) {
				for (uint8 indexAug = EQEmu::inventory::socketBegin; indexAug < EQEmu::inventory::SocketCount; ++indexAug) {
					inst_aug = inst_main->GetItem(indexAug);
					if (!inst_aug) // extant only
						continue;

					item_data = inst_aug->GetItem();
					linker.SetItemInst(inst_aug);

					c->Message(
						(item_data == nullptr),
						".%sAugSlot: %i (Slot #%i, Aug idx #%i), Item: %i (%s), Charges: %i",
						scope_prefix[scopeIndex],
						INVALID_INDEX,
						((scopeBit & peekWorld) ? (EQEmu::legacy::WORLD_BEGIN + indexMain) : indexMain),
						indexAug,
						((item_data == nullptr) ? 0 : item_data->ID),
						linker.GenerateLink().c_str(),
						((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
					);
				}
			}

			if (!scope_bag[scopeIndex] || !(inst_main && inst_main->IsClassBag()))
				continue;

			for (uint8 indexSub = EQEmu::inventory::containerBegin; indexSub < EQEmu::inventory::ContainerCount; ++indexSub) {
				inst_sub = inst_main->GetItem(indexSub);
				if (!inst_sub) // extant only
					continue;

				item_data = inst_sub->GetItem();
				linker.SetItemInst(inst_sub);

				c->Message(
					(item_data == nullptr),
					"..%sBagSlot: %i (Slot #%i, Bag idx #%i), Item: %i (%s), Charges: %i",
					scope_prefix[scopeIndex],
					((scopeBit & peekWorld) ? INVALID_INDEX : EQEmu::InventoryProfile::CalcSlotId(indexMain, indexSub)),
					((scopeBit & peekWorld) ? (EQEmu::legacy::WORLD_BEGIN + indexMain) : indexMain),
					indexSub,
					((item_data == nullptr) ? 0 : item_data->ID),
					linker.GenerateLink().c_str(),
					((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
				);

				if (inst_sub->IsClassCommon()) {
					for (uint8 indexAug = EQEmu::inventory::socketBegin; indexAug < EQEmu::inventory::SocketCount; ++indexAug) {
						inst_aug = inst_sub->GetItem(indexAug);
						if (!inst_aug) // extant only
							continue;

						item_data = inst_aug->GetItem();
						linker.SetItemInst(inst_aug);

						c->Message(
							(item_data == nullptr),
							"...%sAugSlot: %i (Slot #%i, Sub idx #%i, Aug idx #%i), Item: %i (%s), Charges: %i",
							scope_prefix[scopeIndex],
							INVALID_INDEX,
							((scopeBit & peekWorld) ? INVALID_INDEX : EQEmu::InventoryProfile::CalcSlotId(indexMain, indexSub)),
							indexSub,
							indexAug,
							((item_data == nullptr) ? 0 : item_data->ID),
							linker.GenerateLink().c_str(),
							((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
						);
					}
				}
			}
		}

		if ((scopeBit & peekEquip) && (targetClient->ClientVersion() >= EQEmu::versions::ClientVersion::SoF)) {
			inst_main = targetClient->GetInv().GetItem(EQEmu::inventory::slotPowerSource);
			if (inst_main) {
				itemsFound = true;
				item_data = inst_main->GetItem();
			}
			else {
				item_data = nullptr;
			}

			linker.SetItemInst(inst_main);

			c->Message(
				(item_data == nullptr),
				"%sSlot: %i, Item: %i (%s), Charges: %i",
				scope_prefix[scopeIndex],
				EQEmu::inventory::slotPowerSource,
				((item_data == nullptr) ? 0 : item_data->ID),
				linker.GenerateLink().c_str(),
				((inst_main == nullptr) ? 0 : inst_main->GetCharges())
			);

			for (uint8 indexAug = EQEmu::inventory::socketBegin; indexAug < EQEmu::inventory::SocketCount; ++indexAug) {
				inst_aug = inst_main->GetItem(indexAug);
				if (!inst_aug) // extant only
					continue;

				item_data = inst_aug->GetItem();
				linker.SetItemInst(inst_aug);

				c->Message(
					(item_data == nullptr),
					".%sAugSlot: %i (Slot #%i, Aug idx #%i), Item: %i (%s), Charges: %i",
					scope_prefix[scopeIndex],
					INVALID_INDEX,
					EQEmu::inventory::slotPowerSource,
					indexAug,
					((item_data == nullptr) ? 0 : item_data->ID),
					linker.GenerateLink().c_str(),
					((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
				);
			}
		}
		
		if (scopeBit & peekLimbo) {
			int limboIndex = -1;
			for (auto it = targetClient->GetInv().cursor_cbegin(); (it != targetClient->GetInv().cursor_cend()); ++it, ++limboIndex) {
				if (it == targetClient->GetInv().cursor_cbegin())
					continue;

				inst_main = *it;
				if (inst_main) {
					itemsFound = true;
					item_data = inst_main->GetItem();
				}
				else {
					item_data = nullptr;
				}

				linker.SetItemInst(inst_main);

				c->Message(
					(item_data == nullptr),
					"%sSlot: %i, Item: %i (%s), Charges: %i",
					scope_prefix[scopeIndex],
					(8000 + limboIndex),
					((item_data == nullptr) ? 0 : item_data->ID),
					linker.GenerateLink().c_str(),
					((inst_main == nullptr) ? 0 : inst_main->GetCharges())
				);

				if (inst_main && inst_main->IsClassCommon()) {
					for (uint8 indexAug = EQEmu::inventory::socketBegin; indexAug < EQEmu::inventory::SocketCount; ++indexAug) {
						inst_aug = inst_main->GetItem(indexAug);
						if (!inst_aug) // extant only
							continue;

						item_data = inst_aug->GetItem();
						linker.SetItemInst(inst_aug);

						c->Message(
							(item_data == nullptr),
							".%sAugSlot: %i (Slot #%i, Aug idx #%i), Item: %i (%s), Charges: %i",
							scope_prefix[scopeIndex],
							INVALID_INDEX,
							(8000 + limboIndex),
							indexAug,
							((item_data == nullptr) ? 0 : item_data->ID),
							linker.GenerateLink().c_str(),
							((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
						);
					}
				}

				if (!scope_bag[scopeIndex] || !(inst_main && inst_main->IsClassBag()))
					continue;

				for (uint8 indexSub = EQEmu::inventory::containerBegin; indexSub < EQEmu::inventory::ContainerCount; ++indexSub) {
					inst_sub = inst_main->GetItem(indexSub);
					item_data = (inst_sub == nullptr) ? nullptr : inst_sub->GetItem();

					linker.SetItemInst(inst_sub);

					c->Message(
						(item_data == nullptr),
						"..%sBagSlot: %i (Slot #%i, Bag idx #%i), Item: %i (%s), Charges: %i",
						scope_prefix[scopeIndex],
						INVALID_INDEX,
						(8000 + limboIndex),
						indexSub,
						((item_data == nullptr) ? 0 : item_data->ID),
						linker.GenerateLink().c_str(),
						((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
					);

					if (inst_sub->IsClassCommon()) {
						for (uint8 indexAug = EQEmu::inventory::socketBegin; indexAug < EQEmu::inventory::SocketCount; ++indexAug) {
							inst_aug = inst_sub->GetItem(indexAug);
							if (!inst_aug) // extant only
								continue;

							item_data = inst_aug->GetItem();
							linker.SetItemInst(inst_aug);

							c->Message(
								(item_data == nullptr),
								"...%sAugSlot: %i (Slot #%i, Sub idx #%i, Aug idx #%i), Item: %i (%s), Charges: %i",
								scope_prefix[scopeIndex],
								INVALID_INDEX,
								(8000 + limboIndex),
								indexSub,
								indexAug,
								((item_data == nullptr) ? 0 : item_data->ID),
								linker.GenerateLink().c_str(),
								((inst_sub == nullptr) ? 0 : inst_sub->GetCharges())
							);
						}
					}
				}
			}
		}
	}

	if (!itemsFound)
		c->Message(0, "No items found.");
}

Raw Paste Data