/// <summary>
        /// Calculates and applies the damage of an attack(Based on this' damage, block and crit values).
        /// </summary>
        /// <param name="victim">The DynamicGameObject which health is going to be reduced.</param>
        /// <param name="rnd">An already instansiated, random-number generator.</param>
        /// <returns>A new instance of the ScrollingCombatText class, based upon calculated attack.</returns>
        public ScrollingCombatText CalcAndApplyDamage(DynamicGameObject victim, Random rnd)
        {
            int dmg = this is Player?rnd.Next(this.damage / 3, this.damage) : rnd.Next(1, this.damage);

            string  combatText = dmg.ToString();
            SctType textType   = SctType.Normal;

            if (rnd.Next(0, 101) <= victim.block)
            {
                combatText = "Block";
                textType   = SctType.Block;
            }
            else if (rnd.Next(0, 101) <= this.crit)
            {
                dmg          *= 3;
                combatText    = dmg.ToString();
                victim.health = (victim.health - dmg) <= 0 ? 0 : victim.health - dmg;
                textType      = SctType.Critical;
            }
            else
            {
                victim.health = (victim.health - dmg) <= 0 ? 0 : victim.health - dmg;
            }

            return(new ScrollingCombatText(victim.coords, combatText, textType));
        }
Beispiel #2
0
        /// <summary>
        /// Sets moveDirection to a valid direction, based on the Player's current position.
        /// </summary>
        /// <param name="player">The Player</param>
        public void DetermineDirection(DynamicGameObject player)
        {
            if (player.Health <= 0)
            {
                // If player is dead, dont attack + stand still.
                atkMelee      = false;
                moveDirection = EnumDirection.None;
                return;
            }

            int meleeRange = 10;

            this.ProcessValidDirections();
            bool iamColliding = this.collPosition.Count != 0 ? true : false;

            this.offset = new Point(player.Coords.X - coords.X, player.Coords.Y - coords.Y);

            #region DetermineDirection
            moveDirection = this.offset.X < -meleeRange ? EnumDirection.Left : moveDirection;
            moveDirection = this.offset.X > meleeRange ? EnumDirection.Right : moveDirection;
            if (this.offset.Y < -meleeRange)
            {
                moveDirection = EnumDirection.Up;
                moveDirection = this.offset.Y <-meleeRange && this.offset.X> meleeRange ? EnumDirection.RightUp : moveDirection;
                moveDirection = this.offset.Y < -meleeRange && this.offset.X < -meleeRange ? EnumDirection.LeftUp : moveDirection;
            }

            if (this.offset.Y > meleeRange)
            {
                moveDirection = EnumDirection.Down;
                moveDirection = this.offset.Y > meleeRange && this.offset.X > meleeRange ? EnumDirection.RightDown : moveDirection;
                moveDirection = this.offset.Y > meleeRange && this.offset.X < -meleeRange ? EnumDirection.LeftDown : moveDirection;
            }

            // Set atkMelee to true if we're in range, otherwise do nothing
            atkMelee = ((Math.Abs(this.offset.X) <= meleeRange * 5) && (Math.Abs(this.offset.Y) <= meleeRange * 4)) ? true : atkMelee;
            #endregion

            if (iamColliding && !this.postValidDirection.Contains(moveDirection))
            {
                // We're collision, and dirction is invalid
                #region AlternativeDirection
                EnumDirection tmpDir = moveDirection;
                moveDirection = EnumDirection.None;

                switch (tmpDir)
                {
                case EnumDirection.LeftUp:
                    moveDirection = this.postValidDirection.Contains(EnumDirection.RightUp) ? EnumDirection.RightUp : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.LeftDown) ? EnumDirection.LeftDown : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Left) ? EnumDirection.Left : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Up) ? EnumDirection.Up : moveDirection;
                    break;

                case EnumDirection.LeftDown:
                    moveDirection = this.postValidDirection.Contains(EnumDirection.LeftUp) ? EnumDirection.LeftUp : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.RightDown) ? EnumDirection.RightDown : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Left) ? EnumDirection.Left : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Down) ? EnumDirection.Down : moveDirection;
                    break;

                case EnumDirection.RightUp:
                    moveDirection = this.postValidDirection.Contains(EnumDirection.RightDown) ? EnumDirection.RightDown : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.LeftUp) ? EnumDirection.LeftUp : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Right) ? EnumDirection.Right : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Up) ? EnumDirection.Up : moveDirection;
                    break;

                case EnumDirection.RightDown:
                    moveDirection = this.postValidDirection.Contains(EnumDirection.RightUp) ? EnumDirection.RightUp : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.LeftDown) ? EnumDirection.LeftDown : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Right) ? EnumDirection.Right : moveDirection;
                    moveDirection = this.postValidDirection.Contains(EnumDirection.Down) ? EnumDirection.Down : moveDirection;
                    break;
                }
                #endregion
            }
        }