Beispiel #1
0
        private void CheckOwner()
        {
            if (_Region == null || _Battle == null || _Battle.Deleted || !_Battle.InProgress)
            {
                return;
            }

            List <Mobile> list = _Region.GetPlayers();

            int[] counts = new int[BattleController.MaxVirtues];

            for (int i = 0; i < counts.Length; i++)
            {
                counts[i] = 0;
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (!list[i].Alive)
                {
                    continue;
                }

                int idx = _Battle.GetVirtue(list[i]);
                if (idx >= 0 && idx < counts.Length)
                {
                    counts[idx]++;
                }
            }

            int newOwner = -1;
            int first = 0, second = 1;

            if (counts[1] > counts[0])
            {
                first  = 1;
                second = 0;
            }

            for (int i = 2; i < counts.Length; i++)
            {
                if (counts[i] > counts[first])
                {
                    second = first;
                    first  = i;
                }
                else if (counts[i] > counts[second])
                {
                    second = i;
                }
            }

            if (counts[second] == 0 && counts[first] > 0)
            {
                newOwner = first;
            }

            if (counts[first] > (counts[second] + 1))
            {
                newOwner = first;
            }

            if (newOwner != _Owner)
            {
                OnOwnerChange(newOwner);

                _Owner = newOwner;
            }
        }