Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor Notification #373

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ In-Game Command | Description
[**unmute**](commands.md#unmute) | Unmute the bot from the In-Game Team Chat.
[**upkeep**](commands.md#upkeep) | Get the upkeep time of all connected tool cupboard monitors.
[**uptime**](commands.md#uptime-ingame) | Display uptime of the bot and server.
[**vendor**](commands.md#vendor) | Get information about the Traveling Vendor (Current Location, Time since last vendor)
[**wipe**](commands.md#wipe) | Get the time since it was wiped.


Expand Down Expand Up @@ -715,6 +716,14 @@ Subcommand | Description | Required
![In-Game Command uptime Image](images/ingame_commands/uptime_ingame.png)


## **vendor**

> **Get information about the Traveling Vendor (Current Location, Time since last Traveling Vendor).**
<br>Command: `!vendor`

![In-Game Command vendor Image](images/ingame_commands/vendor_ingame.png)


## **wipe**

> **Get the time since it was wiped.**
Expand Down
1 change: 1 addition & 0 deletions docs/full_list_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- **unmute** - Unmute rustplusplus In-Game.
- **upkeep** - Check upkeep of Storage Monitor Tool Cupboards.
- **uptime** - Display the uptime of rustplusplus and currently connected server.
- **vendor** - Get information regarding the Traveling Vendor
- **wipe** - Display time since wipe.

## Smart Devices
Expand Down
Binary file added docs/images/ingame_commands/vendor_ingame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/discordTools/discordEmbeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,14 @@ module.exports = {
const smallOilRigFieldName = Client.client.intlGet(guildId, 'smallOilRig');
const largeOilRigFieldName = Client.client.intlGet(guildId, 'largeOilRig');
const chinook47FieldName = Client.client.intlGet(guildId, 'chinook47');
const travelingVendorFieldName = Client.client.intlGet(guildId, 'travelingVendor');

const cargoShipMessage = rustplus.getCommandCargo(true);
const patrolHelicopterMessage = rustplus.getCommandHeli(true);
const smallOilMessage = rustplus.getCommandSmall(true);
const largeOilMessage = rustplus.getCommandLarge(true);
const ch47Message = rustplus.getCommandChinook(true);
const travelingVendorMessage = rustplus.getCommandTravelingVendor(true);

return module.exports.getEmbed({
title: Client.client.intlGet(guildId, 'eventInfo'),
Expand All @@ -777,7 +779,8 @@ module.exports = {
{ name: patrolHelicopterFieldName, value: `\`${patrolHelicopterMessage}\``, inline: true },
{ name: smallOilRigFieldName, value: `\`${smallOilMessage}\``, inline: true },
{ name: largeOilRigFieldName, value: `\`${largeOilMessage}\``, inline: true },
{ name: chinook47FieldName, value: `\`${ch47Message}\``, inline: true }],
{ name: chinook47FieldName, value: `\`${ch47Message}\``, inline: true },
{ name: travelingVendorFieldName, value: `\`${travelingVendorMessage}\``, inline: true }],
timestamp: true
});
},
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/discordCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ module.exports = {
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxWipe')}`) {
response = rustplus.getCommandWipe();
}
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxTravelingVendor')}` ||
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxTravelingVendor')}`) {
response = rustplus.getCommandTravelingVendor();
}
else {
/* Smart Switches/ Group Switches are not currently supported through discord. */
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/inGameCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ module.exports = {
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxWipe')}`) {
rustplus.sendInGameMessage(rustplus.getCommandWipe());
}
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxTravelingVendor')}` ||
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxTravelingVendor')}`) {
rustplus.sendInGameMessage(rustplus.getCommandTravelingVendor());
}
else {
/* Maybe a custom command? */

Expand Down
12 changes: 12 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"commandSyntaxTimers": "timers",
"commandSyntaxTranslateFromTo": "trf",
"commandSyntaxTranslateTo": "tr",
"commandSyntaxTravelingVendor": "vendor",
"commandSyntaxTwig": "twig",
"commandSyntaxUnmute": "unmute",
"commandSyntaxUnsubscribe": "unsub",
Expand Down Expand Up @@ -708,6 +709,7 @@
"timeSinceLastSinceDestroyedLong": "{time1} since the last Patrol Helicopter was on the map, {time2} since it last got downed{location}.",
"timeSinceLastSinceDestroyedShort": "{time1} since last.\n{time2} since destroyed{location}.",
"timeSincePatrolHelicopterWasOnMap": "{time} since the Patrol Helicopter was on the map.",
"timeSinceTravelingVendorWasOnMap": "{time} since the Traveling Vendor was on the map.",
"timeSinceWipe": "{time} since wipe.",
"timeTill": "Time till {event}",
"timeTillDaylight": "{time} before daylight.",
Expand All @@ -727,6 +729,16 @@
"trackerRemovePlayerDesc": "Remove Player from {tracker}",
"trademarkShownBeforeMessage": "{trademark} will be shown before messages.",
"trainYard": "Train Yard",
"travelingVendor": "Traveling Vendor",
"travelingVendorDetectedSetting": "When the Traveling Vendor is detected, send a notification.",
"travelingVendorHaltedAt": "The Traveling Vendor stopped at {location}.",
"travelingVendorHaltedSetting": "When the Traveling Vendor stops moving, send a notification.",
"travelingVendorLeftSetting": "When the Traveling Vendor left the map, send a notification.",
"travelingVendorLocatedAt": "The Traveling Vendor is located at {location}.",
"travelingVendorLeftMap" : "The Traveling Vendor just left the map at {location}.",
"travelingVendorNotCurrentlyOnMap": "The Traveling Vendor is not currently on the map.",
"travelingVendorResumedAt": "The Traveling Vendor resumed moving at {location}.",
"travelingVendorSpawnedAt": "The Traveling Vendor spawned at {location}.",
"turnOffCap": "TURN OFF",
"turnOnCap": "TURN ON",
"turningGroupOnOff": "Turning Group {group} {status}.",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 82 additions & 1 deletion src/structures/MapMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class MapMarkers {
CargoShip: 5,
Crate: 6,
GenericRadius: 7,
PatrolHelicopter: 8
PatrolHelicopter: 8,
TravelingVendor: 9
}

this._players = [];
Expand All @@ -46,6 +47,7 @@ class MapMarkers {
this._cargoShips = [];
this._genericRadiuses = [];
this._patrolHelicopters = [];
this._travelingVendors = [];

/* Timers */
this.cargoShipEgressTimers = new Object();
Expand All @@ -61,6 +63,7 @@ class MapMarkers {
this.timeSinceLargeOilRigWasTriggered = null;
this.timeSincePatrolHelicopterWasOnMap = null;
this.timeSincePatrolHelicopterWasDestroyed = null;
this.timeSinceTravelingVendorWasOnMap = null;

/* Event location */
this.patrolHelicopterDestroyedLocation = null;
Expand Down Expand Up @@ -92,6 +95,8 @@ class MapMarkers {
set genericRadiuses(genericRadiuses) { this._genericRadiuses = genericRadiuses; }
get patrolHelicopters() { return this._patrolHelicopters; }
set patrolHelicopters(patrolHelicopters) { this._patrolHelicopters = patrolHelicopters; }
get travelingVendors() { return this._travelingVendors; }
set travelingVendors(travelingVendors) { this._travelingVendors = travelingVendors; }

getType(type) {
if (!Object.values(this.types).includes(type)) {
Expand Down Expand Up @@ -123,6 +128,10 @@ class MapMarkers {
return this.patrolHelicopters;
} break;

case this.types.TravelingVendor: {
return this.travelingVendors;
} break;

default: {
return null;
} break;
Expand Down Expand Up @@ -254,6 +263,7 @@ class MapMarkers {
this.updateCH47s(mapMarkers);
this.updateVendingMachines(mapMarkers);
this.updateGenericRadiuses(mapMarkers);
this.updateTravelingVendors(mapMarkers);
}

updatePlayers(mapMarkers) {
Expand Down Expand Up @@ -701,6 +711,75 @@ class MapMarkers {
}
}

updateTravelingVendors(mapMarkers) {
let newMarkers = this.getNewMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);
let leftMarkers = this.getLeftMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);
let remainingMarkers = this.getRemainingMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);

/* TravelingVendor markers that are new. */
for (let marker of newMarkers) {
let mapSize = this.rustplus.info.correctedMapSize;
let pos = Map.getPos(marker.x, marker.y, mapSize, this.rustplus);

marker.location = pos;
marker.isHalted = false;

this.rustplus.sendEvent(
this.rustplus.notificationSettings.travelingVendorDetectedSetting,
this.client.intlGet(this.rustplus.guildId, 'travelingVendorSpawnedAt', { location: pos.string }),
'vendor',
Constants.COLOR_TRAVELING_VENDOR_LOCATED_AT);

this.travelingVendors.push(marker);
}

/* TravelingVendor markers that have left. */
for (let marker of leftMarkers) {
this.rustplus.sendEvent(
this.rustplus.notificationSettings.travelingVendorLeftSetting,
this.client.intlGet(this.rustplus.guildId, 'travelingVendorLeftMap', { location: marker.location.string }),
'vendor',
Constants.COLOR_TRAVELING_VENDOR_LEFT_MAP);

this.timeSinceTravelingVendorWasOnMap = new Date();

this.travelingVendors = this.travelingVendors.filter(e => e.id !== marker.id);
}

/* TravelingVendor markers that still remains. */
for (let marker of remainingMarkers) {
let mapSize = this.rustplus.info.correctedMapSize;
let pos = Map.getPos(marker.x, marker.y, mapSize, this.rustplus);
let travelingVendor = this.getMarkerByTypeId(this.types.TravelingVendor, marker.id);

/* If TravelingVendor is halted */
if (!this.rustplus.isFirstPoll && !travelingVendor.isHalted) {
if (marker.x === travelingVendor.x && marker.y === travelingVendor.y) {
travelingVendor.isHalted = true;
this.rustplus.sendEvent(
this.rustplus.notificationSettings.travelingVendorHaltedSetting,
this.client.intlGet(this.rustplus.guildId, 'travelingVendorHaltedAt', { location: pos.string }),
'vendor',
Constants.COLOR_TRAVELING_VENDOR_HALTED);
}
}
/* If TravelingVendor is moving again */
else if (!this.rustplus.isFirstPoll && travelingVendor.isHalted) {
if (marker.x !== travelingVendor.x || marker.y !== travelingVendor.y) {
travelingVendor.isHalted = false;
this.rustplus.sendEvent(
this.rustplus.notificationSettings.travelingVendorHaltedSetting,
this.client.intlGet(this.rustplus.guildId, 'travelingVendorResumedAt', { location: pos.string }),
'vendor',
Constants.COLOR_TRAVELING_VENDOR_MOVING);
}
}
travelingVendor.x = marker.x;
travelingVendor.y = marker.y;
travelingVendor.location = pos;
}
}



/* Timer notification functions */
Expand Down Expand Up @@ -784,6 +863,7 @@ class MapMarkers {
this.cargoShips = [];
this.genericRadiuses = [];
this.patrolHelicopters = [];
this.travelingVendors = [];

for (const [id, timer] of Object.entries(this.cargoShipEgressTimers)) {
timer.stop();
Expand All @@ -804,6 +884,7 @@ class MapMarkers {
this.timeSinceLargeOilRigWasTriggered = null;
this.timeSincePatrolHelicopterWasOnMap = null;
this.timeSincePatrolHelicopterWasDestroyed = null;
this.timeSinceTravelingVendorWasOnMap = null;

this.patrolHelicopterDestroyedLocation = null;

Expand Down
42 changes: 42 additions & 0 deletions src/structures/RustPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,48 @@ class RustPlus extends RustPlusLib {
});
}
}

getCommandTravelingVendor(isInfoChannel = false) {
const strings = [];
for (const travelingVendor of this.mapMarkers.travelingVendors) {
if (isInfoChannel) {
return Client.client.intlGet(this.guildId, 'atLocation', {
location: travelingVendor.location.string
});
}
else {
strings.push(Client.client.intlGet(this.guildId, 'travelingVendorLocatedAt', {
location: travelingVendor.location.string
}));
}
}

if (strings.length === 0) {
const wasOnMap = this.mapMarkers.timeSinceTravelingVendorWasOnMap;

if (wasOnMap == null) {
return isInfoChannel ? Client.client.intlGet(this.guildId, 'notActive') :
Client.client.intlGet(this.guildId, 'travelingVendorNotCurrentlyOnMap');
}
else if (wasOnMap !== null) {
const secondsSince = (new Date() - wasOnMap) / 1000;
if (isInfoChannel) {
const timeSince = Timer.secondsToFullScale(secondsSince, 's');
return Client.client.intlGet(this.guildId, 'timeSinceLast', {
time: timeSince
});
}
else {
const timeSince = Timer.secondsToFullScale(secondsSince);
return Client.client.intlGet(this.guildId, 'timeSinceTravelingVendorWasOnMap', {
time: timeSince
});
}
}
}

return strings;
}
}

module.exports = RustPlus;
18 changes: 18 additions & 0 deletions src/templates/notificationSettingsTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@
"inGame": false,
"voice": true
},
"travelingVendorDetectedSetting": {
"image": "traveling_vendor_logo.png",
"discord": true,
"inGame": false,
"voice": true
},
"travelingVendorHaltedSetting": {
"image": "traveling_vendor_logo.png",
"discord": true,
"inGame": false,
"voice": true
},
"travelingVendorLeftSetting": {
"image": "traveling_vendor_logo.png",
"discord": true,
"inGame": false,
"voice": true
},
"vendingMachineDetectedSetting": {
"image": "vending_machine_logo.png",
"discord": true,
Expand Down
4 changes: 4 additions & 0 deletions src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ module.exports = {
COLOR_PATROL_HELICOPTER_TRACER: '#00FF00',
COLOR_SETTINGS: '#861C0C',
COLOR_TEAMCHAT_DEFAULT: '#CE412B',
COLOR_TRAVELING_VENDOR_HALTED: '#98C4D8',
COLOR_TRAVELING_VENDOR_LOCATED_AT: '#F4A3E2',
COLOR_TRAVELING_VENDOR_LEFT_MAP: '#5A3E9A',
COLOR_TRAVELING_VENDOR_MOVING: '#7FCE41',

GET_STEAM_PROFILE_LINK: function (steamId) {
return `[${steamId}](${this.STEAM_PROFILES_URL}${steamId})`;
Expand Down