Exemplo n.º 1
0
 //自動匹配 開啓匹配
 public static void beginAotuMatch(bool isHaveTeam, ulong characterId, TeamMatchItem item)
 {
     mStaticImpl.beginAotuMatch(isHaveTeam, characterId, item);
 }
Exemplo n.º 2
0
        public void beginAotuMatch(bool isHaveTeam, ulong characterId, TeamMatchItem item)
        {
            Logger.Info("TeamWorkRefrerrence  beginAotuMatch= " + characterId);

            if (isHaveTeam) // 有队伍开启自动匹配
            {
                List <ulong> oldList = new List <ulong>();
                foreach (var sNull in AutoMatchManager.nullTeamMatchDic)
                {
                    if (sNull.Key != characterId && sNull.Value.teamTarget.type == item.teamTarget.type && sNull.Value.teamTarget.teamTargetID == item.teamTarget.teamTargetID)
                    {
                        //增加到队伍
                        var theTeam = TeamManager.GetCharacterTeam(characterId);

                        oldList.Add(sNull.Key);

                        if (theTeam.team.TeamList.Count == 4)
                        {
                            TeamManager.addOneToTeam(theTeam.team, characterId, TeamState.Member);
                            //TeamChange(TeamChangedType.Request, theTeam, charaID);

                            TeamCharacterProxy proxy;
                            if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(characterId, out proxy))
                            {
                                proxy.AutoMatchStateChange(0);
                            }
                            AutoMatchManager.teamMatchDic.Remove(characterId);
                            break;
                        }

                        TeamManager.addOneToTeam(theTeam.team, sNull.Key, TeamState.Member);
                    }
                }

                for (int r = 0; r < oldList.Count; r++)
                {
                    var sItem = oldList[r];
                    if (AutoMatchManager.nullTeamMatchDic.ContainsKey(sItem))
                    {
                        AutoMatchManager.nullTeamMatchDic.Remove(sItem);
                    }

                    TeamCharacterProxy proxy;
                    if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(sItem, out proxy))
                    {
                        proxy.AutoMatchStateChange(0);
                    }
                }
                oldList.Clear();
            }
            else
            {     // 无队伍开启自动匹配
                bool isGetTeam = false;
                { // 过滤 处于 自动匹配状态的队伍
                    foreach (var sTeam in AutoMatchManager.teamMatchDic)
                    {
                        if (sTeam.Key != characterId)
                        {
                            var theTeam = sTeam.Value.chracter.team;

                            if (null == theTeam || theTeam.TeamList == null || theTeam.TeamList.Count > 4)
                            {
                                continue;
                            }
                            if (theTeam.TeamList.Contains(characterId))
                            {
                                continue;
                            }
                            if (sTeam.Value.teamTarget.teamTargetID != item.teamTarget.teamTargetID || sTeam.Value.teamTarget.type != item.teamTarget.type)
                            {
                                continue;
                            }

                            //AutoMatchManager.teamMatchDic.Remove(sTeam.Key);
                            TeamCharacterProxy proxy;
                            if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(characterId, out proxy))
                            {
                                proxy.AutoMatchStateChange(0);
                            }

                            if (AutoMatchManager.teamMatchDic.ContainsKey(sTeam.Key) && theTeam.TeamList.Count == 4)
                            {
                                TeamCharacterProxy proxy1;
                                if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(sTeam.Key, out proxy1))
                                {
                                    proxy1.AutoMatchStateChange(0);
                                }
                                AutoMatchManager.teamMatchDic.Remove(sTeam.Key);
                            }

                            //增加到队伍
                            TeamManager.addOneToTeam(theTeam, characterId, TeamState.Member);
                            //TeamChange(TeamChangedType.AcceptRequest, theTeam, charaID);
                            isGetTeam = true;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // 过滤 没使用自动匹配但是勾选了“自动接收入队申请”的队伍
                    if (!isGetTeam)
                    {
                        if (TeamManager.mTeams.Count > 0)
                        {
                            foreach (var sFlag in AutoMatchManager.teamFlagDic)
                            {
                                if (sFlag.Key != characterId && sFlag.Value == true)
                                {
                                    if (TeamManager.mTeams.ContainsKey(sFlag.Key))
                                    {
                                        var theTeam = TeamManager.mTeams[sFlag.Key];
                                        if (theTeam.teamTargetID != item.teamTarget.teamTargetID || theTeam.type != item.teamTarget.type)
                                        {
                                            continue;
                                        }
                                        //增加到队伍
                                        TeamManager.addOneToTeam(theTeam, characterId, TeamState.Member);

                                        isGetTeam = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    // 当无队伍可加入,且服务器收到的消息均为无队伍自动匹配申请时
                    if (!isGetTeam)
                    {
                        foreach (var sNullItem in AutoMatchManager.nullTeamMatchDic)
                        {
                            if (sNullItem.Key != characterId)
                            {
                                var theTeam = TeamManager.CreateTeam(sNullItem.Key);// 默认队长(即匹配对象时间靠前的为队长)

                                //增加到队伍
                                TeamManager.addOneToTeam(theTeam, characterId, TeamState.Member);
                                //TeamChange(TeamChangedType.AcceptRequest, sTeam, charaID);

                                if (AutoMatchManager.nullTeamMatchDic.ContainsKey(characterId))
                                {
                                    AutoMatchManager.nullTeamMatchDic.Remove(characterId);
                                }
                                AutoMatchManager.nullTeamMatchDic.Remove(sNullItem.Key);

                                TeamCharacterProxy proxy;
                                if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(characterId, out proxy))
                                {
                                    proxy.AutoMatchStateChange(0);
                                }

                                TeamCharacterProxy proxy1;
                                if (TeamServer.Instance.ServerControl.Proxys.TryGetValue(sNullItem.Key, out proxy1))
                                {
                                    proxy1.AutoMatchStateChange(0);
                                }
                                isGetTeam = true;
                                break;
                            }
                        }
                    }
                }
            }
        }