Git Product home page Git Product logo

lordeckcodespython's Introduction

Python Implementation

Install

python >=3.5 required pip >= 19.0.0

pip install lor-deckcodes

Usage

Ever expanding rich API with method to display cards conveniently

from lor_deckcodes import LoRDeck, CardCodeAndCount


# Decoding
deck = LoRDeck.from_deckcode('CEBAIAIFB4WDANQIAEAQGDAUDAQSIJZUAIAQCBIFAEAQCBAA')

# list all cards with card format 3:01SI001
list(deck)

card = deck.cards[0] # instance of CardCodeAndCount
card.faction # SI/FR...
card.card_id # 111
card.set # 01


# Encoding
# These are equivalent
deck = LoRDeck(['3:01SI015', '3:01SI044'])
deck = LoRDeck([
    CardCodeAndCount.from_card_string('3:01SI015'),
    CardCodeAndCount('01SI015', 3)]
)
# returns encoded string
deck.encode()

lordeckcodespython's People

Contributors

rafalonso avatar shaobaili3 avatar sousa-andre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lordeckcodespython's Issues

Attempt to Decode deck somehow fails when running in Heroku

Just recently, I used the code to run a deck info function for my Discord Bot. The bot is hosted via Heroku, and obviously the bot uses python to run. Decoding session was running fine and smooth.

However, when I deployed and tested the bot again today, somehow it triggered errors. Here's the log if you want to know further
2020-04-26T13:58:57.656093+00:00 app[worker.1]: Ignoring exception in on_message

2020-04-26T13:58:57.657203+00:00 app[worker.1]: Traceback (most recent call last):

2020-04-26T13:58:57.657304+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event

2020-04-26T13:58:57.657305+00:00 app[worker.1]: await coro(*args, **kwargs)

2020-04-26T13:58:57.657350+00:00 app[worker.1]: File "bot.py", line 81, in on_message

2020-04-26T13:58:57.657351+00:00 app[worker.1]: deck = LoRDeck.from_deckcode('CEBAIAIFB4WDANQIAEAQGDAUDAQSIJZUAIAQCBIFAEAQCBAA')

2020-04-26T13:58:57.657419+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/lor_deckcodes/models.py", line 34, in from_deckcode

2020-04-26T13:58:57.657420+00:00 app[worker.1]: return cls(decode_deck(deckcode))

2020-04-26T13:58:57.657453+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/lor_deckcodes/decode.py", line 26, in decode_deck

2020-04-26T13:58:57.657454+00:00 app[worker.1]: raise ValueError("Version/Format not supported.")

2020-04-26T13:58:57.657505+00:00 app[worker.1]: ValueError: Version/Format not supported.

In short words, the problems rises directly in the decode function. I don't know what happened, but everything was running so smooth until this came in. (Is this might be a problem from the previous day's commit?).
Hope there will be responses to this issue.
P/s: If the code still works in Python console, then this is definitely weird

Set 3 Update Notice

Hello there, Riot has recently implemented the code for decoding set 3, so it would be nice if you can take your time updating the code before the third set arrives on August 28th.

The set/faction lists are ordered by increasing length

encode.py
def _encode_card_block(data_stream: BytesIO, cards: List["CardCodeAndCount"]) -> None:
set_faction_combinations = _get_set_faction_combinations(cards)
write_varint(data_stream, len(set_faction_combinations))
(+)(+)(+)
set_faction_combinations = sorted(set_faction_combinations, key=lambda y: (len([card for card in cards if card.faction == y[1] and card.set == y[0]]), y[0], y[1]))
(+)(+)(+)

Integrating to the Pyot Framework

As you may noticed, riot has launched the match api for lor. I am the author of Pyot, its a framework for the riot api in python including all static files endpoints. I will be using this lib as a dependency for the framework, wanted to get a form of contact (prob discord) faster than github issues since I am not able to find you on the discord server.

Format rule for cards with more than 3 copies

A lot of Expdition decks have cards with more than 3 copies. I wish to encode and decode these decks. :)

Univesal basic format in game:

0001 0010 00000000 00000000 00000000 [copies]+[set]+[region]+[number] *n

00000000 *3 are groups for 3, 2 or 1 copy
[copies] can be 1, 2 or 3

source in C#:
https://github.com/RiotGames/LoRDeckCodes/blob/master/LoRDeckCodes/LoRDeckEncoder.cs

My ugly solution for decoding

(+)(+)(+)
def decode_card_block(data_stream: BytesIO) -> List[str]:
n_card_copies = next_varint(data_stream)
set_number = next_varint(data_stream)
faction = next_varint(data_stream)
num = next_varint(data_stream)
return [f'{n_card_copies}:{set_number:02}{faction_mapping.get(faction)}{num:03}']
(+)(+)(+)

def decode_deck(deckcode: str):
...
# 1 card copies
all_cards.extend(_decode_card_block(1, data))
(+)(+)(+)
# more cards
n = data.tell()
c = data.read(1)
data.seek(n)
while c:
all_cards.extend(decode_card_block(data))
n = data.tell()
c = data.read(1)
data.seek(n)
(+)(+)(+)
return all_cards

My ugly solution for encoding:

(+)(+)(+)
def encode_card_block(data_stream: BytesIO, cards: List["CardCodeAndCount"]) -> None:
sorted_cards = sorted(cards, key=lambda y: y.card_code)
for card in sorted_cards:
write_varint(data_stream, card.count)
write_varint(data_stream, card.set)
write_varint(data_stream, faction_mapping.get(card.faction))
write_varint(data_stream, card.card_id)
(+)(+)(+)

def encode_deck(cards: List["CardCodeAndCount"]) -> str:
...
# 1 card copies
one_copies = list(filter(lambda x: x.count == 1, cards))
_encode_card_block(data, one_copies)
(+)(+)(+)
more_copies = list(filter(lambda x: x.count > 3, cards))
encode_card_block(data, more_copies)
(+)(+)(+)
data.seek(0)
return b32encode(data.read()).decode().replace('=', '')

Encode gives diferent deck

I have the following deck:

lor_cards = ['3:01NX020', '3:01NX012', '3:01NX040', '3:01NX015', '3:01NX030', '3:01PZ054', '3:01NX037', '3:02NX004', '3:01PZ017', '1:01NX047', '3:01PZ052', '3:02NX003', '3:01PZ039', '3:01NX002']
deck_lor_code = LoRDeck(lor_cards).encode()

It gives me an encode of a diferent deck (with 49 cards)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.