Пример #1
0
        public bool ClosestAlly(Character src, out CharacterDistance[] allies)
        {
            allies = new CharacterDistance[1];
            if (!IsInTeam(src))
            {
                return(false);
            }
            if (m_characters.Count == 0)
            {
                return(false);
            }

            allies = new CharacterDistance[m_characters.Count - 1];// -1 because src shouldn't be in the list

            int index = 0;

            foreach (Character character in m_characters)
            {
                if (character == src)
                {
                    continue;
                }
                allies[index].character = character;
                allies[index].distance  = (src.Position - character.Position).magnitude;
                index++;
            }
            System.Array.Sort(allies);
            return(true);
        }
Пример #2
0
        protected virtual void Attack() // virtual to make type-specific behavior possible, not done currently
        {                               //default implementation: attack the nearest enemy
            ArrayList enemies;

            if (!Team.Game.GetNearestEnemies(this, out enemies))
            {
                return;             // failed to get the enemie list
            }
            if (enemies.Count <= 0) // there is no ennmy to attack
            {
                return;
            }

            if (!(enemies[0] is CharacterDistance))// shouldn't be
            {
                return;
            }
            CharacterDistance enemyDist = (CharacterDistance)enemies[0];

            if (enemyDist.distance < GrabRange) // if the closest enemy is at range
            {
                int enemyDamage = enemyDist.character.Damage;
                int ourDamage   = Damage;
                Team.Game.NotifyCombat(this, enemyDist.character);
                enemyDist.character.SufferInjuries(this, ourDamage);
                SufferInjuries(enemyDist.character, enemyDamage);
            }
        }