WarTornLands.Entities.Modules.Think.Parts.SwingHitAbility.Hit C# (CSharp) Method

Hit() private method

private Hit ( ) : void
return void
        private void Hit()
        {
            double baseAngle = _startAngle + (float)GetRoundedAngle();

            double maxAddition = _goalAngle - _startAngle;
            double finalAngle = _cm.GetPercentage(_cSwingHit) * maxAddition + baseAngle;
            Vector2 hitPos = _owner.Position + new Vector2(Range * (float)Math.Cos(finalAngle),
                                            Range * (float)Math.Sin(finalAngle));

            // Debug
            if (_owner.Name.Equals("Player"))
            {
                WeaponMarkerA = hitPos - (Player.Instance.Position - new Vector2(0, -Player.Instance.Altitude)) + new Vector2(GraphicsDeviceManager.DefaultBackBufferWidth * .5f, GraphicsDeviceManager.DefaultBackBufferHeight * .5f);
            }
            if (_owner.Name.Equals("GruselUte"))
            {
                WeaponMarkerB = hitPos - Player.Instance.Position + new Vector2(GraphicsDeviceManager.DefaultBackBufferWidth * .5f, GraphicsDeviceManager.DefaultBackBufferHeight * .5f);
            }
            //enddebug

            // Assume weapon in the vertical center of the owner's body
            float swingAltitude = _owner.BodyHeight / 2f + _owner.Altitude;
            if (_owner is PlayerClasses.Player)
            {
                List<Entity> targets = (Game1.Instance.Level.GetEntitiesAt(hitPos));
                foreach (Entity ent in targets)
                {
                    if (ent.Altitude <= swingAltitude && ent.Altitude+ent.BodyHeight >= swingAltitude)
                        ent.Damage(this.Damage);
                }
            }
            else
            {
                // TODO: Check for other Entity the owner can hit
                // code a better check for the Player

                Vector2 toPlayer = Player.Instance.Position - hitPos;
                if(toPlayer.LengthSquared() < 18 * 18)
                {
                    Player p = Player.Instance;
                    if (p.Altitude <= swingAltitude && p.Altitude + p.BodyHeight >= swingAltitude)
                        p.Damage(this.Damage);

                }
            }
        }