-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move "/p freeze" and "/p unfreeze" to JavaScript
- Loading branch information
1 parent
5084b19
commit 4e677b9
Showing
5 changed files
with
161 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
javascript/features/player_commands/commands/freeze_command.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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 { PlayerCommand } from 'features/player_commands/player_command.js'; | ||
|
||
// Implements the "/my freeze" and "/p [player] freeze" commands, which makes it possible to freeze | ||
// a particular player. This action will be relayed to the player directly. | ||
export class FreezeCommand extends PlayerCommand { | ||
get name() { return 'freeze'; } | ||
|
||
// This command is not available to all players, only to administrators. | ||
get playerLevel() { return Player.LEVEL_ADMINISTRATOR; } | ||
|
||
// Called when a player executes the command. Will immediately freeze the |target|, and let them | ||
// know about the adminstrative action being taken on them. | ||
async execute(player, target) { | ||
target.controllable = false; | ||
|
||
if (player === target) { | ||
this.announce().announceToAdministrators( | ||
Message.PLAYER_COMMANDS_FREEZE_SELF_ADMIN, player.name, player.id); | ||
|
||
player.sendMessage(Message.PLAYER_COMMANDS_FREEZE_SELF); | ||
|
||
} else { | ||
this.announce().announceToAdministrators( | ||
Message.PLAYER_COMMANDS_FREEZE_OTHER_ADMIN, player.name, player.id, target.name, | ||
target.id); | ||
|
||
player.sendMessage(Message.PLAYER_COMMANDS_FREEZE_OTHER, target.name, target.id); | ||
target.sendMessage(Message.PLAYER_COMMANDS_FREEZE_FYI, player.name, player.id); | ||
} | ||
} | ||
} | ||
|
||
// Implements the "/my unfreeze" and "/p [player] unfreeze" commands, which do the reverse of the | ||
// freeze command: it makes it possible for the player to move around again. | ||
export class UnfreezeCommand extends PlayerCommand { | ||
get name() { return 'unfreeze'; } | ||
|
||
// This command is not available to all players, only to administrators. | ||
get playerLevel() { return Player.LEVEL_ADMINISTRATOR; } | ||
|
||
// Called when a player executes the command. Will immediately release the given |target|. | ||
async execute(player, target) { | ||
target.controllable = true; | ||
|
||
if (player === target) { | ||
this.announce().announceToAdministrators( | ||
Message.PLAYER_COMMANDS_UNFREEZE_SELF_ADMIN, player.name, player.id); | ||
|
||
player.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_SELF); | ||
|
||
} else { | ||
this.announce().announceToAdministrators( | ||
Message.PLAYER_COMMANDS_UNFREEZE_OTHER_ADMIN, player.name, player.id, target.name, | ||
target.id); | ||
|
||
player.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_OTHER, target.name, target.id); | ||
target.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_FYI, player.name, player.id); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
javascript/features/player_commands/commands/freeze_command.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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. | ||
|
||
describe('FreezeCommand', (it, beforeEach) => { | ||
let gunther = null; | ||
let russell = null; | ||
|
||
beforeEach(async () => { | ||
const feature = server.featureManager.loadFeature('player_commands'); | ||
|
||
gunther = server.playerManager.getById(/* Gunther= */ 0); | ||
russell = server.playerManager.getById(/* Russell= */ 1); | ||
russell.level = Player.LEVEL_ADMINISTRATOR; | ||
|
||
await feature.registry_.initialize(); | ||
await russell.identify(); | ||
}); | ||
|
||
it('should enable administrators to freeze and unfreeze players', async (assert) => { | ||
assert.isTrue(gunther.controllableForTesting); | ||
assert.isTrue(russell.controllableForTesting); | ||
|
||
// (1) Russell has the ability to freeze Gunther. | ||
assert.isTrue(await russell.issueCommand('/p gunt freeze')); | ||
assert.isFalse(gunther.controllableForTesting); | ||
|
||
assert.equal(russell.messages.length, 2); | ||
assert.includes( | ||
russell.messages[0], | ||
Message.format(Message.PLAYER_COMMANDS_FREEZE_OTHER_ADMIN, russell.name, russell.id, | ||
gunther.name, gunther.id)); | ||
|
||
assert.equal( | ||
russell.messages[1], | ||
Message.format(Message.PLAYER_COMMANDS_FREEZE_OTHER, gunther.name, gunther.id)); | ||
|
||
assert.equal(gunther.messages.length, 1); | ||
assert.equal( | ||
gunther.messages[0], | ||
Message.format(Message.PLAYER_COMMANDS_FREEZE_FYI, russell.name, russell.id)); | ||
|
||
// (2) Russell has the ability to unfreeze Gunther. | ||
assert.isTrue(await russell.issueCommand('/p gunt unfreeze')); | ||
assert.isTrue(gunther.controllableForTesting); | ||
|
||
assert.equal(russell.messages.length, 4); | ||
assert.includes( | ||
russell.messages[2], | ||
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_OTHER_ADMIN, russell.name, russell.id, | ||
gunther.name, gunther.id)); | ||
|
||
assert.equal( | ||
russell.messages[3], | ||
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_OTHER, gunther.name, gunther.id)); | ||
|
||
assert.equal(gunther.messages.length, 2); | ||
assert.equal( | ||
gunther.messages[1], | ||
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_FYI, russell.name, russell.id)); | ||
|
||
// (3) Russell has the ability to freeze and unfreeze themselves. | ||
assert.isTrue(await russell.issueCommand('/my freeze')); | ||
assert.isFalse(russell.controllableForTesting); | ||
|
||
assert.equal(russell.messages.length, 6); | ||
assert.includes( | ||
russell.messages[4], | ||
Message.format(Message.PLAYER_COMMANDS_FREEZE_SELF_ADMIN, russell.name, russell.id)); | ||
|
||
assert.equal(russell.messages[5], Message.PLAYER_COMMANDS_FREEZE_SELF); | ||
|
||
assert.isTrue(await russell.issueCommand('/my unfreeze')); | ||
assert.isTrue(russell.controllableForTesting); | ||
|
||
assert.equal(russell.messages.length, 8); | ||
assert.includes( | ||
russell.messages[6], | ||
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_SELF_ADMIN, russell.name, russell.id)); | ||
|
||
assert.equal(russell.messages[7], Message.PLAYER_COMMANDS_UNFREEZE_SELF); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters