TFT-Strategist/src/data_provider_demo.py
2025-04-02 09:35:00 +08:00

110 lines
4.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
数据提供模块演示脚本
"""
from .data_provider import DataLoader, DataQueryAPI
def main():
"""主函数"""
print("=== 云顶之弈数据提供模块演示 ===")
# 初始化数据查询API
print("\n正在加载数据...")
api = DataQueryAPI()
# 显示数据基本信息
print(f"\n当前游戏版本: {api.data_loader.get_latest_version()}")
print(f"职业数量: {len(api.get_all_jobs())}")
print(f"特质数量: {len(api.get_all_races())}")
print(f"棋子数量: {len(api.get_all_chess())}")
# 显示所有羁绊(职业和特质)
print("\n=== 所有羁绊 ===")
all_jobs = api.get_all_jobs()
all_races = api.get_all_races()
print("\n职业羁绊:")
for job in all_jobs:
job_id = job['jobId']
chess_count = len(api.get_chess_by_job(job_id))
level_info = ' / '.join([f"{level}人:{effect}" for level, effect in job.get('level', {}).items()])
print(f" - {job['name']} ({chess_count}个棋子): {level_info}")
print("\n特质羁绊:")
for race in all_races:
race_id = race['raceId']
chess_count = len(api.get_chess_by_race(race_id))
level_info = ' / '.join([f"{level}人:{effect}" for level, effect in race.get('level', {}).items()])
print(f" - {race['name']} ({chess_count}个棋子): {level_info}")
# 显示棋子费用分布
cost_distribution = api.get_chess_cost_distribution()
print("\n=== 棋子费用分布 ===")
for cost, count in sorted(cost_distribution.items()):
if cost != '0': # 排除费用为0的棋子通常是召唤物
print(f" {cost}费棋子: {count}")
# 互动查询示例
print("\n=== 互动查询 ===")
while True:
print("\n请选择查询类型:")
print("1. 查询羁绊下的所有棋子")
print("2. 查询棋子的所有羁绊")
print("3. 查询羁绊等级信息")
print("4. 退出")
choice = input("请输入选项 (1-4): ")
if choice == '1':
name = input("请输入羁绊名称: ")
synergy = api.get_synergy_by_name(name)
if not synergy:
print(f"未找到名为 '{name}' 的羁绊")
continue
synergy_id = synergy.get('jobId') or synergy.get('raceId')
chess_list = api.get_chess_by_synergy(synergy_id)
print(f"\n{name} 羁绊的棋子 ({len(chess_list)}个):")
for chess in sorted(chess_list, key=lambda x: x.get('price', '0')):
price = chess.get('price', '未知')
print(f" - {chess['displayName']} ({price}费)")
elif choice == '2':
name = input("请输入棋子名称: ")
chess = api.get_chess_by_name(name)
if not chess:
print(f"未找到名为 '{name}' 的棋子")
continue
chess_id = chess['chessId']
synergies = api.get_synergies_of_chess(chess_id)
print(f"\n{name} 的羁绊 ({len(synergies)}个):")
for synergy in synergies:
synergy_type = "职业" if 'jobId' in synergy else "特质"
print(f" - {synergy['name']} ({synergy_type})")
elif choice == '3':
name = input("请输入羁绊名称: ")
synergy = api.get_synergy_by_name(name)
if not synergy:
print(f"未找到名为 '{name}' 的羁绊")
continue
synergy_id = synergy.get('jobId') or synergy.get('raceId')
levels = api.get_synergy_levels(synergy_id)
print(f"\n{name} 的羁绊等级效果:")
for level, effect in sorted(levels.items(), key=lambda x: int(x[0])):
print(f" - {level}人: {effect}")
elif choice == '4':
break
else:
print("无效选项,请重新输入")
if __name__ == "__main__":
main()