Пример #1
0
 public void Build(CustomAnimation a1, CustomAnimation a2)
 {
     animations = new List <CustomAnimation> {
         a1, a2
     };
     destroyAfter = true;
 }
Пример #2
0
        private void ToggleView(Control ui, bool isShow)
        {
            DoubleAnimation animation;

            if (isShow)
            {
                if (ui.ActualWidth != 0)
                {
                    return;
                }
                animation = CustomAnimation.GetEnteringScreenAnimation(0,
                                                                       ui is Label ? _widthOfToLabel : _widthOfTimeChooser, false);
                ui.BeginAnimation(WidthProperty, animation);
            }
            else
            {
                if (ui.ActualWidth == 0)
                {
                    return;
                }
                animation =
                    CustomAnimation.GetLeavingScreenAnimation(ui is Label ? _widthOfToLabel : _widthOfTimeChooser, 0,
                                                              false);
                ui.BeginAnimation(WidthProperty, animation);
            }
        }
Пример #3
0
 public void Post(Window targetWindow, bool animated = true)
 {
     window = targetWindow;
     if (window != null)
     {
         if (animated)
         {
             BeforePosting?.Invoke(this, null);
             if (CustomAnimation == null)
             {
                 defaultShowAnimation();
             }
             else
             {
                 CustomAnimation.ShowAnimation(this);
             }
             window.AddLayer(layer);
             layer.RaiseToTop();
             AfterPosting?.Invoke(this, null);
         }
         else
         {
             window.AddLayer(layer);
             layer.RaiseToTop();
         }
     }
 }
Пример #4
0
    public void AddMulti(CustomAnimation a1, CustomAnimation a2)
    {
        GameObject     multiAnimationGO = Instantiate(multiAnimationPrefab, transform);
        MultiAnimation multiAnimation   = multiAnimationGO.GetComponent <MultiAnimation>();

        multiAnimation.Build(a1, a2);
        animations.Add(multiAnimation);
    }
Пример #5
0
 public void Start()
 {
     playerGameObject  = new MovableObject(GameObject.Find("Megaman"), true);
     animator          = GetComponent <Animator> ();
     mainCamera        = Camera.main;
     backStepAnimation = new CustomAnimation("Base Layer.Megaman Backstep", 0.0f, 1.0f, animator);
     UpdateCharsLastLocation();
 }
Пример #6
0
    public CustomAnimation Copy()
    {
        GameObject      animationGO     = Instantiate(gameObject);
        CustomAnimation customAnimation = animationGO.GetComponent <CustomAnimation>();

        customAnimation.destroyAfter = true;
        return(customAnimation);
    }
Пример #7
0
    /// <summary>
    /// Plays a requested animation by animation ID (<see cref="CustomAnimation.animationName"/>)
    /// </summary>
    /// <param name="animation">Animation to request by name.</param>
    public void PlayAnimation(string animation)
    {
        //Creates a predicate that finds an animation in the Animations list based on name.
        Predicate <CustomAnimation> animToPlay = delegate(CustomAnimation ca) { return(ca.animationName == animation); };

        CustomAnimation cusanim = Animations.Find(animToPlay);

        PlayAnimation(cusanim);
    }
        private void GoToUneditableMode()
        {
            var da = CustomAnimation.GetLeavingScreenAnimation(45, 0, false);

            StackPanel_Bottom.BeginAnimation(HeightProperty, da);
            ComboBox.Visibility      = Collapsed;
            TextBlock.Visibility     = Visible;
            Button_Pencil.Visibility = Visible;
        }
        private void GoToEditableMode()
        {
            var da = CustomAnimation.GetEnteringScreenAnimation(0, 45, false);

            StackPanel_Bottom.BeginAnimation(HeightProperty, da);
            ComboBox.Visibility      = Visible;
            TextBlock.Visibility     = Hidden;
            Button_Pencil.Visibility = Hidden;
        }
Пример #10
0
 /// <summary>
 /// Öffnet den Screen mit einer Animation
 /// </summary>
 /// <param name="prevScreen"></param>
 /// <returns></returns>
 public virtual GuiScreen Open(GuiScreen prevScreen)
 {
     this.prevScreen = prevScreen;
     Animation       = new CustomAnimation <float>(-Game.HEIGHT, 0.0f, (float delta, float current) => current + delta)
     {
         Toleranz = 1E-3f
     };
     Animation.Fire();
     return(this);
 }
Пример #11
0
    void Start()
    {
        m_Animator       = GetComponent <CustomAnimation>();
        m_TeamIndication = GetComponent <Team>();

        if (m_TeamIndication.m_Team == Team.TeamType.Blue)
        {
            m_TeamMinions.Add(this);
        }
    }
Пример #12
0
 public void SetAnim(string anim)
 {
     if (anim == animName)
     {
         return;
     }
     if (animMap.ContainsKey(anim))
     {
         animName = anim;
         clip     = animMap[anim];
     }
 }
Пример #13
0
    public void AnimationCallback()
    {
        CustomAnimation completedAnimation = animations[0];

        animations.RemoveAt(0);
        if (completedAnimation.destroyAfter)
        {
            completedAnimation.DestroyIfNeeded();
        }
        OnAnimationEnded?.Invoke();
        StartAnimations();
    }
Пример #14
0
        /// <summary>
        /// Initialisiert die Form und die dafür notwendingen Komponenten für unser Framework
        /// </summary>
        private void Init()
        {
            Text           = NAME;
            Width          = (int)WIDTH;
            Height         = (int)HEIGHT;
            DoubleBuffered = true; //Verhindert Flackern

            //Erstellen der Timer für aktualisierung der Form
            renderTimer = new Timer()
            {
                Interval = (int)(1000.0f / FPS)
            };
            renderTimer.Tick += RenderTimer_Tick;

            tickTimer = new Timer()
            {
                Interval = (int)TPT,
            };
            tickTimer.Tick += TickTimer_Tick;

            watch = new Stopwatch();
            watch.Start();

            //Hinzufügen der Events für interaktionen
            MouseClick += Game_MouseClick;
            MouseMove  += Game_MouseEvent;
            KeyDown    += Game_KeyDown;
            KeyUp      += Game_KeyUp;
            MouseWheel += Game_MouseEvent;
            Resize     += (object sender, EventArgs e) =>
            {
                A_WIDTH  = Width;
                A_HEIGHT = Height;
                currentScreen?.Resize();
            };

            animationHandler = new AnimationHandler();
            zoom             = new CustomAnimation <float>(5, 5, (float current, float delta) =>
            {
                return(current + delta);
            });
            zoom.Fire();
            inputManager = new InputManager();
            AddKeybinds();
            renderTimer.Start();
            tickTimer.Start();

            isIngame = false;
            SetScreen(new GuiStartScreen());//StartScreen setzen
            entities   = new List <Entity>();
            enemyTypes = new Type[] { typeof(EnemyJens) };
        }
Пример #15
0
 public void FishChangeColor()
 {
     SpriteRenderer[] rens = transform.GetComponentsInChildren <SpriteRenderer>();
     foreach (var item in rens)
     {
         item.sprite = sprites[0];
         CustomAnimation customAnimation = item.GetComponent <CustomAnimation>();
         for (int i = 0; i < customAnimation.sps.Length; i++)
         {
             customAnimation.sps[i] = sprites[i];
         }
     }
 }
Пример #16
0
    public void GenerateEnemyFight(GameObject _enemyObject, Enemy _enemy, float roomMultiplier)
    {
        statsMultiplier = roomMultiplier;
        enemy           = _enemy;
        enemy.ResetBehaviour();
        enemyObject     = _enemyObject;
        customAnimation = enemyObject.GetComponentInChildren <CustomAnimation>();

        enemyHealthAndStatus = new HealthAndStatuses();
        enemyHealthAndStatus.SetStatusDisplayer(statusDisplayer);

        enemyHealthText = enemyObject.GetComponentInChildren <TextMeshProUGUI>();
        enemyHealthAndStatus.SetComponent(Mathf.RoundToInt(Random.Range(enemy.minMaximumHealth, enemy.maxMaximumHealth + 1) * statsMultiplier), enemyHealthText, statsMultiplier);
    }
Пример #17
0
 private void CreateNewAnimation()
 {
     check = new CustomAnimation <float>(0.0f, 1.0f, (float current, float delta) => current + delta)
     {
         Toleranz = 1E-3f
     };                         //Animation für den Haken
     check.OnFinish += (object o, EventArgs args) => {
         if (!check.Increments) //Soll wieder groß werden wenn es klein geworden ist
         {
             state = !state;
             token = state ? ((char)10003).ToString() : ((char)10007).ToString();
             check.Reverse();
         }
     };
     check.Fire();
 }
Пример #18
0
        private void AddRuleButton_OnClick(object sender, RoutedEventArgs e)
        {
            ScrollViewer.ScrollToEnd();
            var r = new RuleSetter();

            r.xButton_Clicked += (o, args) => {
                var animation = CustomAnimation.GetLeavingScreenAnimation(r.ActualHeight, 0);
                animation.Completed += (sender1, eventArgs) => { innerSp.Children.Remove(o as RuleSetter); };
                r.BeginAnimation(HeightProperty, animation);
            };
            r.Loaded +=
                (o, args) => {
                r.BeginAnimation(HeightProperty,
                                 CustomAnimation.GetEnteringScreenAnimation(0, r.ActualHeight));
            };
            innerSp.Children.Add(r);
        }
Пример #19
0
    protected void startAnimation(int[] nextPos)
    {
        Direction.Cube upOrDown = Direction.Cube.None;
        if (nextPos[0] < this.curPos[0])
        {
            upOrDown = Direction.Cube.Down;
        }
        else
        {
            upOrDown = Direction.Cube.Up;
        }

        this.curPos = nextPos;
        AnimationClip clip = CustomAnimation.setAnimationTo(gameObject, nextPos, upOrDown);

        anim.AddClip(clip, clip.name);
        anim.Play(clip.name);
    }
Пример #20
0
    /// <summary>
    /// Plays a requested animation.
    /// </summary>
    /// <param name="animation">Animation to play.</param>
    private void PlayAnimation(CustomAnimation animation)
    {
        CheckNullException();

        //procura animação pelo nome.
        string animationN = animation.animationName;

        if (animation == lastAnimationPlayed && !lastAnimationPlayed.repeatable)
        {
            if (lastAnimationPlayed.debug)
            {
                Debug.Log("Não foi possível reproduzir a animação não repetível " + animation + " ja esta reproduzindo");
            }
            return;
        }
        anim.Play(animationN, 0, 0.0f);

        //Sets the last animation played as the one requested.
        lastAnimationPlayed = animation;
    }
        private void AnimateHiddenContent(bool IsExpand)
        {
            double totalHeight = CreateTimetableButton.ActualHeight;

            if (IsExpand)
            {
                if (InnerSp.Height == 0)
                {
                    InnerSp.BeginAnimation(HeightProperty,
                                           CustomAnimation.GetEnteringScreenAnimation(0, totalHeight, false));
                    ResetButton.IsEnabled = true;
                    AddSlotButton.Content = "Add more slots";
                }
            }
            else
            {
                InnerSp.BeginAnimation(HeightProperty, CustomAnimation.GetLeavingScreenAnimation(totalHeight, 0, false));
                ResetButton.IsEnabled = false;
                AddSlotButton.Content = "Add slots";
            }
        }
Пример #22
0
        public EntityLivingBase(Rectangle[] bounds) : base(bounds)
        {
            //TileMaps für die BegweungsAnimationen
            Bitmap[][] images = new Bitmap[][] { ResourceManager.GetImages(this, "Right"), ResourceManager.GetImages(this, "Left") };
            //Einfärben für die Hurttime
            Bitmap[][] hurtTimeImages = new Bitmap[images.Length][];
            for (int i = 0; i < images.Length; i++)
            {
                hurtTimeImages[i] = new Bitmap[images[i].Length];
                for (int j = 0; j < images[i].Length; j++)
                {
                    hurtTimeImages[i][j] = RenderUtils.PaintBitmap(images[i][j], Color.Red, true);
                }
            }
            //Erstellen der Bewegungs-Animation und
            this.animations        = new FrameAnimation[] { new FrameAnimation(FPS, false, images[0]), new FrameAnimation(FPS, false, images[1]) };
            this.hurtTimeAnimation = new FrameAnimation[] { new FrameAnimation(FPS, false, hurtTimeImages[0]), new FrameAnimation(FPS, false, hurtTimeImages[1]) };

            Facing    = EnumFacing.RIGHT;
            animation = animations[0];
            //Erstellen der BoundingBox für Kollisionen
            Box = new BoundingBox(this, animation.Image.Width, animation.Image.Height);
            //Erstellen der Schlag- und TodesAnimation
            swing = CustomAnimation <float> .CreateDefaultAnimation(1.0f);

            swing.Toleranz  = 1E-2f;
            swing.OnFinish += (object sender, EventArgs args) =>
            {
                if (swing.Increments)
                {
                    swing.Reverse();
                }
            };
            swing.Reverse();
            death = CustomAnimation <float> .CreateDefaultAnimation(1.0f);

            death.Toleranz = 1e-5f;
            Health         = 20;
        }
Пример #23
0
    public void AddToLastInParallel(CustomAnimation a)
    {
        if (animations.Count == 0)
        {
            Add(a);
            return;
        }
        // Detaching currently Last animation
        CustomAnimation lastItem = animations[animations.Count - 1];

        animations.Remove(lastItem);

        // Constructing list of next Last parallel animations
        List <CustomAnimation> lastAnimations;

        if (lastItem is MultiAnimation)
        {
            lastAnimations = new List <CustomAnimation>(((MultiAnimation)lastItem).animations);
            Destroy(lastItem.gameObject);
        }
        else
        {
            lastAnimations = new List <CustomAnimation>()
            {
                lastItem
            };
        }
        lastAnimations.Add(a);

        // Instantiating MultiAnimation
        GameObject     multiAnimationGO = Instantiate(multiAnimationPrefab, transform);
        MultiAnimation multiAnimation   = multiAnimationGO.GetComponent <MultiAnimation>();

        multiAnimation.Build(lastAnimations);

        animations.Add(multiAnimation);
    }
Пример #24
0
    private void Update()
    {
        if (fps == 0)
        {
            return;
        }

        if (_innerTimer > (1f / fps))
        {
            if (fps > 0)
            {
                frame++;
                if (frame > clip.Size - 1)
                {
                    frame = 0;
                    if (transitionMap.ContainsKey(clip))
                    {
                        clip = transitionMap[clip];
                    }
                }
                sr.sprite = clip.GetSprite(frame);
            }
            else
            {
                frame--;
                if (frame < 0)
                {
                    frame = clip.Size - 1;
                }
                sr.sprite = clip.GetSprite(frame);
            }

            _innerTimer = 0f;
        }

        _innerTimer += Time.deltaTime;
    }
        private void UpdateBottomPanelVisibility()
        {
            DoubleAnimation da;

            if (UIDofSelectedSlots.Count == 0)
            {
                da = CustomAnimation.GetLeavingScreenAnimation(70, 0, false);
                ViewChanger.Badge = null;
                if (ViewChangerButton.Content.ToString() == "Show all subjects")
                {
                    return;
                }
            }
            else
            {
                da = CustomAnimation.GetEnteringScreenAnimation(0, 70, false);
                ViewChanger.Badge = GetNamesOfCheckedSubject().Length;
                if (BottomPanel.ActualHeight > 0)
                {
                    return;
                }
            }
            BottomPanel.BeginAnimation(HeightProperty, da);
        }
Пример #26
0
        public void Dismiss(bool animated = true)
        {
            if (window != null)
            {
                BeforeDissmising?.Invoke(this, null);

                if (animated)
                {
                    if (CustomAnimation == null)
                    {
                        defaultHideAnimation();
                    }
                    else
                    {
                        CustomAnimation.HideAnimation(this);
                    }
                }
                else
                {
                    window.RemoveLayer(layer);
                }
                AfterDissmising?.Invoke(this, null);
            }
        }
Пример #27
0
    private void heyMonster()
    {
        if(currentAnimation!=null)
            currentAnimation.stopAnimation();

        //Show monster onscreen
        animationQueue.Clear();

        if(!isVisible()){
            appearMonster();
        }

        //Configure the animation
        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"HEYMONSTER");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "MonsterIdleBreaths Hard.mp4";
        heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
        heyMonsterAnimation.direction = new Vector2(0f,0f);
        heyMonsterAnimation.victim = this.gameObject;
        heyMonsterAnimation.animationTime = 2f;
        animationQueue.Enqueue(heyMonsterAnimation);

        StartCoroutine(PlayAnimations());
    }
Пример #28
0
        public void OnTick(object sender, EventArgs e)
        {
            Main.TickCount++;
            try
            {
                Ped player = Game.Player.Character;
                var res    = UIMenu.GetScreenResolutionMantainRatio();

                if (Environment.TickCount - _lastCheck > 1000)
                {
                    _bytesSentPerSecond     = _bytesSent - _lastBytesSent;
                    _bytesReceivedPerSecond = _bytesReceived - _lastBytesReceived;

                    _lastBytesReceived = _bytesReceived;
                    _lastBytesSent     = _bytesSent;


                    _lastCheck = Environment.TickCount;
                }

                if (!string.IsNullOrWhiteSpace(_threadsafeSubtitle))
                {
                    GTA.UI.Screen.ShowSubtitle(_threadsafeSubtitle, 500);
                }

                DEBUG_STEP = 1;

                if (!_hasInitialized)
                {
                    RebuildServerBrowser();
#if INTEGRITYCHECK
                    if (!VerifyGameIntegrity())
                    {
                        _mainWarning          = new Warning("alert", "Could not verify game integrity.\nPlease restart your game, or update Grand Theft Auto V.");
                        _mainWarning.OnAccept = () =>
                        {
                            if (Client != null && IsOnServer())
                            {
                                Client.Disconnect("Quit");
                            }
                            CEFManager.Dispose();
                            CEFManager.DisposeCef();
                            Script.Wait(500);
                            //Environment.Exit(0);
                            Process.GetProcessesByName("GTA5")[0].Kill();
                            Process.GetCurrentProcess().Kill();
                        };
                    }
#endif
                    _hasInitialized = true;
                }
                DEBUG_STEP = 2;

                if (!_hasPlayerSpawned && player != null && player.Handle != 0 && !Game.IsLoading)
                {
                    GTA.UI.Screen.FadeOut(1);
                    ResetPlayer();
                    MainMenu.RefreshIndex();
                    _hasPlayerSpawned     = true;
                    MainMenu.Visible      = true;
                    World.RenderingCamera = MainMenuCamera;

                    var address = Util.Util.FindPattern("\x32\xc0\xf3\x0f\x11\x09", "xxxxxx"); // Weapon/radio slowdown

                    DEBUG_STEP = 3;

                    if (address != IntPtr.Zero)
                    {
                        Util.Util.WriteMemory(address, 0x90, 6);
                    }

                    address = Util.Util.FindPattern("\x48\x85\xC0\x0F\x84\x00\x00\x00\x00\x8B\x48\x50", "xxxxx????xxx");
                    // unlock objects; credit goes to the GTA-MP team

                    DEBUG_STEP = 4;

                    if (address != IntPtr.Zero)
                    {
                        Util.Util.WriteMemory(address, 0x90, 24);
                    }

                    //TerminateGameScripts();

                    GTA.UI.Screen.FadeIn(1000);
                }

                DEBUG_STEP = 5;

                Game.DisableControlThisFrame(0, Control.EnterCheatCode);
                Game.DisableControlThisFrame(0, Control.FrontendPause);
                Game.DisableControlThisFrame(0, Control.FrontendPauseAlternate);
                Game.DisableControlThisFrame(0, Control.FrontendSocialClub);
                Game.DisableControlThisFrame(0, Control.FrontendSocialClubSecondary);

                if (!player.IsJumping)
                {
                    //Game.DisableControlThisFrame(0, Control.MeleeAttack1);
                    Game.DisableControlThisFrame(0, Control.MeleeAttackLight);
                }

                Function.Call(Hash.HIDE_HELP_TEXT_THIS_FRAME);

                if (Game.Player.Character.IsRagdoll)
                {
                    Game.DisableControlThisFrame(0, Control.Attack);
                    Game.DisableControlThisFrame(0, Control.Attack2);
                }

                if (_mainWarning != null)
                {
                    _mainWarning.Draw();
                    return;
                }

                if ((Game.IsControlJustPressed(0, Control.FrontendPauseAlternate) || Game.IsControlJustPressed(0, Control.FrontendPause)) &&
                    !MainMenu.Visible && !_wasTyping)
                {
                    MainMenu.Visible = true;

                    if (!IsOnServer())
                    {
                        if (MainMenu.Visible)
                        {
                            World.RenderingCamera = MainMenuCamera;
                        }
                        else
                        {
                            World.RenderingCamera = null;
                        }
                    }
                    else if (MainMenu.Visible)
                    {
                        RebuildPlayersList();
                    }

                    MainMenu.RefreshIndex();
                }
                else
                {
                    if (!BlockControls)
                    {
                        MainMenu.ProcessControls();
                    }
                    MainMenu.Update();
                    MainMenu.CanLeave = IsOnServer();
                    if (MainMenu.Visible && !MainMenu.TemporarilyHidden && !_mainMapItem.Focused && _hasScAvatar && File.Exists(GTANInstallDir + "\\images\\scavatar.png"))
                    {
                        var safe = new Point(300, 180);
                        Util.Util.DxDrawTexture(0, GTANInstallDir + "images\\scavatar.png", res.Width - safe.X - 64, safe.Y - 80, 64, 64, 0, 255, 255, 255, 255, false);
                    }

                    if (!IsOnServer())
                    {
                        Game.EnableControlThisFrame(0, Control.FrontendPause);
                    }
                }
                DEBUG_STEP = 6;

                if (_isGoingToCar && Game.IsControlJustPressed(0, Control.PhoneCancel))
                {
                    Game.Player.Character.Task.ClearAll();
                    _isGoingToCar = false;
                }

                if (Client == null || Client.ConnectionStatus == NetConnectionStatus.Disconnected || Client.ConnectionStatus == NetConnectionStatus.None)
                {
                    return;
                }
                // BELOW ONLY ON SERVER

                _versionLabel.Position      = new Point((int)(res.Width / 2), 0);
                _versionLabel.TextAlignment = UIResText.Alignment.Centered;
                _versionLabel.Draw();

                DEBUG_STEP = 7;

                if (_wasTyping)
                {
                    Game.DisableControlThisFrame(0, Control.FrontendPauseAlternate);
                }

                var playerCar = Game.Player.Character.CurrentVehicle;

                DEBUG_STEP = 8;

                Watcher.Tick();

                DEBUG_STEP = 9;

                _playerGodMode = Game.Player.IsInvincible;

                //invokeonLocalPlayerShoot
                if (player != null && player.IsShooting)
                {
                    JavascriptHook.InvokeCustomEvent(
                        api =>
                        api?.invokeonLocalPlayerShoot((int)(player.Weapons.Current?.Hash ?? 0),
                                                      RaycastEverything(new Vector2(0, 0)).ToLVector()));
                }


                DEBUG_STEP = 10;

                int           netPlayerCar = 0;
                RemoteVehicle cc           = null;
                if (playerCar != null && (netPlayerCar = NetEntityHandler.EntityToNet(playerCar.Handle)) != 0)
                {
                    var item = NetEntityHandler.NetToStreamedItem(netPlayerCar) as RemoteVehicle;

                    if (item != null)
                    {
                        var lastHealth      = item.Health;
                        var lastDamageModel = item.DamageModel;

                        item.Position    = playerCar.Position.ToLVector();
                        item.Rotation    = playerCar.Rotation.ToLVector();
                        item.Health      = playerCar.EngineHealth;
                        item.IsDead      = playerCar.IsDead;
                        item.DamageModel = playerCar.GetVehicleDamageModel();

                        if (lastHealth != playerCar.EngineHealth)
                        {
                            JavascriptHook.InvokeCustomEvent(api => api?.invokeonVehicleHealthChange((int)lastHealth));
                        }

                        if (playerCar.IsEngineRunning ^ !PacketOptimization.CheckBit(item.Flag, EntityFlag.EngineOff))
                        {
                            playerCar.IsEngineRunning = !PacketOptimization.CheckBit(item.Flag, EntityFlag.EngineOff);
                        }

                        if (lastDamageModel != null)
                        {
                            if (lastDamageModel.BrokenWindows != item.DamageModel.BrokenWindows)
                            {
                                for (int i = 0; i < 8; i++)
                                {
                                    if (((lastDamageModel.BrokenWindows ^ item.DamageModel.BrokenWindows) & 1 << i) != 0)
                                    {
                                        var i1 = i;
                                        JavascriptHook.InvokeCustomEvent(api => api?.invokeonVehicleWindowSmash(i1));
                                    }
                                }
                            }

                            if (lastDamageModel.BrokenDoors != item.DamageModel.BrokenDoors)
                            {
                                for (int i = 0; i < 8; i++)
                                {
                                    if (((lastDamageModel.BrokenDoors ^ item.DamageModel.BrokenDoors) & 1 << i) != 0)
                                    {
                                        var i1 = i;
                                        JavascriptHook.InvokeCustomEvent(api => api?.invokeonVehicleDoorBreak(i1));
                                    }
                                }
                            }
                        }
                    }

                    cc = item;
                }

                DEBUG_STEP = 11;

                if (playerCar != _lastPlayerCar)
                {
                    if (_lastPlayerCar != null)
                    {
                        var c = NetEntityHandler.EntityToStreamedItem(_lastPlayerCar.Handle) as
                                RemoteVehicle;

                        if (VehicleSyncManager.IsSyncing(c))
                        {
                            _lastPlayerCar.IsInvincible = c?.IsInvincible ?? false;
                        }
                        else
                        {
                            _lastPlayerCar.IsInvincible = true;
                        }

                        if (c != null)
                        {
                            Function.Call(Hash.SET_VEHICLE_ENGINE_ON, _lastPlayerCar,
                                          !PacketOptimization.CheckBit(c.Flag, EntityFlag.EngineOff), true, true);
                        }

                        int h  = _lastPlayerCar.Handle;
                        var lh = new LocalHandle(h);
                        JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerExitVehicle(lh));
                        _lastVehicleSiren = false;
                    }

                    if (playerCar != null)
                    {
                        if (!NetEntityHandler.ContainsLocalHandle(playerCar.Handle))
                        {
                            playerCar.Delete();
                            playerCar = null;
                        }
                        else
                        {
                            playerCar.IsInvincible = cc?.IsInvincible ?? false;

                            LocalHandle handle = new LocalHandle(playerCar.Handle);
                            JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerEnterVehicle(handle));
                        }
                    }

                    LastCarEnter = DateTime.Now;
                }

                DEBUG_STEP = 12;

                if (playerCar != null)
                {
                    if (playerCar.GetResponsiblePed().Handle == player.Handle)
                    {
                        playerCar.IsInvincible = cc?.IsInvincible ?? false;
                    }
                    else
                    {
                        playerCar.IsInvincible = true;
                    }

                    var siren = playerCar.SirenActive;

                    if (siren != _lastVehicleSiren)
                    {
                        JavascriptHook.InvokeCustomEvent(api => api?.invokeonVehicleSirenToggle());
                    }

                    _lastVehicleSiren = siren;
                }

                Game.Player.Character.MaxHealth = 200;

                var playerObj = NetEntityHandler.EntityToStreamedItem(Game.Player.Character.Handle) as RemotePlayer;

                if (playerObj != null)
                {
                    Game.Player.IsInvincible = playerObj.IsInvincible;
                }

                if (!string.IsNullOrWhiteSpace(CustomAnimation))
                {
                    var sp = CustomAnimation.Split();

                    if (
                        !Function.Call <bool>(Hash.IS_ENTITY_PLAYING_ANIM, Game.Player.Character,
                                              sp[0], sp[1],
                                              3))
                    {
                        Game.Player.Character.Task.ClearSecondary();

                        Function.Call(Hash.TASK_PLAY_ANIM, Game.Player.Character,
                                      Util.Util.LoadDict(sp[0]), sp[1],
                                      8f, 10f, -1, AnimationFlag, -8f, 1, 1, 1);
                    }
                }

                DEBUG_STEP     = 13;
                _lastPlayerCar = playerCar;


                if (Game.IsControlJustPressed(0, Control.ThrowGrenade) && !Game.Player.Character.IsInVehicle() && IsOnServer() && !Chat.IsFocused)
                {
                    var vehs = World.GetAllVehicles().OrderBy(v => v.Position.DistanceToSquared(Game.Player.Character.Position)).Take(1).ToList();
                    if (vehs.Any() && Game.Player.Character.IsInRangeOfEx(vehs[0].Position, 6f))
                    {
                        var         relPos = vehs[0].GetOffsetFromWorldCoords(Game.Player.Character.Position);
                        VehicleSeat seat   = VehicleSeat.Any;

                        if (relPos.X < 0 && relPos.Y > 0)
                        {
                            seat = VehicleSeat.LeftRear;
                        }
                        else if (relPos.X >= 0 && relPos.Y > 0)
                        {
                            seat = VehicleSeat.RightFront;
                        }
                        else if (relPos.X < 0 && relPos.Y <= 0)
                        {
                            seat = VehicleSeat.LeftRear;
                        }
                        else if (relPos.X >= 0 && relPos.Y <= 0)
                        {
                            seat = VehicleSeat.RightRear;
                        }

                        if (vehs[0].PassengerCapacity == 1)
                        {
                            seat = VehicleSeat.Passenger;
                        }

                        if (vehs[0].PassengerCapacity > 3 && vehs[0].GetPedOnSeat(seat).Handle != 0)
                        {
                            if (seat == VehicleSeat.LeftRear)
                            {
                                for (int i = 3; i < vehs[0].PassengerCapacity; i += 2)
                                {
                                    if (vehs[0].GetPedOnSeat((VehicleSeat)i).Handle == 0)
                                    {
                                        seat = (VehicleSeat)i;
                                        break;
                                    }
                                }
                            }
                            else if (seat == VehicleSeat.RightRear)
                            {
                                for (int i = 4; i < vehs[0].PassengerCapacity; i += 2)
                                {
                                    if (vehs[0].GetPedOnSeat((VehicleSeat)i).Handle == 0)
                                    {
                                        seat = (VehicleSeat)i;
                                        break;
                                    }
                                }
                            }
                        }

                        if (WeaponDataProvider.DoesVehicleSeatHaveGunPosition((VehicleHash)vehs[0].Model.Hash, 0, true) && Game.Player.Character.IsIdle && !Game.Player.IsAiming)
                        {
                            Game.Player.Character.SetIntoVehicle(vehs[0], seat);
                        }
                        else
                        {
                            Game.Player.Character.Task.EnterVehicle(vehs[0], seat, -1, 2f);
                        }
                        _isGoingToCar = true;
                    }
                }

                DEBUG_STEP = 14;

                Game.DisableControlThisFrame(0, Control.SpecialAbility);
                Game.DisableControlThisFrame(0, Control.SpecialAbilityPC);
                Game.DisableControlThisFrame(0, Control.SpecialAbilitySecondary);
                Game.DisableControlThisFrame(0, Control.CharacterWheel);
                Game.DisableControlThisFrame(0, Control.Phone);
                Game.DisableControlThisFrame(0, Control.Duck);

                DEBUG_STEP = 15;

                VehicleSyncManager?.Pulse();

                DEBUG_STEP = 16;

                if (StringCache != null)
                {
                    StringCache?.Pulse();
                }

                DEBUG_STEP = 17;

                double aver = 0;
                lock (_averagePacketSize)
                    aver = _averagePacketSize.Count > 0 ? _averagePacketSize.Average() : 0;

                _statsItem.Text =
                    string.Format(
                        "~h~Bytes Sent~h~: {0}~n~~h~Bytes Received~h~: {1}~n~~h~Bytes Sent / Second~h~: {5}~n~~h~Bytes Received / Second~h~: {6}~n~~h~Average Packet Size~h~: {4}~n~~n~~h~Messages Sent~h~: {2}~n~~h~Messages Received~h~: {3}",
                        _bytesSent, _bytesReceived, _messagesSent, _messagesReceived,
                        aver, _bytesSentPerSecond,
                        _bytesReceivedPerSecond);



                DEBUG_STEP = 18;
                if (Game.IsControlPressed(0, Control.Aim) && !Game.Player.Character.IsInVehicle() && Game.Player.Character.Weapons.Current.Hash != WeaponHash.Unarmed)
                {
                    Game.DisableControlThisFrame(0, Control.Jump);
                }

                //CRASH WORKAROUND: DISABLE PARACHUTE RUINER2
                if (Game.Player.Character.IsInVehicle())
                {
                    if (Game.Player.Character.CurrentVehicle.IsInAir && Game.Player.Character.CurrentVehicle.Model.Hash == 941494461)
                    {
                        Game.DisableAllControlsThisFrame(0);
                    }
                }


                DEBUG_STEP = 19;
                Function.Call((Hash)0x5DB660B38DD98A31, Game.Player, 0f);
                DEBUG_STEP              = 20;
                Game.MaxWantedLevel     = 0;
                Game.Player.WantedLevel = 0;
                DEBUG_STEP              = 21;
                lock (_localMarkers)
                {
                    foreach (var marker in _localMarkers)
                    {
                        World.DrawMarker((MarkerType)marker.Value.MarkerType, marker.Value.Position.ToVector(),
                                         marker.Value.Direction.ToVector(), marker.Value.Rotation.ToVector(),
                                         marker.Value.Scale.ToVector(),
                                         Color.FromArgb(marker.Value.Alpha, marker.Value.Red, marker.Value.Green, marker.Value.Blue));
                    }
                }

                DEBUG_STEP = 22;
                var hasRespawned = (Function.Call <int>(Hash.GET_TIME_SINCE_LAST_DEATH) < 8000 &&
                                    Function.Call <int>(Hash.GET_TIME_SINCE_LAST_DEATH) != -1 &&
                                    Game.Player.CanControlCharacter);

                if (hasRespawned && !_lastDead)
                {
                    _lastDead = true;
                    var msg = Client.CreateMessage();
                    msg.Write((byte)PacketType.PlayerRespawned);
                    Client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.SyncEvent);

                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerRespawn());

                    if (Weather != null)
                    {
                        Function.Call(Hash.SET_WEATHER_TYPE_NOW_PERSIST, Weather);
                    }
                    if (Time.HasValue)
                    {
                        World.CurrentDayTime = new TimeSpan(Time.Value.Hours, Time.Value.Minutes, 00);
                    }

                    Function.Call(Hash.PAUSE_CLOCK, true);

                    var us = NetEntityHandler.EntityToStreamedItem(Game.Player.Character.Handle);

                    NetEntityHandler.ReattachAllEntities(us, true);
                    foreach (
                        var source in
                        Main.NetEntityHandler.ClientMap.Values.Where(
                            item => item is RemoteParticle && ((RemoteParticle)item).EntityAttached == us.RemoteHandle)
                        .Cast <RemoteParticle>())
                    {
                        Main.NetEntityHandler.StreamOut(source);
                        Main.NetEntityHandler.StreamIn(source);
                    }
                }

                var pHealth = player.Health;
                var pArmor  = player.Armor;
                var pGun    = player.Weapons.Current?.Hash ?? WeaponHash.Unarmed;
                var pModel  = player.Model.Hash;

                if (pHealth != _lastPlayerHealth)
                {
                    int test = _lastPlayerHealth;
                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerHealthChange(test));
                }

                if (pArmor != _lastPlayerArmor)
                {
                    int test = _lastPlayerArmor;
                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerArmorChange(test));
                }

                if (pGun != _lastPlayerWeapon)
                {
                    WeaponHash test = _lastPlayerWeapon;
                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerWeaponSwitch((int)test));
                }

                if (pModel != (int)_lastPlayerModel)
                {
                    PedHash test = _lastPlayerModel;
                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerModelChange((int)test));
                }

                _lastPlayerHealth = pHealth;
                _lastPlayerArmor  = pArmor;
                _lastPlayerWeapon = pGun;
                _lastPlayerModel  = (PedHash)pModel;

                DEBUG_STEP = 23;
                _lastDead  = hasRespawned;
                DEBUG_STEP = 24;
                var killed = Game.Player.Character.IsDead;
                DEBUG_STEP = 25;
                if (killed && !_lastKilled)
                {
                    var msg = Client.CreateMessage();
                    msg.Write((byte)PacketType.PlayerKilled);
                    var killer = Function.Call <int>(Hash.GET_PED_SOURCE_OF_DEATH, Game.Player.Character);
                    var weapon = Function.Call <int>(Hash.GET_PED_CAUSE_OF_DEATH, Game.Player.Character);


                    var killerEnt = NetEntityHandler.EntityToNet(killer);
                    msg.Write(killerEnt);
                    msg.Write(weapon);

                    /*
                     * var playerMod = (PedHash)Game.Player.Character.Model.Hash;
                     * if (playerMod != PedHash.Michael && playerMod != PedHash.Franklin && playerMod != PedHash.Trevor)
                     * {
                     *  _lastModel = Game.Player.Character.Model.Hash;
                     *  var lastMod = new Model(PedHash.Michael);
                     *  lastMod.Request(10000);
                     *  Function.Call(Hash.SET_PLAYER_MODEL, Game.Player, lastMod);
                     *  Game.Player.Character.Kill();
                     * }
                     * else
                     * {
                     *  _lastModel = 0;
                     * }
                     */
                    Client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.SyncEvent);

                    JavascriptHook.InvokeCustomEvent(api => api?.invokeonPlayerDeath(new LocalHandle(killer), weapon));

                    NativeUI.BigMessageThread.MessageInstance.ShowColoredShard("WASTED", "", HudColor.HUD_COLOUR_BLACK, HudColor.HUD_COLOUR_RED, 7000);
                    Function.Call(Hash.REQUEST_SCRIPT_AUDIO_BANK, "HUD_MINI_GAME_SOUNDSET", true);
                    Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET");
                }

                /*
                 * if (Function.Call<int>(Hash.GET_TIME_SINCE_LAST_DEATH) < 8000 &&
                 *  Function.Call<int>(Hash.GET_TIME_SINCE_LAST_DEATH) != -1)
                 * {
                 *  if (_lastModel != 0 && Game.Player.Character.Model.Hash != _lastModel)
                 *  {
                 *      var lastMod = new Model(_lastModel);
                 *      lastMod.Request(10000);
                 *      Function.Call(Hash.SET_PLAYER_MODEL, new InputArgument(Game.Player), lastMod.Hash);
                 *  }
                 * }
                 */


                DEBUG_STEP = 28;


                if (!IsSpectating && _lastSpectating)
                {
                    Game.Player.Character.Opacity          = 255;
                    Game.Player.Character.IsPositionFrozen = false;
                    Game.Player.IsInvincible = false;
                    Game.Player.Character.IsCollisionEnabled = true;
                    SpectatingEntity                       = 0;
                    CurrentSpectatingPlayer                = null;
                    _currentSpectatingPlayerIndex          = 100000;
                    Game.Player.Character.PositionNoOffset = _preSpectatorPos;
                }
                if (IsSpectating)
                {
                    if (SpectatingEntity != 0)
                    {
                        Game.Player.Character.Opacity          = 0;
                        Game.Player.Character.IsPositionFrozen = true;
                        Game.Player.IsInvincible = true;
                        Game.Player.Character.IsCollisionEnabled = false;

                        Control[] exceptions = new[]
                        {
                            Control.LookLeftRight,
                            Control.LookUpDown,
                            Control.LookLeft,
                            Control.LookRight,
                            Control.LookUp,
                            Control.LookDown,
                        };

                        Game.DisableAllControlsThisFrame(0);
                        foreach (var c in exceptions)
                        {
                            Game.EnableControlThisFrame(0, c);
                        }

                        var ent = NetEntityHandler.NetToEntity(SpectatingEntity);

                        if (ent != null)
                        {
                            if (Function.Call <bool>(Hash.IS_ENTITY_A_PED, ent) && new Ped(ent.Handle).IsInVehicle())
                            {
                                Game.Player.Character.PositionNoOffset = ent.Position + new GTA.Math.Vector3(0, 0, 1.3f);
                            }
                            else
                            {
                                Game.Player.Character.PositionNoOffset = ent.Position;
                            }
                        }
                    }
                    else if (SpectatingEntity == 0 && CurrentSpectatingPlayer == null &&
                             NetEntityHandler.ClientMap.Values.Count(op => op is SyncPed && !((SyncPed)op).IsSpectating &&
                                                                     (((SyncPed)op).Team == 0 || ((SyncPed)op).Team == Main.LocalTeam) &&
                                                                     (((SyncPed)op).Dimension == 0 || ((SyncPed)op).Dimension == Main.LocalDimension)) > 0)
                    {
                        CurrentSpectatingPlayer =
                            NetEntityHandler.ClientMap.Values.Where(
                                op =>
                                op is SyncPed && !((SyncPed)op).IsSpectating &&
                                (((SyncPed)op).Team == 0 || ((SyncPed)op).Team == Main.LocalTeam) &&
                                (((SyncPed)op).Dimension == 0 || ((SyncPed)op).Dimension == Main.LocalDimension))
                            .ElementAt(_currentSpectatingPlayerIndex %
                                       NetEntityHandler.ClientMap.Values.Count(
                                           op =>
                                           op is SyncPed && !((SyncPed)op).IsSpectating &&
                                           (((SyncPed)op).Team == 0 || ((SyncPed)op).Team == Main.LocalTeam) &&
                                           (((SyncPed)op).Dimension == 0 ||
                                            ((SyncPed)op).Dimension == Main.LocalDimension))) as SyncPed;
                    }
                    else if (SpectatingEntity == 0 && CurrentSpectatingPlayer != null)
                    {
                        Game.Player.Character.Opacity          = 0;
                        Game.Player.Character.IsPositionFrozen = true;
                        Game.Player.IsInvincible = true;
                        Game.Player.Character.IsCollisionEnabled = false;
                        Game.DisableAllControlsThisFrame(0);

                        if (CurrentSpectatingPlayer.Character == null)
                        {
                            Game.Player.Character.PositionNoOffset = CurrentSpectatingPlayer.Position;
                        }
                        else if (CurrentSpectatingPlayer.IsInVehicle)
                        {
                            Game.Player.Character.PositionNoOffset = CurrentSpectatingPlayer.Character.Position + new GTA.Math.Vector3(0, 0, 1.3f);
                        }
                        else
                        {
                            Game.Player.Character.PositionNoOffset = CurrentSpectatingPlayer.Character.Position;
                        }

                        if (Game.IsControlJustPressed(0, Control.PhoneLeft))
                        {
                            _currentSpectatingPlayerIndex--;
                            CurrentSpectatingPlayer = null;
                        }
                        else if (Game.IsControlJustPressed(0, Control.PhoneRight))
                        {
                            _currentSpectatingPlayerIndex++;
                            CurrentSpectatingPlayer = null;
                        }

                        if (CurrentSpectatingPlayer != null)
                        {
                            var center = new Point((int)(res.Width / 2), (int)(res.Height / 2));

                            new UIResText("Now spectating:~n~" + CurrentSpectatingPlayer.Name,
                                          new Point(center.X, (int)(res.Height - 200)), 0.4f, Color.White, GTA.UI.Font.ChaletLondon,
                                          UIResText.Alignment.Centered)
                            {
                                Outline = true,
                            }.Draw();

                            new Sprite("mparrow", "mp_arrowxlarge", new Point(center.X - 264, (int)(res.Height - 232)), new Size(64, 128), 180f, Color.White).Draw();
                            new Sprite("mparrow", "mp_arrowxlarge", new Point(center.X + 200, (int)(res.Height - 232)), new Size(64, 128)).Draw();
                        }
                    }
                }

                _lastSpectating = IsSpectating;

                _lastKilled = killed;

                var collection = new CallCollection();

                collection.Call(Hash.SET_RANDOM_TRAINS, 0);
                collection.Call(Hash.CAN_CREATE_RANDOM_COPS, false);
                DEBUG_STEP = 29;
                collection.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
                collection.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0);
                collection.Call(Hash.SET_PED_POPULATION_BUDGET, 0);
                collection.Call(Hash.SUPPRESS_SHOCKING_EVENTS_NEXT_FRAME);
                collection.Call(Hash.SUPPRESS_AGITATION_EVENTS_NEXT_FRAME);
                collection.Call(Hash.SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
                collection.Call(Hash.SET_PARKED_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
                collection.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, -1);
                collection.Call(Hash.SET_ALL_LOW_PRIORITY_VEHICLE_GENERATORS_ACTIVE, false);
                collection.Call(Hash.SET_FAR_DRAW_VEHICLES, false);
                collection.Call(Hash.DESTROY_MOBILE_PHONE);
                collection.Call((Hash)0x015C49A93E3E086E, true);
                collection.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
                collection.Call(Hash.SET_SCENARIO_PED_DENSITY_MULTIPLIER_THIS_FRAME, 0f, 0f);
                collection.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Game.Player.Character, true, true);
                collection.Call(Hash.SET_PED_CAN_BE_TARGETTED, Game.Player.Character, true);
                collection.Call((Hash)0xF796359A959DF65D, false); // Display distant vehicles
                collection.Call(Hash.SET_AUTO_GIVE_PARACHUTE_WHEN_ENTER_PLANE, Game.Player, false);
                collection.Call((Hash)0xD2B315B6689D537D, Game.Player, false);
                collection.Call(Hash.DISPLAY_CASH, false);
                collection.Execute();
                DEBUG_STEP = 30;


                GameScript.Pulse();

                if ((Game.Player.Character.Position - _lastWaveReset).LengthSquared() > 10000f) // 100f * 100f
                {
                    Function.Call((Hash)0x5E5E99285AE812DB);
                    Function.Call((Hash)0xB96B00E976BE977F, 0f);

                    _lastWaveReset = Game.Player.Character.Position;
                }

                Function.Call((Hash)0x2F9A292AD0A3BD89);
                Function.Call((Hash)0x5F3B7749C112D552);

                if (Function.Call <bool>(Hash.IS_STUNT_JUMP_IN_PROGRESS))
                {
                    Function.Call(Hash.CANCEL_STUNT_JUMP);
                }

                DEBUG_STEP = 31;
                if (Function.Call <int>(Hash.GET_PED_PARACHUTE_STATE, Game.Player.Character) == 2)
                {
                    Game.DisableControlThisFrame(0, Control.Aim);
                    Game.DisableControlThisFrame(0, Control.Attack);
                }
                DEBUG_STEP = 32;


                if (RemoveGameEntities && Util.Util.TickCount - _lastEntityRemoval > 500) // Save ressource
                {
                    _lastEntityRemoval = Util.Util.TickCount;
                    foreach (var entity in World.GetAllPeds())
                    {
                        if (!NetEntityHandler.ContainsLocalHandle(entity.Handle) && entity != Game.Player.Character)
                        {
                            entity.Kill(); //"Some special peds like Epsilon guys or seashark minigame will refuse to despawn if you don't kill them first." - Guad
                            entity.Delete();
                        }
                    }

                    foreach (var entity in World.GetAllVehicles())
                    {
                        if (entity == null)
                        {
                            continue;
                        }
                        var veh = NetEntityHandler.NetToStreamedItem(entity.Handle, useGameHandle: true) as RemoteVehicle;
                        if (veh == null)
                        {
                            entity.Delete();
                            continue;
                        }
                        //TO CHECK
                        if (entity.IsVehicleEmpty() && !VehicleSyncManager.IsInterpolating(entity.Handle) && veh.TraileredBy == 0 && !VehicleSyncManager.IsSyncing(veh) && ((entity.Handle == Game.Player.LastVehicle?.Handle && DateTime.Now.Subtract(LastCarEnter).TotalMilliseconds > 3000) || entity.Handle != Game.Player.LastVehicle?.Handle))
                        {
                            if (entity.Position.DistanceToSquared(veh.Position.ToVector()) > 2f)
                            {
                                entity.PositionNoOffset = veh.Position.ToVector();
                                entity.Quaternion       = veh.Rotation.ToVector().ToQuaternion();
                            }
                        }

                        //veh.Position = entity.Position.ToLVector();
                        //veh.Rotation = entity.Rotation.ToLVector();
                    }
                }
                _whoseturnisitanyways = !_whoseturnisitanyways;

                DEBUG_STEP = 34;
                NetEntityHandler.UpdateAttachments();
                DEBUG_STEP = 35;
                NetEntityHandler.DrawMarkers();
                DEBUG_STEP = 36;
                NetEntityHandler.DrawLabels();
                DEBUG_STEP = 37;
                NetEntityHandler.UpdateMisc();
                DEBUG_STEP = 38;
                NetEntityHandler.UpdateInterpolations();
                DEBUG_STEP = 39;
                WeaponInventoryManager.Update();
                DEBUG_STEP = 40;

                /*string stats = string.Format("{0}Kb (D)/{1}Kb (U), {2}Msg (D)/{3}Msg (U)", _bytesReceived / 1000,
                 *  _bytesSent / 1000, _messagesReceived, _messagesSent);
                 */
                //GTA.UI.Screen.ShowSubtitle(stats);


                PedThread.OnTick("thisaintnullnigga", e);

                DebugInfo.Draw();

                //Thread calcucationThread = new Thread(Work);
                //calcucationThread.IsBackground = true;
                //calcucationThread.Start();

                lock (_threadJumping)
                {
                    if (_threadJumping.Any())
                    {
                        Action action = _threadJumping.Dequeue();
                        if (action != null)
                        {
                            action.Invoke();
                        }
                    }
                }
                DEBUG_STEP = 41;
            }
            catch (Exception ex) // Catch any other exception. (can prevent crash)
            {
                LogManager.LogException(ex, "MAIN OnTick: STEP : " + DEBUG_STEP);
            }
        }
Пример #29
0
    void generateColliders(CustomAnimation customAnimation)
    {
        // Destroy all already existing colliders from the object to prevent duplicates.
        foreach (PolygonCollider2D pc in customAnimation.gameObject.GetComponents<PolygonCollider2D>())
            DestroyImmediate(pc);

        // Create a new array and replace the current array of colliders, rendering it empty and at the right size.
        customAnimation.animationColliders = new PolygonCollider2D[customAnimation.animationFrames.Length];

        // Generate a collider for each frame and add it to the array of colliders.
        for (int i = 0; i < customAnimation.animationFrames.Length; i++)
        {
            // Create a new collider.
            PolygonCollider2D collider = customAnimation.gameObject.AddComponent<PolygonCollider2D>();

            // Create a list of all corners (corners). This will be used to create a collider around the object.
            List<Vector2> corners = new List<Vector2>();

            // Find the borders of the current sprite and assign them to offsets. (Else if the sprite is on a spritesheet, the entire spritesheet would be read)
            int xOffset = Mathf.RoundToInt(customAnimation.animationFrames[i].rect.xMin);
            int yOffset = Mathf.RoundToInt(customAnimation.animationFrames[i].rect.yMin);

            // Find all the corners by searching horizontally on each row.
            for (int y = -1; y < customAnimation.animationFrames[i].rect.height + 1; y++)
            {
                for (int x = -1; x < customAnimation.animationFrames[i].rect.width + 1; x++)
                {
                    // Create a variable that will count the amount of colored pixels surrounding a point.
                    int coloredPixels = 0;

                    // Check if the pixels surrounding a point is colored and if they are, increase the counter.
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x, yOffset + y).a != 0) coloredPixels++;
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x + 1, yOffset + y).a != 0) coloredPixels++;
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x, yOffset + y + 1).a != 0) coloredPixels++;
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x + 1, yOffset + y + 1).a != 0) coloredPixels++;

                    // If the number of colored pixels surrounding the point is 1 or 3, then it's a corner.
                    if (coloredPixels == 1 || coloredPixels == 3)
                        corners.Add(new Vector2(x - customAnimation.animationFrames[i].pivot.x + 1, y - customAnimation.animationFrames[i].pivot.y + 1) / customAnimation.animationFrames[i].pixelsPerUnit);
                }
            }

            // Create a new vector that will be holding all corners of the sprite.
            List<Vector2> newCorners = new List<Vector2>();

            // Add the first corner to the list of new corners, making it the start point.
            newCorners.Add(corners[0]);

            // Remove it from the old list and re-add it at the end, making it the final corner.
            corners.RemoveAt(0);
            //corners.Add(newCorners[0]);

            // A variable used to check for infinite recursion. If the next while-loop loops without finding a new valid corner it will continue to do so forever, and that will freeze the editor too.
            int lastCount = 0;

            // While there are corners who are not currently a part of the collider, find the next one.
            while (corners.Count > 0)
            {
                // Protect against infinite recursion.
                if (lastCount == corners.Count)
                {
                    collider.points = newCorners.ToArray();
                    customAnimation.animationColliders[i] = collider;
                    throw new System.Exception("Infinite loop at " + newCorners[newCorners.Count - 1] + ". Corners left: " + corners.Count);
                }
                else
                    lastCount = corners.Count;

                // Sort the corners by distance to the last corner.
                corners.Sort((v1, v2) => Vector2.Distance(v1, newCorners[newCorners.Count - 1]).CompareTo(Vector2.Distance(v2, newCorners[newCorners.Count - 1])));

                // From the first (closest) corner and forward, check if it is a valid next move. If it is, make it the next corner and stop searching.
                for (int startIndex = 0; startIndex < corners.Count; startIndex++)
                {
                    bool isValid = isValidMove(newCorners[newCorners.Count - 1], corners[startIndex], customAnimation.animationFrames[i]);

                    if (((newCorners[newCorners.Count - 1].x == corners[startIndex].x) || (newCorners[newCorners.Count - 1].y == corners[startIndex].y)) && isValid)
                    {
                        Debug.Log("Moved to: " + corners[startIndex]);

                        newCorners.Add(corners[startIndex]);
                        corners.RemoveAt(startIndex);
                        break;
                    }
                }
            }

            // Update the new collider.
            collider.points = newCorners.ToArray();
            customAnimation.animationColliders[i] = collider;
        }
    }
Пример #30
0
 //Adds an animation to the queue to be played
 public void AddToAnimationQueue(CustomAnimation a_Animation)
 {
     m_Animations.Enqueue(a_Animation);
 }
Пример #31
0
 public void Add(CustomAnimation customAnimation)
 {
     animations.Add(customAnimation);
 }
    void generateColliders(CustomAnimation customAnimation)
    {
        // Destroy all already existing colliders from the object to prevent duplicates.
        foreach (PolygonCollider2D pc in customAnimation.gameObject.GetComponents <PolygonCollider2D>())
        {
            DestroyImmediate(pc);
        }

        // Create a new array and replace the current array of colliders, rendering it empty and at the right size.
        customAnimation.animationColliders = new PolygonCollider2D[customAnimation.animationFrames.Length];

        // Generate a collider for each frame and add it to the array of colliders.
        for (int i = 0; i < customAnimation.animationFrames.Length; i++)
        {
            // Create a new collider.
            PolygonCollider2D collider = customAnimation.gameObject.AddComponent <PolygonCollider2D>();

            // Create a list of all corners (corners). This will be used to create a collider around the object.
            List <Vector2> corners = new List <Vector2>();

            // Find the borders of the current sprite and assign them to offsets. (Else if the sprite is on a spritesheet, the entire spritesheet would be read)
            int xOffset = Mathf.RoundToInt(customAnimation.animationFrames[i].rect.xMin);
            int yOffset = Mathf.RoundToInt(customAnimation.animationFrames[i].rect.yMin);

            // Find all the corners by searching horizontally on each row.
            for (int y = -1; y < customAnimation.animationFrames[i].rect.height + 1; y++)
            {
                for (int x = -1; x < customAnimation.animationFrames[i].rect.width + 1; x++)
                {
                    // Create a variable that will count the amount of colored pixels surrounding a point.
                    int coloredPixels = 0;

                    // Check if the pixels surrounding a point is colored and if they are, increase the counter.
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x, yOffset + y).a != 0)
                    {
                        coloredPixels++;
                    }
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x + 1, yOffset + y).a != 0)
                    {
                        coloredPixels++;
                    }
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x, yOffset + y + 1).a != 0)
                    {
                        coloredPixels++;
                    }
                    if (customAnimation.animationFrames[i].texture.GetPixel(xOffset + x + 1, yOffset + y + 1).a != 0)
                    {
                        coloredPixels++;
                    }

                    // If the number of colored pixels surrounding the point is 1 or 3, then it's a corner.
                    if (coloredPixels == 1 || coloredPixels == 3)
                    {
                        corners.Add(new Vector2(x - customAnimation.animationFrames[i].pivot.x + 1, y - customAnimation.animationFrames[i].pivot.y + 1) / customAnimation.animationFrames[i].pixelsPerUnit);
                    }
                }
            }

            // Create a new vector that will be holding all corners of the sprite.
            List <Vector2> newCorners = new List <Vector2>();

            // Add the first corner to the list of new corners, making it the start point.
            newCorners.Add(corners[0]);

            // Remove it from the old list and re-add it at the end, making it the final corner.
            corners.RemoveAt(0);
            //corners.Add(newCorners[0]);

            // A variable used to check for infinite recursion. If the next while-loop loops without finding a new valid corner it will continue to do so forever, and that will freeze the editor too.
            int lastCount = 0;

            // While there are corners who are not currently a part of the collider, find the next one.
            while (corners.Count > 0)
            {
                // Protect against infinite recursion.
                if (lastCount == corners.Count)
                {
                    collider.points = newCorners.ToArray();
                    customAnimation.animationColliders[i] = collider;
                    throw new System.Exception("Infinite loop at " + newCorners[newCorners.Count - 1] + ". Corners left: " + corners.Count);
                }
                else
                {
                    lastCount = corners.Count;
                }

                // Sort the corners by distance to the last corner.
                corners.Sort((v1, v2) => Vector2.Distance(v1, newCorners[newCorners.Count - 1]).CompareTo(Vector2.Distance(v2, newCorners[newCorners.Count - 1])));

                // From the first (closest) corner and forward, check if it is a valid next move. If it is, make it the next corner and stop searching.
                for (int startIndex = 0; startIndex < corners.Count; startIndex++)
                {
                    bool isValid = isValidMove(newCorners[newCorners.Count - 1], corners[startIndex], customAnimation.animationFrames[i]);

                    if (((newCorners[newCorners.Count - 1].x == corners[startIndex].x) || (newCorners[newCorners.Count - 1].y == corners[startIndex].y)) && isValid)
                    {
                        Debug.Log("Moved to: " + corners[startIndex]);

                        newCorners.Add(corners[startIndex]);
                        corners.RemoveAt(startIndex);
                        break;
                    }
                }
            }

            // Update the new collider.
            collider.points = newCorners.ToArray();
            customAnimation.animationColliders[i] = collider;
        }
    }
Пример #33
0
    private void appearMonster()
    {
        lastResults2 = "In appear monster";
        GameObject.FindGameObjectWithTag(taggedObject).transform.position = new Vector3(GetComponent<BorderCollision>().leftBorder+3f, GameObject.FindGameObjectWithTag(taggedObject).transform.position.y, GameObject.FindGameObjectWithTag(taggedObject).transform.position.z);  // move ship to opposite side
        //Enable bounds in case monster runs out of bounds
        GetComponent<BorderCollision>().enabled = true;

        //Configure the animation
        CustomAnimation appearAnimation = new CustomAnimation(false,false,"APPEAR");
        appearAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        appearAnimation.animation = "MonsterIdleScratches.mp4";
        appearAnimation.audio = "Sounds/MonsterSounds/curious hmm sound 01";
        appearAnimation.direction = new Vector2(0f,0f);
        appearAnimation.victim = this.gameObject;
        appearAnimation.animationTime = 4f;
        //Enqueue it!
        animationQueue.Enqueue(appearAnimation);
    }
Пример #34
0
 private void monsterStop()
 {
     if(currentAnimation!=null)currentAnimation.stopAnimation();
     animationQueue.Clear();
     if(!isVisible()){
         appearMonster();
     }
     //Configure the animation
     CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"STOP");
     heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
     heyMonsterAnimation.animation = "Monster Looks Up.mp4";
     heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
     heyMonsterAnimation.direction = new Vector2(0f,0f);
     heyMonsterAnimation.running = true;
     heyMonsterAnimation.flippedX = true;
     heyMonsterAnimation.victim = this.gameObject;
     heyMonsterAnimation.animationTime = 3f;
     animationQueue.Enqueue(heyMonsterAnimation);
     StartCoroutine(PlayAnimations());
 }
Пример #35
0
    private void askMonster()
    {
        if(currentAnimation!=null)currentAnimation.stopAnimation();

        //Show monster onscreen
        animationQueue.Clear();

        if(!isVisible()){
            appearMonster();
        }

        CustomAnimation askMonsterAnimation = new CustomAnimation(false,false,"NO1");
        askMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        askMonsterAnimation.animation = "Monster NO 1.mp4";
        askMonsterAnimation.audio = "Sounds/MonsterSounds/no sound 01";
        askMonsterAnimation.direction = new Vector2(0f,0f);
        askMonsterAnimation.victim = this.gameObject;
        askMonsterAnimation.animationTime = 6f;
        animationQueue.Enqueue(askMonsterAnimation);

        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"IDLE1");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "MonsterIdleBreaths Hard.mp4";
        heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
        heyMonsterAnimation.animationTime = 2f;
        heyMonsterAnimation.direction = new Vector2(0f,0f);
        heyMonsterAnimation.victim = this.gameObject;

        animationQueue.Enqueue(askMonsterAnimation);
        StartCoroutine(PlayAnimations());
    }
Пример #36
0
    private void monsterUp()
    {
        if(currentAnimation!=null)currentAnimation.stopAnimation();

        animationQueue.Clear();
        if(!isVisible()){
            appearMonster();
        }
        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"UP");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "";
        heyMonsterAnimation.audio = "";
        heyMonsterAnimation.direction = new Vector2(0f,1f);
        heyMonsterAnimation.running = true;
        heyMonsterAnimation.victim = this.gameObject;
        animationQueue.Enqueue(heyMonsterAnimation);
        StartCoroutine(PlayAnimations());
    }
Пример #37
0
    private void rain()
    {
        if(currentAnimation!=null)currentAnimation.stopAnimation();

        animationQueue.Clear();
        if(!isVisible()){
            appearMonster();
        }
        //Change the background
        switchToDay();
        //Bring forth the sun
        switchToNight();
        hideStars();
        hideSun();
        hideFlowers();
        hideThunder();
        showRain();
        //Start the flower animation
        StartCoroutine(StartRain());

        //Monster Look Up animation
        CustomAnimation MonsterLookUp = new CustomAnimation(false,false,"LOOKDOWN");
        MonsterLookUp.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterLookUp.animation = "MonsterIdleBlinks.mp4";
        MonsterLookUp.audio = "Sounds/MonsterSounds/monsterLaughs";
        MonsterLookUp.direction = new Vector2(0f,0f);
        MonsterLookUp.victim = this.gameObject;
        MonsterLookUp.animationTime = 3f;

        animationQueue.Enqueue(MonsterLookUp);

        //Enqueue the monster NO animation
        CustomAnimation MonsterNo2 = new CustomAnimation(false,false,"NO1");
        MonsterNo2.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterNo2.animation = "Monster NO 1.mp4";
        MonsterNo2.audio = "Sounds/MonsterSounds/no sound 01";
        MonsterNo2.direction = new Vector2(0f,0f);
        MonsterNo2.victim = this.gameObject;
        MonsterNo2.animationTime = 5f;

        animationQueue.Enqueue(MonsterNo2);

        //Monster Default Animation
        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"LEFT");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "MonsterRuns03.mp4";
        heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
        heyMonsterAnimation.direction = new Vector2(-1f,0f);
        heyMonsterAnimation.running = true;
        heyMonsterAnimation.animationTime = 3f;
        heyMonsterAnimation.victim = this.gameObject;

        animationQueue.Enqueue(heyMonsterAnimation);

        StartCoroutine(PlayAnimations());
    }
Пример #38
0
    private void sunShine()
    {
        if(currentAnimation!=null)currentAnimation.stopAnimation();

        animationQueue.Clear();
        if(!isVisible()){
            appearMonster();
        }
        //Change the background
        switchToDay();
        //Bring forth the sun
        showSun();
        hideStars();
        hideThunder();
        hideFlowers();
        hideRain();
        //Start the sun shine animation
        StartCoroutine(SunRiseandShine());
        //Monster Look Up animation
        CustomAnimation MonsterLookUp = new CustomAnimation(false,false,"LOOKUP");
        MonsterLookUp.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterLookUp.animation = "Monster Looks Up.mp4";
        MonsterLookUp.audio = "Sounds/MonsterSounds/muttering";
        MonsterLookUp.direction = new Vector2(0f,0f);
        MonsterLookUp.victim = this.gameObject;
        MonsterLookUp.animationTime = 3f;

        animationQueue.Enqueue(MonsterLookUp);

        //Enqueue the monster NO animation
        CustomAnimation MonsterNo2 = new CustomAnimation(false,false,"NO2");
        MonsterNo2.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterNo2.animation = "Monster NO 2.mp4";
        MonsterNo2.audio = "Sounds/MonsterSounds/no sound 02";
        MonsterNo2.direction = new Vector2(0f,0f);
        MonsterNo2.victim = this.gameObject;
        MonsterNo2.animationTime = 7f;

        animationQueue.Enqueue(MonsterNo2);

        //Monster Default Animation
        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"IDLE1");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "MonsterIdleBreaths Hard.mp4";
        heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
        heyMonsterAnimation.direction = new Vector2(0f,0f);
        heyMonsterAnimation.animationTime = 3f;
        heyMonsterAnimation.victim = this.gameObject;

        animationQueue.Enqueue(heyMonsterAnimation);
        StartCoroutine(PlayAnimations());
    }
Пример #39
0
 public IEnumerator PlayAnimations()
 {
     for(int i = 1;i<=animationQueue.Count-1;i++){
         CustomAnimation current = (CustomAnimation) animationQueue.Peek();
         current.loadAnimation();
         currentAnimation = current;
         setAnimationProperties();
         current.startAnimation();
         currentAnimation = current;
         yield return new WaitForSeconds(current.animationTime);
         animationQueue.Dequeue();
     }
     if(animationQueue.Count>1)
         animationQueue.Dequeue();
     CustomAnimation last =(CustomAnimation)  animationQueue.Peek();
     last.screenItem.m_bLoop = true;
     last.screenItem.m_bAutoPlay = true;
     last.loadAnimation();
     setAnimationProperties();
     last.startAnimation();
     currentAnimation = last;
 }
Пример #40
0
    private void thunder()
    {
        if(currentAnimation!=null)
            currentAnimation.stopAnimation();

        animationQueue.Clear();

        if(!isVisible()){
            appearMonster();
        }
        //Change the background
        switchToNight();
        //Bring forth the stars
        hideStars();
        //Shove the sun back
        hideSun();
        hideFlowers();
        hideRain();
        showThunder();

        //Start the sun shine animation
        StartCoroutine(StartThunder());
        //Monster Look Up animation

        CustomAnimation MonsterLookUp = new CustomAnimation(false,false,"LOOKUP");
        MonsterLookUp.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterLookUp.animation = "Monster Looks Up.mp4";
        MonsterLookUp.audio = "Sounds/MonsterSounds/positive hmm sound";
        MonsterLookUp.direction = new Vector2(0f,0f);
        MonsterLookUp.victim = this.gameObject;
        MonsterLookUp.animationTime = 4f;
        animationQueue.Enqueue(MonsterLookUp);

        //Enqueue the monster NO animation
        CustomAnimation MonsterNo2 = new CustomAnimation(false,false,"YES");
        MonsterNo2.screenItem = GetComponent<MediaPlayerCtrl>();
        MonsterNo2.animation = "Monster Looks Up.mp4";
        MonsterNo2.audio = "Sounds/MonsterSounds/yes sound 01";
        MonsterNo2.direction = new Vector2(0f,0f);
        MonsterNo2.victim = this.gameObject;
        MonsterNo2.animationTime = 3f;

        animationQueue.Enqueue(MonsterNo2);

        CustomAnimation heyMonsterAnimation = new CustomAnimation(false,false,"IDLE1");
        heyMonsterAnimation.screenItem = GetComponent<MediaPlayerCtrl>();
        heyMonsterAnimation.animation = "MonsterIdleBreaths Hard.mp4";
        heyMonsterAnimation.audio = "Sounds/MonsterSounds/breath01";
        heyMonsterAnimation.direction = new Vector2(0f,0f);
        heyMonsterAnimation.animationTime = 3f;
        heyMonsterAnimation.victim = this.gameObject;

        animationQueue.Enqueue(heyMonsterAnimation);

        StartCoroutine(PlayAnimations());
    }