From a13ee770c39ad37cb3a12c9e4921b0f298d797aa Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Tue, 22 Mar 2022 22:31:37 +0100 Subject: [PATCH] Added Multiplayer and multi character support for Transformation progress --- eid_api.lua | 31 +++++++++++++++++++++++-------- main.lua | 18 +++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 6e8dfee1..a10dcdb5 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -417,9 +417,8 @@ function EID:getTransformation(id, variant, subType) local default = EID.EntityTransformations[entityString] if default~= nil then listToTest = default end - local customLegacy = nil if id == 5 and variant == 100 then - customLegacy = __eidItemTransformations[adjustedSubtype] + local customLegacy = __eidItemTransformations[adjustedSubtype] if customLegacy~= nil then listToTest = listToTest..","..customLegacy end end @@ -1418,12 +1417,28 @@ EID.TransformationLookup = {} function EID:buildTransformationTables() EID.TransformationLookup = {} for entityString, transformationData in pairs(EID.EntityTransformations) do - for transformation in string.gmatch(transformationData, '([^,]+)') do - if EID.TransformationLookup[transformation] == nil then - EID.TransformationLookup[transformation] = {} - end - EID.TransformationLookup[transformation][entityString] = true + EID:alterTransformationLookup(entityString, transformationData, true) + end + -- legacy + for subType, transformationData in pairs(__eidItemTransformations) do + EID:alterTransformationLookup("5.100."..subType, transformationData, true) + end + -- add custom + for entityString, transformationData in pairs(EID.CustomTransformAssignments) do + EID:alterTransformationLookup(entityString, transformationData, true) + end + -- custom remove + for entityString, transformationData in pairs(EID.CustomTransformRemovals) do + EID:alterTransformationLookup(entityString, transformationData, nil) + end +end + +function EID:alterTransformationLookup(entityString, transformString, addToList) + for transformation in string.gmatch(transformString, '([^,]+)') do + if EID.TransformationLookup[transformation] == nil then + EID.TransformationLookup[transformation] = {} end + EID.TransformationLookup[transformation][entityString] = addToList end end @@ -1442,7 +1457,7 @@ function EID:evaluateTransformationProgress(transformation) EID.TransformationProgress[i][transformation] = transformData.NumNeeded or 3 else for entityString, _ in pairs(EID.TransformationLookup[transformation]) do - eType, eVariant, eSubType = entityString:match("([^.]+).([^.]+).([^.]+)") + local eType, eVariant, eSubType = entityString:match("([^.]+).([^.]+).([^.]+)") if tonumber(eType) == EntityType.ENTITY_PICKUP then if tonumber(eVariant) == PickupVariant.PICKUP_COLLECTIBLE then if EID.TouchedActiveItems[i][tonumber(eSubType)] then diff --git a/main.lua b/main.lua index 11056ed6..c41de738 100644 --- a/main.lua +++ b/main.lua @@ -664,14 +664,22 @@ function EID:printDescription(desc, cachedID) if EID.Config["TransformationText"] or EID.Config["TransformationProgress"] then local transformationName = "" if EID.Config["TransformationText"] then - transformationName = EID:getTransformationName(transform).." " + transformationName = EID:getTransformationName(transform) end if EID.Config["TransformationProgress"] then - -- TODO: call evaluate only when ItemQueue of player changes to save performance EID:evaluateTransformationProgress(transform) - local numCollected = EID.TransformationProgress[EID:getPlayerID(EID.player)][transform] - local numMax = EID.TransformationData[transform] and EID.TransformationData[transform].NumNeeded or 3 - transformationName = transformationName.."("..numCollected.."/"..numMax..")" + transformationName = transformationName .. " " + for _, player in ipairs(EID.players) do + if player:GetPlayerType() ~= PlayerType.PLAYER_THESOUL_B then + if #EID.players > 1 then + local playerIcon = EID:getIcon("Player"..player.SubType) ~= EID.InlineIcons["ERROR"] and "{{Player"..player.SubType.."}}" or "{{CustomTransformation}}" + transformationName = transformationName .. playerIcon + end + local numCollected = EID.TransformationProgress[EID:getPlayerID(player)][transform] + local numMax = EID.TransformationData[transform] and EID.TransformationData[transform].NumNeeded or 3 + transformationName = transformationName.."("..numCollected.."/"..numMax..") " + end + end end local iconWidth = transformSprite[3] or -1 local iconHeight = transformSprite[4] or -1