Skip to main content

Dragon City Utils, a collection of tools and utilities for managing static assets and performing calculations related to the Dragon City game.

Project description

dragon-city-utils

Welcome to the documentation of Dragon City Utils, a collection of tools and utilities for managing static assets and performing calculations related to the game Dragon City. Below, you'll find detailed explanations and code snippets for various functionalities.

Static Files

Sprites

Dragon Sprite

You can download a dragon sprite using the following code:

from dcutils.static.sprites import DragonSprite

dragon_sprite = DragonSprite(
    image_name = "1000_dragon_nature",
    phase = 3,
    skin = "skin1",
    image_quality = 2
)

dragon_sprite.download(output="dragon_nature_sprite.png")

Dragon Thumb

To download a dragon thumb:

from dcutils.static.sprites import DragonThumb

dragon_thumb = DragonThumb(
    image_name = "1000_dragon_nature",
    phase = 3,
    skin = "skin1"
)

dragon_thumb.download(output="dragon_nature_thumb.png")

Animations

Dragon Animation (Flash Animation)

To download a dragon flash animation:

from dcutils.static.animations import DragonFlashAnimation

dragon_flash_animation = DragonFlashAnimation(
    image_name = "1000_dragon_nature",
    phase = 3,
    skin = "skin1"
)

dragon_flash_animation.download(output="dragon_nature_flash_animation.swf")

Dragon Animation (Spine Animation)

To download a dragon spine animation:

from dcutils.static.animations import DragonSpineAnimation

dragon_spine_animation = DragonSpineAnimation(
    image_name = "1000_dragon_nature",
    phase = 3,
    skin = 1
)

dragon_spine_animation.download(output="dragon_spine_animation.zip")

Island Packages

To download an island package:

from dcutils.static.islands import IslandPackage

island_package = IslandPackage(uri = "/mobile/ui/heroicraces_islands/hr_71_heroicorigins.zip")

island_package.download(output = "island_package.zip")

Sounds

Music

To download music:

from dcutils.static.sounds import GeneralMusic

music = GeneralMusic(music_name = "531_dc_party_planning_island")

music.download(output = "531_dc_party_planning_island.mp3")

Tools

Calculators

Calculate Element Strengths

from dcutils.tools.calculators import calculate_strongs

strongs = calculate_strongs(elements = ["terra", "flame"])

Output:

['electric', 'flame', 'nature', 'ice']

Calculate Element Weaknesses

from dcutils.tools.calculators import calculate_weaknesses

weaknesses = calculate_weaknesses(first_element="terra")

Output:

['metal', 'war']

Calculate Orb Recall Gain

from dcutils.tools.calculators import calculate_orb_recall_gain

orb_recall_gain = calculate_orb_recall_gain(dragon_level = 15, dragon_stars = 2)

Output:

389

Calculate Attack Damage

You can calculate attack damage using the calculate_attack_damage function.

from dcutils.tools.calculators.dragon import calculate_attack_damage

damage_info = calculate_attack_damage(
    category = 1,
    level = 50,
    attack_power=  1000,
    rank_class = 3,
    stars = 2
)

Calculate

You can calculate dragon status using the calculate_status function.

from dcutils.tools.calculators.dragon import calculate_status

status_info = calculate_status(
    category = 1,
    rarity = "R",
    level = 50,
    rank_class = 3,
    stars = 2,
    hp_runes = 5,
    damage_runes = 3,
    with_tower_bonus = True,
    extra_hp_multiplier=  0.1,
    extra_damage_multiplier = 0.05
)

AI (Artificial Intelligence)

Elements Detector

from dcutils.tools.ai.elements_detector import ElementsDetectorAI

elements_detector = ElementsDetectorAI()

elements_result = elements_detector.detect(image_path = "ui_3110_dragon_hoardereternal_1@2x.png", limit = 4)

Output:

[{'element': 'ice', 'confidence_score': 0.4871271550655365}, {'element': 'nature', 'confidence_score': 0.296091228723526}, {'element': 'flame', 'confidence_score': 0.16774502396583557}, {'element': 'sea', 'confidence_score': 0.03868602588772774}]

Phase Detector

from dcutils.tools.ai.phase_detector import PhaseDetectorAI

phase_detector = PhaseDetectorAI()

phase_result = phase_detector.detect(image_path="ui_3110_dragon_hoardereternal_1@2x.png")

Output:

{'phase': 'baby', 'confidence_score': 0.9999938011169434}

URL Parser

Dragon URL Parser

You can parse various information from Dragon URLs:

from dcutils.tools.url_parser.dragon import DragonUrlParser

# Example URLs
url_flash_animation = "https://dci-static-s1.socialpointgames.com/static/dragoncity/assets/sprites/1000_dragon_nature_skin1_3.swf"
url_spine_animation = "https://dci-static-s1.socialpointgames.com/static/dragoncity/mobile/engine/version_1_1/dragons/1000_dragon_nature_3/1000_dragon_nature_skin1_3_HD_tweened_dxt5.zip"
url_sprite = "https://dci-static-s1.socialpointgames.com/static/dragoncity/mobile/ui/dragons/ui_1000_dragon_nature_skin1_3@2x.png"
url_thumb = "https://dci-static-s1.socialpointgames.com/static/dragoncity/mobile/ui/dragons/HD/thumb_1000_dragon_nature_skin1_3.png"

# Parse from URLs
result_flash_animation = DragonUrlParser.from_flash_animation(url_flash_animation)
result_spine_animation = DragonUrlParser.from_spine_animation(url_spine_animation)
result_sprite = DragonUrlParser.from_sprite(url_sprite)
result_thumb = DragonUrlParser.from_thumb(url_thumb)

# Get specific information
dragon_id = DragonUrlParser.get_id(url_thumb)
image_name = DragonUrlParser.get_image_name(url_thumb)
image_quality = DragonUrlParser.get_image_quality(url_sprite)
phase = DragonUrlParser.get_phase(url_sprite)
skin = DragonUrlParser.get_skin(url_sprite)

Each function returns relevant information parsed from the given Dragon URL.

Feel free to explore these functionalities and integrate them into your projects!

Localization

The Localization class allows you to handle localization data efficiently. You can load localization from files, fetch it from an endpoint, and perform various operations on the data.

from dcutils.static.localization import Localization

# Example usage
loc = Localization(language = "en")
print(loc)

Methods

load_file

Load localization data from a file.

loc = Localization.load_file(file_path = "localization.json")

load_compressed_file

Load compressed localization data from a file.

loc = Localization.load_compressed_file(file_path = "localization.gz")

fetch

Fetch localization data from an endpoint.

loc_data = Localization.fetch(language = "en")

get_value_from_key

Get the value from a key in the localization data.

value = loc.get_value_from_key("key_name")

get_key_from_value

Get the key from a value in the localization data.

key = loc.get_key_from_value("value_name")

get_dragon_name

Get the name of a dragon based on its ID.

name = loc.get_dragon_name(id = 1000)

get_dragon_description

Get the description of a dragon based on its ID.

description = loc.get_dragon_description(id = 1000)

get_attack_name

Get the name of an attack based on its ID.

name = loc.get_attack_name(id = 1)

get_skill_name

Get the name of a skill based on its ID.

name = loc.get_skill_name(id = 1)

get_skill_description

Get the description of a skill based on its ID.

description = loc.get_skill_description(id = 1)

search_keys

Search for keys containing a specific query.

keys = loc.search_keys(query = "search_query")

search_values

Search for values containing a specific query.

values = loc.search_values(query = "search_query")

compare

Compare the current localization data with old localization data.

comparison = loc.compare(old_localization = old_loc)

Properties

list

Get the localization data as a list.

loc_list = loc.list

dict

Get the localization data as a dictionary.

loc_dict = loc.dict

Feel free to explore these functionalities and integrate them into your projects!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dragon_city_utils-2.1.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dragon_city_utils-2.1.1-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file dragon_city_utils-2.1.1.tar.gz.

File metadata

  • Download URL: dragon_city_utils-2.1.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.2 Windows/10

File hashes

Hashes for dragon_city_utils-2.1.1.tar.gz
Algorithm Hash digest
SHA256 9d7c972bd9ac2a049d979845de9bf873de43c333b47ea7f76e6890363a16d888
MD5 3b576ccb675930ec7bc6e965bdefe35e
BLAKE2b-256 c6cb4c0b38e618bcd483cd1b5d2aa26f3771a42b747a47c773c7fb3f4d06197f

See more details on using hashes here.

File details

Details for the file dragon_city_utils-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: dragon_city_utils-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.2 Windows/10

File hashes

Hashes for dragon_city_utils-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a911da9b95df72d0ad215c244567b1f63a3be6def72aaada014a58da6c009e67
MD5 4eeb1ac2e6f2e36a1084b5fa90b6444f
BLAKE2b-256 4f32086789b3bbc366749c8f48d296534825180398ebe713b921f689357f0338

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page