#!/usr/bin/env python3
"""
모든 궁극기 상세 정보 추출 (desc 포함)
"""

import json
import sys
from pathlib import Path

STALKERS = ['hilda', 'urud', 'nave', 'baran', 'rio', 'clad', 'rene', 'sinobu', 'lian', 'cazimord']

def main():
    if len(sys.argv) < 2:
        print("사용법: python extract_all_ultimates_detailed.py <DataTable.json 경로>")
        sys.exit(1)

    json_path = Path(sys.argv[1])

    with open(json_path, 'r', encoding='utf-8') as f:
        data = json.load(f)

    assets = data.get('Assets', [])

    # DT_CharacterStat에서 궁극기 ID 추출
    dt_char_stat = next((dt for dt in assets if dt.get('AssetName') == 'DT_CharacterStat'), None)
    stalker_ultimates = {}
    for row in dt_char_stat.get('Rows', []):
        row_name = row['RowName']
        if row_name in STALKERS:
            stalker_ultimates[row_name] = row['Data'].get('ultimateSkill', '')

    # DT_Skill에서 궁극기 정보 확인
    dt_skill = next((dt for dt in assets if dt.get('AssetName') == 'DT_Skill'), None)

    print("=" * 120)
    print("모든 궁극기 상세 정보")
    print("=" * 120)

    for stalker in STALKERS:
        ult_id = stalker_ultimates.get(stalker, '')
        if not ult_id:
            continue

        skill_row = next((row for row in dt_skill['Rows'] if row['RowName'] == ult_id), None)
        if not skill_row:
            continue

        d = skill_row['Data']

        print(f"\n{'='*120}")
        print(f"【{stalker.upper()}】 {ult_id}")
        print(f"{'='*120}")
        print(f"이름: {d.get('name', 'N/A')}")
        print(f"설명: {d.get('desc', 'N/A')}")
        print(f"간단 설명: {d.get('simpleDesc', 'N/A')}")
        print(f"\n기본 정보:")
        print(f"  - bIsUltimate: {d.get('bIsUltimate', False)}")
        print(f"  - skillDamageRate: {d.get('skillDamageRate', 0)}")
        print(f"  - skillAttackType: {d.get('skillAttackType', 'N/A')}")
        print(f"  - skillElementType: {d.get('skillElementType', 'N/A')}")
        print(f"  - castingTime: {d.get('castingTime', 0)}초")
        print(f"  - activeDuration: {d.get('activeDuration', 0)}초")
        print(f"  - manaCost: {d.get('manaCost', 0)}")
        print(f"  - coolTime: {d.get('coolTime', 0)}")

        effect_set = d.get('gameplayEffectSet', [])
        if effect_set:
            print(f"\ngameplayEffectSet: {len(effect_set)}개 효과")
            for i, effect in enumerate(effect_set, 1):
                ge_class = effect.get('gEClass', '')
                trigger = effect.get('trigger', '')
                tag_values = effect.get('gETagValues', [])

                # Ignore 효과는 간단히 표시
                if 'Ignore' in ge_class:
                    print(f"  [{i}] {trigger}: {ge_class.split('/')[-1].split('.')[0]} (면역 효과)")
                else:
                    ge_name = ge_class.split('/')[-1].split('.')[0]
                    print(f"  [{i}] {trigger}: {ge_name}")
                    if tag_values:
                        for tv in tag_values:
                            tag_name = tv.get('tag', {}).get('tagName', 'Unknown')
                            value = tv.get('value', 0)
                            print(f"      → {tag_name}: {value}")
        else:
            print(f"\ngameplayEffectSet: 비어있음")

if __name__ == "__main__":
    main()
