Skip to content

Commit c23f11e

Browse files
committed
Add travellingVendor related events
1 parent 1dadb24 commit c23f11e

File tree

5 files changed

+99
-59
lines changed

5 files changed

+99
-59
lines changed

src/languages/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@
125125
"eventNotificationSetting-patrolHelicopterSpawned": "Patrol Helicopter Spawned",
126126
"eventNotificationSetting-travellingVendorDespawned": "Travelling Vendor Despawned",
127127
"eventNotificationSetting-travellingVendorSpawned": "Travelling Vendor Spawned",
128-
"eventNotificationSetting-travellingVendorStarted": "Travelling Vendor Started Moving",
129-
"eventNotificationSetting-travellingVendorStopped": "Travelling Vendor Stopped Moving",
130128
"eventNotificationSetting-vendingMachineDespawned": "Vending Machine Despawned",
131129
"eventNotificationSetting-vendingMachineSpawned": "Vending Machine Spawned",
132130
"expireAt": "Expire: {time}",
@@ -174,6 +172,10 @@
174172
"inGameEvent-patrolHelicopterSpawned": "Patrol Helicopter spawned at {location}.",
175173
"inGameEvent-patrolHelicopterSpawned-enters": "Patrol Helicopter enters the map from {location}.",
176174
"inGameEvent-patrolHelicopterSpawned-located": "Patrol Helicopter is located at {location}.",
175+
"inGameEvent-travellingVendorDespawned": "Travelling Vendor despawned at {location}.",
176+
"inGameEvent-travellingVendorDespawned-soon": "Travelling Vendor at {location} will leave in 5 min.",
177+
"inGameEvent-travellingVendorSpawned": "Travelling Vendor spawned at {location}.",
178+
"inGameEvent-travellingVendorSpawned-located": "Travelling Vendor is located at {location}.",
177179
"inGameEvent-vendingMachineSpawned": "A new Vending Machine located at {location}.",
178180
"inGameTime": "In-Game time: {time}.",
179181
"issuedAt": "Issued: {time}",

src/managers/guildInstanceManager.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ export interface EventNotificationSettings {
166166
patrolHelicopterLeaving: EventNotificationSetting;
167167
travellingVendorSpawned: EventNotificationSetting;
168168
travellingVendorDespawned: EventNotificationSetting;
169-
travellingVendorStopped: EventNotificationSetting;
170-
travellingVendorStarted: EventNotificationSetting;
171169
}
172170

173171
export interface EventNotificationSetting {
@@ -216,8 +214,6 @@ export interface SettingsMessages {
216214
patrolHelicopterLeaving: types.MessageId | null;
217215
travellingVendorSpawned: types.MessageId | null;
218216
travellingVendorDespawned: types.MessageId | null;
219-
travellingVendorStopped: types.MessageId | null;
220-
travellingVendorStarted: types.MessageId | null;
221217
}
222218

223219
export interface Alias {
@@ -619,9 +615,7 @@ export class GuildInstanceManager {
619615
patrolHelicopterDestroyed: null,
620616
patrolHelicopterLeaving: null,
621617
travellingVendorSpawned: null,
622-
travellingVendorDespawned: null,
623-
travellingVendorStopped: null,
624-
travellingVendorStarted: null
618+
travellingVendorDespawned: null
625619
},
626620
aliases: [],
627621
blacklist: {
@@ -1077,9 +1071,7 @@ export function isValidEventNotificationSettings(object: unknown): object is Eve
10771071
'patrolHelicopterDestroyed',
10781072
'patrolHelicopterLeaving',
10791073
'travellingVendorSpawned',
1080-
'travellingVendorDespawned',
1081-
'travellingVendorStopped',
1082-
'travellingVendorStarted'
1074+
'travellingVendorDespawned'
10831075
];
10841076

10851077
const errors: (vu.ValidationError | null)[] = [];
@@ -1116,10 +1108,6 @@ export function isValidEventNotificationSettings(object: unknown): object is Eve
11161108
isValidEventNotificationSetting));
11171109
errors.push(vu.validateInterface('travellingVendorDespawned', obj.travellingVendorDespawned,
11181110
isValidEventNotificationSetting));
1119-
errors.push(vu.validateInterface('travellingVendorStopped', obj.travellingVendorStopped,
1120-
isValidEventNotificationSetting));
1121-
errors.push(vu.validateInterface('travellingVendorStarted', obj.travellingVendorStarted,
1122-
isValidEventNotificationSetting));
11231111

11241112
const filteredErrors = errors.filter((error): error is vu.ValidationError => error !== null);
11251113

@@ -1215,9 +1203,7 @@ export function isValidSettingsMessages(object: unknown): object is SettingsMess
12151203
'patrolHelicopterDestroyed',
12161204
'patrolHelicopterLeaving',
12171205
'travellingVendorSpawned',
1218-
'travellingVendorDespawned',
1219-
'travellingVendorStopped',
1220-
'travellingVendorStarted'
1206+
'travellingVendorDespawned'
12211207
];
12221208

12231209
const errors: (vu.ValidationError | null)[] = [];
@@ -1261,8 +1247,6 @@ export function isValidSettingsMessages(object: unknown): object is SettingsMess
12611247
errors.push(vu.validateType('patrolHelicopterLeaving', obj.patrolHelicopterLeaving, 'string', null));
12621248
errors.push(vu.validateType('travellingVendorSpawned', obj.travellingVendorSpawned, 'string', null));
12631249
errors.push(vu.validateType('travellingVendorDespawned', obj.travellingVendorDespawned, 'string', null));
1264-
errors.push(vu.validateType('travellingVendorStopped', obj.travellingVendorStopped, 'string', null));
1265-
errors.push(vu.validateType('travellingVendorStarted', obj.travellingVendorStarted, 'string', null));
12661250

12671251
const filteredErrors = errors.filter((error): error is vu.ValidationError => error !== null);
12681252

src/structures/rustPlusMapMarkers.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const CARGO_SHIP_HARBOR_UNDOCKED_DISTANCE = 280;
5252
const CARGO_SHIP_LEAVE_AFTER_HARBOR_NO_CRATES_MS = 2 * 60 * 1000; /* 2 min */
5353
const CARGO_SHIP_LEAVE_AFTER_HARBOR_WITH_CRATES_MS = 19.5 * 60 * 1000; /* 19.5 min */
5454
const PATROL_HELICOPTER_LEAVING_SPEED_MIN = 400;
55+
const TRAVELLING_VENDOR_ACTIVE_TIME_MS = 30 * 60 * 1000;
5556

5657
export interface CargoShipMetaData {
5758
lockedCrateSpawnCounter: number;
@@ -90,6 +91,7 @@ export class RustPlusMapMarkers {
9091
public cargoShipEgressAfterHarbor2TimeoutIds: { [cargoShip: number]: Timer };
9192
public cargoShipLockedCrateSpawnIntervalIds: { [cargoShip: number]: NodeJS.Timeout };
9293
public cargoShipUndockingNotificationTimeoutIds: { [cargoShip: number]: NodeJS.Timeout };
94+
public travellingVendorLeavingNotificationTimeoutIds: { [travellingVendor: number]: NodeJS.Timeout };
9395

9496
public timeSinceSmallOilRigWasTriggered: Date | null;
9597
public timeSinceLargeOilRigWasTriggered: Date | null;
@@ -124,6 +126,7 @@ export class RustPlusMapMarkers {
124126
this.cargoShipEgressAfterHarbor1TimeoutIds = {}
125127
this.cargoShipLockedCrateSpawnIntervalIds = {};
126128
this.cargoShipUndockingNotificationTimeoutIds = {};
129+
this.travellingVendorLeavingNotificationTimeoutIds = {};
127130

128131
/* Event dates */
129132
this.timeSinceSmallOilRigWasTriggered = null;
@@ -715,9 +718,55 @@ export class RustPlusMapMarkers {
715718
}
716719
}
717720

718-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
719721
private updateTravellingVendors(mapMarkers: rp.AppMapMarkers) {
722+
const type = rp.AppMarkerType.TravellingVendor;
723+
const gInstance = gim.getGuildInstance(this.rpInstance.guildId) as GuildInstance;
724+
const language = gInstance.generalSettings.language;
725+
726+
const newMarkers = this.getNewMarkersById(type, mapMarkers.markers);
727+
const leftMarkers = this.getLeftMarkersById(type, mapMarkers.markers);
728+
const remainingMarkers = this.getRemainingMarkersById(type, mapMarkers.markers);
729+
730+
/* Markers that are new. */
731+
for (const marker of newMarkers) {
732+
const travellingVendorPos = getPos(marker.x, marker.y, this.rpInstance) as Position;
733+
const travellingVendorPosString = getPosString(travellingVendorPos, this.rpInstance, false, true);
734+
735+
const phrase = 'inGameEvent-travellingVendorSpawned' + (this.firstPoll ? '-located' : '');
736+
const eventText = lm.getIntl(language, phrase, { location: travellingVendorPosString });
737+
this.rpInstance.sendEventNotification('travellingVendorSpawned', eventText);
738+
739+
/* Notify 5 min before leaving */
740+
this.travellingVendorLeavingNotificationTimeoutIds[marker.id] = setTimeout(
741+
this.notifyTravellingVendorLeavingSoon.bind(this, marker.id),
742+
TRAVELLING_VENDOR_ACTIVE_TIME_MS - (5 * 60 * 1000)
743+
);
744+
745+
this.travellingVendors.push(marker);
746+
}
747+
748+
/* Markers that have left. */
749+
for (const marker of leftMarkers) {
750+
const travellingVendorPos = getPos(marker.x, marker.y, this.rpInstance) as Position;
751+
const travellingVendorPosString = getPosString(travellingVendorPos, this.rpInstance, false, true);
720752

753+
const phrase = 'inGameEvent-travellingVendorDespawned';
754+
const eventText = lm.getIntl(language, phrase, { location: travellingVendorPosString });
755+
this.rpInstance.sendEventNotification('travellingVendorDespawned', eventText);
756+
757+
if (Object.hasOwn(this.travellingVendorLeavingNotificationTimeoutIds, marker.id)) {
758+
clearTimeout(this.travellingVendorLeavingNotificationTimeoutIds[marker.id]);
759+
delete this.travellingVendorLeavingNotificationTimeoutIds[marker.id];
760+
}
761+
762+
this.travellingVendors = this.travellingVendors.filter(e => e.id !== marker.id);
763+
}
764+
765+
/* Markers that still remains. */
766+
for (const marker of remainingMarkers) {
767+
const travellingVendor = this.travellingVendors.find(e => e.id === marker.id) as rp.AppMarker;
768+
Object.assign(travellingVendor, marker);
769+
}
721770
}
722771

723772

@@ -901,4 +950,25 @@ export class RustPlusMapMarkers {
901950
delete this.cargoShipUndockingNotificationTimeoutIds[cargoShipId];
902951
}
903952
}
953+
954+
private notifyTravellingVendorLeavingSoon(travellingVendorId: number) {
955+
const gInstance = gim.getGuildInstance(this.rpInstance.guildId) as GuildInstance;
956+
const language = gInstance.generalSettings.language;
957+
958+
const travellingVendor = this.travellingVendors.find(e => e.id === travellingVendorId);
959+
if (!travellingVendor) return;
960+
961+
const travellingVendorPos = getPos(travellingVendor.x, travellingVendor.y, this.rpInstance);
962+
if (travellingVendorPos) {
963+
const travellingVendorPosString = getPosString(travellingVendorPos, this.rpInstance, false, true);
964+
const phrase = 'inGameEvent-travellingVendorDespawned-soon';
965+
const eventText = lm.getIntl(language, phrase, { location: travellingVendorPosString });
966+
this.rpInstance.sendEventNotification('travellingVendorDespawned', eventText);
967+
}
968+
969+
if (Object.hasOwn(this.travellingVendorLeavingNotificationTimeoutIds, travellingVendorId)) {
970+
clearTimeout(this.travellingVendorLeavingNotificationTimeoutIds[travellingVendorId]);
971+
delete this.travellingVendorLeavingNotificationTimeoutIds[travellingVendorId];
972+
}
973+
}
904974
}

src/templates/eventNotificationSettingsTemplate.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,5 @@
145145
"image": "travelling_vendor_logo.png",
146146
"inGame": false,
147147
"voice": true
148-
},
149-
"travellingVendorStopped": {
150-
"color": "#7FFF00",
151-
"discord": true,
152-
"image": "travelling_vendor_logo.png",
153-
"inGame": false,
154-
"voice": true
155-
},
156-
"travellingVendorStarted": {
157-
"color": "#8B008B",
158-
"discord": true,
159-
"image": "travelling_vendor_logo.png",
160-
"inGame": false,
161-
"voice": true
162148
}
163149
}

v2_todo.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,27 @@
112112
- [ ] vending machine handler
113113

114114
### RustPlus events
115-
- [ ] Vending Machine spawned
116-
- [ ] Vending Machine despawned
117-
- [ ] CH47 spawned
118-
- [ ] CH47 despawned
119-
- [ ] CH47 destroyed
120-
- [ ] Locked crate dropped
121-
- [ ] Heavy scientists called to oil rig
122-
- [ ] Locked crate unlocked at oil rig
123-
- [ ] cargoship spawned
124-
- [ ] cargoship despawned
125-
- [ ] cargoship leaving
126-
- [ ] cargoship docking
127-
- [ ] cargoship docked
128-
- [ ] cargoship undocking
129-
- [ ] cargoship locked crate spawned
130-
- [ ] patrol helicopter spawned
131-
- [ ] patrol helicopter despawned
132-
- [ ] patrol helicopter destroyed
133-
- [ ] patrol helicopter leaving
134-
- [ ] travelling vendor spawned
135-
- [ ] travelling vendor despawned
136-
- [ ] travelling vendor stopped moving
137-
- [ ] travelling vendor started moving
115+
- [x] Vending Machine spawned
116+
- [x] Vending Machine despawned
117+
- [x] CH47 spawned
118+
- [x] CH47 despawned
119+
- [x] CH47 destroyed
120+
- [x] Locked crate dropped
121+
- [x] Heavy scientists called to oil rig
122+
- [x] Locked crate unlocked at oil rig
123+
- [x] cargoship spawned
124+
- [x] cargoship despawned
125+
- [x] cargoship leaving
126+
- [x] cargoship docking
127+
- [x] cargoship docked
128+
- [x] cargoship undocking
129+
- [x] cargoship locked crate spawned
130+
- [x] patrol helicopter spawned
131+
- [x] patrol helicopter despawned
132+
- [x] patrol helicopter destroyed
133+
- [x] patrol helicopter leaving
134+
- [x] travelling vendor spawned
135+
- [x] travelling vendor despawned
138136

139137
## Trackers
140138
- [ ] Class

0 commit comments

Comments
 (0)