<commit_before>
module SkillSpriteRandomizer
  def randomize_skill_sprites
    skills = game.items[SKILL_GLOBAL_ID_RANGE]
    max_skill_sprite_index = skills.map{|skill| skill["Sprite"]}.max
    
    skills.each do |skill|
      if GAME == "dos" || GAME == "por"
        skills_of_same_type = skills.select do |other_skill|
          other_skill["Type"] == skill["Type"]
        end
      elsif GAME == "ooe"
        case skill["Item ID"]
        when 0x00..0x36
          skills_of_same_type = skills[0x00..0x36]
        when 0x37..0x4F
          skills_of_same_type = skills[0x37..0x4F]
        when 0x50..0x6E
          skills_of_same_type = skills[0x50..0x6E]
        end
      end
      
      possible_sprite_indexes = skills_of_same_type.map{|skill| skill["Sprite"]}.uniq
      
      new_sprite_index = possible_sprite_indexes.sample(random: rng)
      skill["Sprite"] = new_sprite_index
      skill.write_to_rom()
    end
  end
end
<commit_msg>Skill sprite rando: Reduce chance of getting skills with no hitbox<commit_after>
module SkillSpriteRandomizer
  def randomize_skill_sprites
    skills = game.items[SKILL_GLOBAL_ID_RANGE]
    
    skills.each do |skill|
      next if skill["Sprite"] == 0 # Skill with no sprite
      
      if GAME == "dos" || GAME == "por"
        skills_of_same_type = skills.select do |other_skill|
          other_skill["Type"] == skill["Type"]
        end
      elsif GAME == "ooe"
        case skill["Item ID"]
        when 0x00..0x36
          skills_of_same_type = skills[0x00..0x36]
        when 0x37..0x4F
          skills_of_same_type = skills[0x37..0x4F]
        when 0x50..0x6E
          skills_of_same_type = skills[0x50..0x6E]
        end
      end
      
      possible_sprite_indexes = skills_of_same_type.map{|skill| skill["Sprite"]}.uniq
      possible_sprite_indexes -= [0] # Not a valid sprite
      
      new_sprite_index = possible_sprite_indexes.sample(random: rng)
      skill["Sprite"] = new_sprite_index
      skill.write_to_rom()
      
      skill_gfx = SkillGfx.new(new_sprite_index-1, game.fs)
      sprite = Sprite.new(skill_gfx.sprite_file_pointer, game.fs)
      
      if GAME == "dos"
        no_hitbox_frames = sprite.frames.select{|frame| frame.number_of_hitboxes == 0}
        hitbox_frames = sprite.frames.select{|frame| frame.number_of_hitboxes > 0}
        if hitbox_frames.any?
          no_hitbox_frames.each do |no_hitbox_frame|
            hitbox_frame = hitbox_frames.first
            no_hitbox_frame.number_of_hitboxes = hitbox_frame.number_of_hitboxes
            no_hitbox_frame.first_hitbox_offset = hitbox_frame.first_hitbox_offset
          end
        end
        sprite.write_to_rom()
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09275683665927568, 'fraction_numerical': 0.025498891352549888, 'mean_word_length': 2.501940491591203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '236942', 'n_tokens_mistral': 971, 'n_tokens_neox': 976, 'n_words': 167}