Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #44 from chujie/new/yyx-import
Browse files Browse the repository at this point in the history
add support for yyx snapshot
  • Loading branch information
chujie authored Mar 6, 2019
2 parents 82b1653 + c82d915 commit 732d57f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
13 changes: 13 additions & 0 deletions calculator_of_Onmyoji/data_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,16 @@

ATTACK_MITAMA_TYPE = [t for t, e in list(MITAMA_ENHANCE.items())
if e['加成类型'] in ['', '攻击加成', '暴击']]

SUIT_ID_TO_NAME = {300002: '雪幽魂', 300003: '地藏像', 300004: '蝠翼',
300006: '涅槃之火', 300007: '三味', 300008: '魍魉之匣',
300009: '被服', 300010: '招财猫', 300011: '反枕',
300012: '轮入道', 300013: '日女巳时', 300014: '镜姬',
300015: '钟灵', 300018: '狰', 300019: '火灵', 300020: '鸣屋',
300021: '薙魂', 300022: '心眼', 300023: '木魅', 300024: '树妖',
300026: '网切', 300027: '阴摩罗', 300029: '伤魂鸟',
300030: '破势', 300031: '镇墓兽', 300032: '珍珠',
300033: '骰子鬼', 300034: '蚌精', 300035: '魅妖',
300036: '针女', 300039: '返魂香', 300048: '狂骨',
300049: '幽谷响', 300050: '土蜘蛛', 300051: '胧车',
300052: '荒骷髅', 300053: '地震鲶', 300054: '蜃气楼'}
64 changes: 59 additions & 5 deletions calculator_of_Onmyoji/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def get_mitama_data_json(filename, ignore_serial):
with open(filename) as f:
data = json.load(f)

if isinstance(data, dict):
return load_json_from_editor(data, ignore_serial)
if isinstance(data, dict) and 'data' in data:
if isinstance(data['data'], list):
return load_json_from_editor(data, ignore_serial)
else:
return load_json_from_yyx(data, ignore_serial)
elif isinstance(data, list):
return load_json_from_ocr_editor(data, ignore_serial)
else:
Expand All @@ -54,8 +57,8 @@ def get_mitama_data_json(filename, ignore_serial):
def load_json_from_ocr_editor(data, ignore_serial):
'''从OCR录入器读取数据'''
mitama_data = dict()
percent = ['攻击加成', '防御加成', '暴击', '暴击伤害',
'生命加成', '效果命中', '效果抵抗']
PERCENT_PROP = ['攻击加成', '防御加成', '暴击', '暴击伤害',
'生命加成', '效果命中', '效果抵抗']

data_version = 1
if data[0] == "yuhun_ocr2.0":
Expand All @@ -75,13 +78,61 @@ def load_json_from_ocr_editor(data, ignore_serial):
continue
# 百分比类数据乘100
for p in d:
if p in percent:
if p in PERCENT_PROP:
d[p] *= 100
mitama_data[serial] = d

return mitama_data


def load_json_from_yyx(data, ignore_serial):
'''从痒痒熊读取数据'''
PROP_NAME_MAP = {'Hp': '生命', 'Defense': '防御', 'Attack': '攻击',
'HpRate': '生命加成', 'DefenseRate': '防御加成',
'AttackRate': '攻击加成', 'Speed': '速度', 'CritRate': '暴击',
'CritPower': '暴击伤害', 'EffectHitRate': '效果命中',
'EffectResistRate': '效果抵抗'}

PERCENT_PROP = ['攻击加成', '防御加成', '暴击', '暴击伤害',
'生命加成', '效果命中', '效果抵抗']

MITAMA_COL_MAP = {'御魂序号': 'id', '御魂类型': 'suit_id',
'位置': 'pos'}

def mitama_json_to_dict(json_obj):
serial = json_obj['id']
if skip_serial(serial, ignore_serial) \
or json_obj.get('level', 15) < 15:
return None
mitama = {}
for col_name in data_format.MITAMA_COL_NAME_ZH[1:]:
if col_name in MITAMA_COL_MAP:
mitama[col_name] = json_obj[MITAMA_COL_MAP[col_name]]
else:
mitama[col_name] = 0

mitama['御魂类型'] = data_format.SUIT_ID_TO_NAME.get(mitama['御魂类型'])
mitama['位置'] += 1

attr_list = [json_obj['base_attr']]
attr_list.extend(json_obj['attrs'])
if 'single_attrs' in json_obj:
attr_list.extend(json_obj['single_attrs'])

for prop in attr_list:
prop_name = PROP_NAME_MAP.get(prop['type'], None)
if prop_name in data_format.MITAMA_PROPS:
if prop_name in PERCENT_PROP:
mitama[prop_name] += float(prop['value'])*100
else:
mitama[prop_name] += float(prop['value'])

return (serial, mitama)

mitama_list = map(mitama_json_to_dict, data['data'].get('hero_equips', []))
return dict([x for x in mitama_list if x])


def load_json_from_editor(data, ignore_serial):
'''从网页版御魂编辑器读取数据'''
def mitama_json_to_dict(json_obj):
Expand Down Expand Up @@ -210,3 +261,6 @@ def sep_mitama_by_loc(mitama_data):
print(d)
l_d = sep_mitama_by_loc(d)
print(l_d)

from calculator_of_Onmyoji import write_data
write_data.write_original_mitama_data('test.xls', d)

0 comments on commit 732d57f

Please sign in to comment.