public virtual void CleanUp(bool isTerminating)
 {
     if (currentCallout != null)
     {
         currentCallout.Finish();
         currentCallout = null;
     }
 }
 private void OnCurrentCalloutFinished()
 {
     Game.LogTrivial("Finishing callout");
     runCalloutUpdate       = false;
     isDisplayingNewCallout = false;
     lastCalloutFinishTime  = DateTime.UtcNow;
     secondsForNextCallout  = GetTimeForNextCallout();
     currentCallout         = null;
 }
        protected override void OnCalloutCreated(Callout callout)
        {
            base.OnCalloutCreated(callout);

            for (int i = 0; i < FireStationsManager.Instance.Buildings.Length; i++)
            {
                if (FireStationsManager.Instance.Buildings[i].IsCreated && !FireStationsManager.Instance.Buildings[i].IsAlarmPlaying)
                {
                    FireStationsManager.Instance.Buildings[i].StartAlarm(10000);
                }
            }
        }
        public void StartCallout(TCalloutData data)
        {
            FinishCurrentCallout();

            if (waitCalloutAcceptanceFiber != null)
            {
                waitCalloutAcceptanceFiber.Abort();
                waitCalloutAcceptanceFiber = null;
            }

            TCalloutData calloutData = data;

            isDisplayingNewCallout = true;
            Game.LogTrivial("Starting callout " + calloutData.InternalName);
            currentCallout           = (Callout)Activator.CreateInstance(calloutData.CalloutType);
            currentCallout.Finished += OnCurrentCalloutFinished;
            OnCalloutCreated(currentCallout);
            Game.LogTrivial("Callout - OnBeforeCalloutDisplayed");
            if (currentCallout.OnBeforeCalloutDisplayed())
            {
                const double notificationDisplayTime = 20.0;
                Game.LogTrivial("Callout - Showing notification");
                Notification.Show(currentCallout.DisplayName, currentCallout.DisplayExtraInfo, notificationDisplayTime);
                NativeFunction.Natives.FlashMinimapDisplay();
                DateTime startTime = DateTime.UtcNow;

                waitCalloutAcceptanceFiber = GameFiber.StartNew(() =>
                {
                    bool accepted = false;
                    Game.LogTrivial("Callout - Start accept key press detect loop");
                    float?dist = currentCallout.CalloutAreaBlip ? Vector3.Distance(Game.LocalPlayer.Character.Position, currentCallout.CalloutAreaBlip.Position) : (float?)null;
                    while ((DateTime.UtcNow - startTime).TotalSeconds < notificationDisplayTime + 2.0)
                    {
                        GameFiber.Yield();

                        if (dist.HasValue)
                        {
                            Game.SetRadarZoomLevelThisFrame(Math.Min(dist.Value, 800f));
                        }

                        if (Plugin.Controls["ACCEPT_CALLOUT"].IsJustPressed())
                        {
                            Game.LogTrivial("Callout - Pressed accept key, breaking loop");
                            accepted = true;
                            break;
                        }
                    }

                    if (accepted)
                    {
                        Game.LogTrivial("Callout - OnCalloutAccepted");
                        currentCallout.HasBeenAccepted = true;
                        if (currentCallout.OnCalloutAccepted())
                        {
                            Game.LogTrivial("Callout - OnCalloutAccepted:True");
                            runCalloutUpdate = true;
                        }
                        else
                        {
                            Game.LogTrivial("Callout - OnCalloutAccepted:False");
                            FinishCurrentCallout();
                        }
                    }
                    else
                    {
                        Game.LogTrivial("Callout - OnCalloutNotAccepted");
                        currentCallout?.OnCalloutNotAccepted();
                        FinishCurrentCallout();
                    }

                    waitCalloutAcceptanceFiber = null;
                }, "Wait for callout acceptance fiber - Callout:" + calloutData.InternalName);
            }
            else
            {
                FinishCurrentCallout();
            }
        }
 protected virtual void OnCalloutCreated(Callout callout)
 {
 }