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,122 +1,122 @@
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
- let score = 0
10
-
11
- switch (gotchi.specialId) {
12
- case 1: // Ninja
13
- score = 2
14
- break
15
- case 2: // Enlightened
16
- score = 6
17
- break
18
- case 3: // Cleaver
19
- score = 1
20
- break
21
- case 4: // Tank
22
- score = 2
23
- break
24
- case 5: // Cursed
25
- score = 4
26
- break
27
- case 6: // Healer
28
- // If leader is healer then healer is good up front
29
- if (leader.specialId === 6) {
30
- score = 5
31
- } else {
32
- score = 1
33
- }
34
- break
35
- case 7: // Mage
36
- score = 0
37
- break
38
- case 8: // Troll
39
- score = 1
40
- break
41
- }
42
-
43
- return score
44
- }
45
-
46
- // High health gotchis do well up front
47
- const isHighHealth = gotchi.nrg < 50
48
-
49
- // High armor gotchis do well up front
50
- const isLowAgg = gotchi.agg < 50
51
-
52
- // High evasion gotchis do well up front
53
- const isHighSpk = gotchi.spk >= 50
54
-
55
- const isLowBrn = gotchi.brn < 50
56
-
57
- // Create a score from 0 to 6 based on how much they favour the front
58
-
59
- let score = 0
60
-
61
- if (gotchi.specialId === 2) score +=2 // Enlightened
62
- if (isHighHealth) score++
63
- if (isLowBrn) score++
64
- if (isLowAgg) score++
65
- if (isHighSpk) score++
66
-
67
- return score
68
- }
69
-
70
- module.exports = (team) => {
71
- // All gotchis are currently in the back row
72
- // Get the score for each gotchi for how much they favour the front row
73
- const teamFrontRowScores = team.formation.back.map((gotchi) => getFrontRowScore(gotchi.id, team.leader));
74
-
75
- [0,1,2,3,4].forEach((i) => {
76
- const gotchi = team.formation.back[i]
77
- const score = teamFrontRowScores[i]
78
-
79
- // If score is >= 3 then move to front row
80
- if (score >= 3) {
81
- team.formation.front[i] = gotchi
82
- team.formation.back[i] = null
83
- }
84
- })
85
-
86
- // If you have 5 gotchis in the front then send the lowest 2 to the back
87
- const frontGotchis = team.formation.front.filter(gotchi => gotchi)
88
- if (frontGotchis.length === 5) {
89
- // Sort the gotchis by score in ascending order (lowest score first)
90
- const orderedGotchis = JSON.parse(JSON.stringify(frontGotchis)).sort((a, b) => getFrontRowScore(a.id, team.leader) - getFrontRowScore(b.id, team.leader));
91
-
92
- // 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
93
- let hasMoved = 0
94
- team.formation.front.forEach((gotchi, i) => {
95
- if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
96
- team.formation.back[i] = gotchi
97
- team.formation.front[i] = null
98
-
99
- hasMoved++
100
- }
101
- })
102
- }
103
-
104
- // If you have 5 gotchis in the back then send the highest 2 to the front
105
- const backGotchis = team.formation.back.filter(gotchi => gotchi)
106
- if (backGotchis.length === 5) {
107
- // Sort the gotchis by score in descending order (highest score first)
108
- const orderedGotchis = JSON.parse(JSON.stringify(backGotchis)).sort((a, b) => getFrontRowScore(b.id, team.leader) - getFrontRowScore(a.id, team.leader));
109
-
110
- // 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
111
- let hasMoved = 0
112
- team.formation.back.forEach((gotchi, i) => {
113
- if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
114
- team.formation.front[i] = gotchi
115
- team.formation.back[i] = null
116
-
117
- hasMoved++
118
- }
119
- })
120
- }
121
- }
122
-
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
+ let score = 0
10
+
11
+ switch (gotchi.specialId) {
12
+ case 1: // Ninja
13
+ score = 2
14
+ break
15
+ case 2: // Enlightened
16
+ score = 6
17
+ break
18
+ case 3: // Cleaver
19
+ score = 1
20
+ break
21
+ case 4: // Tank
22
+ score = 2
23
+ break
24
+ case 5: // Cursed
25
+ score = 4
26
+ break
27
+ case 6: // Healer
28
+ // If leader is healer then healer is good up front
29
+ if (leader.specialId === 6) {
30
+ score = 5
31
+ } else {
32
+ score = 1
33
+ }
34
+ break
35
+ case 7: // Mage
36
+ score = 0
37
+ break
38
+ case 8: // Troll
39
+ score = 1
40
+ break
41
+ }
42
+
43
+ return score
44
+ }
45
+
46
+ // High health gotchis do well up front
47
+ const isHighHealth = gotchi.nrg < 50
48
+
49
+ // High armor gotchis do well up front
50
+ const isLowAgg = gotchi.agg < 50
51
+
52
+ // High evasion gotchis do well up front
53
+ const isHighSpk = gotchi.spk >= 50
54
+
55
+ const isLowBrn = gotchi.brn < 50
56
+
57
+ // Create a score from 0 to 6 based on how much they favour the front
58
+
59
+ let score = 0
60
+
61
+ if (gotchi.specialId === 2) score +=2 // Enlightened
62
+ if (isHighHealth) score++
63
+ if (isLowBrn) score++
64
+ if (isLowAgg) score++
65
+ if (isHighSpk) score++
66
+
67
+ return score
68
+ }
69
+
70
+ module.exports = (team) => {
71
+ // All gotchis are currently in the back row
72
+ // Get the score for each gotchi for how much they favour the front row
73
+ const teamFrontRowScores = team.formation.back.map((gotchi) => getFrontRowScore(gotchi.id, team.leader));
74
+
75
+ [0,1,2,3,4].forEach((i) => {
76
+ const gotchi = team.formation.back[i]
77
+ const score = teamFrontRowScores[i]
78
+
79
+ // If score is >= 3 then move to front row
80
+ if (score >= 3) {
81
+ team.formation.front[i] = gotchi
82
+ team.formation.back[i] = null
83
+ }
84
+ })
85
+
86
+ // If you have 5 gotchis in the front then send the lowest 2 to the back
87
+ const frontGotchis = team.formation.front.filter(gotchi => gotchi)
88
+ if (frontGotchis.length === 5) {
89
+ // Sort the gotchis by score in ascending order (lowest score first)
90
+ const orderedGotchis = JSON.parse(JSON.stringify(frontGotchis)).sort((a, b) => getFrontRowScore(a.id, team.leader) - getFrontRowScore(b.id, team.leader));
91
+
92
+ // 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
93
+ let hasMoved = 0
94
+ team.formation.front.forEach((gotchi, i) => {
95
+ if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
96
+ team.formation.back[i] = gotchi
97
+ team.formation.front[i] = null
98
+
99
+ hasMoved++
100
+ }
101
+ })
102
+ }
103
+
104
+ // If you have 5 gotchis in the back then send the highest 2 to the front
105
+ const backGotchis = team.formation.back.filter(gotchi => gotchi)
106
+ if (backGotchis.length === 5) {
107
+ // Sort the gotchis by score in descending order (highest score first)
108
+ const orderedGotchis = JSON.parse(JSON.stringify(backGotchis)).sort((a, b) => getFrontRowScore(b.id, team.leader) - getFrontRowScore(a.id, team.leader));
109
+
110
+ // 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
111
+ let hasMoved = 0
112
+ team.formation.back.forEach((gotchi, i) => {
113
+ if (hasMoved < 2 && (gotchi.id === orderedGotchis[0].id || gotchi.id === orderedGotchis[1].id)) {
114
+ team.formation.front[i] = gotchi
115
+ team.formation.back[i] = null
116
+
117
+ hasMoved++
118
+ }
119
+ })
120
+ }
121
+ }
122
+