gotchi-battler-game-logic 2.0.7 → 3.0.0

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 (67) hide show
  1. package/.vscode/settings.json +4 -4
  2. package/Dockerfile +9 -9
  3. package/README.md +49 -49
  4. package/cloudbuild.yaml +27 -27
  5. package/constants/tournamentManagerAbi.json +208 -208
  6. package/game-logic/index.js +7 -6
  7. package/game-logic/v1.4/constants.js +114 -114
  8. package/game-logic/v1.4/index.js +1366 -1366
  9. package/game-logic/v1.6/constants.js +123 -123
  10. package/game-logic/v1.6/index.js +1406 -1406
  11. package/game-logic/v1.7/constants.js +142 -140
  12. package/game-logic/v1.7/helpers.js +610 -593
  13. package/game-logic/v1.7/index.js +802 -795
  14. package/game-logic/v1.8/constants.js +135 -0
  15. package/game-logic/v1.8/helpers.js +628 -0
  16. package/game-logic/v1.8/index.js +826 -0
  17. package/index.js +12 -12
  18. package/package.json +26 -26
  19. package/schemas/team.json +349 -343
  20. package/scripts/balancing/createCSV.js +126 -126
  21. package/scripts/balancing/createTrainingGotchis.js +267 -0
  22. package/scripts/balancing/extractOnchainTraits.js +61 -0
  23. package/scripts/balancing/fixTrainingGotchis.js +155 -259
  24. package/scripts/balancing/processSims.js +229 -229
  25. package/scripts/balancing/sims.js +278 -278
  26. package/scripts/balancing/v1.7/class_combos.js +43 -43
  27. package/scripts/balancing/v1.7/mapGotchi.js +119 -0
  28. package/scripts/balancing/v1.7/setTeamPositions.js +105 -105
  29. package/scripts/balancing/v1.7/training_gotchis.json +20161 -20161
  30. package/scripts/balancing/v1.7/training_gotchis_traits.json +520 -0
  31. package/scripts/balancing/v1.7/trait_combos.json +9 -9
  32. package/scripts/balancing/v1.7.1/class_combos.js +43 -43
  33. package/scripts/balancing/v1.7.1/mapGotchi.js +119 -0
  34. package/scripts/balancing/v1.7.1/setTeamPositions.js +122 -122
  35. package/scripts/balancing/v1.7.1/training_gotchis.json +22401 -22401
  36. package/scripts/balancing/v1.7.1/training_gotchis_traits.json +520 -0
  37. package/scripts/balancing/v1.7.1/trait_combos.json +9 -9
  38. package/scripts/balancing/v1.7.2/class_combos.js +44 -0
  39. package/scripts/balancing/v1.7.2/mapGotchi.js +157 -0
  40. package/scripts/balancing/v1.7.2/setTeamPositions.js +122 -0
  41. package/scripts/balancing/v1.7.2/training_gotchis.json +22402 -0
  42. package/scripts/balancing/v1.7.2/training_gotchis_traits.json +520 -0
  43. package/scripts/balancing/v1.7.2/trait_combos.json +10 -0
  44. package/scripts/balancing/v1.7.3/class_combos.js +44 -0
  45. package/scripts/balancing/v1.7.3/mapGotchi.js +164 -0
  46. package/scripts/balancing/v1.7.3/setTeamPositions.js +122 -0
  47. package/scripts/balancing/v1.7.3/training_gotchis.json +22402 -0
  48. package/scripts/balancing/v1.7.3/training_gotchis_traits.json +37 -0
  49. package/scripts/balancing/v1.7.3/trait_combos.json +10 -0
  50. package/scripts/data/team1.json +213 -213
  51. package/scripts/data/team2.json +200 -200
  52. package/scripts/data/tournaments.json +71 -66
  53. package/scripts/{runBattle.js → runLocalBattle.js} +18 -18
  54. package/scripts/runRealBattle.js +52 -0
  55. package/scripts/simRealBattle.js +121 -0
  56. package/scripts/validateBattle.js +83 -70
  57. package/scripts/validateTournament.js +101 -101
  58. package/utils/contracts.js +12 -12
  59. package/utils/errors.js +29 -29
  60. package/utils/mapGotchi.js +119 -0
  61. package/utils/transforms.js +89 -88
  62. package/utils/validations.js +39 -39
  63. package/debug.log +0 -2
  64. package/game-logic/v1.6/debug.log +0 -1
  65. package/game-logic/v1.7/debug.log +0 -3
  66. package/scripts/data/debug.log +0 -2
  67. package/scripts/debug.log +0 -1
@@ -0,0 +1,119 @@
1
+ const mapTeam = (team) => {
2
+ for(const gotchi of team.formation.front) {
3
+ if (gotchi) mapGotchi(gotchi)
4
+ }
5
+
6
+ for(const gotchi of team.formation.back) {
7
+ if (gotchi) mapGotchi(gotchi)
8
+ }
9
+ }
10
+
11
+ // This is copied/hacked from the mapGotchi function in the backend
12
+ const mapGotchi = (gotchi) => {
13
+ const traitMaps = {
14
+ speed: {
15
+ baseFormula: 100,
16
+ multiplier: 1,
17
+ traitKey: 0,
18
+ isNegative: false
19
+ },
20
+ health: {
21
+ baseFormula: 'brs*0.75',
22
+ multiplier: 12,
23
+ traitKey: 0,
24
+ isNegative: true
25
+ },
26
+ crit: {
27
+ baseFormula: 0,
28
+ multiplier: 0.5,
29
+ traitKey: 1,
30
+ isNegative: false
31
+ },
32
+ armor: {
33
+ baseFormula: 0,
34
+ multiplier: 2,
35
+ traitKey: 1,
36
+ isNegative: true
37
+ },
38
+ evade: {
39
+ baseFormula: 0,
40
+ multiplier: 0.3,
41
+ traitKey: 2,
42
+ isNegative: false
43
+ },
44
+ resist: {
45
+ baseFormula: 0,
46
+ multiplier: 1,
47
+ traitKey: 2,
48
+ isNegative: true
49
+ },
50
+ magic: {
51
+ baseFormula: 'brs*0.25',
52
+ multiplier: 5,
53
+ traitKey: 3,
54
+ isNegative: false
55
+ },
56
+ physical: {
57
+ baseFormula: 'brs*0.25',
58
+ multiplier: 5,
59
+ traitKey: 3,
60
+ isNegative: true
61
+ },
62
+ accuracy: {
63
+ baseFormula: 50,
64
+ multiplier: 0.5,
65
+ traitKey: 45,
66
+ isNegative: false
67
+ }
68
+ }
69
+
70
+ const traitValue = (trait) => {
71
+ return trait < 50 ? 50 - trait : trait - 50 + 1
72
+ }
73
+
74
+ const onchainVals = [
75
+ gotchi.nrg,
76
+ gotchi.agg,
77
+ gotchi.spk,
78
+ gotchi.brn,
79
+ gotchi.eyc,
80
+ gotchi.eys
81
+ ]
82
+ // Convert trait value to in-game value
83
+ const traitValues = onchainVals.map(x => { return traitValue(x) })
84
+
85
+ // Map traits
86
+ for(const trait in traitMaps) {
87
+ const traitMap = traitMaps[trait]
88
+ const onchainVal = onchainVals[traitMap.traitKey]
89
+
90
+ let base = traitMap.baseFormula
91
+
92
+ // If baseFormula is a string and contains a * then it is a formula
93
+ if (typeof traitMap.baseFormula === 'string' && traitMap.baseFormula.includes('*')) {
94
+ const formula = traitMap.baseFormula.split('*')
95
+
96
+ if (!gotchi[formula[0]]) throw new Error('Trait not found: ', formula[0])
97
+
98
+ base = Math.round(Number(gotchi[formula[0]]) * Number(formula[1]))
99
+ }
100
+
101
+ let newTrait
102
+ if (trait !== 'accuracy') {
103
+ if (traitMap.isNegative) {
104
+ newTrait = onchainVal < 50 ? Math.round(base + (traitValues[traitMap.traitKey] * traitMap.multiplier)) : base
105
+ } else {
106
+ newTrait = onchainVal < 50 ? base : Math.round(base + (traitValues[traitMap.traitKey] * traitMap.multiplier))
107
+ }
108
+ } else {
109
+ newTrait = base + ((traitValues[4] + traitValues[5]) * traitMap.multiplier)
110
+ }
111
+
112
+ if (newTrait !== gotchi[trait]) gotchi[trait] = newTrait
113
+ }
114
+ }
115
+
116
+ module.exports = {
117
+ mapGotchi,
118
+ mapTeam
119
+ }
@@ -1,105 +1,105 @@
1
- const trainingGotchis = require('./training_gotchis.json')
2
-
3
- const getFrontRowScore = (gotchiId, leaderId) => {
4
- const gotchi = trainingGotchis.find(gotchi => gotchi.id === gotchiId)
5
- const leader = trainingGotchis.find(gotchi => gotchi.id === leaderId)
6
-
7
- if (gotchi.name.includes(' avg ')) {
8
-
9
- if (gotchi.specialId === 2) {
10
- // Enlightened are the best up front
11
- return 6
12
- } else if (leader.specialId === 6 && gotchi.specialId === 6) {
13
- // Healer with a healer leader are the second best up front
14
- return 5
15
- } else if (gotchi.specialId === 5) {
16
- // Cursed are the third best up front
17
- return 4
18
- } else if (gotchi.specialId === 6) {
19
- // Healers do ok
20
- return 2
21
- } else if (gotchi.specialId === 7) {
22
- // Mages always go to the back
23
- return 0
24
- } else {
25
- return 1
26
- }
27
- }
28
-
29
- // High health gotchis do well up front
30
- const isHighHealth = gotchi.nrg < 50
31
-
32
- // High armor gotchis do well up front
33
- const isLowAgg = gotchi.agg < 50
34
-
35
- // High evasion gotchis do well up front
36
- const isHighSpk = gotchi.spk >= 50
37
-
38
- const isLowBrn = gotchi.brn < 50
39
-
40
- // Create a score from 0 to 6 based on how much they favour the front
41
-
42
- let score = 0
43
-
44
- if (gotchi.specialId === 2) score +=2 // Enlightened
45
- if (isHighHealth) score++
46
- if (isLowBrn) score++
47
- if (isLowAgg) score++
48
- if (isHighSpk) score++
49
-
50
- return score
51
- }
52
-
53
- module.exports = (team) => {
54
- // All gotchis are currently in the back row
55
- // Get the score for each gotchi for how much they favour the front row
56
- const teamFrontRowScores = team.formation.back.map((gotchi) => getFrontRowScore(gotchi.id, team.leader));
57
-
58
- [0,1,2,3,4].forEach((i) => {
59
- const gotchi = team.formation.back[i]
60
- const score = teamFrontRowScores[i]
61
-
62
- // If score is >= 3 then move to front row
63
- if (score >= 3) {
64
- team.formation.front[i] = gotchi
65
- team.formation.back[i] = null
66
- }
67
- })
68
-
69
- // If you have 5 gotchis in the front then send the lowest 2 to the back
70
- const frontGotchis = team.formation.front.filter(gotchi => gotchi)
71
- if (frontGotchis.length === 5) {
72
- // Sort the gotchis by score in ascending order (lowest score first)
73
- const orderedGotchis = JSON.parse(JSON.stringify(frontGotchis)).sort((a, b) => getFrontRowScore(a.id, team.leader) - getFrontRowScore(b.id, team.leader));
74
-
75
- // Loop through the front row and the first 2 gotchis that have a score of either orderedGotchis[0] or orderedGotchis[1] move to the back
76
- let hasMoved = 0
77
- team.formation.front.forEach((gotchi, i) => {
78
- if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
79
- team.formation.back[i] = gotchi
80
- team.formation.front[i] = null
81
-
82
- hasMoved++
83
- }
84
- })
85
- }
86
-
87
- // If you have 5 gotchis in the back then send the highest 2 to the front
88
- const backGotchis = team.formation.back.filter(gotchi => gotchi)
89
- if (backGotchis.length === 5) {
90
- // Sort the gotchis by score in descending order (highest score first)
91
- const orderedGotchis = JSON.parse(JSON.stringify(backGotchis)).sort((a, b) => getFrontRowScore(b.id, team.leader) - getFrontRowScore(a.id, team.leader));
92
-
93
- // Loop through the back row and the first 2 gotchis that have a score of either orderedGotchis[0] or orderedGotchis[1] move to the front
94
- let hasMoved = 0
95
- team.formation.back.forEach((gotchi, i) => {
96
- if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
97
- team.formation.front[i] = gotchi
98
- team.formation.back[i] = null
99
-
100
- hasMoved++
101
- }
102
- })
103
- }
104
- }
105
-
1
+ const trainingGotchis = require('./training_gotchis.json')
2
+
3
+ const getFrontRowScore = (gotchiId, leaderId) => {
4
+ const gotchi = trainingGotchis.find(gotchi => gotchi.id === gotchiId)
5
+ const leader = trainingGotchis.find(gotchi => gotchi.id === leaderId)
6
+
7
+ if (gotchi.name.includes(' avg ')) {
8
+
9
+ if (gotchi.specialId === 2) {
10
+ // Enlightened are the best up front
11
+ return 6
12
+ } else if (leader.specialId === 6 && gotchi.specialId === 6) {
13
+ // Healer with a healer leader are the second best up front
14
+ return 5
15
+ } else if (gotchi.specialId === 5) {
16
+ // Cursed are the third best up front
17
+ return 4
18
+ } else if (gotchi.specialId === 6) {
19
+ // Healers do ok
20
+ return 2
21
+ } else if (gotchi.specialId === 7) {
22
+ // Mages always go to the back
23
+ return 0
24
+ } else {
25
+ return 1
26
+ }
27
+ }
28
+
29
+ // High health gotchis do well up front
30
+ const isHighHealth = gotchi.nrg < 50
31
+
32
+ // High armor gotchis do well up front
33
+ const isLowAgg = gotchi.agg < 50
34
+
35
+ // High evasion gotchis do well up front
36
+ const isHighSpk = gotchi.spk >= 50
37
+
38
+ const isLowBrn = gotchi.brn < 50
39
+
40
+ // Create a score from 0 to 6 based on how much they favour the front
41
+
42
+ let score = 0
43
+
44
+ if (gotchi.specialId === 2) score +=2 // Enlightened
45
+ if (isHighHealth) score++
46
+ if (isLowBrn) score++
47
+ if (isLowAgg) score++
48
+ if (isHighSpk) score++
49
+
50
+ return score
51
+ }
52
+
53
+ module.exports = (team) => {
54
+ // All gotchis are currently in the back row
55
+ // Get the score for each gotchi for how much they favour the front row
56
+ const teamFrontRowScores = team.formation.back.map((gotchi) => getFrontRowScore(gotchi.id, team.leader));
57
+
58
+ [0,1,2,3,4].forEach((i) => {
59
+ const gotchi = team.formation.back[i]
60
+ const score = teamFrontRowScores[i]
61
+
62
+ // If score is >= 3 then move to front row
63
+ if (score >= 3) {
64
+ team.formation.front[i] = gotchi
65
+ team.formation.back[i] = null
66
+ }
67
+ })
68
+
69
+ // If you have 5 gotchis in the front then send the lowest 2 to the back
70
+ const frontGotchis = team.formation.front.filter(gotchi => gotchi)
71
+ if (frontGotchis.length === 5) {
72
+ // Sort the gotchis by score in ascending order (lowest score first)
73
+ const orderedGotchis = JSON.parse(JSON.stringify(frontGotchis)).sort((a, b) => getFrontRowScore(a.id, team.leader) - getFrontRowScore(b.id, team.leader));
74
+
75
+ // Loop through the front row and the first 2 gotchis that have a score of either orderedGotchis[0] or orderedGotchis[1] move to the back
76
+ let hasMoved = 0
77
+ team.formation.front.forEach((gotchi, i) => {
78
+ if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
79
+ team.formation.back[i] = gotchi
80
+ team.formation.front[i] = null
81
+
82
+ hasMoved++
83
+ }
84
+ })
85
+ }
86
+
87
+ // If you have 5 gotchis in the back then send the highest 2 to the front
88
+ const backGotchis = team.formation.back.filter(gotchi => gotchi)
89
+ if (backGotchis.length === 5) {
90
+ // Sort the gotchis by score in descending order (highest score first)
91
+ const orderedGotchis = JSON.parse(JSON.stringify(backGotchis)).sort((a, b) => getFrontRowScore(b.id, team.leader) - getFrontRowScore(a.id, team.leader));
92
+
93
+ // Loop through the back row and the first 2 gotchis that have a score of either orderedGotchis[0] or orderedGotchis[1] move to the front
94
+ let hasMoved = 0
95
+ team.formation.back.forEach((gotchi, i) => {
96
+ if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
97
+ team.formation.front[i] = gotchi
98
+ team.formation.back[i] = null
99
+
100
+ hasMoved++
101
+ }
102
+ })
103
+ }
104
+ }
105
+