示例#1
0
        /// <summary>
        /// See if the Attacker is next to the Defender by the distance of Range
        ///
        /// If either the X or Y distance is less than or equal the range, then they can hit
        /// </summary>
        /// <param name="Attacker"></param>
        /// <param name="Defender"></param>
        /// <returns></returns>
        public bool IsTargetInRange(BattleEntityModel Attacker, BattleEntityModel Defender)
        {
            var locationAttacker = GetLocationForPlayer(Attacker);
            var locationDefender = GetLocationForPlayer(Defender);

            if (locationAttacker == null)
            {
                return(false);
            }

            if (locationDefender == null)
            {
                return(false);
            }

            // Get X distance in absolute value
            var distance = Math.Abs(CalculateDistance(locationAttacker, locationDefender));

            var AttackerRange = Attacker.Range;

            // Can Reach?
            if (distance <= AttackerRange)
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Find the Player on the map
        /// Return their information
        ///
        /// If they don't exist, return null
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public MapModelLocation GetLocationForPlayer(BattleEntityModel player)
        {
            if (player == null)
            {
                return(null);
            }

            foreach (var data in MapGridLocation)
            {
                if (data.Player.Id.Equals(player.Id))
                {
                    return(data);
                }
            }

            return(null);
        }
示例#3
0
        /// <summary>
        /// Remove the Player from the Map
        /// Replaces with Empty Square
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool RemovePlayerFromMap(BattleEntityModel data)
        {
            for (var x = 0; x < MapXAxesCount; x++)
            {
                for (var y = 0; y < MapYAxesCount; y++)
                {
                    if (MapGridLocation[x, y].Player.Id.Equals(data.Id))
                    {
                        MapGridLocation[x, y] = new MapModelLocation {
                            Column = x, Row = y, Player = EmptySquare
                        };
                        return(true);
                    }
                }
            }

            // Not found
            return(false);
        }