@dchighs/dc-core 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +211 -0
  2. package/package.json +5 -3
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # dc-core
2
+
3
+ `@dchighs/dc-core` is a TypeScript/JavaScript library that simulates core Dragon City game logic.
4
+
5
+ It provides:
6
+
7
+ - **Calculators** for attack damage, feed cost, orb recall gain, and element strengths/weaknesses.
8
+ - **Validation tools** for dragon metadata.
9
+ - **Static configuration** for dragons, islands, sounds, elements, and more.
10
+ - **Enums** for strongly-typed values used across the package.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @dchighs/dc-core
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```ts
21
+ import {
22
+ calculateAttackDamage,
23
+ calculateDragonFeedCost,
24
+ calculateElementStrengths,
25
+ DragonElement,
26
+ } from "@dchighs/dc-core"
27
+
28
+ const damage = calculateAttackDamage({
29
+ attackPower: 1800,
30
+ dragon: {
31
+ category: 9,
32
+ level: 40,
33
+ rank: 2,
34
+ stars: 3,
35
+ },
36
+ })
37
+
38
+ console.log(damage)
39
+ // { minimum: ..., maximum: ..., average: ..., random: ... }
40
+
41
+ const feedCost = calculateDragonFeedCost({ initialLevel: 1, finalLevel: 40 })
42
+ console.log(feedCost)
43
+
44
+ const strengths = calculateElementStrengths(DragonElement.Legend)
45
+ console.log(strengths)
46
+ ```
47
+
48
+ ## Main exports
49
+
50
+ ### Calculators
51
+
52
+ - `calculateAttackDamage(options)`
53
+ - `calculateDragonFeedCost(options)`
54
+ - `calculateElementStrengths(element)`
55
+ - `calculateElementsStrengths(elements)`
56
+ - `calculateElementWeaknesses(element)`
57
+ - `calculateOrbRecallGain(options)`
58
+
59
+ #### `calculateAttackDamage(options)`
60
+
61
+ Calculates the expected damage range for a dragon attack.
62
+
63
+ - **Input**
64
+ - `attackPower: number`
65
+ - `dragon: { category: number; level: number; rank: number; stars: number }`
66
+ - **Validation**
67
+ - Checks category, rank, and level/stars compatibility.
68
+ - **Output**
69
+ - `{ minimum: number; maximum: number; average: number; random: number }`
70
+ - **Notes**
71
+ - Uses dragon category, level scaling, rank bonus, and star bonus from `dragonSettings`.
72
+ - `random` is sampled from the internal damage variance range.
73
+
74
+ #### `calculateDragonFeedCost(options)`
75
+
76
+ Computes the total food required based on dragon levels.
77
+
78
+ - **Input**
79
+ - `initialLevel: number`
80
+ - `finalLevel: number`
81
+ - **Validation**
82
+ - Validates both levels and throws if `initialLevel > finalLevel`.
83
+ - **Output**
84
+ - `number` (total food cost)
85
+
86
+ #### `calculateElementStrengths(element)`
87
+
88
+ Returns which elements are strong against a single element.
89
+
90
+ - **Input**
91
+ - `element: string` (ideally from `DragonElement`)
92
+ - **Validation**
93
+ - Validates if the element exists in internal settings.
94
+ - **Output**
95
+ - `DragonElement[]`
96
+
97
+ #### `calculateElementsStrengths(elements)`
98
+
99
+ Combines strengths for multiple elements and removes duplicates.
100
+
101
+ - **Input**
102
+ - `elements: string[]`
103
+ - **Validation**
104
+ - Validates each provided element.
105
+ - **Output**
106
+ - `string[]` with unique strengths from all provided elements.
107
+
108
+ #### `calculateElementWeaknesses(element)`
109
+
110
+ Returns which elements can hit the provided element effectively.
111
+
112
+ - **Input**
113
+ - `element: string` (ideally from `DragonElement`)
114
+ - **Validation**
115
+ - Validates if the element exists in internal settings.
116
+ - **Output**
117
+ - `DragonElement[]`
118
+
119
+ #### `calculateOrbRecallGain(options)`
120
+
121
+ Calculates how many orbs are returned when recalling a dragon.
122
+
123
+ - **Input**
124
+ - `level: number`
125
+ - `stars?: number` (defaults to `0`)
126
+ - **Validation**
127
+ - Validates level/stars compatibility.
128
+ - **Output**
129
+ - `number` (total recalled orbs)
130
+ - **Notes**
131
+ - Recall level contribution is capped internally at level `30`.
132
+
133
+ ### Tools
134
+
135
+ - `validateDragonLevelCompatibilityWithStars(options)`
136
+ - `validateDragonCategory(category, options?)`
137
+ - `validateDragonRarity(rarity, options?)`
138
+ - `validateDragonStars(stars, options?)`
139
+ - `validateElementName(element, options?)`
140
+ - `validateDragonLevel(level, options?)`
141
+ - `validateDragonRank(rank, options?)`
142
+ - `getMusicKeyNameFromTag(tag)`
143
+ - `DragonStaticFileUrlParser`
144
+
145
+ ### Settings
146
+
147
+ - `dragonSettings`
148
+ - `feedCostSettings`
149
+ - `orbRecallReturnSettings`
150
+ - `elementSettings`
151
+ - `islandSettings`
152
+ - `soundSettings`
153
+
154
+ ### Enums
155
+
156
+ All enums are exported from the package root, including:
157
+
158
+ - `DragonElement`
159
+ - `DragonRarity`
160
+ - `DragonCategory`
161
+ - `DragonRank`
162
+ - `DragonPhase`
163
+ - `ConfigPlatform`
164
+ - `ConfigLanguage`
165
+
166
+ ## Example: validating values before calculations
167
+
168
+ ```ts
169
+ import {
170
+ validateDragonLevelCompatibilityWithStars,
171
+ validateDragonCategory,
172
+ validateDragonRank,
173
+ } from "@dchighs/dc-core"
174
+
175
+ validateDragonLevelCompatibilityWithStars({
176
+ level: 40,
177
+ stars: 3,
178
+ throwOnError: true,
179
+ })
180
+
181
+ validateDragonCategory(9, { throwOnError: true })
182
+ validateDragonRank(2, { throwOnError: true })
183
+ ```
184
+
185
+ ## Example: parsing static asset URLs
186
+
187
+ ```ts
188
+ import { DragonStaticFileUrlParser } from "@dchighs/dc-core"
189
+
190
+ const spriteUrl = "https://aws-static.socialpointgames.com/static/dragoncity/mobile/ui/dragons/112_terra_3@2x.png"
191
+
192
+ const parsed = DragonStaticFileUrlParser.parseFromSprite(spriteUrl)
193
+ console.log(parsed)
194
+ // {
195
+ // platformPrefix: 'aws',
196
+ // id: 112,
197
+ // imageName: '112_terra',
198
+ // phase: 3,
199
+ // skin: null,
200
+ // imageQuality: '@2x'
201
+ // }
202
+ ```
203
+
204
+ ## Notes
205
+
206
+ - Functions may throw if invalid values are provided and `throwOnError: true` is used.
207
+ - This package is distributed as CommonJS with TypeScript definitions.
208
+
209
+ ## License
210
+
211
+ MIT
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@dchighs/dc-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "A library focused on simulating some of the logic of the game Dragon City.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "files": [
9
9
  "dist/*",
10
- "!/**/__tests__"
10
+ "!/**/__tests__",
11
+ "README.md",
12
+ "LICENSE"
11
13
  ],
12
14
  "scripts": {
13
15
  "test": "jest",
@@ -32,6 +34,6 @@
32
34
  },
33
35
  "repository": {
34
36
  "type": "git",
35
- "url": "https://github.com/dchighs/dc-core.git"
37
+ "url": "https://github.com/dc-highs/dc-core.git"
36
38
  }
37
39
  }