public bool IsPlayerNearby(TriggerProfile control, bool playerOutsideDistance = false) { IMyPlayer player = null; var remotePosition = Vector3D.Transform(control.PlayerNearPositionOffset, RemoteControl.WorldMatrix); if (control.MinPlayerReputation != -1501 || control.MaxPlayerReputation != 1501) { player = TargetHelper.GetClosestPlayerWithReputation(remotePosition, _owner.FactionId, control); } else { player = TargetHelper.GetClosestPlayer(remotePosition); } if (player == null) { //Logger.MsgDebug(control.ProfileSubtypeId + ": No Eligible Player for PlayerNear Check", DebugTypeEnum.Trigger); return(false); } var playerDist = Vector3D.Distance(player.GetPosition(), remotePosition); if (playerOutsideDistance) { if (playerDist < control.TargetDistance) { return(false); } } else { if (playerDist > control.TargetDistance) { return(false); } } if (control.InsideAntenna == true) { var antenna = _behavior.Grid.GetAntennaWithHighestRange(control.InsideAntennaName); if (antenna != null) { playerDist = Vector3D.Distance(player.GetPosition(), antenna.GetPosition()); if (playerDist > antenna.Radius) { return(false); } } else { return(false); } } return(true); }
public void ProcessTimers(BehaviorMode mode, bool invalidTarget = false) { if (this.RemoteControl == null) { return; } this.NearestPlayer = TargetHelper.GetClosestPlayer(this.RemoteControl.GetPosition()); if (mode == BehaviorMode.Retreat) { if (this.NearestPlayer?.Controller?.ControlledEntity?.Entity != null) { if (Vector3D.Distance(this.RemoteControl.GetPosition(), this.NearestPlayer.GetPosition()) > this.RetreatDespawnDistance) { Logger.MsgDebug("Retreat Despawn: Player Far Enough", DebugTypeEnum.Despawn); DoDespawn = true; } } else { Logger.MsgDebug("Retreat Despawn: No Player", DebugTypeEnum.Despawn); DoDespawn = true; } } if (this.UsePlayerDistanceTimer == true) { if (this.NearestPlayer == null) { PlayerDistanceTimer++; } else if (this.NearestPlayer?.Controller?.ControlledEntity?.Entity != null) { if (Vector3D.Distance(this.NearestPlayer.GetPosition(), this.RemoteControl.GetPosition()) > this.PlayerDistanceTrigger) { PlayerDistanceTimer++; if (PlayerDistanceTimer >= PlayerDistanceTimerTrigger) { Logger.MsgDebug("No Player Within Distance", DebugTypeEnum.Despawn); DoDespawn = true; } } else { PlayerDistanceTimer = 0; } } } if (this.UseNoTargetTimer == true && this.SuspendNoTargetTimer == false) { if (invalidTarget == true) { this.NoTargetTimer++; if (this.NoTargetTimer >= this.NoTargetTimerTrigger) { this.NoTargetExpire = true; } } else { this.NoTargetTimer = 0; } } if (this.UseRetreatTimer == true && this.DoRetreat == false) { RetreatTimer++; if (RetreatTimer >= RetreatTimerTrigger) { DoRetreat = true; } } if (DoDespawn) { DespawnGrid(); } }