Skip to content

Commit 530a73d

Browse files
authored
Vendor Notification (#373)
* add travelingvendor map stuff * add traveling vendor commands for ingame and discord * fixes and img change for testing * changed the traveling vendor command from trvendor to vendor * updated image links for the discord embed * update docs for traveling vendor * changed spawned event message * add vendor image. thanks to davinator for the image * added halted and moving again setting * added missing translation * fixxed misspell * add information embed * vender -> vendor * new icon for traveling vendor (thanks to threedm on discord)
1 parent 832158c commit 530a73d

File tree

12 files changed

+180
-2
lines changed

12 files changed

+180
-2
lines changed

docs/commands.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ In-Game Command | Description
380380
[**unmute**](commands.md#unmute) | Unmute the bot from the In-Game Team Chat.
381381
[**upkeep**](commands.md#upkeep) | Get the upkeep time of all connected tool cupboard monitors.
382382
[**uptime**](commands.md#uptime-ingame) | Display uptime of the bot and server.
383+
[**vendor**](commands.md#vendor) | Get information about the Traveling Vendor (Current Location, Time since last vendor)
383384
[**wipe**](commands.md#wipe) | Get the time since it was wiped.
384385

385386

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

717718

719+
## **vendor**
720+
721+
> **Get information about the Traveling Vendor (Current Location, Time since last Traveling Vendor).**
722+
<br>Command: `!vendor`
723+
724+
![In-Game Command vendor Image](images/ingame_commands/vendor_ingame.png)
725+
726+
718727
## **wipe**
719728

720729
> **Get the time since it was wiped.**

docs/full_list_features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
- **unmute** - Unmute rustplusplus In-Game.
6161
- **upkeep** - Check upkeep of Storage Monitor Tool Cupboards.
6262
- **uptime** - Display the uptime of rustplusplus and currently connected server.
63+
- **vendor** - Get information regarding the Traveling Vendor
6364
- **wipe** - Display time since wipe.
6465

6566
## Smart Devices
138 KB
Loading

src/discordTools/discordEmbeds.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,12 +759,14 @@ module.exports = {
759759
const smallOilRigFieldName = Client.client.intlGet(guildId, 'smallOilRig');
760760
const largeOilRigFieldName = Client.client.intlGet(guildId, 'largeOilRig');
761761
const chinook47FieldName = Client.client.intlGet(guildId, 'chinook47');
762+
const travelingVendorFieldName = Client.client.intlGet(guildId, 'travelingVendor');
762763

763764
const cargoShipMessage = rustplus.getCommandCargo(true);
764765
const patrolHelicopterMessage = rustplus.getCommandHeli(true);
765766
const smallOilMessage = rustplus.getCommandSmall(true);
766767
const largeOilMessage = rustplus.getCommandLarge(true);
767768
const ch47Message = rustplus.getCommandChinook(true);
769+
const travelingVendorMessage = rustplus.getCommandTravelingVendor(true);
768770

769771
return module.exports.getEmbed({
770772
title: Client.client.intlGet(guildId, 'eventInfo'),
@@ -777,7 +779,8 @@ module.exports = {
777779
{ name: patrolHelicopterFieldName, value: `\`${patrolHelicopterMessage}\``, inline: true },
778780
{ name: smallOilRigFieldName, value: `\`${smallOilMessage}\``, inline: true },
779781
{ name: largeOilRigFieldName, value: `\`${largeOilMessage}\``, inline: true },
780-
{ name: chinook47FieldName, value: `\`${ch47Message}\``, inline: true }],
782+
{ name: chinook47FieldName, value: `\`${ch47Message}\``, inline: true },
783+
{ name: travelingVendorFieldName, value: `\`${travelingVendorMessage}\``, inline: true }],
781784
timestamp: true
782785
});
783786
},

src/handlers/discordCommandHandler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ module.exports = {
200200
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxWipe')}`) {
201201
response = rustplus.getCommandWipe();
202202
}
203+
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxTravelingVendor')}` ||
204+
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxTravelingVendor')}`) {
205+
response = rustplus.getCommandTravelingVendor();
206+
}
203207
else {
204208
/* Smart Switches/ Group Switches are not currently supported through discord. */
205209
return false;

src/handlers/inGameCommandHandler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ module.exports = {
207207
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxWipe')}`) {
208208
rustplus.sendInGameMessage(rustplus.getCommandWipe());
209209
}
210+
else if (commandLowerCase === `${prefix}${client.intlGet('en', 'commandSyntaxTravelingVendor')}` ||
211+
commandLowerCase === `${prefix}${client.intlGet(guildId, 'commandSyntaxTravelingVendor')}`) {
212+
rustplus.sendInGameMessage(rustplus.getCommandTravelingVendor());
213+
}
210214
else {
211215
/* Maybe a custom command? */
212216

src/languages/en.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"commandSyntaxTimers": "timers",
161161
"commandSyntaxTranslateFromTo": "trf",
162162
"commandSyntaxTranslateTo": "tr",
163+
"commandSyntaxTravelingVendor": "vendor",
163164
"commandSyntaxTwig": "twig",
164165
"commandSyntaxUnmute": "unmute",
165166
"commandSyntaxUnsubscribe": "unsub",
@@ -708,6 +709,7 @@
708709
"timeSinceLastSinceDestroyedLong": "{time1} since the last Patrol Helicopter was on the map, {time2} since it last got downed{location}.",
709710
"timeSinceLastSinceDestroyedShort": "{time1} since last.\n{time2} since destroyed{location}.",
710711
"timeSincePatrolHelicopterWasOnMap": "{time} since the Patrol Helicopter was on the map.",
712+
"timeSinceTravelingVendorWasOnMap": "{time} since the Traveling Vendor was on the map.",
711713
"timeSinceWipe": "{time} since wipe.",
712714
"timeTill": "Time till {event}",
713715
"timeTillDaylight": "{time} before daylight.",
@@ -727,6 +729,16 @@
727729
"trackerRemovePlayerDesc": "Remove Player from {tracker}",
728730
"trademarkShownBeforeMessage": "{trademark} will be shown before messages.",
729731
"trainYard": "Train Yard",
732+
"travelingVendor": "Traveling Vendor",
733+
"travelingVendorDetectedSetting": "When the Traveling Vendor is detected, send a notification.",
734+
"travelingVendorHaltedAt": "The Traveling Vendor stopped at {location}.",
735+
"travelingVendorHaltedSetting": "When the Traveling Vendor stops moving, send a notification.",
736+
"travelingVendorLeftSetting": "When the Traveling Vendor left the map, send a notification.",
737+
"travelingVendorLocatedAt": "The Traveling Vendor is located at {location}.",
738+
"travelingVendorLeftMap" : "The Traveling Vendor just left the map at {location}.",
739+
"travelingVendorNotCurrentlyOnMap": "The Traveling Vendor is not currently on the map.",
740+
"travelingVendorResumedAt": "The Traveling Vendor resumed moving at {location}.",
741+
"travelingVendorSpawnedAt": "The Traveling Vendor spawned at {location}.",
730742
"turnOffCap": "TURN OFF",
731743
"turnOnCap": "TURN ON",
732744
"turningGroupOnOff": "Turning Group {group} {status}.",
15.1 KB
Loading

src/structures/MapMarkers.js

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class MapMarkers {
3737
CargoShip: 5,
3838
Crate: 6,
3939
GenericRadius: 7,
40-
PatrolHelicopter: 8
40+
PatrolHelicopter: 8,
41+
TravelingVendor: 9
4142
}
4243

4344
this._players = [];
@@ -46,6 +47,7 @@ class MapMarkers {
4647
this._cargoShips = [];
4748
this._genericRadiuses = [];
4849
this._patrolHelicopters = [];
50+
this._travelingVendors = [];
4951

5052
/* Timers */
5153
this.cargoShipEgressTimers = new Object();
@@ -61,6 +63,7 @@ class MapMarkers {
6163
this.timeSinceLargeOilRigWasTriggered = null;
6264
this.timeSincePatrolHelicopterWasOnMap = null;
6365
this.timeSincePatrolHelicopterWasDestroyed = null;
66+
this.timeSinceTravelingVendorWasOnMap = null;
6467

6568
/* Event location */
6669
this.patrolHelicopterDestroyedLocation = null;
@@ -92,6 +95,8 @@ class MapMarkers {
9295
set genericRadiuses(genericRadiuses) { this._genericRadiuses = genericRadiuses; }
9396
get patrolHelicopters() { return this._patrolHelicopters; }
9497
set patrolHelicopters(patrolHelicopters) { this._patrolHelicopters = patrolHelicopters; }
98+
get travelingVendors() { return this._travelingVendors; }
99+
set travelingVendors(travelingVendors) { this._travelingVendors = travelingVendors; }
95100

96101
getType(type) {
97102
if (!Object.values(this.types).includes(type)) {
@@ -123,6 +128,10 @@ class MapMarkers {
123128
return this.patrolHelicopters;
124129
} break;
125130

131+
case this.types.TravelingVendor: {
132+
return this.travelingVendors;
133+
} break;
134+
126135
default: {
127136
return null;
128137
} break;
@@ -254,6 +263,7 @@ class MapMarkers {
254263
this.updateCH47s(mapMarkers);
255264
this.updateVendingMachines(mapMarkers);
256265
this.updateGenericRadiuses(mapMarkers);
266+
this.updateTravelingVendors(mapMarkers);
257267
}
258268

259269
updatePlayers(mapMarkers) {
@@ -701,6 +711,75 @@ class MapMarkers {
701711
}
702712
}
703713

714+
updateTravelingVendors(mapMarkers) {
715+
let newMarkers = this.getNewMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);
716+
let leftMarkers = this.getLeftMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);
717+
let remainingMarkers = this.getRemainingMarkersOfTypeId(this.types.TravelingVendor, mapMarkers.markers);
718+
719+
/* TravelingVendor markers that are new. */
720+
for (let marker of newMarkers) {
721+
let mapSize = this.rustplus.info.correctedMapSize;
722+
let pos = Map.getPos(marker.x, marker.y, mapSize, this.rustplus);
723+
724+
marker.location = pos;
725+
marker.isHalted = false;
726+
727+
this.rustplus.sendEvent(
728+
this.rustplus.notificationSettings.travelingVendorDetectedSetting,
729+
this.client.intlGet(this.rustplus.guildId, 'travelingVendorSpawnedAt', { location: pos.string }),
730+
'vendor',
731+
Constants.COLOR_TRAVELING_VENDOR_LOCATED_AT);
732+
733+
this.travelingVendors.push(marker);
734+
}
735+
736+
/* TravelingVendor markers that have left. */
737+
for (let marker of leftMarkers) {
738+
this.rustplus.sendEvent(
739+
this.rustplus.notificationSettings.travelingVendorLeftSetting,
740+
this.client.intlGet(this.rustplus.guildId, 'travelingVendorLeftMap', { location: marker.location.string }),
741+
'vendor',
742+
Constants.COLOR_TRAVELING_VENDOR_LEFT_MAP);
743+
744+
this.timeSinceTravelingVendorWasOnMap = new Date();
745+
746+
this.travelingVendors = this.travelingVendors.filter(e => e.id !== marker.id);
747+
}
748+
749+
/* TravelingVendor markers that still remains. */
750+
for (let marker of remainingMarkers) {
751+
let mapSize = this.rustplus.info.correctedMapSize;
752+
let pos = Map.getPos(marker.x, marker.y, mapSize, this.rustplus);
753+
let travelingVendor = this.getMarkerByTypeId(this.types.TravelingVendor, marker.id);
754+
755+
/* If TravelingVendor is halted */
756+
if (!this.rustplus.isFirstPoll && !travelingVendor.isHalted) {
757+
if (marker.x === travelingVendor.x && marker.y === travelingVendor.y) {
758+
travelingVendor.isHalted = true;
759+
this.rustplus.sendEvent(
760+
this.rustplus.notificationSettings.travelingVendorHaltedSetting,
761+
this.client.intlGet(this.rustplus.guildId, 'travelingVendorHaltedAt', { location: pos.string }),
762+
'vendor',
763+
Constants.COLOR_TRAVELING_VENDOR_HALTED);
764+
}
765+
}
766+
/* If TravelingVendor is moving again */
767+
else if (!this.rustplus.isFirstPoll && travelingVendor.isHalted) {
768+
if (marker.x !== travelingVendor.x || marker.y !== travelingVendor.y) {
769+
travelingVendor.isHalted = false;
770+
this.rustplus.sendEvent(
771+
this.rustplus.notificationSettings.travelingVendorHaltedSetting,
772+
this.client.intlGet(this.rustplus.guildId, 'travelingVendorResumedAt', { location: pos.string }),
773+
'vendor',
774+
Constants.COLOR_TRAVELING_VENDOR_MOVING);
775+
}
776+
}
777+
travelingVendor.x = marker.x;
778+
travelingVendor.y = marker.y;
779+
travelingVendor.location = pos;
780+
}
781+
}
782+
704783

705784

706785
/* Timer notification functions */
@@ -784,6 +863,7 @@ class MapMarkers {
784863
this.cargoShips = [];
785864
this.genericRadiuses = [];
786865
this.patrolHelicopters = [];
866+
this.travelingVendors = [];
787867

788868
for (const [id, timer] of Object.entries(this.cargoShipEgressTimers)) {
789869
timer.stop();
@@ -804,6 +884,7 @@ class MapMarkers {
804884
this.timeSinceLargeOilRigWasTriggered = null;
805885
this.timeSincePatrolHelicopterWasOnMap = null;
806886
this.timeSincePatrolHelicopterWasDestroyed = null;
887+
this.timeSinceTravelingVendorWasOnMap = null;
807888

808889
this.patrolHelicopterDestroyedLocation = null;
809890

src/structures/RustPlus.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,48 @@ class RustPlus extends RustPlusLib {
27042704
});
27052705
}
27062706
}
2707+
2708+
getCommandTravelingVendor(isInfoChannel = false) {
2709+
const strings = [];
2710+
for (const travelingVendor of this.mapMarkers.travelingVendors) {
2711+
if (isInfoChannel) {
2712+
return Client.client.intlGet(this.guildId, 'atLocation', {
2713+
location: travelingVendor.location.string
2714+
});
2715+
}
2716+
else {
2717+
strings.push(Client.client.intlGet(this.guildId, 'travelingVendorLocatedAt', {
2718+
location: travelingVendor.location.string
2719+
}));
2720+
}
2721+
}
2722+
2723+
if (strings.length === 0) {
2724+
const wasOnMap = this.mapMarkers.timeSinceTravelingVendorWasOnMap;
2725+
2726+
if (wasOnMap == null) {
2727+
return isInfoChannel ? Client.client.intlGet(this.guildId, 'notActive') :
2728+
Client.client.intlGet(this.guildId, 'travelingVendorNotCurrentlyOnMap');
2729+
}
2730+
else if (wasOnMap !== null) {
2731+
const secondsSince = (new Date() - wasOnMap) / 1000;
2732+
if (isInfoChannel) {
2733+
const timeSince = Timer.secondsToFullScale(secondsSince, 's');
2734+
return Client.client.intlGet(this.guildId, 'timeSinceLast', {
2735+
time: timeSince
2736+
});
2737+
}
2738+
else {
2739+
const timeSince = Timer.secondsToFullScale(secondsSince);
2740+
return Client.client.intlGet(this.guildId, 'timeSinceTravelingVendorWasOnMap', {
2741+
time: timeSince
2742+
});
2743+
}
2744+
}
2745+
}
2746+
2747+
return strings;
2748+
}
27072749
}
27082750

27092751
module.exports = RustPlus;

0 commit comments

Comments
 (0)