Skip to content

Commit 7e314e4

Browse files
committed
Add chinook 47 related events (locked crate, oil rig etc...)
1 parent d5a848d commit 7e314e4

File tree

6 files changed

+238
-42
lines changed

6 files changed

+238
-42
lines changed

src/languages/en.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@
115115
"eventNotificationSetting-cargoShipUndocking": "Cargo Ship Undocking",
116116
"eventNotificationSetting-ch47Despawned": "Chinook (CH47) Despawned",
117117
"eventNotificationSetting-ch47Destroyed": "Chinook (CH47) Destroyed",
118-
"eventNotificationSetting-ch47DroppedLockedCrate": "Locked Crate Dropped",
119118
"eventNotificationSetting-ch47HeavyScientistsCalled": "Heavy Scientists Called to Oil Rig",
119+
"eventNotificationSetting-ch47MaybeDroppedLockedCrate": "Chinook (CH47) dropped locked crate.",
120120
"eventNotificationSetting-ch47OilRigLockedCrateUnlocked": "Locked Crate Unlocked at Oil Rig",
121121
"eventNotificationSetting-ch47Spawned": "Chinook (CH-47) Spawned",
122122
"eventNotificationSetting-patrolHelicopterDespawned": "Patrol Helicopter Despawned",
@@ -146,6 +146,14 @@
146146
"hbhfSensor": "HBHF Sensor",
147147
"heater": "Heater",
148148
"id": "ID",
149+
"inGameEvent-ch47Despawned": "Chinook 47 left the map at {location}.",
150+
"inGameEvent-ch47Despawned-destroyed": "Chinook 47 got destroyed at {location}.",
151+
"inGameEvent-ch47HeavyScientistsCalled": "Heavy Scientists got called to the {rig} at {location}.",
152+
"inGameEvent-ch47MaybeDroppedLockedCrate": "Chinook 47 is considering dropped locked crate at {monument} ({grid}).",
153+
"inGameEvent-ch47OilRigLockedCrateUnlocked": "Locked Crate at {rig} at {location} has been unlocked.",
154+
"inGameEvent-ch47Spawned": "Chinook 47 spawned at {location}.",
155+
"inGameEvent-ch47Spawned-enters": "Chinook 47 enters the map from {location} to drop off a Locked Crate.",
156+
"inGameEvent-ch47Spawned-located": "Chinook 47 is located at {location}.",
149157
"inGameEvent-vendingMachineSpawned": "A new Vending Machine located at {location}.",
150158
"inGameTime": "In-Game time: {time}.",
151159
"issuedAt": "Issued: {time}",

src/managers/fcmListenerManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ async function pairingServer(flm: FcmListenerManager, steamId: types.SteamId, bo
463463
storageMonitorConfigMap: serverInfo ? serverInfo.storageMonitorConfigMap : {},
464464
smartSwitchGroupConfigMap: serverInfo ? serverInfo.smartSwitchGroupConfigMap : {},
465465
dayDurationSeconds: serverInfo ? serverInfo.dayDurationSeconds : null,
466-
nightDurationSeconds: serverInfo ? serverInfo.nightDurationSeconds : null
466+
nightDurationSeconds: serverInfo ? serverInfo.nightDurationSeconds : null,
467+
oilRigLockedCrateUnlockTimeMs: serverInfo ? serverInfo.oilRigLockedCrateUnlockTimeMs :
468+
constants.DEFAULT_OIL_RIG_LOCKED_CRATE_UNLOCK_TIME_MS
467469
};
468470

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

src/managers/guildInstanceManager.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export interface EventNotificationSettings {
150150
ch47Spawned: EventNotificationSetting;
151151
ch47Despawned: EventNotificationSetting;
152152
ch47Destroyed: EventNotificationSetting;
153-
ch47DroppedLockedCrate: EventNotificationSetting;
153+
ch47MaybeDroppedLockedCrate: EventNotificationSetting;
154154
ch47HeavyScientistsCalled: EventNotificationSetting;
155155
ch47OilRigLockedCrateUnlocked: EventNotificationSetting;
156156
cargoShipSpawned: EventNotificationSetting;
@@ -200,7 +200,7 @@ export interface SettingsMessages {
200200
ch47Spawned: types.MessageId | null;
201201
ch47Despawned: types.MessageId | null;
202202
ch47Destroyed: types.MessageId | null;
203-
ch47DroppedLockedCrate: types.MessageId | null;
203+
ch47MaybeDroppedLockedCrate: types.MessageId | null;
204204
ch47HeavyScientistsCalled: types.MessageId | null;
205205
ch47OilRigLockedCrateUnlocked: types.MessageId | null;
206206
cargoShipSpawned: types.MessageId | null;
@@ -284,6 +284,7 @@ export interface ServerInfo {
284284
smartSwitchGroupConfigMap: SmartSwitchGroupConfigMap;
285285
dayDurationSeconds: number | null;
286286
nightDurationSeconds: number | null;
287+
oilRigLockedCrateUnlockTimeMs: number;
287288
}
288289

289290
export interface SmartSwitchConfig {
@@ -602,7 +603,7 @@ export class GuildInstanceManager {
602603
ch47Spawned: null,
603604
ch47Despawned: null,
604605
ch47Destroyed: null,
605-
ch47DroppedLockedCrate: null,
606+
ch47MaybeDroppedLockedCrate: null,
606607
ch47HeavyScientistsCalled: null,
607608
ch47OilRigLockedCrateUnlocked: null,
608609
cargoShipSpawned: null,
@@ -1060,7 +1061,7 @@ export function isValidEventNotificationSettings(object: unknown): object is Eve
10601061
'ch47Spawned',
10611062
'ch47Despawned',
10621063
'ch47Destroyed',
1063-
'ch47DroppedLockedCrate',
1064+
'ch47MaybeDroppedLockedCrate',
10641065
'ch47HeavyScientistsCalled',
10651066
'ch47OilRigLockedCrateUnlocked',
10661067
'cargoShipSpawned',
@@ -1088,7 +1089,7 @@ export function isValidEventNotificationSettings(object: unknown): object is Eve
10881089
errors.push(vu.validateInterface('ch47Spawned', obj.ch47Spawned, isValidEventNotificationSetting));
10891090
errors.push(vu.validateInterface('ch47Despawned', obj.ch47Despawned, isValidEventNotificationSetting));
10901091
errors.push(vu.validateInterface('ch47Destroyed', obj.ch47Destroyed, isValidEventNotificationSetting));
1091-
errors.push(vu.validateInterface('ch47DroppedLockedCrate', obj.ch47DroppedLockedCrate,
1092+
errors.push(vu.validateInterface('ch47MaybeDroppedLockedCrate', obj.ch47MaybeDroppedLockedCrate,
10921093
isValidEventNotificationSetting));
10931094
errors.push(vu.validateInterface('ch47HeavyScientistsCalled', obj.ch47HeavyScientistsCalled,
10941095
isValidEventNotificationSetting));
@@ -1198,7 +1199,7 @@ export function isValidSettingsMessages(object: unknown): object is SettingsMess
11981199
'ch47Spawned',
11991200
'ch47Despawned',
12001201
'ch47Destroyed',
1201-
'ch47DroppedLockedCrate',
1202+
'ch47MaybeDroppedLockedCrate',
12021203
'ch47HeavyScientistsCalled',
12031204
'ch47OilRigLockedCrateUnlocked',
12041205
'cargoShipSpawned',
@@ -1243,7 +1244,7 @@ export function isValidSettingsMessages(object: unknown): object is SettingsMess
12431244
errors.push(vu.validateType('ch47Spawned', obj.ch47Spawned, 'string', null));
12441245
errors.push(vu.validateType('ch47Despawned', obj.ch47Despawned, 'string', null));
12451246
errors.push(vu.validateType('ch47Destroyed', obj.ch47Destroyed, 'string', null));
1246-
errors.push(vu.validateType('ch47DroppedLockedCrate', obj.ch47DroppedLockedCrate, 'string', null));
1247+
errors.push(vu.validateType('ch47MaybeDroppedLockedCrate', obj.ch47MaybeDroppedLockedCrate, 'string', null));
12471248
errors.push(vu.validateType('ch47HeavyScientistsCalled', obj.ch47HeavyScientistsCalled, 'string', null));
12481249
errors.push(vu.validateType('ch47OilRigLockedCrateUnlocked', obj.ch47OilRigLockedCrateUnlocked, 'string', null));
12491250
errors.push(vu.validateType('cargoShipSpawned', obj.cargoShipSpawned, 'string', null));
@@ -1473,7 +1474,8 @@ export function isValidServerInfo(object: unknown): object is ServerInfo {
14731474
'storageMonitorConfigMap',
14741475
'smartSwitchGroupConfigMap',
14751476
'dayDurationSeconds',
1476-
'nightDurationSeconds'
1477+
'nightDurationSeconds',
1478+
'oilRigLockedCrateUnlockTimeMs'
14771479
];
14781480

14791481
const errors: (vu.ValidationError | null)[] = [];
@@ -1500,6 +1502,7 @@ export function isValidServerInfo(object: unknown): object is ServerInfo {
15001502
isValidSmartSwitchGroupConfig));
15011503
errors.push(vu.validateType('dayDurationSeconds', obj.dayDurationSeconds, 'number', null));
15021504
errors.push(vu.validateType('nightDurationSeconds', obj.nightDurationSeconds, 'number', null));
1505+
errors.push(vu.validateType('oilRigLockedCrateUnlockTimeMs', obj.oilRigLockedCrateUnlockTimeMs, 'number'));
15031506

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

src/structures/rustPlusMap.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,30 @@ 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 } from '../utils/map';
28+
import { getGridPos, getMonumentsInfo, getDistance } 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+
3237
export class RustPlusMap {
3338
public rpInstance: RustPlusInstance;
3439
public appMap: rp.AppMap;
3540

41+
public invalidClosestMonuments: string[];
42+
3643
private static fontsRegistered = false;
3744

3845
constructor(rpInstance: RustPlusInstance, appMap: rp.AppMap) {
3946
this.rpInstance = rpInstance;
4047
this.appMap = appMap;
48+
49+
this.invalidClosestMonuments = [
50+
'DungeonBase', 'train_tunnel_display_name', 'train_tunnel_link_display_name'
51+
];
4152
}
4253

4354
public updateMap(appMap: rp.AppMap) {
@@ -208,4 +219,20 @@ export class RustPlusMap {
208219
private async drawMarkers(ctx: SKRSContext2D) {
209220
// TODO! TBD
210221
}
222+
223+
public getMonumentPointIfInside(point: Point, monumentName: string, radius: number): Point | null {
224+
const monument = this.appMap.monuments.find(e => monumentName === e.token &&
225+
getDistance(point.x, point.y, e.x, e.y) <= radius);
226+
227+
return monument ? { x: monument.x, y: monument.y } : null;
228+
}
229+
230+
public getClosestMonument(point: Point): rp.AppMap_Monument {
231+
const validMonuments = this.appMap.monuments.filter(e => !this.invalidClosestMonuments.includes(e.token));
232+
return validMonuments.reduce((closest, monument) => {
233+
const currentDistance = getDistance(point.x, point.y, monument.x, monument.y);
234+
const closestDistance = getDistance(point.x, point.y, closest.x, closest.y);
235+
return currentDistance < closestDistance ? monument : closest;
236+
});
237+
}
211238
}

0 commit comments

Comments
 (0)