public override void BeHit(int damage)
 {
     base.BeHit(damage);
     GlobalVariables.PlayEffectSound("behit");
 }
        public override void Update(GameTime gameTime)
        {
            if (_listPoisonDamage.Count != 0)
            {
                IsPoisoning = true;
            }
            else
            {
                IsPoisoning = false;
            }
            for (int i = 0; i < _listPoisonDamage.Count; ++i)
            {
                if (_listPoisonDamage[i].Duration % _listPoisonDamage[i].EffectMoment == 0)
                {
                    RecentHPLost += _listPoisonDamage[i].DamageValue;
                }
                _listPoisonDamage[i].Duration -= 1;
                if (_listPoisonDamage[i].Duration == 0)
                {
                    _listPoisonDamage.Remove(_listPoisonDamage[i]);
                }
            }
            if (CheckForDisplayDamage == 0)
            {
                if (RecentHPLost != 0)
                {
                    StateOwner._displayMessageLayer.MessageArray.Add(new DisplayMessageLayer.Message
                    {
                        X              = this.X,
                        Y              = this.Y - 2 * GlobalVariables.MapCollisionDim,
                        Owner          = this,
                        DeltaY         = -1,
                        LifeTime       = 45,
                        MessageContent = RecentHPLost.ToString(),
                        TextColor      = Color.Red,
                        MinY           = (int)this.Y - 2 * GlobalVariables.MapCollisionDim - 30,
                    });
                }

                Hp                   += RecentHPLost;
                RecentHPLost          = 0;
                CheckForDisplayDamage = 30;
            }
            else
            {
                --CheckForDisplayDamage;
            }
            if (IsDying || IsDyed)
            {
                BashTime = 0;
            }
            for (int i = 0; i < AdditionnalEffect.Count; ++i)
            {
                AdditionnalEffect[i].Update(gameTime);

                if (AdditionnalEffect[i].IsCollisionWith(this) && AdditionnalEffect[i].HitFrames.Contains(AdditionnalEffect[i]._sprite[0].Itexture2D) && AdditionnalEffect[i]._sprite[0].Check == 0 && !this.EffectedSkill.Contains(AdditionnalEffect[i].SkillOwner))
                {
                    this.BeHit(GlobalVariables.GlobalRandom.Next(AdditionnalEffect[i].MinDamage, AdditionnalEffect[i].MaxDamage));
                    if (AdditionnalEffect[i].SkillOwner != null)
                    {
                        AdditionnalEffect[i].SkillOwner.DoAdditionalEffect(this);
                    }
                    this.EffectedSkill.Add(AdditionnalEffect[i].SkillOwner);
                }
                else
                if (AdditionnalEffect[i]._sprite[0].Itexture2D == AdditionnalEffect[i]._sprite[0].Ntexture2D - 2)
                {
                    this.EffectedSkill.Remove(AdditionnalEffect[i].SkillOwner);
                }

                if (AdditionnalEffect[i]._sprite[0].Itexture2D == AdditionnalEffect[i]._sprite[0].Ntexture2D - 1)
                {
                    AdditionnalEffect.Remove(AdditionnalEffect[i]);
                }
            }
            if (BashTime > 0)
            {
                --BashTime;
                return;
            }

            _sprite[Dir].Update(gameTime);

            if (this.Hp <= 0 && !IsDying && !IsDyed)
            {
                IsDying = true;
            }

            if (IsDying)
            {
                UpdateDirection(X, Y);
                if (Target != null)
                {
                    Target = null;
                }
                if (_sprite[Dir].Itexture2D == _sprite[Dir].Ntexture2D - 1)
                {
                    IsDyed = true;
                    GlobalVariables.PlayEffectSound("monster" + GlobalVariables.GlobalRandom.Next(1, 17).ToString());
                    int dropItemRate = GlobalVariables.GlobalRandom.Next(0, 100);
                    if (dropItemRate < 35)
                    {
                        int     portionKindRate = GlobalVariables.GlobalRandom.Next(0, 100);
                        Portion portion         = new Portion();
                        portion.PlayerOwner = StateOwner._char;
                        if (portionKindRate < 40)
                        {
                            portion.HP = 1500;
                            portion.MP = 0;
                            StateOwner._char.HPPortion.Add(portion);
                            StateOwner._displayMessageLayer.InfoMessageArray.Add(new DisplayMessageLayer.InfoMessage
                            {
                                MessageContent = "Gain HP portion",
                                LifeTime       = 120,
                                TextColor      = Color.LightCoral,
                            });
                        }
                        if (40 <= portionKindRate && portionKindRate < 80)
                        {
                            portion.HP = 0;
                            portion.MP = 1000;
                            StateOwner._char.MPPortion.Add(portion);
                            StateOwner._displayMessageLayer.InfoMessageArray.Add(new DisplayMessageLayer.InfoMessage
                            {
                                MessageContent = "Gain MP portion",
                                LifeTime       = 120,
                                TextColor      = Color.LightBlue,
                            });
                        }
                        if (80 <= portionKindRate)
                        {
                            portion.HP = 1500;
                            portion.MP = 1000;
                            StateOwner._char.RestorePortion.Add(portion);
                            StateOwner._displayMessageLayer.InfoMessageArray.Add(new DisplayMessageLayer.InfoMessage
                            {
                                MessageContent = "Gain Restore portion",
                                LifeTime       = 120,
                                TextColor      = Color.Violet,
                            });
                        }
                    }
                    StateOwner._char.CurrentEXP += ExpReward;

                    StateOwner._displayMessageLayer.InfoMessageArray.Add(new DisplayMessageLayer.InfoMessage
                    {
                        MessageContent = "Gain " + ExpReward.ToString() + " exp",
                        LifeTime       = 120,
                        TextColor      = Color.Wheat,
                    });
                    if (StateOwner._char.CurrentEXP >= StateOwner._char.NextLevelEXP)
                    {
                        StateOwner._char.DoLevelUp();
                    }
                }
                return;
            }

            if (IsDyed)
            {
                return;
            }
            if (_target != null && IsAttacking && this.IsCollisionWith(_target))
            {
                UpdateDirection(_target.X, _target.Y);
                return;
            }
            if (_target == null)
            {
                if (!IsCasting)
                {
                    Move();
                    UpdateDirection(DestPoint.X, DestPoint.Y);
                }
            }
            else
            {
                if (this.IsCollisionWith(_target))
                {
                    if (!IsAttacking)
                    {
                        IsAttacking = true;
                        UpdateDirection(_target.X, _target.Y);
                        DestPoint  = new Point((int)X, (int)Y);
                        CellToMove = new List <Point>();
                    }
                }
                else
                {
                    CellToMove = Utility.FindPath(Map.Matrix, Map.PointToCell(new Point((int)X, (int)Y)), Map.PointToCell(new Point((int)Target.X, (int)Target.Y)));
                    if (CellToMove.Count >= 1)
                    {
                        IsMoving = true;
                        Move();
                        UpdateDirection(DestPoint.X, DestPoint.Y);
                    }
                    else
                    {
                        IsAttacking = true;
                        UpdateDirection(_target.X, _target.Y);
                        CellToMove = new List <Point>();
                    }
                }
            }

            if (Hp <= 0 && !(IsDying || IsDyed))
            {
                IsDying = true;
                UpdateDirection(this.X, this.Y);
            }
        }
        public override void Update(GameTime gameTime)
        {
            PassiveSkillCheck -= 1;
            if (PassiveSkillCheck == 0)
            {
                PassiveSkillCheck = 60;
                this.Hp          += _listPassiveSkill[0].ListLevel[_listPassiveSkill[0].Level].ListSkillInfo[0].Hp;
                this.Mp          += _listPassiveSkill[0].ListLevel[_listPassiveSkill[0].Level].ListSkillInfo[0].Mp;
            }
            for (int i = 0; i < ListLeftHandSkill.Count; ++i)
            {
                if (ListLeftHandSkill[i] != null)
                {
                    ListLeftHandSkill[i].Update(gameTime);
                }
            }
            for (int i = 0; i < ListRightHandSkill.Count; ++i)
            {
                if (ListRightHandSkill[i] != null)
                {
                    ListRightHandSkill[i].Update(gameTime);
                }
            }
            if (IsWaveForm)
            {
                ListRightHandSkill[RightHandSkillIndex].DoEffect(null);
                return;
            }
            base.Update(gameTime);
            if (BashTime > 0)
            {
                IsStanding = true;
                CellToMove = new List <Point>();
            }

            if (IsDying || IsDyed)
            {
                return;
            }

            if (IsAttacking)
            {
                if (_sprite[Dir].Itexture2D == HitFrame && _sprite[Dir].Check == 0)
                {
                    this.Hit();
                }
                if (_sprite[Dir].Itexture2D == 0)
                {
                    int rate = GlobalVariables.GlobalRandom.Next(0, 100);
                    if (rate < this.CriticalRate || (_leftHandSkillIndex != 0 && _listLeftHandSkill[_leftHandSkillIndex].Level != 0))
                    {
                        State = 16;
                    }
                    else
                    {
                        State = 24;
                    }
                    UpdateDirection(this.X, this.Y);
                }
            }

            if (GlobalVariables.CurrentMouseState.X >= 0 && GlobalVariables.CurrentMouseState.Y >= 0 && GlobalVariables.CurrentMouseState.X <= GlobalVariables.ScreenWidth && GlobalVariables.CurrentMouseState.Y <= GlobalVariables.ScreenHeight && !GlobalVariables.AlreadyUseRightMouse && GlobalVariables.PreviousMouseState.RightButton == ButtonState.Released && GlobalVariables.CurrentMouseState.RightButton == ButtonState.Pressed && GlobalVariables.CurrentMouseState.LeftButton == ButtonState.Released && !IsCasting)
            {
                if (Map.Matrix[(int)(GlobalVariables.GameCursor.Y / GlobalVariables.MapCollisionDim)][(int)(GlobalVariables.GameCursor.X / GlobalVariables.MapCollisionDim)] != false)
                {
                    if (Mp + ListRightHandSkill[RightHandSkillIndex].ListLevel[ListRightHandSkill[RightHandSkillIndex].Level].ListSkillInfo[0].Mp < 0)
                    {
                        StateOwner._displayMessageLayer.MessageArray.Add(new DisplayMessageLayer.Message
                        {
                            MessageContent = "No enough mana",
                            TextColor      = Color.OrangeRed,
                            X         = this.X,
                            Y         = this.Y - 32,
                            LifeTime  = 150,
                            MinY      = 0,
                            DelayTime = 0,
                            DeltaY    = -1,
                            Owner     = this,
                        });
                        GlobalVariables.PlayEffectSound("hero1");
                    }
                    else
                    {
                        if (ListRightHandSkill[RightHandSkillIndex].CheckCoolDown != 0)
                        {
                            StateOwner._displayMessageLayer.MessageArray.Add(new DisplayMessageLayer.Message
                            {
                                MessageContent = "This skill is not ready yet",
                                TextColor      = Color.Yellow,
                                X         = this.X,
                                Y         = this.Y - 32,
                                LifeTime  = 150,
                                MinY      = 0,
                                DelayTime = 0,
                                DeltaY    = -1,
                                Owner     = this,
                            });
                            GlobalVariables.PlayEffectSound("hero2");
                        }
                        else
                        {
                            if (ListRightHandSkill[RightHandSkillIndex].ListLevel[ListRightHandSkill[RightHandSkillIndex].Level].ListSkillInfo[0].CastRange < Math.Sqrt(Math.Pow(this.X - GlobalVariables.GameCursor.X, 2) + Math.Pow(this.Y - GlobalVariables.GameCursor.Y, 2)))
                            {
                                StateOwner._displayMessageLayer.MessageArray.Add(new DisplayMessageLayer.Message
                                {
                                    MessageContent = "Target out of range",
                                    TextColor      = Color.Yellow,
                                    X         = this.X,
                                    Y         = this.Y - 32,
                                    LifeTime  = 150,
                                    MinY      = 0,
                                    DelayTime = 0,
                                    DeltaY    = -1,
                                    Owner     = this,
                                });
                                GlobalVariables.PlayEffectSound("hero3");
                            }
                            else
                            {
                                IsCasting  = true;
                                waitToCast = true;
                                Target     = null;
                                CellToMove = new List <Point>();
                                DestPoint  = new Point((int)this.X, (int)this.Y);
                                UpdateCastingDirection(GlobalVariables.GameCursor.X, GlobalVariables.GameCursor.Y);
                                targetSkillX = GlobalVariables.GameCursor.X;
                                targetSkillY = GlobalVariables.GameCursor.Y;
                            }
                        }
                    }
                }
                else
                {
                    StateOwner._displayMessageLayer.MessageArray.Add(new DisplayMessageLayer.Message
                    {
                        MessageContent = "Cannot cast skill there",
                        TextColor      = Color.Yellow,
                        X         = this.X,
                        Y         = this.Y - 32,
                        LifeTime  = 150,
                        MinY      = 0,
                        DelayTime = 0,
                        DeltaY    = -1,
                        Owner     = this,
                    });
                    GlobalVariables.PlayEffectSound("hero3");
                }
            }

            if (48 <= Dir && Dir <= 55)
            {
                if (_sprite[Dir].Itexture2D == CastFrame)
                {
                    CastSkill();
                }
                if (_sprite[Dir].Itexture2D == _sprite[Dir].Ntexture2D - 1)
                {
                    _sprite[Dir].Itexture2D = 0;
                    IsStanding = true;
                }
            }

            if (Target != null && (Target.IsDying || Target.IsDyed) && !IsCasting)
            {
                Target     = null;
                CellToMove = new List <Point>();
                DestPoint  = new Point((int)this.X, (int)this.Y);
                _sprite[Dir].Itexture2D = 0;
                IsStanding = true;
            }

            if (GlobalVariables.CurrentMouseState.LeftButton == ButtonState.Pressed && !GlobalVariables.AlreadyUseLeftMouse)
            {
                if (GlobalVariables.CurrentMouseState.X < GlobalVariables.ScreenWidth && GlobalVariables.CurrentMouseState.Y < GlobalVariables.ScreenHeight && GlobalVariables.CurrentMouseState.X >= 0 && GlobalVariables.CurrentMouseState.Y >= 0)
                {
                    if (this.Target != null)
                    {
                        this.Target      = null;
                        this.IsAttacking = false;
                        this.DestPoint   = new Point((int)this.X, (int)this.Y);
                        this.CellToMove  = new List <Point>();
                    }
                    Point newCell = StateOwner._map.PointToCell(new Point((int)GlobalVariables.GameCursor.X, (int)GlobalVariables.GameCursor.Y));
                    if (StateOwner._map.Matrix[newCell.Y][newCell.X] == true)
                    {
                        StateOwner._char.CellToMove = Utility.FindPath(StateOwner._map.Matrix, StateOwner._map.PointToCell(new Point((int)this.X, (int)this.Y)), newCell);
                    }
                    IsMoving = true;
                    GlobalVariables.AlreadyUseLeftMouse = true;
                }
            }

            //RH

            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.Q) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.Q))
            {
                if (_listRightHandSkill[0].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 0;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.W) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.W))
            {
                if (_listRightHandSkill[1].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 1;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.E) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.E))
            {
                if (_listRightHandSkill[2].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 2;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.R) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.R))
            {
                if (_listRightHandSkill[3].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 3;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.T) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.T))
            {
                if (_listRightHandSkill[4].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 4;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.Y) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.Y))
            {
                if (_listRightHandSkill[5].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 5;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.U) && !GlobalVariables.PreviousKeyboardState.IsKeyDown(Keys.U))
            {
                if (_listRightHandSkill[6].Level > 0)
                {
                    _listRightHandSkill[_rightHandSkillIndex].Deactive();
                    _rightHandSkillIndex = 6;
                    _listRightHandSkill[_rightHandSkillIndex].Active();
                    Update_To_HealthBar(_listRightHandSkill[_rightHandSkillIndex], false);
                }
            }

            //LH
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.A))
            {
                if (_listLeftHandSkill[0].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 0;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }

            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.S))
            {
                if (_listLeftHandSkill[1].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 1;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.D))
            {
                if (_listLeftHandSkill[2].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 2;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.F))
            {
                if (_listLeftHandSkill[3].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 3;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.G))
            {
                if (_listLeftHandSkill[4].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 4;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.H))
            {
                if (_listLeftHandSkill[5].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 5;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.J))
            {
                if (_listLeftHandSkill[6].Level > 0)
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Deactive();
                    _leftHandSkillIndex = 6;
                    _listLeftHandSkill[_leftHandSkillIndex].Active();
                    Update_To_HealthBar(_listLeftHandSkill[_leftHandSkillIndex], true);
                }
            }


            if (_listLeftHandSkill[_leftHandSkillIndex] != null)
            {
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.Z))
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Level = 1;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.X))
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Level = 2;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.C))
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Level = 3;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.V))
                {
                    _listLeftHandSkill[_leftHandSkillIndex].Level = 0;
                }
            }

            if (_listRightHandSkill[_rightHandSkillIndex] != null)
            {
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.D1))
                {
                    _listRightHandSkill[_rightHandSkillIndex].Level = 1;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.D2))
                {
                    _listRightHandSkill[_rightHandSkillIndex].Level = 2;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.D3))
                {
                    _listRightHandSkill[_rightHandSkillIndex].Level = 3;
                }
                if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.D4))
                {
                    _listRightHandSkill[_rightHandSkillIndex].Level = 0;
                }
            }

            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.NumPad1) && GlobalVariables.PreviousKeyboardState.IsKeyUp(Keys.NumPad1))
            {
                if (_hPPortion.Count > 0)
                {
                    _hPPortion[0].DoEffect();
                    _hPPortion.Remove(_hPPortion[0]);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.NumPad2) && GlobalVariables.PreviousKeyboardState.IsKeyUp(Keys.NumPad2))
            {
                if (_mPPortion.Count > 0)
                {
                    _mPPortion[0].DoEffect();
                    _mPPortion.Remove(_mPPortion[0]);
                }
            }
            if (GlobalVariables.CurrentKeyboardState.IsKeyDown(Keys.NumPad3) && GlobalVariables.PreviousKeyboardState.IsKeyUp(Keys.NumPad3))
            {
                if (_restorePortion.Count > 0)
                {
                    _restorePortion[0].DoEffect();
                    _restorePortion.Remove(_restorePortion[0]);
                }
            }
        }