-
Notifications
You must be signed in to change notification settings - Fork 23
/
fights.js
89 lines (69 loc) · 3.65 KB
/
fights.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.
import { Feature } from 'components/feature_manager/feature.js';
import { FightGame } from 'features/fights/fight_game.js';
import { FightRegistry } from 'features/fights/fight_registry.js';
import { Setting } from 'entities/setting.js';
// The Fights infrastructure powers games intended for players to have matches with each other. It
// ranges from 1-on-1 fights, to free-for-all games and team battles. Uses the DeathmatchGame base
// for most functionality, with custom maps on top of that.
export default class Fights extends Feature {
games_ = null;
registry_ = null;
settings_ = null;
constructor() {
super();
// Depend on the deathmatch specialization for games, which powers these features.
this.games_ = this.defineDependency('games_deathmatch');
this.games_.addReloadObserver(this, () => this.registerFightingGames());
// Various parts of the fighting system are configurable through "/lvp settings".
this.settings_ = this.defineDependency('settings');
// Has knowledge of the locations and commands (+presets) of games that are available on the
// server. Will be immediately initialized, even for tests.
this.registry_ = new FightRegistry(this.games_);
this.registry_.initialize();
// Register all games known to this feature when the Settings feature has been loaded, as
// we depend on a number of settings in order to be able to initialize the feature.
this.settings_().ready.then(() => this.registerFightingGames());
}
// Registers the fighting games available on Las Venturas Playground. Each is represented by a
// DeathmatchGame class with an object to specialize behaviour. The minimum number of players
// for a fight is configurable through "/lvp settings", primarily for testing purposes.
registerFightingGames() {
const defaultLocation = this.settings_().getValue('games/fight_default_location');
const minimumPlayers = this.settings_().getValue('games/fight_minimum_players');
this.games_().registerGame(FightGame, {
name: Fights.prototype.composeGameName.bind(this),
goal: 'Defeat all other players to win the fight.',
minimumPlayers,
maximumPlayers: 16,
settings: [
// Option: Name (internal, string)
new Setting('internal', 'name', Setting.TYPE_STRING, null, 'Display name'),
// Option: Location (string)
new Setting(
'fights', 'location', [ ...this.registry_.locations.keys() ], defaultLocation,
'Location'),
// Option: Pickups (boolean)
new Setting('fights', 'pickups', Setting.TYPE_BOOLEAN, true, 'Pickups'),
],
}, this.registry_);
}
// Composes the display name of the fighting game that's about to be started. This should be set
// in the internal values for predefined games, but will otherwise be composed of the settings
// that the game is being started with.
composeGameName(settings) {
const base = settings.get('internal/name') ?? 'Deathmatch Fight';
// TODO: Specialise based on the given |settings|.
return base;
}
dispose() {
this.registry_.dispose();
this.registry_ = null;
this.games_().removeGame(FightGame);
this.settings_ = null;
this.games_.removeReloadObserver(this);
this.games_ = null;
}
}