Esempio n. 1
0
 public void SendFightProposition(ArenaInvitation invitation)
 {
     this.Foreach(entry =>
     {
         //entry.SetArenaInvitation(invitation);
     });
 }
        private void TryCreateTeams()
        {
            try
            {
                var time = DateTime.Now;

                Character red = null, blue = null;

                List <ArenaParty> p3;
                List <ArenaParty> p2;
                List <Character>  p1;

                #region Initializing

                lock (this.m_lock)
                {
                    p3 = this.m_partyQueue.Where(entry => entry.MembersCount == 3 && !entry.IsTag()).ToList();
                    p2 = this.m_partyQueue.Where(entry => entry.MembersCount == 2 && !entry.IsTag()).ToList();
                    p1 = this.m_queue.Where(entry => entry.ArenaInvitation == null).ToList().OrderByDescending(entry => entry.Record.HiddenArenaRank).ToList();
                }

                #endregion

                #region Handle P3

                while (p3.Count > 0)
                {
                    var current = p3[0];
                    p3.Remove(current);

                    var opponent = p3.FirstOrDefault(entry => Math.Abs(this.GetProbability((short)((entry.GetHiddenRankSum() - current.GetHiddenRankSum()) / 3)) - 0.5) < 1.0);
                    if (opponent == null)
                    {
                        var party = this.TryCreateBalancedTeam(current, ref p2, ref p1);
                        if (party != null)
                        {
                            var invitation = new ArenaInvitation(new ArenaPartyCreation(current), party);
                        }
                    }
                    else
                    {
                        p3.Remove(opponent);

                        var invitation = new ArenaInvitation(new ArenaPartyCreation(current), new ArenaPartyCreation(opponent));
                    }
                }
                #endregion

                #region Handle P2

                while (p2.Count > 0)
                {
                    var current = p2[0];
                    p2.Remove(current);

                    var opponent = p2.FirstOrDefault(entry => Math.Abs(this.GetProbability((short)((entry.GetHiddenRankSum() - current.GetHiddenRankSum()) / 2)) - 0.5) < 1.0);
                    if (opponent == null)
                    {
                        // TODO
                    }
                    else
                    {
                        if (this.CanGetBalancedOpponents(ref p1, ref red, ref blue))
                        {
                            p2.Remove(opponent);

                            var invitation = new ArenaInvitation(new ArenaPartyCreation(current, red), new ArenaPartyCreation(opponent, blue));
                        }
                    }
                }

                #endregion

                #region Handle P1

                var possibleCombinaisons = new List <KeyValuePair <Character, Character> >();
                while (this.CanGetBalancedOpponents(ref p1, ref red, ref blue))
                {
                    possibleCombinaisons.Add(new KeyValuePair <Character, Character>(red, blue));
                }

                for (int i = 0; i < possibleCombinaisons.Count / 3; i++)
                {
                    var redTeam  = new Character[3];
                    var blueTeam = new Character[3];

                    for (int j = 0; j < 3; j++)
                    {
                        var pair = possibleCombinaisons[i * 3 + j];

                        redTeam[j]  = pair.Key;
                        blueTeam[j] = pair.Value;
                    }

                    var invitation = new ArenaInvitation(new ArenaPartyCreation(redTeam), new ArenaPartyCreation(blueTeam));
                }

                #endregion

                this.logger.Debug(string.Format("TryCreateTeams() executed : {0} ms", (DateTime.Now - time).Milliseconds));
            }
            finally
            {
                ArenaManager.m_queueRefresherTask = Task.Factory.StartNewDelayed(ArenaManager.QueueRefresherElapsedTime, new Action(this.TryCreateTeams));
            }
        }