@@ -23,9 +23,10 @@ import * as rp from 'rustplus-ts';
2323import { localeManager as lm , guildInstanceManager as gim } from '../../index' ;
2424import { RustPlusInstance } from '../managers/rustPlusManager' ;
2525import {
26- getDistance , getGridPos , getPos , getPosString , isOutsideGridSystem , isSameDirection , Point , Position
26+ getDistance , getGridPos , getPos , getPosString , isOutsideGridSystem , isSameDirection , Point , Position ,
27+ getAngleBetweenPoints
2728} from '../utils/map' ;
28- import { GuildInstance } from '../managers/guildInstanceManager' ;
29+ import { EventNotificationSettings , GuildInstance } from '../managers/guildInstanceManager' ;
2930import * as constants from '../utils/constants' ;
3031import { Timer } from '../utils/timer' ;
3132
@@ -50,6 +51,7 @@ const CARGO_SHIP_HARBOR_DOCKING_DISTANCE = 480;
5051const CARGO_SHIP_HARBOR_UNDOCKED_DISTANCE = 280 ;
5152const CARGO_SHIP_LEAVE_AFTER_HARBOR_NO_CRATES_MS = 2 * 60 * 1000 ; /* 2 min */
5253const CARGO_SHIP_LEAVE_AFTER_HARBOR_WITH_CRATES_MS = 19.5 * 60 * 1000 ; /* 19.5 min */
54+ const PATROL_HELICOPTER_LEAVING_SPEED_MIN = 400 ;
5355
5456export interface CargoShipMetaData {
5557 lockedCrateSpawnCounter : number ;
@@ -60,6 +62,11 @@ export interface CargoShipMetaData {
6062 isDepartureCertain : boolean ;
6163}
6264
65+ export interface PatrolHelicopterMetaData {
66+ prevPoint : Point | null ;
67+ isLeaving : boolean ;
68+ }
69+
6370export class RustPlusMapMarkers {
6471 public rpInstance : RustPlusInstance ;
6572 public appMapMarkers : rp . AppMapMarkers ;
@@ -91,6 +98,7 @@ export class RustPlusMapMarkers {
9198 public oilRigCh47s : number [ ] ;
9299 public ch47LockedCrateNotified : number [ ] ;
93100 public cargoShipMetaData : { [ cargoShip : number ] : CargoShipMetaData } ;
101+ public patrolHelicopterMetaData : { [ cargoShip : number ] : PatrolHelicopterMetaData } ;
94102
95103 constructor ( rpInstance : RustPlusInstance , appMapMarkers : rp . AppMapMarkers ) {
96104 this . rpInstance = rpInstance ;
@@ -125,6 +133,7 @@ export class RustPlusMapMarkers {
125133 this . oilRigCh47s = [ ] ;
126134 this . ch47LockedCrateNotified = [ ] ;
127135 this . cargoShipMetaData = { } ;
136+ this . patrolHelicopterMetaData = { } ;
128137 }
129138
130139
@@ -435,8 +444,8 @@ export class RustPlusMapMarkers {
435444 continue ;
436445 }
437446
438- const prevDist = getDistance ( cargoShip . x , cargoShip . y , harbor . x , harbor . y )
439- const currDist = getDistance ( marker . x , marker . y , harbor . x , harbor . y )
447+ const prevDist = getDistance ( cargoShip . x , cargoShip . y , harbor . x , harbor . y ) ;
448+ const currDist = getDistance ( marker . x , marker . y , harbor . x , harbor . y ) ;
440449 const harborAlreadyDocked = this . cargoShipMetaData [ marker . id ] . harborsDocked . some ( e =>
441450 e . x === harbor . x && e . y === harbor . y ) ;
442451 const hasDockingStatus = this . cargoShipMetaData [ marker . id ] . dockingStatus !== null ;
@@ -589,14 +598,121 @@ export class RustPlusMapMarkers {
589598 /* No longer used in Rust+ */
590599 }
591600
592- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
593601 private updateGenericRadii ( mapMarkers : rp . AppMapMarkers ) {
602+ const type = rp . AppMarkerType . GenericRadius ;
603+ const newMarkers = this . getNewMarkersById ( type , mapMarkers . markers ) ;
604+ const leftMarkers = this . getLeftMarkersById ( type , mapMarkers . markers ) ;
605+ const remainingMarkers = this . getRemainingMarkersById ( type , mapMarkers . markers ) ;
606+
607+ /* Markers that are new. */
608+ for ( const marker of newMarkers ) {
609+ this . genericRadii . push ( marker ) ;
610+ }
611+
612+ /* Markers that have left. */
613+ for ( const marker of leftMarkers ) {
614+ this . genericRadii = this . genericRadii . filter ( e => e . id !== marker . id ) ;
615+ }
594616
617+ /* Markers that still remains. */
618+ for ( const marker of remainingMarkers ) {
619+ const genericRadius = this . genericRadii . find ( e => e . id === marker . id ) as rp . AppMarker ;
620+ Object . assign ( genericRadius , marker ) ;
621+ }
595622 }
596623
597- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
598624 private updatePatrolHelicopters ( mapMarkers : rp . AppMapMarkers ) {
625+ const type = rp . AppMarkerType . PatrolHelicopter ;
626+ const gInstance = gim . getGuildInstance ( this . rpInstance . guildId ) as GuildInstance ;
627+ const language = gInstance . generalSettings . language ;
628+
629+ const newMarkers = this . getNewMarkersById ( type , mapMarkers . markers ) ;
630+ const leftMarkers = this . getLeftMarkersById ( type , mapMarkers . markers ) ;
631+ const remainingMarkers = this . getRemainingMarkersById ( type , mapMarkers . markers ) ;
632+
633+ if ( ! this . rpInstance . rpMap || ! this . rpInstance . rpInfo ) return ;
634+
635+ const mapSize = this . rpInstance . rpInfo . appInfo . mapSize ;
636+ const numberOfGrids = Math . floor ( mapSize / constants . GRID_DIAMETER ) ;
637+ const gridDiameter = mapSize / numberOfGrids ;
638+
639+ /* Markers that are new. */
640+ for ( const marker of newMarkers ) {
641+ this . patrolHelicopterMetaData [ marker . id ] = {
642+ prevPoint : null ,
643+ isLeaving : false
644+ }
645+
646+ const offset = 4 * gridDiameter ;
647+ const isOutside = isOutsideGridSystem ( marker . x , marker . y , mapSize , offset ) ;
648+
649+ const patrolHelicopterPos = getPos ( marker . x , marker . y , this . rpInstance ) as Position ;
650+ const patrolHelicopterPosString = getPosString ( patrolHelicopterPos , this . rpInstance , false , true ) ;
651+
652+ const phrase = 'inGameEvent-patrolHelicopterSpawned' + ( this . firstPoll ? '-located' :
653+ ( isOutside ? '-enters' : '' ) ) ;
654+ const eventText = lm . getIntl ( language , phrase , { location : patrolHelicopterPosString } ) ;
655+ this . rpInstance . sendEventNotification ( 'patrolHelicopterSpawned' , eventText ) ;
656+
657+ this . patrolHelicopters . push ( marker ) ;
658+ }
599659
660+ /* Markers that have left. */
661+ for ( const marker of leftMarkers ) {
662+ const isOutside = isOutsideGridSystem ( marker . x , marker . y , mapSize ) ;
663+ const phrase = 'inGameEvent-patrolHelicopter' + ( isOutside ? 'Despawned' : 'Destroyed' ) ;
664+ const settingsKey = 'patrolHelicopter' + ( isOutside ? 'Despawned' : 'Destroyed' ) ;
665+
666+ const patrolHelicopterPos = getPos ( marker . x , marker . y , this . rpInstance ) ;
667+ if ( patrolHelicopterPos ) {
668+ const patrolHelicopterPosString = getPosString ( patrolHelicopterPos , this . rpInstance , false , true ) ;
669+ const eventText = lm . getIntl ( language , phrase , { location : patrolHelicopterPosString } ) ;
670+ this . rpInstance . sendEventNotification ( settingsKey as keyof EventNotificationSettings , eventText ) ;
671+ }
672+
673+ delete this . patrolHelicopterMetaData [ marker . id ] ;
674+ this . patrolHelicopters = this . patrolHelicopters . filter ( e => e . id !== marker . id ) ;
675+ }
676+
677+ /* Markers that still remains. */
678+ for ( const marker of remainingMarkers ) {
679+ const patrolHelicopter = this . patrolHelicopters . find ( e => e . id === marker . id ) as rp . AppMarker ;
680+
681+ if ( this . patrolHelicopterMetaData [ marker . id ] . prevPoint !== null ) {
682+ const prevPoint = this . patrolHelicopterMetaData [ marker . id ] . prevPoint as Point ;
683+ const prevDist = getDistance ( prevPoint . x , prevPoint . y , patrolHelicopter . x , patrolHelicopter . y ) ;
684+ const currDist = getDistance ( patrolHelicopter . x , patrolHelicopter . y , marker . x , marker . y ) ;
685+ const isLeaving = this . patrolHelicopterMetaData [ marker . id ] . isLeaving ;
686+ const isSameDir = isSameDirection ( prevPoint ,
687+ { x : patrolHelicopter . x , y : patrolHelicopter . y } ,
688+ { x : marker . x , y : marker . y }
689+ ) ;
690+
691+ const startLeavingMap =
692+ prevDist >= PATROL_HELICOPTER_LEAVING_SPEED_MIN &&
693+ currDist >= PATROL_HELICOPTER_LEAVING_SPEED_MIN &&
694+ isSameDir && ! isLeaving ;
695+
696+ if ( startLeavingMap ) {
697+ this . patrolHelicopterMetaData [ marker . id ] . isLeaving = true ;
698+
699+ const patrolHelicopterPos = getPos ( marker . x , marker . y , this . rpInstance ) ;
700+ if ( patrolHelicopterPos ) {
701+ const patrolHelicopterPosString = getPosString (
702+ patrolHelicopterPos , this . rpInstance , false , true ) ;
703+ const direction = getAngleBetweenPoints ( prevPoint . x , prevPoint . y , marker . x , marker . y ) ;
704+ const eventText = lm . getIntl ( language , 'inGameEvent-patrolHelicopterLeaving' , {
705+ location : patrolHelicopterPosString ,
706+ direction : `${ direction } `
707+ } ) ;
708+ this . rpInstance . sendEventNotification ( 'cargoShipDocking' , eventText ) ;
709+ }
710+ }
711+ }
712+
713+ this . patrolHelicopterMetaData [ marker . id ] . prevPoint = { x : patrolHelicopter . x , y : patrolHelicopter . y } ;
714+ Object . assign ( patrolHelicopter , marker ) ;
715+ }
600716 }
601717
602718 /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
0 commit comments