101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
import csv
|
||
import random
|
||
|
||
def update_main_quest_rewards(input_path, output_path=None):
|
||
if output_path is None:
|
||
output_path = input_path
|
||
|
||
with open(input_path, 'r', encoding='utf-8') as f:
|
||
lines = f.readlines()
|
||
|
||
fieldnames = lines[2].strip().split(',')
|
||
|
||
data_lines = lines[3:]
|
||
reader = csv.DictReader(data_lines, fieldnames=fieldnames)
|
||
|
||
main_quests = []
|
||
other_quests = []
|
||
|
||
for row in reader:
|
||
if int(row.get('category', 0)) == 1:
|
||
main_quests.append(row)
|
||
else:
|
||
other_quests.append(row)
|
||
|
||
main_quests.sort(key=lambda x: int(x['id']))
|
||
|
||
rewards_history = []
|
||
current_10000001 = 2400
|
||
current_10000002 = 50
|
||
|
||
for i, row in enumerate(main_quests):
|
||
if i == 0:
|
||
current_10000001 = 2400
|
||
current_10000002 = 50
|
||
else:
|
||
increase_10000001 = random.randint(400, 450)
|
||
current_10000001 += increase_10000001
|
||
current_10000002 += 50
|
||
|
||
row['rewards'] = f"item_10000001_{current_10000001},item_10000002_{current_10000002}"
|
||
|
||
rewards_history.append({
|
||
'id': row['id'],
|
||
'reward_10000001': current_10000001,
|
||
'reward_10000002': current_10000002
|
||
})
|
||
|
||
all_rows = main_quests + other_quests
|
||
all_rows.sort(key=lambda x: int(x['id']))
|
||
|
||
with open(output_path, 'w', encoding='utf-8', newline='') as f:
|
||
f.writelines(lines[:3])
|
||
|
||
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||
writer.writerows(all_rows)
|
||
|
||
print(f"更新完成,共更新 {len(main_quests)} 条主线任务的奖励配置")
|
||
print("\n奖励增长预览(前10条):")
|
||
for i, record in enumerate(rewards_history[:10], 1):
|
||
print(f" 任务ID {record['id']}: item_10000001={record['reward_10000001']}, item_10000002={record['reward_10000002']}")
|
||
|
||
print(f"\n最后一条主线任务奖励:")
|
||
last_record = rewards_history[-1]
|
||
print(f" 任务ID {last_record['id']}: item_10000001={last_record['reward_10000001']}, item_10000002={last_record['reward_10000002']}")
|
||
|
||
return rewards_history
|
||
|
||
def test_reward_calculation():
|
||
print("\n=== 奖励计算测试 ===")
|
||
|
||
initial_1 = 2400
|
||
initial_2 = 50
|
||
total_tasks = 115
|
||
|
||
test_history = []
|
||
current_1 = initial_1
|
||
current_2 = initial_2
|
||
|
||
for i in range(total_tasks):
|
||
if i > 0:
|
||
increase = random.randint(400, 450)
|
||
current_1 += increase
|
||
current_2 += 50
|
||
test_history.append((current_1, current_2))
|
||
|
||
print(f"初始值: item_10000001={initial_1}, item_10000002={initial_2}")
|
||
print(f"任务总数: {total_tasks}")
|
||
print(f"第100条任务奖励: item_10000001={test_history[99][0]}, item_10000002={test_history[99][1]}")
|
||
print(f"最后一条任务奖励: item_10000001={test_history[-1][0]}, item_10000002={test_history[-1][1]}")
|
||
|
||
min_increase = 400 * (total_tasks - 1)
|
||
max_increase = 450 * (total_tasks - 1)
|
||
print(f"\nitem_10000001理论范围: [{initial_1 + min_increase}, {initial_1 + max_increase}]")
|
||
print(f"item_10000002理论值: {initial_2 + 50 * (total_tasks - 1)}")
|
||
|
||
return test_history
|
||
|
||
if __name__ == '__main__':
|
||
test_reward_calculation()
|
||
print("\n" + "="*60)
|
||
update_main_quest_rewards('csv_output/quest.csv') |