Skip to content

Commit

Permalink
tools: tu-deck-grabber: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuchka committed Sep 28, 2024
1 parent 1762fb9 commit 0b66898
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions tools/tu-deck-grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import urllib
import urllib3
import json
import readline
import atexit
import certifi
import configparser
Expand Down Expand Up @@ -263,7 +262,7 @@ def formatUnitSkill(skill):
xml_file_hash = int(st.st_mtime * 0x1b1 + st.st_size) & 0xFFFFFFFF
print('INFO: fusion recipes xml file: {} (hash: 0x{:08x})'.format(xml_fname, xml_file_hash))

dump_fname = re.sub('\.xml$', '.pck', xml_fname)
dump_fname = re.sub(r'\.xml$', '.pck', xml_fname)
if os.path.exists(dump_fname):
with open(dump_fname, 'rb') as f:
xmagic = pickle.load(f)
Expand Down Expand Up @@ -321,7 +320,7 @@ def recp_get_attr(attr, castType=None, defValue=None):
xml_file_hash = int(((st.st_mtime * 31) + i) * 31 + st.st_size) & 0xFFFFFFFF
print('INFO: next cards xml file: {} (hash: 0x{:08x})'.format(xml_fname, xml_file_hash))

dump_fname = re.sub('\.xml$', '.pck', xml_fname)
dump_fname = re.sub(r'\.xml$', '.pck', xml_fname)
if os.path.exists(dump_fname):
with open(dump_fname, 'rb') as f:
xmagic = pickle.load(f)
Expand Down Expand Up @@ -862,8 +861,8 @@ def doGrabLastDeck(client):
if config.getboolean('CORE', 'output_eds'):
out += 'eds{:02d}.'.format(enemy_size)
if config.getboolean('CORE', 'output_guild'):
out += re.sub('(?a)[^\w]', '_', enemy_guild_name) + '.'
out += re.sub('(?a)[^\w]', '_', enemy_name)
out += re.sub(r'(?a)[^\w]', '_', enemy_guild_name) + '.'
out += re.sub(r'(?a)[^\w]', '_', enemy_name)
if config.getboolean('CORE', 'output_missing'):
missing_cards = enemy_size - enemy_played_cards_count
if (missing_cards > 0):
Expand All @@ -890,11 +889,20 @@ def doGrabLastDeck(client):
print('Grabbed deck: ' + out)

## configure readline

_win32 = False
if sys.platform == 'win32':
_win32 = True
import pyreadline3 as readline
else:
import readline

histfile = os.path.join(os.path.expanduser('~'), '.tu_deck_grabber_history')
if os.path.exists(histfile):
readline.read_history_file(histfile)
readline.set_history_length(1000)
readline.read_init_file()
if not _win32:
readline.set_history_length(1000)
readline.read_init_file()
atexit.register(readline.write_history_file, histfile)


Expand Down Expand Up @@ -947,7 +955,7 @@ def _up(x_id):
print(f'Upgrade card: {_cn(x_id)} => {_cn(target_cid)}')
rsp = client.upgradeCard(x_id, in_deck = in_deck)
if (not rsp):
print(f'ERROR: failed to upgrade {_cn(x_id)}')
print(f'ERROR: failed to upgrade {_cn(x_id)} (deps: {dep_list})')
return None
print('SP: {}'.format(rsp['user_data']['salvage']))
return x_id
Expand All @@ -962,11 +970,11 @@ def _up(x_id):
# it's 1st level, check fusion receipt
else:
if (not is_neocyte_dual) and (target['low_id'] != target_cid):
print(f'ERROR: DB: is not low level id: {_cn(target_cid)}')
print(f'ERROR: DB: is not low level id: {_cn(target_cid)} (deps: {dep_list})')
return None
from_cards = fusion_from_cards.get(target_cid, None)
if (not from_cards):
print(f'ERROR: No owned card {_cn(target_cid)}')
print(f'ERROR: No owned card {_cn(target_cid)} (deps: {dep_list})')
return None
from_cids = []
for d_id, count in from_cards.items():
Expand All @@ -980,7 +988,7 @@ def _up(x_id):
prev_xcnt = xcnt
xcnt = int(client.lastUserCards[sdid]['num_owned'] or 0)
if (prev_xcnt == xcnt):
print(f'ERROR: num owned is not changed for {sdid}')
print(f'ERROR: num owned is not changed for {sdid} (deps: {dep_list})')
return None
print(f'Fuse card: {from_cids} => {_cn(target_cid)}')
rsp = client.fuseCard(target_cid)
Expand Down Expand Up @@ -1307,7 +1315,12 @@ def write_dump_safe(name, data, append = False):
break
elif (args[0] == 'init'):
client.getUserAccount()
client.runInit()
ud = client.runInit()['user_data']
print(f' << player [{ud["name"]}] Lv. {ud["level"]} >>')
print(f' * Gold: {ud["money"]}')
print(f' * Energy: {ud["energy"]}')
print(f' * Stamina: {ud["stamina"]}')
print(f' * SP: {ud["salvage"]}')
elif (args[0] == 'grab'):
doGrabLastDeck(client)
elif (args[0] == 'hunt'):
Expand Down

0 comments on commit 0b66898

Please sign in to comment.