diff --git a/src/languages/en.json b/src/languages/en.json index eea4eb360..1b25904e3 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -70,9 +70,12 @@ "cargoLocatedAt": "Cargo Ship is located at {location}.", "cargoNotCurrentlyOnMap": "Cargo Ship is not currently on the map.", "cargoShipDetectedSetting": "When Cargo Ship is detected, send a notification.", + "cargoShipDockingAtHarbor": "Cargo ship just docked at the Harbor at {location}", + "cargoShipDockingAtHarborSetting": "When Cargo Ship is docked at a harbor, send a notification.", "cargoShipEgressSetting": "When Cargo Ship enters egress stage, send a notification.", "cargoShipEntersEgressStage": "Cargo Ship should be in the egress stage at {location}.", "cargoShipEntersMap": "Cargo Ship enters the map from {location}.", + "cargoShipLeftHarbor": "Cargo ship just left the Harbor at {location}", "cargoShipLeftMap": "Cargo Ship just left the map at {location}.", "cargoShipLeftSetting": "When Cargo Ship left the map, send a notification.", "cargoShipLocated": "Cargo Ship is located at {location}.", diff --git a/src/structures/MapMarkers.js b/src/structures/MapMarkers.js index 9b6118d00..6518d834d 100644 --- a/src/structures/MapMarkers.js +++ b/src/structures/MapMarkers.js @@ -64,6 +64,8 @@ class MapMarkers { /* Event location */ this.patrolHelicopterDestroyedLocation = null; + this.oldCargoShipLocation = null; + this.isCargoShipDocked = null; /* Vending Machine variables */ this.knownVendingMachines = []; @@ -539,12 +541,56 @@ class MapMarkers { let mapSize = this.rustplus.info.correctedMapSize; let pos = Map.getPos(marker.x, marker.y, mapSize, this.rustplus); let cargoShip = this.getMarkerByTypeId(this.types.CargoShip, marker.id); + + let harbors = []; + for (let monument of this.rustplus.map.monuments) { + if (/harbor/.test(monument.token)) { + harbors.push({ x: monument.x, y: monument.y }) + } + } this.rustplus.cargoShipTracers[marker.id].push({ x: marker.x, y: marker.y }); cargoShip.x = marker.x; cargoShip.y = marker.y; cargoShip.location = pos; + + /* If CargoShip is docked at Harbor */ + if(!this.rustplus.isFirstPoll && !this.isCargoShipDocked) { + for(let harbor of harbors){ + if(Map.getDistance(cargoShip.x, cargoShip.y, harbor.x, harbor.y) <= Constants.HARBOR_DOCK_DISTANCE){ + if(cargoShip.x === this.oldCargoShipLocation.x && cargoShip.y === this.oldCargoShipLocation.y){ + let harborLocation = Map.getPos(harbor.x, harbor.y, mapSize, this.rustplus); + this.isCargoShipDocked = true; + this.rustplus.sendEvent( + this.rustplus.notificationSettings.cargoShipDockingAtHarborSetting, + this.client.intlGet(this.rustplus.guildId, 'cargoShipDockingAtHarbor', + { location: harborLocation.location }), + 'cargo', + Constants.COLOR_CARGO_SHIP_DOCKED + ); + } + } + } + } + else if(!this.rustplus.isFirstPoll && this.isCargoShipDocked){ + for (let harbor of harbors) { + if(Map.getDistance(cargoShip.x, cargoShip.y, harbor.x, harbor.y) <= Constants.HARBOR_DOCK_DISTANCE){ + if(cargoShip.x !== this.oldCargoShipLocation.x && cargoShip.y !== this.oldCargoShipLocation.y){ + let harborLocation = Map.getPos(harbor.x, harbor.y, mapSize, this.rustplus); + this.isCargoShipDocked = false; + this.rustplus.sendEvent( + this.rustplus.notificationSettings.cargoShipDockingAtHarborSetting, + this.client.intlGet(this.rustplus.guildId, 'cargoShipLeftHarbor', + { location: harborLocation.location }), + 'cargo', + Constants.COLOR_CARGO_SHIP_DOCKED + ); + } + } + } + } + this.oldCargoShipLocation = { x: cargoShip.x, y: cargoShip.y }; } } diff --git a/src/templates/notificationSettingsTemplate.json b/src/templates/notificationSettingsTemplate.json index dbade3baf..456c38667 100644 --- a/src/templates/notificationSettingsTemplate.json +++ b/src/templates/notificationSettingsTemplate.json @@ -17,6 +17,12 @@ "inGame": false, "voice": true }, + "cargoShipDockingAtHarborSetting": { + "image": "cargoship_logo.png", + "discord": true, + "inGame": false, + "voice": true + }, "patrolHelicopterDetectedSetting": { "image": "patrol_helicopter_logo.png", "discord": true, diff --git a/src/util/constants.js b/src/util/constants.js index 1186b7a92..22d4b6dd6 100644 --- a/src/util/constants.js +++ b/src/util/constants.js @@ -61,6 +61,7 @@ module.exports = { PATROL_HELI_DOWNED_RADIUS: 400, OIL_RIG_CHINOOK_47_MAX_SPAWN_DISTANCE: 550, PROXIMITY_SETTING_DEFAULT_METERS: 500, + HARBOR_DOCK_DISTANCE: 100, /* Emojis */ ONLINE_EMOJI: ':green_circle:', @@ -79,6 +80,7 @@ module.exports = { COLOR_ACTIVE: '#00FF40', COLOR_CARGO_SHIP_ENTERS_EGRESS_STAGE: '#4B0082', COLOR_CARGO_SHIP_ENTERS_MAP: '#9932CC', + COLOR_CARGO_SHIP_DOCKED: '#4444C7', COLOR_CARGO_SHIP_LEFT_MAP: '#8B008B', COLOR_CARGO_SHIP_LOCATED: '#191970', COLOR_CARGO_TRACER: '#FF0000',