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

📄 damagemeters_report.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
	if (DamageMeters_Quantity_TIME == DamageMeters_quantity) then
		return GetTime() - playerStruct.lastTime;
	else
		local quantDef = DM_QUANTDEFS[quantity];

		local value = 0;
		if (nil ~= playerStruct) then
			if (nil ~= quantDef.pfnGetValue) then
				value = quantDef.pfnGetValue(playerStruct);
			else
				value = playerStruct.dmiData[quantDef.dmi].q;
			end

			if (DamageMeters_IsQuantityPS(quantity)) then
				value = DamageMeters_GetCombatValuePS(value);
			end
		end

		return value;
	end
end

-- This is a slow function.  Not used much, I think.
function DamageMeters_GetQuantityValueString(quantity, playerName)

	local quantDef = DM_QUANTDEFS[quantity];
	local tableIndex;
	if (quantDef.bUsesFightTable) then
		tableIndex = DMT_FIGHT;
	else
		tableIndex = DMT_ACTIVE;
	end

	local playerIndex = DamageMeters_GetPlayerIndex(playerName, tableIndex);
	if (playerIndex ~= nil) then
		local value = DamageMeters_GetQuantityValue(quantity, tableIndex, playerIndex);
		
		local formatString;
		if (quantDef.formatString) then
			formatString = quantDef.formatString;
		else
			if (DamageMeters_IsQuantityPS(quantity)) then
				formatString = "%0.1f";
			else
				formatString = "%d";
			end
		end

		return string.format(formatString, value);
	else
		return "-";
	end
end

function DamageMeters_GetQuantityString(quantity, forcePSFlag)
	if (DamageMeters_IsQuantityPS(quantity, forcePSFlag)) then
		return DM_QUANTDEFS[quantity].psName;
	end

	return DM_QUANTDEFS[quantity].name;
end

function DamageMeters_GetPlayerIndex(player, searchTableIndex)
	if (nil == searchTableIndex) then
		searchTableIndex = DMT_ACTIVE;
	end

	local i;
	for i = 1, table.getn(DamageMeters_tables[searchTableIndex]) do
		if (DamageMeters_tables[searchTableIndex][i].player == player) then
			return i;
		end
	end
	
	return nil;
end

DMSortTemp_sortType = 1;
DMSortTemp_quantity = 1;
DMSortTemp_dmi = 1;

-- This could be broken into two separate increasing/decreasing functions
-- for increased performance.
function DMSortFunc_Default(a,b) 	
	local result;
	if (a.dmiData[DMSortTemp_dmi].q == b.dmiData[DMSortTemp_dmi].q) then
		if (DMSortTemp_sortType == DamageMeters_Sort_INCREASING) then
			result = a.player > b.player;
		else
			result = a.player < b.player;
		end
	else
		if (DMSortTemp_sortType == DamageMeters_Sort_INCREASING) then
			result = a.dmiData[DMSortTemp_dmi].q < b.dmiData[DMSortTemp_dmi].q;
		else
			result = a.dmiData[DMSortTemp_dmi].q > b.dmiData[DMSortTemp_dmi].q;
		end
	end

	return result;
end

function DMSortFunc_Alphabetical(a, b)
	return a.player < b.player;
end

function DMSortFunc_Time(a, b)
	local result;
	if (a.lastTime == b.lastTime) then
		result = a.player < b.player;
	else
		result = a.lastTime < b.lastTime;
	end

	if (DMSortTemp_sortType == DamageMeters_Sort_INCREASING) then
		result = not result;
	end
	return result;
end

function DMSortFunc_Custom(a, b)
	local valfunc = DM_QUANTDEFS[DMSortTemp_quantity].pfnGetValue;
	local aValue = valfunc(a);
	local bValue = valfunc(b);
	local result;
	if (aValue == bValue) then
		if (DMSortTemp_sortType == DamageMeters_Sort_INCREASING) then
			result = a.player > b.player;
		else
			result = a.player < b.player;
		end
	else
		if (DMSortTemp_sortType == DamageMeters_Sort_INCREASING) then
			result = aValue < bValue;
		else
			result = aValue > bValue;
		end
	end

	return result;
end

-- In the case of a tie, sort alphabetically.
function DamageMeters_DoSort(tableToSort, quantity, sortType)
	if (DM_Bypass["Sort"] == true) then
		return;
	end

	if (nil == sortType) then
		sortType = DamageMeters_sort;
	end
	DMSortTemp_sortType = sortType;
	DMSortTemp_quantity = quantity;
	DMSortTemp_dmi = DM_QUANTDEFS[quantity].dmi;

	if (DamageMeters_Sort_ALPHABETICAL == sortType) then
		table.sort(tableToSort, DMSortFunc_Alphabetical);
		return;
	end

	if (quantity == DamageMeters_Quantity_TIME) then
		table.sort(tableToSort, DMSortFunc_Time);
		return;
	elseif (DM_QUANTDEFS[quantity].pfnGetValue ~= nil) then
		table.sort(tableToSort, DMSortFunc_Custom);
		return;
	else
		DMSortTemp_quantity = DamageMeters_GetQuantityDMI(quantity);
		table.sort(tableToSort, DMSortFunc_Default);
		return;
	end
end

-- No reason to believe this doesn't work but it has never been used.
--[[
function DamageMeters_BuildSortHash(sortType)
	DamageMeters_tableSortHash = {};

	-- Build the unsorted hash.
	local quant;
	for quant = 1, DamageMeters_Quantity_MAX do
		DamageMeters_tableSortHash[quant] = {};

		local quantTable = (DM_QUANTDEFS[quant].bUsesFightTable) and DMT_FIGHT or DMT_ACTIVE;

		-- Populate the table for this quantity.
		local playerIndex;
		for playerIndex = 1, table.getn(DamageMeters_tables[quantTable]) do
			DamageMeters_tableSortHash[quant][playerIndex] = {};
			DamageMeters_tableSortHash[quant][playerIndex].playerName = DamageMeters_tables[quantTable][playerIndex].player;
			DamageMeters_tableSortHash[quant][playerIndex].playerIndex = playerIndex;
			DamageMeters_tableSortHash[quant][playerIndex].value = DamageMeters_GetQuantityValue(quant, quantTable, playerIndex);
		end

		-- Sort this quantity.
		table.sort(DamageMeters_tableSortHash[quant],
			function(a,b)
				if (a.value == b.value or DamageMeters_Sort_ALPHABETICAL == sortType) then
					return a.playerName < b.playerName;
				elseif (DamageMeters_Sort_INCREASING == sortType) then
					return a.value > b.value;
				else -- DamageMeters_Sort_DECREASING implied.
					return a.value < b.value;
				end
			end	
			);
	end
end
]]--


DM_fakeTables = {};
DM_fakeTablesInitialized = false;

function DamageMeters_InitFakeTables()	
	for ix = 1, 2 do
		DM_fakeTables[ix] = {};
		for index = 1, DamageMeters_TABLE_MAX do
			DM_fakeTables[ix][index] = {};
			DM_fakeTables[ix][index].player = nil;
			DM_fakeTables[ix][index].lastTime = -1;
			DM_fakeTables[ix][index].dmiData = {};
			for dmi = 1, DMI_MAX do
				DM_fakeTables[ix][index].dmiData[dmi] = {};
				DM_fakeTables[ix][index].dmiData[dmi].q = 0;
			end
		end
	end

	DM_fakeTablesInitialized = true;
end


-- The bRankQuantities parameter is a hack.  Its only used by TitanDamageMeters.lua.
-- It will only work as expected if the tableIx isn't DMT_FIGHT already.
-- If true, this function will determine the ranks of -quantities-, not DMIs.
function DamageMeters_DetermineRanks(tableIx, bRankQuantities)
	if (DM_Bypass["Determine Ranks"] == true) then
		return;
	end

	if (not DM_fakeTablesInitialized) then
		DamageMeters_InitFakeTables();
	end

	local index, playerStruct;
	local indexMax = table.getn(DamageMeters_tables[tableIx]);
	for index = 1, indexMax do
		if (nil == DM_fakeTables[1][index]) then
			DM_fakeTables[1][index] = {};
			DM_fakeTables[1][index].dmiData = {};
			for dmi = 1, DMI_MAX do
				DM_fakeTables[1][index].dmiData[dmi] = {};
			end
		end

		DM_fakeTables[1][index].player = DamageMeters_tables[tableIx][index].player;
		DM_fakeTables[1][index].lastTime = DamageMeters_tables[tableIx][index].lastTime;
		local dmi;
		for dmi = 1, DMI_MAX do
			DM_fakeTables[1][index].dmiData[dmi].q = DamageMeters_tables[tableIx][index].dmiData[dmi].q;
		end
	end
	for index = (indexMax + 1), DamageMeters_TABLE_MAX do
		DM_fakeTables[1][index] = nil;
	end

	if (bRankQuantities) then
		local indexMax = table.getn(DamageMeters_tables[DMT_FIGHT]);
		for index = 1, indexMax do
			if (nil == DM_fakeTables[2][index]) then
				DM_fakeTables[2][index] = {};
				DM_fakeTables[2][index].dmiData = {};
				for dmi = 1, DMI_MAX do
					DM_fakeTables[2][index].dmiData[dmi] = {};
				end
			end

			DM_fakeTables[2][index].player = DamageMeters_tables[DMT_FIGHT][index].player;
			DM_fakeTables[2][index].lastTime = DamageMeters_tables[DMT_FIGHT][index].lastTime;
			local dmi;
			for dmi = 1, DMI_MAX do
				DM_fakeTables[2][index].dmiData[dmi].q = DamageMeters_tables[DMT_FIGHT][index].dmiData[dmi].q;
			end
		end
		for index = (indexMax + 1), DamageMeters_TABLE_MAX do
			DM_fakeTables[2][index] = nil;
		end
	end

	-----------
	if (DM_Bypass["Determine Ranks 1"] == true) then
		return;
	end

	local count = table.getn(DamageMeters_tables[tableIx]);
	local countPS = table.getn(DamageMeters_tables[DMT_FIGHT]);

	local quantity;
	local max = bRankQuantities and DamageMeters_Quantity_MAX or DMI_MAX;
	for quantity = 1, max do
		local fakeTableToUseIndex;
		local countToUse;
		local tableIxToUse;
		if (bRankQuantities and DamageMeters_IsQuantityPS(quantity)) then
			fakeTableToUseIndex = 2;
			countToUse = countPS;
			tableIxToUse = DMT_FIGHT;
		else
			fakeTableToUseIndex = 1;
			countToUse = count;
			tableIxToUse = tableIx;
		end

		DamageMeters_DoSort(DM_fakeTables[fakeTableToUseIndex], quantity, DamageMeters_Sort_DECREASING);

		-- Mark all players as unused in the rank table.  We'll mark them used as we
		-- need to in the next loop.
		for playerName, struct in DamageMeters_rankTables[tableIxToUse] do
			struct._used = false;
		end

		local index;
		for index = 1, countToUse do
			local playerName = DM_fakeTables[fakeTableToUseIndex][index].player;
			if (DamageMeters_rankTables[tableIxToUse][playerName] == nil) then
				DamageMeters_rankTables[tableIxToUse][playerName] = {};
			end	
			DamageMeters_rankTables[tableIxToUse][playerName][quantity] = index;
			DamageMeters_rankTables[tableIxToUse][playerName]._used = true;
		end

		-- Remove any players from the rank table we aren't using.
		for playerName, struct in DamageMeters_rankTables[tableIxToUse] do
			if (struct._used == false) then
				DamageMeters_rankTables[tableIxToUse][playerName] = nil;
			end
		end
	end
end

function DamageMeters_DetermineTotals()
	--DamageMeters_totalsTable = {};
	DamageMeters_DetermineTotalsForATable(DMT_ACTIVE);	
	DamageMeters_DetermineTotalsForATable(DMT_FIGHT);	
end

function DamageMeters_DetermineTotalsForATable(tableIx)
	--DamageMeters_totalsTable[tableIx] = {};
	local dmi;
	for dmi = 1, DMI_MAX do
		DamageMeters_totalsTable[tableIx][dmi] = 0;
	end

	local index, info;
	for index,info in DamageMeters_tables[tableIx] do 
		for dmi = 1, DMI_MAX do
			DamageMeters_totalsTable[tableIx][dmi] = DamageMeters_totalsTable[tableIx][dmi] + info.dmiData[dmi].q;

⌨️ 快捷键说明

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