文章编辑人员:雪舞
内容测试时间:2023-6-13 19:16:38
测试环境:Ruby+Devkit 3.2.2-1 (x64)
测试版本:Windows 10
为了运行这段Ruby代码,你需要确保你的机器上已经安装了Ruby。下面是在Windows、macOS和Linux上安装Ruby的简单步骤:
在Windows上安装Ruby:
你可以从RubyInstaller的官方网站下载安装包。选择一个合适的版本下载并按照提示进行安装。网址是:https://rubyinstaller.org/
你可以通过在命令行上运行 ruby <文件名>.rb 来执行此Ruby脚本,其中 <文件名> 需要替换为你保存该脚本的文件名。请注意,你需要先安装Ruby运行环境才能运行Ruby脚本。
def load_file(filename)
data = []
File.open(filename, "r:GBK") do |f|
f.each_line do |line|
next if line.strip.empty? || line.strip.start_with?("#") || !line.include?("\t")
data << line.split("\t")
end
end
data
end
monster_drops = load_file('MonsterDropBoxs.txt')
drop_box_contents = load_file('DropBoxContent.txt')
monster_attrs = load_file('MonsterAttrExTable.txt')
common_items = load_file('CommonItem.txt')
equip_bases = load_file('EquipBase.txt')
gem_infos = load_file('GemInfo.txt')
def create_dict(data, key_col, val_col)
data.each_with_object({}) do |row, h|
h[row[key_col]] = row[val_col]
end
end
monster_dict = create_dict(monster_attrs, 0, 1)
common_item_dict = create_dict(common_items, 0, 6)
equip_base_dict = create_dict(equip_bases, 0, 10)
gem_info_dict = create_dict(gem_infos, 0, 7)
monster_drops_dict = {}
monster_drops.each do |drop|
monster_id = drop[0]
monster_name = monster_dict[monster_id] || 'Unknown'
drop_boxes = drop[3..]
drop_boxes.each do |box_id|
next if box_id == '-1'
box_contents = drop_box_contents.find { |content| content[0] == box_id }
next if box_contents.nil?
items = box_contents[4..]
items.each do |item_id|
next if item_id == '-1'
item_name = common_item_dict[item_id] || equip_base_dict[item_id] || gem_info_dict[item_id]
next if item_name.nil?
monster_drops_dict[monster_name] ||= Set.new
monster_drops_dict[monster_name] << item_name
end
end
end
monster_drops_dict.each do |monster, drops|
puts "Monster: #{monster}, Drops: #{drops.to_a.join(", ")}"
end
|