Skip to content

Commit f10aaea

Browse files
committed
Add cargoship related events
1 parent a30cb00 commit f10aaea

File tree

8 files changed

+511
-39
lines changed

8 files changed

+511
-39
lines changed

src/languages/en.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@
146146
"hbhfSensor": "HBHF Sensor",
147147
"heater": "Heater",
148148
"id": "ID",
149+
"inGameEvent-cargoShipDespawned": "Cargo Ship left the map at {location}.",
150+
"inGameEvent-cargoShipDocked": "Cargo Ship is docked at {location} ({grid}).",
151+
"inGameEvent-cargoShipDocking": "Cargo Ship is docking at {location} ({grid}).",
152+
"inGameEvent-cargoShipLeaving": "Cargo Ship is leaving the map at {location}.",
153+
"inGameEvent-cargoShipLeaving-inTime": "Cargo Ship will leave in {min} min.",
154+
"inGameEvent-cargoShipLeaving-maybe": "Cargo Ship might be leaving the map at {location}.",
155+
"inGameEvent-cargoShipLeaving-noLockedCratesLeft": "Cargo Ship is leaving the map at {location} if no locked crates are left on it.",
156+
"inGameEvent-cargoShipLeaving-soon": "Cargo Ship will leave in {first} min or {second} min.",
157+
"inGameEvent-cargoShipLockedCrateSpawned": "Locked Crate just spawned on Cargo Ship at {location}.",
158+
"inGameEvent-cargoShipSpawned": "Cargo Ship spawned at {location}.",
159+
"inGameEvent-cargoShipSpawned-enters": "Cargo Ship enters the map from {location}.",
160+
"inGameEvent-cargoShipSpawned-located": "Cargo Ship is located at {location}.",
161+
"inGameEvent-cargoShipUndocking": "Cargo Ship is undocking from {location} ({grid}).",
162+
"inGameEvent-cargoShipUndocking-soon": "Cargo Ship will soon undock from {location} ({grid}).",
149163
"inGameEvent-ch47Despawned": "Chinook 47 left the map at {location}.",
150164
"inGameEvent-ch47Despawned-destroyed": "Chinook 47 got destroyed at {location}.",
151165
"inGameEvent-ch47HeavyScientistsCalled": "Heavy Scientists got called to the {rig} at {location}.",

src/managers/fcmListenerManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ async function pairingServer(flm: FcmListenerManager, steamId: types.SteamId, bo
465465
dayDurationSeconds: serverInfo ? serverInfo.dayDurationSeconds : null,
466466
nightDurationSeconds: serverInfo ? serverInfo.nightDurationSeconds : null,
467467
oilRigLockedCrateUnlockTimeMs: serverInfo ? serverInfo.oilRigLockedCrateUnlockTimeMs :
468-
constants.DEFAULT_OIL_RIG_LOCKED_CRATE_UNLOCK_TIME_MS
468+
constants.DEFAULT_OIL_RIG_LOCKED_CRATE_UNLOCK_TIME_MS,
469+
cargoShipEgressTimeMs: serverInfo ? serverInfo.cargoShipEgressTimeMs :
470+
constants.DEFAULT_CARGO_SHIP_EGRESS_TIME_MS
469471
};
470472

471473
updatePairingDetails(gInstance.pairingDataMap, serverId, steamId, body);

src/managers/guildInstanceManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export interface ServerInfo {
285285
dayDurationSeconds: number | null;
286286
nightDurationSeconds: number | null;
287287
oilRigLockedCrateUnlockTimeMs: number;
288+
cargoShipEgressTimeMs: number;
288289
}
289290

290291
export interface SmartSwitchConfig {
@@ -1475,7 +1476,8 @@ export function isValidServerInfo(object: unknown): object is ServerInfo {
14751476
'smartSwitchGroupConfigMap',
14761477
'dayDurationSeconds',
14771478
'nightDurationSeconds',
1478-
'oilRigLockedCrateUnlockTimeMs'
1479+
'oilRigLockedCrateUnlockTimeMs',
1480+
'cargoShipEgressTimeMs'
14791481
];
14801482

14811483
const errors: (vu.ValidationError | null)[] = [];
@@ -1503,6 +1505,7 @@ export function isValidServerInfo(object: unknown): object is ServerInfo {
15031505
errors.push(vu.validateType('dayDurationSeconds', obj.dayDurationSeconds, 'number', null));
15041506
errors.push(vu.validateType('nightDurationSeconds', obj.nightDurationSeconds, 'number', null));
15051507
errors.push(vu.validateType('oilRigLockedCrateUnlockTimeMs', obj.oilRigLockedCrateUnlockTimeMs, 'number'));
1508+
errors.push(vu.validateType('cargoShipEgressTimeMs', obj.cargoShipEgressTimeMs, 'number'));
15061509

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

src/structures/rustPlusMap.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ import * as path from 'path';
2525

2626
import { guildInstanceManager as gim, localeManager as lm } from '../../index';
2727
import { RustPlusInstance } from '../managers/rustPlusManager';
28-
import { getGridPos, getMonumentsInfo, getDistance } from '../utils/map';
28+
import { getGridPos, getMonumentsInfo, getDistance, Point } from '../utils/map';
2929
import * as constants from '../utils/constants';
3030
import { GuildInstance } from '../managers/guildInstanceManager';
3131

32-
export interface Point {
33-
x: number;
34-
y: number;
35-
}
36-
3732
export class RustPlusMap {
3833
public rpInstance: RustPlusInstance;
3934
public appMap: rp.AppMap;
4035

4136
public invalidClosestMonuments: string[];
37+
public harborMonuments: string[];
4238

4339
private static fontsRegistered = false;
4440

@@ -49,6 +45,9 @@ export class RustPlusMap {
4945
this.invalidClosestMonuments = [
5046
'DungeonBase', 'train_tunnel_display_name', 'train_tunnel_link_display_name'
5147
];
48+
this.harborMonuments = [
49+
'harbor_display_name', 'harbor_2_display_name'
50+
];
5251
}
5352

5453
public updateMap(appMap: rp.AppMap) {
@@ -235,4 +234,24 @@ export class RustPlusMap {
235234
return currentDistance < closestDistance ? monument : closest;
236235
});
237236
}
237+
238+
public getNumberOfHarbors(): number {
239+
return this.appMap.monuments.filter(m =>
240+
this.harborMonuments.includes(m.token)
241+
).length;
242+
}
243+
244+
public getClosestHarbor(point: Point): rp.AppMap_Monument | null {
245+
const harbors = this.appMap.monuments.filter(m =>
246+
this.harborMonuments.includes(m.token)
247+
);
248+
249+
if (harbors.length === 0) return null;
250+
251+
return harbors.reduce((closest, harbor) => {
252+
const currentDistance = getDistance(point.x, point.y, harbor.x, harbor.y);
253+
const closestDistance = getDistance(point.x, point.y, closest.x, closest.y);
254+
return currentDistance < closestDistance ? harbor : closest;
255+
});
256+
}
238257
}

0 commit comments

Comments
 (0)