GE Lua Documentation

Press F to search!

addCareerRewardInfo

Definition


-- @/lua/ge/extensions/gameplay/missions/progress.lua:581

M.addCareerRewardInfo = function(starRewards, mission, attempt)
  if not career_career.isActive() then
    return
  end
  -- for each attribute, add an element to the list with total rewards
  local formattedRewards = {list = {}}

  -- Group rewards by attribute
  local rewardsByAttribute = {}
  for star, rewards in pairs(starRewards.originalRewardsPerStar) do
    for _, reward in ipairs(rewards) do
      if not rewardsByAttribute[reward.attributeKey] then
        rewardsByAttribute[reward.attributeKey] = {
          attributeKey = reward.attributeKey,
          total = 0,
          icon = career_branches.getBranchIcon(reward.attributeKey),
          breakdown = {}
        }
      end

      -- Add to total if star was unlocked
      if attempt.unlockedStars[star] then
        local rewardAmount = reward.rewardAmount
        rewardsByAttribute[reward.attributeKey].total = rewardsByAttribute[reward.attributeKey].total + rewardAmount
      end
    end
  end

  -- Create single breakdown entry with total for each attribute
  for _, rewardData in pairs(rewardsByAttribute) do
    if rewardData.total > 0 then
      -- Calculate duration based on total reward
      local duration = calculateRewardDuration(rewardData.total)
      table.insert(rewardData.breakdown, {
        label = "Earned",
        before = 0,
        after = rewardData.total,
        duration = -1
      })
      if rewardData.attributeKey == "money" and starRewards.rewardMultiplierAdditionalAmount > 0 and starRewards.rewardMultiplierBasedOnBranch then
        local branch = career_branches.getBranchById(starRewards.rewardMultiplierBasedOnBranch)
        table.insert(rewardData.breakdown, {
          label = {txt = "ui.career.rewards.branchMultiplier", context = {branch = branch.longName or branch.name}},
          before = starRewards.rewardMultiplierAdditionalAmount,
          after = starRewards.rewardMultiplierAdditionalAmount,
        })
      end
    end
  end

  -- Convert to ordered list
  local ordered = tableKeysSorted(rewardsByAttribute)
  career_branches.orderAttributeKeysByBranchOrder(ordered)
  for _, key in ipairs(ordered) do
    local rewardInfo = rewardsByAttribute[key]

    -- Add attribute name/label and color
    local branch = career_branches.getBranchById(key)
    rewardInfo.soundClass = "progressBar"
    local endSound = false
    local scaleFactor = 300
    if branch and not branch.missing then
      rewardInfo.attributeName = translateLanguage(branch.name, branch.name, true)
      rewardInfo.attributeColor = branch.color
      rewardInfo.icon = branch.icon
      endSound = "event:>UI>Career>EndScreen_Receive_XP"
      rewardInfo.soundClass = "xp"
      scaleFactor = 50
    elseif key == "money" then
      rewardInfo.attributeName = "Money"
      rewardInfo.icon = "beamCurrency"
      rewardInfo.soundClass = "money"
      endSound = "event:>UI>Career>EndScreen_Receive_Money"
      scaleFactor = 1000
    elseif key == "beamXP" then
      rewardInfo.attributeName = "BeamXP"
      rewardInfo.icon = "beamXPLong"
      endSound = "event:>UI>Career>EndScreen_Receive_XP"
      rewardInfo.soundClass = "xp"
      scaleFactor = 50
    elseif key == "vouchers" then
      rewardInfo.attributeName = "Vouchers"
      rewardInfo.icon = "voucherHorizontal3"
      rewardInfo.attributeColor = "var(--bng-add-blue-400-rgb)"
      endSound = "event:>UI>Career>EndScreen_Receive_Voucher"
      rewardInfo.tickingOneShots = "event:>UI>Career>EndScreen_Counting_Voucher"
      scaleFactor = 1
    end

    -- Calculate duration for progress bar based on total reward
    local progressBarDuration, pitch = calculateRewardDuration(rewardInfo.total, scaleFactor)
    if scaleFactor == 1 then
      progressBarDuration = 0.3*rewardInfo.total
    end
    local totalDuration = progressBarDuration

    local totalReward = {
      before = career_modules_playerAttributes.getAttributeValue(key),
      after = career_modules_playerAttributes.getAttributeValue(key) + rewardInfo.total,
      large = true,
      label = "Total",
      duration = progressBarDuration,
      endSound = endSound,
      pitch = pitch
    }
    table.insert(rewardInfo.breakdown, totalReward)



    -- Add progress bar info
    if career_career and career_career.isActive() and not branch.missing then
      local level, curLvlProgress, neededForNext, prevThreshold, nextThreshold =
        career_branches.calcBranchLevelFromValue(
          career_modules_playerAttributes.getAttributeValue(key),
          key
        )
      local levelAfter, curLvlProgressAfter, neededForNextAfter, prevThresholdAfter, nextThresholdAfter =
        career_branches.calcBranchLevelFromValue(
          career_modules_playerAttributes.getAttributeValue(key) + rewardInfo.total,
          key
        )

      rewardInfo.progressBar = {
        name = translateLanguage(branch.name, branch.name),
        level = "Level " .. level,
        levelAfter = "Level " .. levelAfter,
        animations = {}
      }

      if level == levelAfter then
        -- Same level animation
        table.insert(rewardInfo.progressBar.animations, {
          level = level,
          min = 0,
          max = neededForNext,
          from = curLvlProgress,
          to = curLvlProgress + rewardInfo.total,
          duration = progressBarDuration
        })
      else
        local totalDuration = 0
        -- First animation: current level progress to max
        local weight = (neededForNext-curLvlProgress) / rewardInfo.total
        table.insert(rewardInfo.progressBar.animations, {
          level = level,
          min = 0,
          max = neededForNext,
          from = curLvlProgress,
          to = neededForNext,
          duration = weight * progressBarDuration
        })
        totalDuration = totalDuration + weight * progressBarDuration

        -- Middle animations: full levels if needed
        for l = level + 1, levelAfter - 1 do
          local branch = career_branches.getBranchByPath(key)
          -- Check if both current and next level exist
          if branch.levels[l] and branch.levels[l + 1] then
            local prevT = 0
            local nextT = branch.levels[l + 1].requiredValue - branch.levels[l].requiredValue
            local weight = (nextT-prevT) / rewardInfo.total
            table.insert(rewardInfo.progressBar.animations, {
              level = l,
              min = prevT,
              max = nextT,
              from = prevT,
              to = nextT,
              duration = weight * progressBarDuration
            })
            totalDuration = totalDuration + weight * progressBarDuration
          end
        end

        -- Final animation: 0 to final progress in new level
        local weight = (curLvlProgressAfter-0) / rewardInfo.total
        table.insert(rewardInfo.progressBar.animations, {
          level = levelAfter,
          min = 0,
          max = neededForNextAfter,
          from = 0,
          to = curLvlProgressAfter,
          duration = weight * progressBarDuration
        })
        totalDuration = totalDuration + weight * progressBarDuration
      end
      rewardInfo.duration = totalDuration
    end


    for _, bd in ipairs(rewardInfo.breakdown) do
      bd.soundClass = rewardInfo.soundClass
      bd.tickingOneShots = rewardInfo.tickingOneShots
      bd.pitch = bd.pitch or 0
    end
    table.insert(formattedRewards.list, rewardInfo)
  end
  return formattedRewards
end

Callers

@/lua/ge/extensions/gameplay/missions/progress.lua
  -- add career rewards info
  local formattedRewards = M.addCareerRewardInfo(starRewards, mission, attempt)