- name: containers
  regex: '(?-s)capacity="(?<capacity>!num)"(?:!anyslotsperrow="(?<slotsperrow>!num))?'
  lua: |
    capacity=capacity*2
    if not slotsperrow then return true end
    slotsperrow=1
    while slotsperrow * slotsperrow < capacity do
      slotsperrow = slotsperrow + 1
    end
  files:
    - '**/*.xml'

- name: containerscontainable
  regex: (?-s)Containable!anyitems="([^"]+)"
  lua: |
    -- If we fuck with the diving gear the game fucking explodes
    -- Thinking we don't have oxygen tanks and killing us
    if file:find("divinggear.xml") then
      return false
    end
    local gurantee = {"ammobox", "deepdiving", "smallitem", "mediumitem", "largeitem"}
    local has = {}
    
    local items = strsplit(s1, ",")
    for i, item in pairs(items) do
      for _, g in pairs(gurantee) do
        if string.find(item, g) then
          has[g] = true
        end
      end
    end
    
    for _, g in pairs(gurantee) do
      if not has[g] then
        s1 = s1 .. "," .. g
      end
    end
  files:
    - '**/*.xml'
    
- name: excludeditems
  regex: <Containable!any(\s?excludeditems="[^"]+")
  lua: |
    s1 = ""
  files:
    - '**/*.xml'

- name: upgrade
  regex: (?:maxforce|capacity|maxrechargespeed|overloadvoltage|healthmultiplier|maxhealth|fabricationspeed|deconstructionspeed|rotationspeedlowskill|offsetonselectedmultiplier|range|maxpoweroutput|meltdowndelay|maxflow|fixdurationlowskill|skillrequirementmultiplier)="\+?!num%?"
  lua: |
    *2
  files:
    - '**/UpgradeModules.xml'
- name: upgradetooltip
  regex: 'increaseontooltip="(?<increaseontooltip>!num)"'
  lua: |
    increaseontooltip=increaseontooltip*2
  files:
    - '**/UpgradeModules.xml'

- name: missionreward
  regex: 'reward="!num'
  lua: |
    *4
  files:
    - '**/Missions.xml'

- name: maxstacksize
  regex: 'maxstacksize="!num'
  lua: |
    *2
  files:
    - '**/*.xml'

- name: lightrange
  regex: '(?-s)LightComponent!anyrange="(!num)"'
  lua: |
    *4
  files:
    - '**/*.xml'

- name: talenttrees
  regex: (<TalentOptions!any>!any</TalentOptions>)
  lua: |
    local talentOptions = 0
    local lines = strsplit(s1, "\n")
    for i, line in pairs(lines) do
      if string.find(line, "<TalentOption ") then
        talentOptions = talentOptions + 1
      end
    end

    if lines[1]:find("maxchosentalents") then
      print("maxchosentalents found, updating")
      local optionsElement = lines[1]
      optionsElement = optionsElement:gsub("maxchosentalents=\"%d+\"", "maxchosentalents=\"" .. talentOptions .. "\"")
      replacement = s1:gsub(lines[1], optionsElement)
      return false
    end

    print("maxchosentalents not found, creating")
    local optionsElement = lines[1]
    local optionsElement = optionsElement:gsub("<TalentOptions", "<TalentOptions maxchosentalents=\"" .. talentOptions .. "\"")
    replacement = s1:gsub(lines[1], optionsElement)
  files:
    - '**/TalentTrees.xml'
