• Новые темы в этом разделе публикуются автоматически при добавлении файла в менеджер ресурсов.
    Ручное создание новых тем невозможно.
Иконка ресурса

Change Drop Chance Lucera2 2024-11-21

Нет прав для скачивания

MetaMan

Интересующийся
VIP
Сообщения
30
Розыгрыши
0
Репутация
181
Реакции
215
Баллы
323
MetaMan добавил(а) новый ресурс:

Change Drop Chance Lucera2 - Change Drop Chance Lucera2


Узнать больше об этом ресурсе...
 
To adjust the chances for the specific item ID after processing the files, you can add some additional logic at the end of your process_file function.
Specifically, you need to look for the <reward> elements with item_id="57" and then modify their chance attribute.



If I'm not mistaken the drop chance of adena in global npcs is 70%.

Update:
CSS:
import tkinter as tk
from tkinter import messagebox
import os
import xml.etree.ElementTree as ET
import xml.dom.minidom as minidom

def adjust_rewards(group_chance, rewards):
    adjusted_rewards = []
    for reward in rewards:
        item_id = reward.get('item_id')
        if item_id == "57":
            adjusted_rewards.append(reward)
        else:
            adjusted_chance = float(reward.get('chance')) * (float(group_chance) / 100)
            adjusted_rewards.append(ET.Element("reward", {
                'item_id': item_id,
                'min': reward.get('min'),
                'max': reward.get('max'),
                'chance': f'{adjusted_chance:.4f}'
            }))
    return adjusted_rewards

def process_file(input_file, output_file):
    parser = ET.XMLParser(target=ET.TreeBuilder(insert_comments=True))
    tree = ET.parse(input_file, parser=parser)
    root = tree.getroot()

    for rewardlist in root.findall('.//rewardlist'):
        if rewardlist.get('type') != 'NOT_RATED_GROUPED':
            for group in rewardlist.findall('.//group'):
                group_chance = group.get('chance')
                rewards = group.findall('reward')

                adjusted_rewards = adjust_rewards(group_chance, rewards)

                for reward in rewards:
                    group.remove(reward)

                for adj_reward in adjusted_rewards:
                    group.append(adj_reward)

                group.set('chance', '100')

    # Set chance to 70.0 for item_id="57"
    for reward in root.findall('.//reward[@item_id="57"]'):
        reward.set('chance', '70.0')

    xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent="   ")
    xmlstr_no_blank_lines = "\n".join([line for line in xmlstr.split("\n") if line.strip()])

    with open(output_file, "w", encoding='utf-8') as f:
        f.write(f'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE list SYSTEM "npc.dtd">\n')
        f.write(xmlstr_no_blank_lines.split("<?xml version=\"1.0\" ?>")[1])

def process_all_files(input_folder, output_folder):
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
   
    for filename in os.listdir(input_folder):
        if filename.endswith(".xml"):
            input_file = os.path.join(input_folder, filename)
            output_file = os.path.join(output_folder, filename)
            process_file(input_file, output_file)

def ask_question():
    response = messagebox.askyesno("Question", "Do you love MetaMan?")
    if not response:
        exit()

if __name__ == "__main__":
    root = tk.Tk()
    root.withdraw()
    ask_question()

    input_folder = 'npc'
    output_folder = 'npc_new'
    process_all_files(input_folder, output_folder)

With this code when it completes the process it will do one more task which will be to change the drop chance on adena to 70%.
 
Последнее редактирование:

Похожие темы