private async Task RunPinkieScript(PinkieEvent script, Image pinkieImage)
 {
     foreach (PinkieLine?line in script)
     {
         if (line.ImagePath != null)
         {
             pinkieImage.Source = ImageExtension.GetPlatformIndependentPath(line.ImagePath);
         }
         _ = _mainPageReference.ShowFloatingText(line.Text, Color.HotPink);
         await Task.Delay(line.MillisecondsTime);
     }
 }
        public async Task Run(Button giftBase, Button giftTop, AbsoluteLayout specialEventCanvas)
        {
            Rectangle baseRect     = giftBase.Bounds;
            double    xMid         = baseRect.X + baseRect.Width / 2;
            double    pinkieHeight = 94;
            double    pinkieWidth  = 94;

            var pinkieImage = new Image
            {
                HeightRequest = 94,
                WidthRequest  = 94,
                Source        = ImageExtension.GetPlatformIndependentPath("pinkie_woundup_1.png"),
            };
            double pinkieMid = pinkieImage.WidthRequest / 2;

            pinkieImage.Rotation = 270;

            AbsoluteLayout.SetLayoutBounds(
                pinkieImage,
                new Rectangle(xMid - pinkieMid, baseRect.Y - Y(40), pinkieWidth, pinkieHeight)
                );
            specialEventCanvas.Children.Add(pinkieImage);

            double totalMillis        = 3000.0;
            double tick               = 25.0 / totalMillis;
            var    boxShudderSlamOpen = new Animation
            {
                {
                    0.0,
                    tick * 1,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 1,
                        tick * 2,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 2,
                        tick * 3,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 3,
                        tick * 4,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 4,
                        tick * 5,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 5,
                        tick * 6,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 6,
                        tick * 7,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 7,
                        tick * 8,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 8,
                        tick * 9,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 9,
                        tick * 10,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 10,
                        tick * 11,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 11,
                        tick * 12,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 12,
                        tick * 13,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 13,
                        tick * 14,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 14,
                        tick * 15,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 15,
                        tick * 16,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 16,
                        tick * 17,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 17,
                        tick * 18,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 18,
                        tick * 19,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 19,
                        tick * 20,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 20,
                        tick * 21,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 21,
                        tick * 22,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 22,
                        tick * 23,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 23,
                        tick * 24,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 24,
                        tick * 25,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 25,
                        tick * 26,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 26,
                        tick * 27,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 27,
                        tick * 28,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationX = v;
                        giftTop.TranslationX  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    tick * 28,
                        tick * 29,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        0,
                        10
                        )
                },
                {
                    tick * 29,
                        tick * 30,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        10,
                        -10
                        )
                },
                {
                    tick * 30,
                        tick * 31,
                    new Animation(
                        v =>
                    {
                        giftBase.TranslationY = v;
                        giftTop.TranslationY  = v;
                    },
                        -10,
                        0
                        )
                },
                {
                    0.95,
                    0.97,
                    new Animation(
                        v =>
                        pinkieImage.Source = ImageExtension.GetPlatformIndependentPath(
                            "pinkie_woundup_2.png"
                            ),
                        0,
                        0
                        )
                },
                {
                    0.95,
                    0.98,
                    new Animation(v => giftBase.TranslationY = v, 0, -30, Easing.SpringOut)
                },
                {
                    0.97,
                    1.0,
                    new Animation(
                        v =>
                        pinkieImage.Source = ImageExtension.GetPlatformIndependentPath(
                            "pinkie_woundup_3.png"
                            ),
                        0,
                        0
                        )
                },
                {
                    0.98,
                    1.0,
                    new Animation(v => giftBase.TranslationY = v, -30, 0, Easing.SpringOut)
                },
                {
                    0.95,
                    1.0,
                    new Animation(v => giftTop.TranslationY = v, 0, -500, Easing.CubicOut)
                }
            };

            boxShudderSlamOpen.Commit(giftBase, "BoxShduder", 16, (uint)totalMillis);
            await Task.Delay((int)totalMillis);

            await pinkieImage.TranslateTo(0, Y(50), 1000, Easing.SpringIn);

            pinkieImage.Rotation = 0;
            pinkieImage.Source   = ImageExtension.GetPlatformIndependentPath(
                "pinkie_bounce_up_3.png"
                );
            await pinkieImage.TranslateTo(0, Y(-20), 300, Easing.SpringOut);

            if (Settings.PinkieSeenCount == 0)
            {
                await RunPinkieScript(_firstTimeEvent, pinkieImage);
            }
            else
            {
                if (_seenScripts.Count == _pinkieEvents.Count)
                {
                    _seenScripts.Clear();
                }

                PinkieEvent[] unusedScripts = _pinkieEvents
                                              .Where(x => !_seenScripts.Any(y => x.Id == y))
                                              .ToArray();

                PinkieEvent randomScript = unusedScripts[rand.Next(unusedScripts.Length)];

                await RunPinkieScript(randomScript, pinkieImage);

                _seenScripts.Add(randomScript.Id);
            }
            Settings.PinkieSeenCount += 1;

            await pinkieImage.TranslateTo(0, Y(40), 300, Easing.SpringIn);

            pinkieImage = null;
            specialEventCanvas.Children.Clear();
            await giftTop.TranslateTo(0, 0, 300, Easing.SpringIn);
        }