⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quickequip.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
					qEAE_PlayerItems[itemLinkId..":2"] = slot; 
				else
					EAE_PlayerItems[itemLinkId] = slot; 
				end
			end; 
		end; 
	end; 
	local index, value; 
	for index, slotName in EAE_Slots do 
		local itemName, itemLinkId = EAE_GetItemInfo("inventory", slotName); 
		if (itemName and itemLinkId) then 
			local slot = {}; 
			slot.type = "inventory"; 
			slot.slotId = GetInventorySlotInfo(slotName); 
			if (EAE_PlayerItems[itemLinkId]) then
				EAE_PlayerItems[itemLinkId..":2"] = slot; 
			else
				EAE_PlayerItems[itemLinkId] = slot; 
			end
		end; 
	end; 
end; 
function EAE_IsLoadSetLocked() 
	local index, itemPare
	for index, itemPare in EAE_LoadSet do 
		if (EAE_IsSlotItemLocked(itemPare.srcSlot) or EAE_IsSlotItemLocked(itemPare.dstSlot)) then 
			return 1; 
		end
	end
end
function EAE_GetBagEmptyNums()
	local bag, totalSlots, slot;
	BagEmptyNums = {};
	TotalBagEmptyNums = 0;
	for bag = 0, 4 do
		BagEmptyNums[bag] = 0;
		totalSlots = GetContainerNumSlots(bag);
		for slot=1, totalSlots do
			if not GetContainerItemInfo(bag, slot) then
				BagEmptyNums[bag] = BagEmptyNums[bag] + 1;
				TotalBagEmptyNums = TotalBagEmptyNums + 1;
			end
		end
	end
end
function EAE_IfExist(slot)
	for _,s in EAE_LoadSet do
		if (EAE_IsSlotEqual(slot, s.srcSlot)) then return true; end
	end
	return false;
end
function EAE_LoadPlayerEquipSet(setId, showMsg)
	EAE_GetPlayerItems()
	local equipSet = EAE_GetPlayerEquipSet(setId) 
	if ( not equipSet ) then 
		EAE_SetCurrentSetId(setId);
		return 
	end
	EAE_LoadSet = {} 
	EAE_LoadSetFirst = {} 
	
	if (showMsg == 1) then
		DEFAULT_CHAT_FRAME:AddMessage(string.format(EAE_MSG_LOAD_SET, setId), 1, 0.75 , 0);
	end

	local slotName, itemData
	local UnequipItems = {};
	for slotName, itemData in equipSet do
		if (itemData.link) then
			local srcSlot = EAE_PlayerItems[itemData.link]
			if (srcSlot) then 
				local dstSlot = {}
				dstSlot.type = "inventory";
				dstSlot.slotId = GetInventorySlotInfo(slotName);
				if ( EAE_MustPickUp(srcSlot, dstSlot, setId) ) then
					if (srcSlot.type == "inventory") then
							local index, s, b
							for index,s in EAE_LoadSetFirst do
								if (EAE_IsSlotEqual(dstSlot, s.srcSlot)) then
									table.remove(EAE_LoadSetFirst, index)
									EAE_SaveItemPareToLoadSet(srcSlot, dstSlot, 1)
									b = true;
									break;
								end
							end
						if (not b) then
							EAE_SaveItemPareToLoadSet(srcSlot, dstSlot, 0)
						end
					elseif( EAE_IfExist(srcSlot)) then
						local srcSlot2 = EAE_PlayerItems[itemData.link..":2"];
						if (srcSlot2) then
							if (srcSlot2.type == "inventory") then
								if (not EAE_IsSlotEqual(srcSlot2, dstSlot)) then
									EAE_SaveItemPareToLoadSet(srcSlot2, dstSlot, 0)
								end
							else
								EAE_SaveItemPareToLoadSet(srcSlot2, dstSlot, 1)
							end
						else
							EAE_SaveItemPareToLoadSet(srcSlot, dstSlot, 1)
						end
					else
						EAE_SaveItemPareToLoadSet(srcSlot, dstSlot, 1)
					end
				end
			else
				if (showMsg == 1) then
					DEFAULT_CHAT_FRAME:AddMessage(string.format(EAE_MSG_ITEM_NOTEXISTS, itemData.name), 1, 0.75, 0);
				end;
			end
		elseif (slotName ~= "AmmoSlot" and GetInventorySlotInfo(slotName)) then
			local dstSlot = {}
			dstSlot.type = "inventory";
			dstSlot.slotId = GetInventorySlotInfo(slotName);
			table.insert(UnequipItems, dstSlot);
		end
	end 
	
	if (EAE_IsLoadSetLocked() and showMsg == 1 ) then 
		DEFAULT_CHAT_FRAME:AddMessage(EAE_MSG_ITEM_LOCKED, 1, 0.75, 0);
		return;
	end;

	local index, value, slotPare, slot2
	EAE_GetBagEmptyNums();
		
	for index, slotPare in EAE_LoadSetFirst do 
		if (TotalBagEmptyNums == 0 and showMsg == 1 ) then
			DEFAULT_CHAT_FRAME:AddMessage(EAE_MSG_BAG_FULL, 1, 0.75, 0);
			break;
		end
		EAE_PickUpItem(slotPare.dstSlot) 
		if ( CursorHasItem() ) then 
			for bag = 0, 4 do
				if (BagEmptyNums[bag] > 0) then
					if (bag == 0) then
						PutItemInBackpack(); 
					else
						PutItemInBag(19+bag);
					end
					BagEmptyNums[bag] = BagEmptyNums[bag] - 1;
					TotalBagEmptyNums = TotalBagEmptyNums - 1;
					break;
				end
			end
		end
		EAE_PickUpItem(slotPare.srcSlot) 
		if ( CursorHasItem() ) then 
			EquipCursorItem(slotPare.dstSlot.slotId-1) 
		end 
	end
		
	for index, slotPare in EAE_LoadSet do 
		EAE_PickUpItem(slotPare.srcSlot) 
		if ( CursorHasItem() ) then 
			EAE_PickUpItem(slotPare.dstSlot) 
		end 
	end
	
	for index, slot2 in UnequipItems do
		if (TotalBagEmptyNums == 0 and showMsg == 1 ) then
			DEFAULT_CHAT_FRAME:AddMessage(EAE_MSG_BAG_FULL, 1, 0.75, 0);
			break;
		end
		EAE_PickUpItem(slot2) 
		if (CursorHasItem()) then
			for bag = 0, 4 do
				if (BagEmptyNums[bag] > 0) then
					if (bag == 0) then
						PutItemInBackpack(); 
					else
						PutItemInBag(19+bag);
					end
					BagEmptyNums[bag] = BagEmptyNums[bag] - 1;
					TotalBagEmptyNums = TotalBagEmptyNums - 1;
					break;
				end
			end
		end
	end
	EAE_PlayerItems = {};
	EAE_LoadSet = {};
	EAE_LoadSetFirst = {};
	EAE_SetCurrentSetId(setId)
end
function EAE_SetCurrentSetId(setId)
	if (not EAE_Config[EAE_PlayerId]) then
		EAE_Config[EAE_PlayerId] = {};
	end;
	EAE_Config[EAE_PlayerId].CurrentSetId = setId;
end; 

StaticPopupDialogs["SAVE_QUERY"] = {
	text = "是否覆盖并储存当前装备信息?",
	button1 = TEXT(YES),
	button2 = TEXT(NO),
	OnAccept = function() QuickEquip_Save(QuickEquip_Current) end,
	OnCancel = function(prevFrame) end,
	showAlert = 1,
	timeout = 0,
};

function QuickEquipSave_OnQuery()
	StaticPopup_Show("SAVE_QUERY");
end

function QuickEquip_Enabler(toggle)
	if ( toggle == 1 ) then
		QuickEquipFrame:Show();
		QuickEquip_Enable = 1;
		QuickEquip.Enable = 1;
	else
		QuickEquipFrame:Hide();
		QuickEquip_Enable = 0;
		QuickEquip.Enable = 0;
	end
end

function QuickEquip_ClearAll()
	QuickEquip_Enable = 0;
	QuickEquip_Current = 1;
	QuickEquipButton1:SetChecked(1);
	QuickEquipButton2:SetChecked(nil);
	QuickEquipButton3:SetChecked(nil);
	QuickEquipButton4:SetChecked(nil);
	EAE_Config[EAE_PlayerId] = {};
end

function QuickEquip_SwitchPrev()
	local prev;
	prev = QuickEquip_Current - 1;
	if ( prev == 0 ) then
		prev = 6;
	end
	QuickEquipButton_OnClick(prev);
end

function QuickEquip_SwitchNext()
	local next;
	if ( QuickEquip_Current == 4 ) then
		next = 1;
	else
		next = QuickEquip_Current + 1;
	end
	QuickEquipButton_OnClick(next);
end

-- Base Functions
function EAE_SaveItemPareToLoadSet(srceLoc, destLoc, flag) 
	local index, value, TempLoadSet
	if ( flag == 0) then
		TempLoadSet = EAE_LoadSetFirst;
	else
		TempLoadSet = EAE_LoadSet;
	end
	-- Check if they are already in load set
	for index, itemPare in TempLoadSet do 
		if ( EAE_IsSlotEqual(itemPare.srcSlot, srceLoc) and EAE_IsSlotEqual(itemPare.dstSlot, destLoc) ) then 
			return;
		end 
		if ( EAE_IsSlotEqual(itemPare.srcSlot, destLoc) and EAE_IsSlotEqual(itemPare.dstSlot, srceLoc)) then
			return;
		end 
	end 

	local itemPare = {} 
	itemPare.srcSlot = srceLoc; 
	itemPare.dstSlot = destLoc; 
	table.insert(TempLoadSet, itemPare); 
end 

function EAE_IsSlotEqual(slot1, slot2) 
	return (slot1.type == slot2.type and slot1.bagId == slot2.bagId and slot1.slotId == slot2.slotId) 
end 

function EAE_IsSlotItemLocked(slot) 
	if ( slot.type == "container" ) then 
		local _, _, isLocked, _, _ = GetContainerItemInfo(slot.bagId, slot.slotId);
		return isLocked;
	elseif ( slot.type == "inventory" ) then 
		return IsInventoryItemLocked(slot.slotId);
	end 
end

function EAE_IsLoadSetLocked() 
	local index, itemPare
	for index, itemPare in EAE_LoadSet do 
		if (EAE_IsSlotItemLocked(itemPare.srcSlot) or EAE_IsSlotItemLocked(itemPare.dstSlot)) then 
			return 1; 
		end
	end
end

function EAE_PickUpItem(slot) 
	if (slot.type == "container") then 
		PickupContainerItem(slot.bagId, slot.slotId) 
	elseif (slot.type == "inventory") then 
		PickupInventoryItem(slot.slotId) 
	end 
end 

function EAE_GetPlayerItems()
	-- Generate a dataset, index is item linkid, value is item's slotinfo
	-- 扫描数据的记录,查找到物品的链接.看一下物品放在哪一个格子里面
	EAE_PlayerItems = {};
	local bagIndex; 
	for bagIndex = 0, NUM_CONTAINER_FRAMES, 1 do 
		local slotIndex; 
		for slotIndex = 1, GetContainerNumSlots(bagIndex), 1 do 
			local itemName, itemLinkId = EAE_GetItemInfo("container", bagIndex, slotIndex); 
			if (itemName and itemLinkId) then 
				local slot = {}; 
				slot.type = "container"; 
				slot.bagId = bagIndex; 
				slot.slotId = slotIndex; 
				if (EAE_PlayerItems[itemLinkId]) then
					EAE_PlayerItems[itemLinkId..":2"] = slot; 
				else
					EAE_PlayerItems[itemLinkId] = slot; 
				end
			end; 
		end; 
	end; 
	local index, value; 
	for index, slotName in EAE_Slots do 
		local itemName, itemLinkId = EAE_GetItemInfo("inventory", slotName); 
		if (itemName and itemLinkId) then 
			local slot = {}; 
			slot.type = "inventory"; 
			slot.slotId = GetInventorySlotInfo(slotName); 
			if (EAE_PlayerItems[itemLinkId]) then
				EAE_PlayerItems[itemLinkId..":2"] = slot; 
			else
				EAE_PlayerItems[itemLinkId] = slot; 
			end
		end; 
	end; 
end; 

function EAE_GetPlayerEquipSet(setId) 
	local numSetId = tonumber(setId) 
	if ( not numSetId ) then 
		return
	end 
	if (not EAE_Config) then
		EAE_Config = {}
	end
	if (not EAE_Config[EAE_PlayerId]) then
		EAE_Config[EAE_PlayerId] = {}
	end
	if ( not EAE_Config[EAE_PlayerId][numSetId]) then 
		EAE_Config[EAE_PlayerId][numSetId] = {} 
	end 
	return EAE_Config[EAE_PlayerId][numSetId] 
end 

function EAE_GetCurrentSetId()
	if (not EAE_Config[EAE_PlayerId]) then
		EAE_Config[EAE_PlayerId] = {};
	end;
	if (not EAE_Config[EAE_PlayerId].CurrentSetId) then
		EAE_Config[EAE_PlayerId].CurrentSetId = 0;
	end;
	return EAE_Config[EAE_PlayerId].CurrentSetId;
end;

function EAE_SetCurrentSetId(setId)
	if (not EAE_Config[EAE_PlayerId]) then
		EAE_Config[EAE_PlayerId] = {};
	end;
	EAE_Config[EAE_PlayerId].CurrentSetId = setId;
end; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -