aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/data/extract_nano_learning.py (2038B)


      1 import hashlib
      2 import json
      3 import pathlib
      4 import struct
      5 
      6 import ao_database
      7 import extract_items
      8 
      9 
     10 def main():
     11     client = pathlib.Path('anarchy-vanilla-14.9.1')
     12     assert (client / 'version.id').read_text().strip() == '14.9.1'
     13     database = ao_database.Database(client)
     14 
     15     # Retain each supported crystal and the program it uploads.
     16     records = []
     17     for kind, identity in ((1000020, 43330), (1040005, 43324), (1000020, 29625), (1040005, 29618),
     18                            (1000020, 27305), (1040005, 27169), (1000020, 26469), (1040005, 26342),
     19                            (1000020, 26487), (1040005, 26360), (1000020, 27217), (1040005, 27086),
     20                            (1000020, 27270), (1040005, 27134), (1000020, 27290), (1040005, 27154),
     21                            (1000020, 27304), (1040005, 27168), (1000020, 28778), (1040005, 28665)):
     22         raw = database.read(kind, identity)
     23         item = extract_items.parse_item(raw, kind, identity)
     24         records.append(dict(record=item, payload_sha256=hashlib.sha256(raw).hexdigest()))
     25     assert [record['record']['quality'] for record in records] == [1, 1, 1, 1, 7, 3, 7, 3, 4, 2, 7, 3, 7, 3, 7, 3, 7, 3, 1, 1]
     26     assert records[0]['record']['header_words'][0] == 51005
     27     assert records[1]['record']['header_words'][0] == 51051
     28 
     29     # Keep the supported nano skill and initiative ability weights.
     30     weights = {}
     31     for stat in (127, 128, 129, 130, 131, 132, 149, 152):
     32         raw = database.read(1000204, stat)
     33         weights[stat] = dict(weights=struct.unpack('<6i', raw), payload_hex=raw.hex(),
     34                              payload_sha256=hashlib.sha256(raw).hexdigest())
     35     database.close()
     36 
     37     output = pathlib.Path('local/reports/nano-learning-14.9.1.json')
     38     output.parent.mkdir(parents=True, exist_ok=True)
     39     output.write_text(json.dumps(dict(index_sha256=hashlib.sha256(database.index).hexdigest(),
     40                                      records=records, skill_weights=weights), indent=2) + '\n')
     41     print(output)
     42 
     43 
     44 if __name__ == '__main__':
     45     main()