Skip to content
Permalink
Browse files
Add a command to see available /benefits
Fixes #698
  • Loading branch information
RussellLVP committed Aug 6, 2020
1 parent 7d7f217 commit 861b26be9aca868ad59203e965737dd1846b4e7f
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 39 deletions.
@@ -11,8 +11,8 @@ import { CollectableDatabase } from 'features/collectables/collectable_database.

// Spray Tag achievements: awarded when the player gathers { 10, 40, 90, 100 } spray tags.
export const kAchievementSprayTagBronze = 1; // kBenefitBasicSprayQuickVehicleAccess
export const kAchievementSprayTagSilver = 2;
export const kAchievementSprayTagGold = 3; // kBenefitBombShop
export const kAchievementSprayTagSilver = 2; // kBenefitBombShop
export const kAchievementSprayTagGold = 3;
export const kAchievementSprayTagPlatinum = 4; // kBenefitFullQuickVehicleAccess

// Red Barrel achievements: awarded when the player gathers { 10, 40, 90, 100 } red barrels.
@@ -0,0 +1,85 @@
// 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 * as achievements from 'features/collectables/achievements.js';

// Whether a player is able to use the quick vehicle commands. (/nrg & co.)
export const kBenefitBasicSprayQuickVehicleAccess = 0;
export const kBenefitBasicBarrelQuickVehicleAccess = 1;
export const kBenefitFullQuickVehicleAccess = 2;

// Whether a player is able to use the bomb shop.
export const kBenefitBombShop = 3;

// Whether a player can use the vehicle colour changing keys.
export const kBenefitVehicleKeysColour = 4;

// Whether a player can use the vehicle jump keys outside of Las Venturas.
export const kBenefitVehicleKeysJump = 5;

// Whether a player can use the vehicle nitro key outside of Las Venturas.
export const kBenefitVehicleKeysNitro = 6;

// Whether a player can use the vehicle gravity key outside of Las Venturas.
export const kBenefitVehicleKeysGravity = 7;

// Mapping of which benefits map to having to obtain which achievements.
export const kBenefits = new Map([
[
kBenefitBasicSprayQuickVehicleAccess,
{
achievement: achievements.kAchievementSprayTagBronze,
name: 'Spawn /pre and /sul vehicles',
}
],
[
kBenefitBasicBarrelQuickVehicleAccess,
{
achievement: achievements.kAchievementRedBarrelBronze,
name: 'Spawn /ele and /tur vehicles',
}
],
[
kBenefitFullQuickVehicleAccess,
{
achievement: achievements.kAchievementSprayTagPlatinum,
name: 'Spawn /inf and /nrg vehicles',
}
],
[
kBenefitBombShop,
{
achievement: achievements.kAchievementSprayTagSilver,
name: 'Ability to use the Bomb Shop',
}
],
[
kBenefitVehicleKeysColour,
{
achievement: achievements.kAchievementRedBarrelSilver,
name: `Vehicle Key to change colours`,
}
],
[
kBenefitVehicleKeysJump,
{
achievement: achievements.kAchievementRedBarrelPlatinum,
name: `Vehicle Key to jump your vehicle`,
}
],
[
kBenefitVehicleKeysNitro,
{
achievement: achievements.kAchievementReactionTestSilver,
name: `Vehicle Key to add nitro`,
}
],
[
kBenefitVehicleKeysGravity,
{
achievement: achievements.kAchievementTreasuresPlatinium,
name: `Vehicle Key to invert gravity`,
}
]
]);

This file was deleted.

@@ -9,6 +9,7 @@ import { Menu } from 'components/menu/menu.js';
import { Treasures } from 'features/collectables/treasures.js';

import { kAchievements } from 'features/collectables/achievements.js';
import { kBenefits } from 'features/collectables/benefits.js';

import { alert } from 'components/dialogs/alert.js';
import { confirm } from 'components/dialogs/confirm.js';
@@ -51,6 +52,15 @@ export class CollectableCommands {
.description('Status and hints for collecting Red Barrels.')
.build(CollectableCommands.prototype.onSpecificSeriesCommand.bind(this, 'barrels'));

// /benefits [player]?
server.commandManager.buildCommand('benefits')
.description('Displays the available benefits you can collect.')
.sub(CommandBuilder.kTypePlayer, 'player')
.description('Displays information about benefits available to another player.')
.restrict(Player.LEVEL_ADMINISTRATOR)
.build(CollectableCommands.prototype.onBenefitsCommand.bind(this))
.build(CollectableCommands.prototype.onBenefitsCommand.bind(this));

// /collectables
server.commandManager.buildCommand('collectables')
.description('Status and hints for all available collectables.')
@@ -96,6 +106,39 @@ export class CollectableCommands {

// ---------------------------------------------------------------------------------------------

// /benefits [player]?
//
// Displays information about the benefits that are available on the server, and which of the
// achievements are able to unlock them. Will highlight benefits already obtained.
async onBenefitsCommand(currentPlayer, targetPlayer) {
const player = targetPlayer || currentPlayer;
const dialog = new Menu('Benefits', [
'Name',
'Description',

], { pageSize: 25 });

const achievements = this.manager_.getDelegate(CollectableDatabase.kAchievement);
const benefits = [ ...kBenefits ];

// Sort the |benefits| alphabetically by their name, to have a point of recognition.
benefits.sort((lhs, rhs) => lhs[1].name.localeCompare(rhs[1].name));

for (const [ benefit, info ] of benefits) {
const achievement = kAchievements.get(info.achievement);
const achieved =
achievements.hasAchievement(player, info.achievement, /* round= */ false);

const colour = achieved ? '{FFFF00}' : '{CCCCCC}';

dialog.addItem(colour + info.name, colour + achievement.text);
}

await dialog.displayForPlayer(currentPlayer);
}

// ---------------------------------------------------------------------------------------------

// /collectables
//
// Shows players the base of the /collectables command, which displays a dialog with options
@@ -410,6 +453,7 @@ export class CollectableCommands {
dispose() {
server.commandManager.removeCommand('treasures');
server.commandManager.removeCommand('tags');
server.commandManager.removeCommand('benefits');
server.commandManager.removeCommand('barrels');

server.commandManager.removeCommand('collectables');
@@ -63,6 +63,16 @@ describe('CollectableCommands', (it, beforeEach) => {
assert.deepEqual(gunther.getLastDialogAsTable(), directResult);
});

it('should be able to display the available benefits', async (assert) => {
// (1) Executing the /benefits command.
gunther.respondToDialog({ response: 0 /* Dismiss */ });

assert.isTrue(await gunther.issueCommand('/benefits'));
console.log(gunther.getLastDialogAsTable());

assert.isTrue(false);
});

it('should enable players to read the instructions for a series', async (assert) => {
gunther.respondToDialog({ listitem: 1 /* Red Barrels */ }).then(
() => gunther.respondToDialog({ listitem: 0 /* Instructions */ })).then(
@@ -7,18 +7,7 @@ import { CollectableDatabase } from 'features/collectables/collectable_database.
import { CollectableManager } from 'features/collectables/collectable_manager.js';
import { Feature } from 'components/feature_manager/feature.js';

import * as achievements from 'features/collectables/achievements.js';
import * as benefits from 'features/collectables/collectable_benefits.js';

// Mapping of which benefits map to having to obtain which achievements.
const kBenefitMapping = new Map([
[ benefits.kBenefitBasicSprayQuickVehicleAccess, achievements.kAchievementSprayTagBronze ],
[ benefits.kBenefitBasicBarrelQuickVehicleAccess, achievements.kAchievementRedBarrelBronze ],
[ benefits.kBenefitFullQuickVehicleAccess, achievements.kAchievementSprayTagPlatinum ],
[ benefits.kBenefitBombShop, achievements.kAchievementSprayTagSilver ],
[ benefits.kBenefitVehicleKeysColour, achievements.kAchievementRedBarrelSilver ],
[ benefits.kBenefitVehicleKeysJump, achievements.kAchievementRedBarrelPlatinum ],
]);
import { kBenefits } from 'features/collectables/benefits.js';

// Implementation of the Red Barrels feature, which scatters a series of barrels throughout San
// Andreas that players can "collect" by blowing them up.
@@ -86,7 +75,9 @@ export default class Collectables extends Feature {
// tied to a particular achievement that can be awarded to the |player|. This method is the
// canonical place for such associations to live, used by both JavaScript and Pawn code.
isPlayerEligibleForBenefit(player, benefit) {
const requiredAchievement = kBenefitMapping.get(benefit);
const mapping = kBenefits.get(benefit);
const requiredAchievement = mapping?.achievement;

const achievements = this.manager_.getDelegate(CollectableDatabase.kAchievement);

// Allow the |benefit| if the requirements are not known, otherwise it's unachievable.
@@ -6,7 +6,7 @@ import { CommandBuilder } from 'components/commands/command_builder.js';
import { Menu } from 'components/menu/menu.js';
import { VehicleModel } from 'entities/vehicle_model.js';

import * as benefits from 'features/collectables/collectable_benefits.js';
import * as benefits from 'features/collectables/benefits.js';
import { toSafeInteger } from 'base/string_util.js';
import { Message } from 'base/message.js';

0 comments on commit 861b26b

Please sign in to comment.