enefel 1.2.0 → 1.2.2

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.
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "enefel",
3
+ "version": "1.2.2",
4
+ "description": "Blood Bowl 2 game engine",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js",
9
+ "./*": "./dist/*.js"
10
+ },
11
+ "typesVersions": {
12
+ "*": {
13
+ "*": [
14
+ "./dist/*"
15
+ ]
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "watch": "tsc -w",
21
+ "prepare": "yarn build",
22
+ "test": "jest",
23
+ "test:watch": "jest --watch"
24
+ },
25
+ "keywords": [],
26
+ "author": "Manest",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "seedrandom": "3.0.5",
30
+ "yup": "^0.29.3"
31
+ },
32
+ "packageManager": "yarn@3.6.4+sha512.e70835d4d6d62c07be76b3c1529cb640c7443f0fe434ef4b6478a5a399218cbaf1511b396b3c56eb03bc86424cff2320f6167ad2fde273aa0df6e60b7754029f",
33
+ "devDependencies": {
34
+ "@jest/globals": "^29.7.0",
35
+ "@types/jest": "^29.5.14",
36
+ "@types/node": "^22.13.13",
37
+ "@types/seedrandom": "^3.0.8",
38
+ "@types/yup": "^0.29.3",
39
+ "jest": "^29.7.0",
40
+ "ts-jest": "^29.3.0",
41
+ "typescript": "^5.3.3"
42
+ }
43
+ }
package/dist/pitch.js ADDED
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TILES = void 0;
4
+ exports.coordinatesConvertorX = coordinatesConvertorX;
5
+ exports.coordinatesConvertorY = coordinatesConvertorY;
6
+ exports.getCenterTile = getCenterTile;
7
+ exports.getHalfStadium = getHalfStadium;
8
+ exports.getIndexFromXY = getIndexFromXY;
9
+ exports.getLateralATile = getLateralATile;
10
+ exports.getLateralBTile = getLateralBTile;
11
+ exports.getNumberPlayerZone = getNumberPlayerZone;
12
+ exports.getScrimmageTile = getScrimmageTile;
13
+ exports.getTdTile = getTdTile;
14
+ exports.getTile = getTile;
15
+ const index_1 = require("./index");
16
+ const status_1 = require("./status");
17
+ var TILES;
18
+ (function (TILES) {
19
+ TILES["TD1"] = "b";
20
+ TILES["CENTRE1"] = "c";
21
+ TILES["SCRIMMAGE1"] = "j";
22
+ TILES["LATERALA1"] = "d";
23
+ TILES["LATERALB1"] = "e";
24
+ TILES["TD2"] = "f";
25
+ TILES["CENTRE2"] = "g";
26
+ TILES["SCRIMMAGE2"] = "k";
27
+ TILES["LATERALA2"] = "h";
28
+ TILES["LATERALB2"] = "i";
29
+ TILES["NEUTRAL"] = "a";
30
+ })(TILES || (exports.TILES = TILES = {}));
31
+ function coordinatesConvertorY(y, isDev = false) {
32
+ if (isDev) {
33
+ return y;
34
+ }
35
+ return y < 0 ? y : String.fromCharCode(y + 65);
36
+ }
37
+ function coordinatesConvertorX(x, isDev = false) {
38
+ if (isDev) {
39
+ return x;
40
+ }
41
+ return x + 1;
42
+ }
43
+ function getScrimmageTile(teamNumber) {
44
+ return teamNumber === 1 ? TILES.SCRIMMAGE1 : TILES.SCRIMMAGE2;
45
+ }
46
+ function getLateralATile(teamNumber) {
47
+ return teamNumber === 1 ? TILES.LATERALA1 : TILES.LATERALA2;
48
+ }
49
+ function getLateralBTile(teamNumber) {
50
+ return teamNumber === 1 ? TILES.LATERALB1 : TILES.LATERALB2;
51
+ }
52
+ function getTdTile(teamNumber) {
53
+ return teamNumber === 1 ? TILES.TD1 : TILES.TD2;
54
+ }
55
+ function getCenterTile(teamNumber) {
56
+ return teamNumber === 1 ? TILES.CENTRE1 : TILES.CENTRE2;
57
+ }
58
+ function getTile(game, x, y) {
59
+ return game.stadium_zone[getIndexFromXY(x, y, game.stadium_width)];
60
+ }
61
+ function getIndexFromXY(x, y, width) {
62
+ return width * y + x;
63
+ }
64
+ function getHalfStadium(side, width) {
65
+ let offset = 0;
66
+ if (width === 20) {
67
+ offset = 3;
68
+ }
69
+ else if (width === 22) {
70
+ offset = 2;
71
+ }
72
+ else if (width === 24) {
73
+ offset = 1;
74
+ }
75
+ let minX = 0;
76
+ if (side === 2) {
77
+ minX = width / 2 + offset;
78
+ }
79
+ let maxX = width - 1;
80
+ if (side === 1) {
81
+ maxX = width / 2 - 1 - offset;
82
+ }
83
+ return (0, index_1.p)(minX, maxX);
84
+ }
85
+ function getNumberPlayerZone(teamNumber, players, game) {
86
+ const scrimmage = getScrimmageTile(teamNumber);
87
+ const laterala = getLateralATile(teamNumber);
88
+ const lateralb = getLateralBTile(teamNumber);
89
+ const center = getCenterTile(teamNumber);
90
+ let playerScrimmage = 0;
91
+ let playerLateralA = 0;
92
+ let playerLateralB = 0;
93
+ let playerCenter = 0;
94
+ players.forEach((player) => {
95
+ if (!(0, status_1.hasStatusStanding)(player) || player.x == null || player.y == null) {
96
+ return;
97
+ }
98
+ const tile = getTile(game, player.x, player.y);
99
+ if (tile === scrimmage) {
100
+ playerScrimmage += 1;
101
+ }
102
+ if (tile === laterala) {
103
+ playerLateralA += 1;
104
+ }
105
+ if (tile === lateralb) {
106
+ playerLateralB += 1;
107
+ }
108
+ if (tile === center) {
109
+ playerCenter += 1;
110
+ }
111
+ });
112
+ return { playerScrimmage, playerLateralA, playerLateralB, playerCenter };
113
+ }
package/dist/player.js ADDED
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLAYER_INJURY = exports.PLAYER_CARAC = exports.AGING_SIZE_RANGE = exports.AGING_MIN_BONUS = exports.AGING_INITIAL_BONUS = void 0;
4
+ exports.areFromSameTeam = areFromSameTeam;
5
+ exports.arePlayingSameGame = arePlayingSameGame;
6
+ exports.BB2020Carac = BB2020Carac;
7
+ exports.gamesforAgingRoll = gamesforAgingRoll;
8
+ exports.getAgingBonus = getAgingBonus;
9
+ exports.getCareerBaseCarac = getCareerBaseCarac;
10
+ exports.getCareerBaseCaracLimit = getCareerBaseCaracLimit;
11
+ exports.getMaxAG = getMaxAG;
12
+ exports.getMaxAV = getMaxAV;
13
+ exports.getMaxCarac = getMaxCarac;
14
+ exports.getMaxCommun = getMaxCommun;
15
+ exports.getMaxGfi = getMaxGfi;
16
+ exports.getMaxMA = getMaxMA;
17
+ exports.getMaxST = getMaxST;
18
+ exports.hasMove = hasMove;
19
+ exports.hasTeam = hasTeam;
20
+ exports.isPlaying = isPlaying;
21
+ exports.isPlayingGame = isPlayingGame;
22
+ exports.isRookie = isRookie;
23
+ exports.isTeam1 = isTeam1;
24
+ exports.isTeamPlaying = isTeamPlaying;
25
+ exports.isTeamPlayingGame = isTeamPlayingGame;
26
+ const improvement_1 = require("./improvement");
27
+ const meteo_1 = require("./meteo");
28
+ const race_1 = require("./race");
29
+ const skill_1 = require("./skill");
30
+ var PLAYER_INJURY;
31
+ (function (PLAYER_INJURY) {
32
+ PLAYER_INJURY["BADLY_HURT"] = "badly-hurt";
33
+ PLAYER_INJURY["SERIOUSLY_HURT"] = "seriously-hurt";
34
+ PLAYER_INJURY["SERIOUS"] = "serious";
35
+ PLAYER_INJURY["LASTING"] = "lasting";
36
+ PLAYER_INJURY["DEAD"] = "dead";
37
+ })(PLAYER_INJURY || (exports.PLAYER_INJURY = PLAYER_INJURY = {}));
38
+ var PLAYER_CARAC;
39
+ (function (PLAYER_CARAC) {
40
+ PLAYER_CARAC["AG"] = "AG";
41
+ PLAYER_CARAC["AV"] = "AV";
42
+ PLAYER_CARAC["MA"] = "MA";
43
+ PLAYER_CARAC["ST"] = "ST";
44
+ })(PLAYER_CARAC || (exports.PLAYER_CARAC = PLAYER_CARAC = {}));
45
+ function hasMove(player, game) {
46
+ if (player.current_MA >= getMaxCarac(player, PLAYER_CARAC.MA, game) &&
47
+ player.current_gfi >= getMaxGfi(player) &&
48
+ !(0, skill_1.hasUsedSkill)(player, skill_1.SKILL_NAMES.JUMP_UP)) {
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+ function arePlayingSameGame(p1, p2) {
54
+ return p1.gameId == p2.gameId;
55
+ }
56
+ function hasTeam(player) {
57
+ return player.teamId != null;
58
+ }
59
+ function areFromSameTeam(p1, p2) {
60
+ return p1.teamId == p2.teamId;
61
+ }
62
+ function isPlaying(player) {
63
+ return player.gameId != null;
64
+ }
65
+ function isPlayingGame(player, game) {
66
+ return player.gameId == game.id;
67
+ }
68
+ function isTeamPlaying(team) {
69
+ return team.game_id != null;
70
+ }
71
+ function isTeamPlayingGame(team, game) {
72
+ return team.game_id == game.id;
73
+ }
74
+ function isTeam1(player, game) {
75
+ return player.teamId == game.team1_id;
76
+ }
77
+ function isRookie(player) {
78
+ const date = new Date(player.userCreatedAt);
79
+ const fourMonthsAgo = new Date();
80
+ fourMonthsAgo.setMonth(fourMonthsAgo.getMonth() - 3);
81
+ return +fourMonthsAgo < +date;
82
+ }
83
+ function getCareerBaseCarac(player, carac) {
84
+ const career = (0, race_1.getCareerFromPlayer)(player);
85
+ if (!career) {
86
+ throw new Error("No career for player " + player.id + ": " + player.race_id);
87
+ }
88
+ return career[carac];
89
+ }
90
+ function getCareerBaseCaracLimit(player, value, carac) {
91
+ const base = getCareerBaseCarac(player, carac);
92
+ if (value > base + 2) {
93
+ value = base + 2;
94
+ }
95
+ if (value < base - 2) {
96
+ value = base - 2;
97
+ }
98
+ return value;
99
+ }
100
+ function getMaxCarac(player, carac, game) {
101
+ if (!player) {
102
+ return -1;
103
+ }
104
+ if (carac === PLAYER_CARAC.AG) {
105
+ return getMaxAG(player, game);
106
+ }
107
+ else if (carac === PLAYER_CARAC.MA) {
108
+ return getMaxMA(player, game);
109
+ }
110
+ else if (carac === PLAYER_CARAC.AV) {
111
+ return getMaxAV(player, game);
112
+ }
113
+ else if (carac === PLAYER_CARAC.ST) {
114
+ return getMaxST(player, game);
115
+ }
116
+ return -1;
117
+ }
118
+ function getMaxCommun(player, carac, _game) {
119
+ let c = player[carac];
120
+ if (!player.tempCarac) {
121
+ return c;
122
+ }
123
+ let obj;
124
+ try {
125
+ obj = JSON.parse(player.tempCarac);
126
+ }
127
+ catch (e) {
128
+ return c;
129
+ }
130
+ for (const value of Object.values(obj)) {
131
+ // TODO : Check if this is correct
132
+ if (value.gainCarac === PLAYER_CARAC[carac]) {
133
+ c += 1;
134
+ }
135
+ if (value.loseCarac === PLAYER_CARAC[carac]) {
136
+ c -= 1;
137
+ }
138
+ }
139
+ c = getCareerBaseCaracLimit(player, c, PLAYER_CARAC[carac]);
140
+ return c;
141
+ }
142
+ function getLimitedValue(c) {
143
+ if (c > 10) {
144
+ c = 10;
145
+ }
146
+ if (c < 0) {
147
+ c = 0;
148
+ }
149
+ return c;
150
+ }
151
+ function getMaxAV(player, game) {
152
+ let c = getMaxCommun(player, PLAYER_CARAC.AV, game);
153
+ return getLimitedValue(c);
154
+ }
155
+ function getMaxST(player, game) {
156
+ let c = getMaxCommun(player, PLAYER_CARAC.ST, game);
157
+ return getLimitedValue(c);
158
+ }
159
+ function getMaxAG(player, game) {
160
+ let c = getMaxCommun(player, PLAYER_CARAC.AG, game);
161
+ return getLimitedValue(c);
162
+ }
163
+ function getMaxMA(player, game) {
164
+ let c = getMaxCommun(player, PLAYER_CARAC.MA, game);
165
+ if (game) {
166
+ const maxMA = (0, meteo_1.meteoMaxMA)(game.meteo);
167
+ if (c > maxMA) {
168
+ c = maxMA;
169
+ }
170
+ }
171
+ return getLimitedValue(c);
172
+ }
173
+ function getMaxGfi(player) {
174
+ return (0, skill_1.hasSkill)(player, skill_1.SKILL_NAMES.SPRINT) ? 3 : 2;
175
+ }
176
+ const AGING_SIZE_RANGE = 5;
177
+ exports.AGING_SIZE_RANGE = AGING_SIZE_RANGE;
178
+ function gamesforAgingRoll(totalGames) {
179
+ if (totalGames <= 0) {
180
+ return AGING_SIZE_RANGE;
181
+ }
182
+ if (totalGames % AGING_SIZE_RANGE === 0) {
183
+ return 0;
184
+ }
185
+ return AGING_SIZE_RANGE - (totalGames % AGING_SIZE_RANGE);
186
+ }
187
+ const AGING_INITIAL_BONUS = 5;
188
+ exports.AGING_INITIAL_BONUS = AGING_INITIAL_BONUS;
189
+ const AGING_MIN_BONUS = -3;
190
+ exports.AGING_MIN_BONUS = AGING_MIN_BONUS;
191
+ function getAgingBonus(player, totalGames) {
192
+ if (player.experience < (0, improvement_1.getAgingMinExperience)()) {
193
+ return null;
194
+ }
195
+ if (gamesforAgingRoll(totalGames) !== 0) {
196
+ return null;
197
+ }
198
+ const range = totalGames / AGING_SIZE_RANGE;
199
+ // 5 = 1 = 4
200
+ // 10 = 2 = 3
201
+ // 15 = 3 = 2
202
+ // 20 = 4 = 1
203
+ // 25 = 5 = 0
204
+ // 30 = 6 = -1
205
+ // 35 = 7 = -2
206
+ // 40 = 8 = -3
207
+ let bonus = AGING_INITIAL_BONUS - range;
208
+ if (bonus < AGING_MIN_BONUS) {
209
+ bonus = AGING_MIN_BONUS;
210
+ }
211
+ return bonus;
212
+ }
213
+ function BB2020Carac(value, carac) {
214
+ // CHARACTERISTIC TABLE
215
+ // Characteristic MA ST AG PA AV
216
+ // Maximum 9 8 1+ 1+ 11+
217
+ //Minimum 1 1 6+ 6+ 3+
218
+ if (carac === PLAYER_CARAC.AV && value) {
219
+ // TODO: min3+, max11+
220
+ return `${+value + 1}+`;
221
+ }
222
+ else if (carac === PLAYER_CARAC.AG && value) {
223
+ let newValue = 6;
224
+ if (value <= 1)
225
+ newValue = 6;
226
+ if (value === 2)
227
+ newValue = 5;
228
+ else if (value === 3)
229
+ newValue = 4;
230
+ else if (value === 4)
231
+ newValue = 3;
232
+ else if (value === 5)
233
+ newValue = 2;
234
+ else if (value >= 6)
235
+ newValue = 1;
236
+ newValue -= 1;
237
+ if (newValue <= 1)
238
+ newValue = 1;
239
+ if (newValue >= 6)
240
+ newValue = 6;
241
+ return `${newValue}+`;
242
+ }
243
+ return value;
244
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAdjacent = void 0;
4
+ exports.getEnemyTackleZones = getEnemyTackleZones;
5
+ const status_1 = require("./status");
6
+ const isAdjacent = (p1, p2) => {
7
+ if (!p1 || !p2) {
8
+ return false;
9
+ }
10
+ return ((p1.x !== p2.x || p1.y !== p2.y) &&
11
+ Math.abs(p1.x - p2.x) <= 1 &&
12
+ Math.abs(p1.y - p2.y) <= 1);
13
+ };
14
+ exports.isAdjacent = isAdjacent;
15
+ function getEnemyTackleZones(location, teamId, players) {
16
+ // player a un format : { id1: {player1}, id2:{player2} etc...}
17
+ return Object.values(players).filter((player) => {
18
+ const res = (0, status_1.hasStatusTacleZone)(player) &&
19
+ player.teamId !== teamId &&
20
+ isAdjacent(player, location);
21
+ return res;
22
+ });
23
+ }