Skip to content

Commit

Permalink
add Cargo Docking at Harbor Notification (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
FaiThiX authored Jul 18, 2024
1 parent a9d885a commit 28d6552
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}.",
Expand Down
46 changes: 46 additions & 0 deletions src/structures/MapMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MapMarkers {

/* Event location */
this.patrolHelicopterDestroyedLocation = null;
this.oldCargoShipLocation = null;
this.isCargoShipDocked = null;

/* Vending Machine variables */
this.knownVendingMachines = [];
Expand Down Expand Up @@ -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 };
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/templates/notificationSettingsTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand All @@ -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',
Expand Down

0 comments on commit 28d6552

Please sign in to comment.