@dchighs/dc-core is a TypeScript/JavaScript library that simulates core Dragon City game logic.
It provides:
- Calculators for attack damage, feed cost, orb recall gain, and element strengths/weaknesses.
- Validation tools for dragon metadata.
- Static configuration for dragons, islands, sounds, elements, and more.
- Enums for strongly-typed values used across the package.
npm install @dchighs/dc-coreimport {
calculateAttackDamage,
calculateDragonFeedCost,
calculateElementStrengths,
DragonElement,
} from "@dchighs/dc-core"
const damage = calculateAttackDamage({
attackPower: 1800,
dragon: {
category: 9,
level: 40,
rank: 2,
stars: 3,
},
})
console.log(damage)
// { minimum: ..., maximum: ..., average: ..., random: ... }
const feedCost = calculateDragonFeedCost({ initialLevel: 1, finalLevel: 40 })
console.log(feedCost)
const strengths = calculateElementStrengths(DragonElement.Legend)
console.log(strengths)calculateAttackDamage(options)calculateDragonFeedCost(options)calculateElementStrengths(element)calculateElementsStrengths(elements)calculateElementWeaknesses(element)calculateOrbRecallGain(options)
Calculates the expected damage range for a dragon attack.
- Input
attackPower: numberdragon: { category: number; level: number; rank: number; stars: number }
- Validation
- Checks category, rank, and level/stars compatibility.
- Output
{ minimum: number; maximum: number; average: number; random: number }
- Notes
- Uses dragon category, level scaling, rank bonus, and star bonus from
dragonSettings. randomis sampled from the internal damage variance range.
- Uses dragon category, level scaling, rank bonus, and star bonus from
Computes the total food required based on dragon levels.
- Input
initialLevel: numberfinalLevel: number
- Validation
- Validates both levels and throws if
initialLevel > finalLevel.
- Validates both levels and throws if
- Output
number(total food cost)
Returns which elements are strong against a single element.
- Input
element: string(ideally fromDragonElement)
- Validation
- Validates if the element exists in internal settings.
- Output
DragonElement[]
Combines strengths for multiple elements and removes duplicates.
- Input
elements: string[]
- Validation
- Validates each provided element.
- Output
string[]with unique strengths from all provided elements.
Returns which elements can hit the provided element effectively.
- Input
element: string(ideally fromDragonElement)
- Validation
- Validates if the element exists in internal settings.
- Output
DragonElement[]
Calculates how many orbs are returned when recalling a dragon.
- Input
level: numberstars?: number(defaults to0)
- Validation
- Validates level/stars compatibility.
- Output
number(total recalled orbs)
- Notes
- Recall level contribution is capped internally at level
30.
- Recall level contribution is capped internally at level
validateDragonLevelCompatibilityWithStars(options)validateDragonCategory(category, options?)validateDragonRarity(rarity, options?)validateDragonStars(stars, options?)validateElementName(element, options?)validateDragonLevel(level, options?)validateDragonRank(rank, options?)getMusicKeyNameFromTag(tag)DragonStaticFileUrlParser
dragonSettingsfeedCostSettingsorbRecallReturnSettingselementSettingsislandSettingssoundSettings
All enums are exported from the package root, including:
DragonElementDragonRarityDragonCategoryDragonRankDragonPhaseConfigPlatformConfigLanguage
import {
validateDragonLevelCompatibilityWithStars,
validateDragonCategory,
validateDragonRank,
} from "@dchighs/dc-core"
validateDragonLevelCompatibilityWithStars({
level: 40,
stars: 3,
throwOnError: true,
})
validateDragonCategory(9, { throwOnError: true })
validateDragonRank(2, { throwOnError: true })import { DragonStaticFileUrlParser } from "@dchighs/dc-core"
const spriteUrl = "https://aws-static.socialpointgames.com/static/dragoncity/mobile/ui/dragons/112_terra_3@2x.png"
const parsed = DragonStaticFileUrlParser.parseFromSprite(spriteUrl)
console.log(parsed)
// {
// platformPrefix: 'aws',
// id: 112,
// imageName: '112_terra',
// phase: 3,
// skin: null,
// imageQuality: '@2x'
// }- Functions may throw if invalid values are provided and
throwOnError: trueis used. - This package is distributed as CommonJS with TypeScript definitions.
MIT