Example #1
0
        public static void SendEvent()
        {
            ServerManager.Instance.Broadcast(UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("RAINBOW_SECONDS"), 10), 1));
            Thread.Sleep(10 * 1000);
            ServerManager.Instance.Broadcast(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("RAINBOW_STARTED"), 1));
            //qnaml 3 #guri^506 The Meteorite Game is starting! Join now!
            ServerManager.Instance.Broadcast("qnaml 100 #guri^506 The Rainbow Battle started! Join now!");
            ServerManager.Instance.EventInWaiting = true;
            Thread.Sleep(30 * 1000);
            ServerManager.Instance.Sessions.Where(s => s.Character?.IsWaitingForEvent == false).ToList().ForEach(s => s.SendPacket("esf"));
            ServerManager.Instance.EventInWaiting = false;
            IEnumerable <ClientSession> sessions = ServerManager.Instance.Sessions.Where(s => s.Character?.IsWaitingForEvent == true && s.Character.MapInstance.MapInstanceType == MapInstanceType.BaseMapInstance);

            MapInstance map = ServerManager.GenerateMapInstance(2004, MapInstanceType.EventGameInstance, new InstanceBag());

            if (Map != null)
            {
                foreach (ClientSession sess in sessions)
                {
                    ServerManager.Instance.TeleportOnRandomPlaceInMap(sess, Map.MapInstanceId);
                    sess.SendPacket(UserInterfaceHelper.GenerateBSInfo(2, 7, 0, 0));
                    sess.SendPacket("rsfp 0 0");
                    sess.Character.DisableBuffs(BuffType.All);
                    foreach (var mate in sess.Character.Mates.Where(s => s.IsTeamMember))
                    {
                        mate.RemoveTeamMember(true);
                    }
                }

                ServerManager.Instance.Sessions.Where(s => s.Character != null).ToList().ForEach(s => s.Character.IsWaitingForEvent = false);
                ServerManager.Instance.StartedEvents.Remove(EventType.RAINBOWBATTLE);
            }


            if (Map.Sessions.Count() < 1)
            {
                Map.Broadcast(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("RAINBOW_NOT_ENOUGH_PLAYERS"), 0));
                EventHelper.Instance.ScheduleEvent(TimeSpan.FromSeconds(5), new EventContainer(Map, EventActionType.DISPOSEMAP, null));
                return;
            }
            RainbowThread task = new RainbowThread();

            Observable.Timer(TimeSpan.FromSeconds(10)).Subscribe(X => task.RunEvent(Map));
        }
            public void Run()
            {
                byte[] levelCaps = { 40, 50, 60, 70, 80, 85, 90, 95, 100, 120, 150, 180, 255 };
                while (!_shouldStop)
                {
                    IEnumerable <IGrouping <byte, ClientSession> > groups = from sess in RegisteredParticipants.GetAllItems()
                                                                            group sess by Array.Find(levelCaps, s => s > sess.Character.Level) into grouping
                                                                            select grouping;

                    foreach (IGrouping <byte, ClientSession> group in groups)
                    {
                        foreach (List <ClientSession> grp in group.ToList().Split(3).Where(s => s.Count == 3))
                        {
                            Group g = new Group
                            {
                                GroupType         = GroupType.TalentArena,
                                TalentArenaBattle = new TalentArenaBattle
                                {
                                    GroupLevel = group.Key
                                }
                            };

                            foreach (ClientSession sess in grp)
                            {
                                RegisteredParticipants.Remove(sess);
                                g.JoinGroup(sess);
                                sess.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 3, -1, 6));
                                Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(observer => sess?.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 3, 300, 1)));
                            }
                            RegisteredGroups[g.GroupId] = g;
                        }
                    }

                    Thread.Sleep(5000);
                }
            }
            public void Run()
            {
                while (!_shouldStop)
                {
                    IEnumerable <IGrouping <byte, Group> > groups = from grp in RegisteredGroups.GetAllItems()
                                                                    where grp.TalentArenaBattle != null
                                                                    group grp by grp.TalentArenaBattle.GroupLevel into grouping
                                                                    select grouping;

                    foreach (IGrouping <byte, Group> group in groups)
                    {
                        Group prevGroup = null;

                        foreach (Group g in group)
                        {
                            if (prevGroup == null)
                            {
                                prevGroup = g;
                            }
                            else
                            {
                                RegisteredGroups.Remove(g);
                                RegisteredGroups.Remove(prevGroup);

                                MapInstance mapInstance = ServerManager.GenerateMapInstance(2015, MapInstanceType.NormalInstance, new InstanceBag());
                                mapInstance.IsPVP = true;

                                g.TalentArenaBattle.MapInstance         = mapInstance;
                                prevGroup.TalentArenaBattle.MapInstance = mapInstance;

                                g.TalentArenaBattle.Side         = 0;
                                prevGroup.TalentArenaBattle.Side = 1;

                                g.TalentArenaBattle.Calls         = 5;
                                prevGroup.TalentArenaBattle.Calls = 5;

                                IEnumerable <ClientSession> gs = g.Characters.GetAllItems().Concat(prevGroup.Characters.GetAllItems());
                                foreach (ClientSession sess in gs)
                                {
                                    sess.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 3, -1, 2));
                                }
                                Thread.Sleep(1000);
                                foreach (ClientSession sess in gs)
                                {
                                    sess.SendPacket(UserInterfaceHelper.GenerateBSInfo(2, 3, 0, 0));
                                    sess.SendPacket(UserInterfaceHelper.GenerateTeamArenaClose());
                                }
                                Thread.Sleep(5000);
                                foreach (ClientSession sess in gs)
                                {
                                    sess.SendPacket(UserInterfaceHelper.GenerateTeamArenaMenu(0, 0, 0, 0, 0));
                                    short x = 125;
                                    if (sess.Character.Group.TalentArenaBattle.Side == 0)
                                    {
                                        x = 15;
                                    }
                                    ServerManager.Instance.ChangeMapInstance(sess.Character.CharacterId, mapInstance.MapInstanceId, x, 39);
                                    sess.SendPacketAfter(UserInterfaceHelper.GenerateTeamArenaMenu(3, 0, 0, 60, 0), 5000);
                                }

                                PlayingGroups[g.GroupId] = new List <Group> {
                                    g, prevGroup
                                };

                                BattleThread battleThread = new BattleThread();
                                Observable.Timer(TimeSpan.FromSeconds(0)).Subscribe(observer => battleThread.Run(PlayingGroups[g.GroupId]));

                                prevGroup = null;
                            }
                        }
                    }

                    Thread.Sleep(5000);
                }
            }
Example #4
0
        public static void NRun(ClientSession Session, NRunPacket packet)
        {
            if (!Session.HasCurrentMapInstance)
            {
                return;
            }
            MapNpc        npc = Session.CurrentMapInstance.Npcs.Find(s => s.MapNpcId == packet.NpcId);
            TeleporterDTO tp;

            switch (packet.Runner)
            {
            case 1:
                if (Session.Character.Class != (byte)ClassType.Adventurer)
                {
                    Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ADVENTURER"), 0));
                    return;
                }
                if (Session.Character.Level < 15 || Session.Character.JobLevel < 20)
                {
                    Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LOW_LVL"), 0));
                    return;
                }
                if (packet.Type == (byte)Session.Character.Class)
                {
                    return;
                }
                if (Session.Character.Inventory.All(i => i.Type != InventoryType.Wear))
                {
                    Session.Character.Inventory.AddNewToInventory((short)(4 + (packet.Type * 14)), type: InventoryType.Wear);
                    Session.Character.Inventory.AddNewToInventory((short)(81 + (packet.Type * 13)), type: InventoryType.Wear);
                    switch (packet.Type)
                    {
                    case 1:
                        Session.Character.Inventory.AddNewToInventory(68, type: InventoryType.Wear);
                        Session.Character.Inventory.AddNewToInventory(2082, 10);
                        break;

                    case 2:
                        Session.Character.Inventory.AddNewToInventory(78, type: InventoryType.Wear);
                        Session.Character.Inventory.AddNewToInventory(2083, 10);
                        break;

                    case 3:
                        Session.Character.Inventory.AddNewToInventory(86, type: InventoryType.Wear);
                        break;
                    }
                    Session.CurrentMapInstance?.Broadcast(Session.Character.GenerateEq());
                    Session.SendPacket(Session.Character.GenerateEquipment());
                    Session.Character.ChangeClass((ClassType)packet.Type);
                }
                else
                {
                    Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EQ_NOT_EMPTY"), 0));
                }
                break;

            case 2:
                Session.SendPacket("wopen 1 0");
                break;

            case 4:
                Mate mate = Session.Character.Mates.Find(s => s.MateTransportId == packet.NpcId);
                switch (packet.Type)
                {
                case 2:
                    if (mate != null)
                    {
                        if (Session.Character.Level >= mate.Level)
                        {
                            Mate teammate = Session.Character.Mates.Where(s => s.IsTeamMember).FirstOrDefault(s => s.MateType == mate.MateType);
                            if (teammate != null)
                            {
                                teammate.IsTeamMember = false;
                                teammate.MapX         = teammate.PositionX;
                                teammate.MapY         = teammate.PositionY;
                            }
                            mate.IsTeamMember = true;
                        }
                        else
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("PET_HIGHER_LEVEL"), 0));
                        }
                    }
                    break;

                case 3:
                    if (mate != null && Session.Character.Miniland == Session.Character.MapInstance)
                    {
                        mate.IsTeamMember = false;
                        mate.MapX         = mate.PositionX;
                        mate.MapY         = mate.PositionY;
                    }
                    break;

                case 4:
                    if (mate != null)
                    {
                        if (Session.Character.Miniland == Session.Character.MapInstance)
                        {
                            mate.IsTeamMember = false;
                            mate.MapX         = mate.PositionX;
                            mate.MapY         = mate.PositionY;
                        }
                        else
                        {
                            Session.SendPacket($"qna #n_run^4^5^3^{mate.MateTransportId} {Language.Instance.GetMessageFromKey("ASK_KICK_PET")}");
                        }
                        break;
                    }
                    break;

                case 5:
                    if (mate != null)
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateDelay(3000, 10, $"#n_run^4^6^3^{mate.MateTransportId}"));
                    }
                    break;

                case 6:
                    if (mate != null && Session.Character.Miniland != Session.Character.MapInstance)
                    {
                        mate.IsTeamMember = false;
                        Session.CurrentMapInstance.Broadcast(mate.GenerateOut());
                        Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("PET_KICKED"), mate.Name), 11));
                        Session.SendPacket(UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("PET_KICKED"), mate.Name), 0));
                    }
                    break;

                case 7:
                    if (mate != null)
                    {
                        if (Session.Character.Mates.Any(s => s.MateType == mate.MateType && s.IsTeamMember))
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ALREADY_PET_IN_TEAM"), 11));
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("ALREADY_PET_IN_TEAM"), 0));
                        }
                        else
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateDelay(3000, 10, $"#n_run^4^9^3^{mate.MateTransportId}"));
                        }
                    }
                    break;

                case 9:
                    if (mate != null && Session.Character.Level >= mate.Level)
                    {
                        mate.PositionX    = (short)(Session.Character.PositionX + (mate.MateType == MateType.Partner ? -1 : 1));
                        mate.PositionY    = (short)(Session.Character.PositionY + 1);
                        mate.IsTeamMember = true;
                        Session.CurrentMapInstance?.Broadcast(mate.GenerateIn());
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("PET_HIGHER_LEVEL"), 0));
                    }
                    break;
                }
                Session.SendPacket(Session.Character.GeneratePinit());
                Session.SendPackets(Session.Character.GeneratePst());
                break;

            case 10:
                Session.SendPacket("wopen 3 0");
                break;

            case 12:
                Session.SendPacket($"wopen {packet.Type} 0");
                break;

            case 14:
                Session.SendPacket("wopen 27 0");
                string recipelist = "m_list 2";
                if (npc != null)
                {
                    List <Recipe> tps = npc.Recipes;
                    recipelist  = tps.Where(s => s.Amount > 0).Aggregate(recipelist, (current, s) => current + $" {s.ItemVNum}");
                    recipelist += " -100";
                    Session.SendPacket(recipelist);
                }
                break;

            case 15:
                if (npc != null)
                {
                    if (packet.Value == 2)
                    {
                        Session.SendPacket($"qna #n_run^15^1^1^{npc.MapNpcId} {Language.Instance.GetMessageFromKey("ASK_CHANGE_SPAWNLOCATION")}");
                    }
                    else
                    {
                        switch (npc.MapId)
                        {
                        case 1:
                            Session.Character.SetRespawnPoint(1, 79, 116);
                            break;

                        case 20:
                            Session.Character.SetRespawnPoint(20, 9, 92);
                            break;

                        case 145:
                            Session.Character.SetRespawnPoint(145, 13, 110);
                            break;
                        }
                        Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("RESPAWNLOCATION_CHANGED"), 0));
                    }
                }
                break;

            case 16:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    if (Session.Character.Gold >= 1000 * packet.Type)
                    {
                        Session.Character.Gold -= 1000 * packet.Type;
                        Session.SendPacket(Session.Character.GenerateGold());
                        ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    }
                }
                break;

            case 17:
                double currentRunningSeconds   = (DateTime.Now - Process.GetCurrentProcess().StartTime.AddSeconds(-50)).TotalSeconds;
                double timeSpanSinceLastPortal = currentRunningSeconds - Session.Character.LastPortal;
                if (!(timeSpanSinceLastPortal >= 4) || !Session.HasCurrentMapInstance || ServerManager.Instance.ChannelId == 51 || Session.CurrentMapInstance.MapInstanceId == ServerManager.Instance.ArenaInstance.MapInstanceId || Session.CurrentMapInstance.MapInstanceId == ServerManager.Instance.FamilyArenaInstance.MapInstanceId)
                {
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_MOVE"), 10));
                    return;
                }
                if (Session.Character.Gold >= 500 * (1 + packet.Type))
                {
                    Session.Character.LastPortal = currentRunningSeconds;
                    Session.Character.Gold      -= 500 * (1 + packet.Type);
                    Session.SendPacket(Session.Character.GenerateGold());
                    MapCell pos = packet.Type == 0 ? ServerManager.Instance.ArenaInstance.Map.GetRandomPosition() : ServerManager.Instance.FamilyArenaInstance.Map.GetRandomPosition();
                    ServerManager.Instance.ChangeMapInstance(Session.Character.CharacterId, packet.Type == 0 ? ServerManager.Instance.ArenaInstance.MapInstanceId : ServerManager.Instance.FamilyArenaInstance.MapInstanceId, pos.X, pos.Y);
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                }
                break;

            case 18:
                Session.SendPacket(Session.Character.GenerateNpcDialog(17));
                break;

            case 26:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    if (Session.Character.Gold >= 5000 * packet.Type)
                    {
                        Session.Character.Gold -= 5000 * packet.Type;
                        ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    }
                }
                break;

            case 45:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    if (Session.Character.Gold >= 500)
                    {
                        Session.Character.Gold -= 500;
                        Session.SendPacket(Session.Character.GenerateGold());
                        ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    }
                }
                break;

            case 132:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                }
                break;

            case 135:
                if (TalentArena.IsRunning)
                {
                    TalentArena.RegisteredParticipants[Session.Character.CharacterId] = Session;
                    Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 3, 300, 5));
                }
                break;

            case 150:
                if (npc != null)
                {
                    if (Session.Character.Family != null)
                    {
                        if (Session.Character.Family.LandOfDeath != null && npc.EffectActivated)
                        {
                            if (Session.Character.Level >= 55)
                            {
                                ServerManager.Instance.ChangeMapInstance(Session.Character.CharacterId, Session.Character.Family.LandOfDeath.MapInstanceId, 153, 145);
                            }
                            else
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LOD_REQUIERE_LVL"), 0));
                            }
                        }
                        else
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LOD_CLOSED"), 0));
                        }
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NEED_FAMILY"), 0));
                    }
                }
                break;

            case 301:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                }
                break;

            case 1600:
                Session.SendPacket(Session.Character.OpenFamilyWarehouse());
                break;

            case 1601:
                Session.SendPackets(Session.Character.OpenFamilyWarehouseHist());
                break;

            case 1602:
                if (Session.Character.Family?.FamilyLevel >= 3 && Session.Character.Family.WarehouseSize < 21)
                {
                    if (Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head)
                    {
                        if (500000 >= Session.Character.Gold)
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                            return;
                        }
                        Session.Character.Family.WarehouseSize = 21;
                        Session.Character.Gold -= 500000;
                        Session.SendPacket(Session.Character.GenerateGold());
                        FamilyDTO fam = Session.Character.Family;
                        DAOFactory.FamilyDAO.InsertOrUpdate(ref fam);
                        ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 10));
                        Session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 1));
                    }
                }
                break;

            case 1603:
                if (Session.Character.Family?.FamilyLevel >= 7 && Session.Character.Family.WarehouseSize < 49)
                {
                    if (Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head)
                    {
                        if (2000000 >= Session.Character.Gold)
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                            return;
                        }
                        Session.Character.Family.WarehouseSize = 49;
                        Session.Character.Gold -= 2000000;
                        Session.SendPacket(Session.Character.GenerateGold());
                        FamilyDTO fam = Session.Character.Family;
                        DAOFactory.FamilyDAO.InsertOrUpdate(ref fam);
                        ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 10));
                        Session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 1));
                    }
                }
                break;

            case 1604:
                if (Session.Character.Family?.FamilyLevel >= 5 && Session.Character.Family.MaxSize < 70)
                {
                    if (Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head)
                    {
                        if (5000000 >= Session.Character.Gold)
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                            return;
                        }
                        Session.Character.Family.MaxSize = 70;
                        Session.Character.Gold          -= 5000000;
                        Session.SendPacket(Session.Character.GenerateGold());
                        FamilyDTO fam = Session.Character.Family;
                        DAOFactory.FamilyDAO.InsertOrUpdate(ref fam);
                        ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 10));
                        Session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 1));
                    }
                }
                break;

            case 1605:
                if (Session.Character.Family?.FamilyLevel >= 9 && Session.Character.Family.MaxSize < 100)
                {
                    if (Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head)
                    {
                        if (10000000 >= Session.Character.Gold)
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                            return;
                        }
                        Session.Character.Family.MaxSize = 100;
                        Session.Character.Gold          -= 10000000;
                        Session.SendPacket(Session.Character.GenerateGold());
                        FamilyDTO fam = Session.Character.Family;
                        DAOFactory.FamilyDAO.InsertOrUpdate(ref fam);
                        ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId);
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 10));
                        Session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ONLY_HEAD_CAN_BUY"), 1));
                    }
                }
                break;

            case 23:
                if (packet.Type == 0)
                {
                    if (Session.Character.Group?.CharacterCount == 3)
                    {
                        foreach (ClientSession s in Session.Character.Group.Characters.GetAllItems())
                        {
                            if (s.Character.Family != null)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("GROUP_MEMBER_ALREADY_IN_FAMILY")));
                                return;
                            }
                        }
                    }
                    if (Session.Character.Group == null || Session.Character.Group.CharacterCount != 3)
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("FAMILY_GROUP_NOT_FULL")));
                        return;
                    }
                    Session.SendPacket(UserInterfaceHelper.GenerateInbox($"#glmk^ {14} 1 {Language.Instance.GetMessageFromKey("CREATE_FAMILY").Replace(' ', '^')}"));
                }
                else
                {
                    if (Session.Character.Family == null)
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_IN_FAMILY")));
                        return;
                    }
                    if (Session.Character.Family != null && Session.Character.FamilyCharacter != null && Session.Character.FamilyCharacter.Authority != FamilyAuthority.Head)
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_FAMILY_HEAD")));
                        return;
                    }
                    Session.SendPacket($"qna #glrm^1 {Language.Instance.GetMessageFromKey("DISMISS_FAMILY")}");
                }

                break;

            case 60:
                StaticBonusDTO medal = Session.Character.StaticBonusList.Find(s => s.StaticBonusType == StaticBonusType.BazaarMedalGold || s.StaticBonusType == StaticBonusType.BazaarMedalSilver);
                byte           Medal = 0;
                int            Time  = 0;
                if (medal != null)
                {
                    Medal = medal.StaticBonusType == StaticBonusType.BazaarMedalGold ? (byte)MedalType.Gold : (byte)MedalType.Silver;
                    Time  = (int)(medal.DateEnd - DateTime.Now).TotalHours;
                }
                Session.SendPacket($"wopen 32 {Medal} {Time}");
                break;

            case 5002:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    //Session.SendPacket("it 3");
                    if (ServerManager.Instance.ChannelId == 51)
                    {
                        string connection = CommunicationServiceClient.Instance.RetrieveOriginWorld(Session.Account.AccountId);
                        if (string.IsNullOrWhiteSpace(connection))
                        {
                            return;
                        }
                        Session.Character.MapId = tp.MapId;
                        Session.Character.MapX  = tp.MapX;
                        Session.Character.MapY  = tp.MapY;
                        int port = Convert.ToInt32(connection.Split(':')[1]);
                        Session.Character.ChangeChannel(connection.Split(':')[0], port, 3);
                    }
                    else
                    {
                        ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                    }
                }
                break;

            case 5001:
                if (npc != null)
                {
                    MapInstance map = null;
                    switch (Session.Character.Faction)
                    {
                    case FactionType.None:
                        Session.SendPacket(UserInterfaceHelper.GenerateInfo("You need to be part of a faction to join Act 4"));
                        return;

                    case FactionType.Angel:
                        map = ServerManager.GetAllMapInstances().Find(s => s.MapInstanceType.Equals(MapInstanceType.Act4ShipAngel));

                        break;

                    case FactionType.Demon:
                        map = ServerManager.GetAllMapInstances().Find(s => s.MapInstanceType.Equals(MapInstanceType.Act4ShipDemon));

                        break;
                    }
                    if (map == null || npc.EffectActivated)
                    {
                        Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SHIP_NOTARRIVED"), 0));
                        return;
                    }
                    if (3000 > Session.Character.Gold)
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                        return;
                    }
                    Session.Character.Gold -= 3000;
                    MapCell pos = map.Map.GetRandomPosition();
                    ServerManager.Instance.ChangeMapInstance(Session.Character.CharacterId, map.MapInstanceId, pos.X, pos.Y);
                }
                break;

            case 5004:
                if (npc != null)
                {
                    ServerManager.Instance.ChangeMap(Session.Character.CharacterId, 145, 50, 41);
                }
                break;

            case 5011:
                if (npc != null)
                {
                    ServerManager.Instance.ChangeMap(Session.Character.CharacterId, 170, 127, 46);
                }
                break;

            case 5012:
                tp = npc?.Teleporters?.FirstOrDefault(s => s.Index == packet.Type);
                if (tp != null)
                {
                    ServerManager.Instance.ChangeMap(Session.Character.CharacterId, tp.MapId, tp.MapX, tp.MapY);
                }
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_NRUN_HANDLER"), packet.Runner));
                break;
            }
        }
Example #5
0
        internal static void GenerateTalentArena()
        {
            long        groupid = 0;
            int         seconds = 0;
            IDisposable obs     = Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(start2 =>
            {
                lock (ServerManager.Instance.ArenaMembers)
                {
                    ServerManager.Instance.ArenaMembers.ToList().Where(s => s.ArenaType == EventType.TALENTARENA).ToList().ForEach(s =>
                    {
                        s.Time -= 1;
                        List <long> groupids = new List <long>();
                        ServerManager.Instance.ArenaMembers.ToList().Where(o => o.GroupId != null).ToList().ForEach(o =>
                        {
                            if (ServerManager.Instance.ArenaMembers.ToList().Count(g => g.GroupId == o.GroupId) != 3)
                            {
                                return;
                            }
                            if (o.GroupId != null)
                            {
                                groupids.Add(o.GroupId.Value);
                            }
                        });

                        if (s.Time > 0)
                        {
                            if (s.GroupId == null)
                            {
                                List <ArenaMember> members = ServerManager.Instance.ArenaMembers.ToList()
                                                             .Where(e => e.Session != s.Session && e.ArenaType == EventType.TALENTARENA && e.Session.Character.Level <= s.Session.Character.Level + 5 &&
                                                                    e.Session.Character.Level >= s.Session.Character.Level - 5).ToList();
                                members.RemoveAll(o => o.GroupId != null && groupids.Contains(o.GroupId.Value));
                                ArenaMember member = members.FirstOrDefault();
                                if (member == null)
                                {
                                    return;
                                }
                                else
                                {
                                    if (member.GroupId == null)
                                    {
                                        groupid++;
                                        member.GroupId = groupid;
                                    }
                                    s.GroupId = member.GroupId;
                                    ServerManager.Instance.ArenaMembers.ToList().Where(e => e.ArenaType == EventType.TALENTARENA && e.GroupId == member.GroupId).ToList().ForEach(o =>
                                    {
                                        o.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 2, -1, 6));
                                        o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ARENA_TEAM_FOUND"), 10));
                                        Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(time =>
                                        {
                                            s.Time = 300;
                                            if (ServerManager.Instance.ArenaMembers.ToList().Count(g => g.GroupId == s.GroupId) < 3)
                                            {
                                                o.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 2, s.Time, 8));
                                                o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SEARCH_ARENA_TEAM"), 10));
                                            }
                                            else
                                            {
                                                o.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 2, s.Time, 1));
                                                o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SEARCH_RIVAL_ARENA_TEAM"), 10));
                                            }
                                        });
                                    });
                                }
                            }
                            else
                            {
                                if (ServerManager.Instance.ArenaMembers.ToList().Count(g => g.GroupId == s.GroupId) != 3)
                                {
                                    return;
                                }

                                ArenaMember member =
                                    ServerManager.Instance.ArenaMembers.ToList().FirstOrDefault(o => o.GroupId != null && o.GroupId != s.GroupId && groupids.Contains(o.GroupId.Value) &&
                                                                                                o.Session.Character.Level <= s.Session.Character.Level + 5 &&
                                                                                                o.Session.Character.Level >= s.Session.Character.Level - 5);
                                if (member == null)
                                {
                                    return;
                                }

                                MapInstance map = ServerManager.GenerateMapInstance(2015, MapInstanceType.TalentArenaMapInstance, new InstanceBag());
                                map.IsPVP       = true;
                                ConcurrentBag <ArenaTeamMember> arenaTeam = new ConcurrentBag <ArenaTeamMember>();
                                ServerManager.Instance.ArenaTeams.Add(arenaTeam);

                                ArenaMember[] arenamembers = ServerManager.Instance.ArenaMembers.ToList().Where(o => o.GroupId == member.GroupId || o.GroupId == s.GroupId).OrderBy(o => o.GroupId)
                                                             .ToArray();
                                for (int i = 0; i < 6; i++)
                                {
                                    ItemInstance item = Inventory.InstantiateItemInstance((short)(4433 + (i > 2 ? 5 - i : i)), member.Session.Character.CharacterId);
                                    item.Design       = (short)(4433 + (i > 2 ? 5 - i : i));
                                    map.MapDesignObjects.Add(new MapDesignObject
                                    {
                                        ItemInstance   = item,
                                        ItemInstanceId = item.Id,
                                        CharacterId    = member.Session.Character.CharacterId,
                                        MapX           = (short)(i > 2 ? 120 : 19),
                                        MapY           = (short)(i > 2 ? 35 + i % 3 * 4 : 36 + i % 3 * 4)
                                    });
                                }
                                map.InstanceBag.Clock.TotalSecondsAmount = 60;
                                map.InstanceBag.Clock.SecondsRemaining   = 600;
                                map.InstanceBag.Clock.StartClock();
                                IDisposable obs4    = null;
                                IDisposable obs2    = null;
                                IDisposable obs3    = null;
                                IDisposable obs6    = null;
                                bool WinLoseMsgSent = false;
                                Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(time2 =>
                                {
                                    obs3 = Observable.Interval(TimeSpan.FromSeconds(5)).Subscribe(effect =>
                                    {
                                        arenamembers.Where(c => !c.Session.Character.Invisible).ToList().ForEach(o => map.Broadcast(o.Session.Character.GenerateEff(o.GroupId == s.GroupId ? 3012 : 3013)));
                                    });
                                });
                                IDisposable obs5 = Observable.Interval(TimeSpan.FromMilliseconds(500)).Subscribe(start3 =>
                                {
                                    map.Broadcast(arenamembers.FirstOrDefault(o => o.Session != null)?.Session.Character.GenerateTaPs());
                                    List <ArenaTeamMember> erenia = arenaTeam.Replace(team => team.ArenaTeamType == ArenaTeamType.ERENIA).ToList();
                                    List <ArenaTeamMember> zenas  = arenaTeam.Replace(team => team.ArenaTeamType == ArenaTeamType.ZENAS).ToList();
                                    BuffTeam(erenia);
                                    BuffTeam(zenas);
                                });
                                arenamembers.ToList().ForEach(o =>
                                {
                                    o.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 2, s.Time, 2));
                                    o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RIVAL_ARENA_TEAM_FOUND"), 10));

                                    Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(time =>
                                    {
                                        o.Session.SendPacket("ta_close");
                                        Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(time2 =>
                                        {
                                            if (o.Session.Character.IsVehicled)
                                            {
                                                o.Session.Character.RemoveVehicle();
                                            }
                                            Group grp = o.Session.Character.Group;
                                            if (grp != null)
                                            {
                                                grp.LeaveGroup(o.Session);
                                            }
                                            o.Session.Character.Mates.Where(m => m.IsTeamMember).ToList().ForEach(m => m.BackToMiniland());
                                            o.Session.Character.GeneralLogs.Add(new GeneralLogDTO
                                            {
                                                AccountId   = o.Session.Account.AccountId,
                                                CharacterId = o.Session.Character.CharacterId,
                                                IpAddress   = o.Session.IpAddress,
                                                LogData     = "Entry",
                                                LogType     = "TalentArena",
                                                Timestamp   = DateTime.Now
                                            });
                                            List <BuffType> bufftodisable = new List <BuffType> {
                                                BuffType.Bad, BuffType.Good, BuffType.Neutral
                                            };
                                            o.Session.Character.DisableBuffs(bufftodisable);
                                            int i = Array.IndexOf(arenamembers, o) + 1;
                                            o.Session.Character.Hp = (int)o.Session.Character.HPLoad();
                                            o.Session.Character.Mp = (int)o.Session.Character.MPLoad();
                                            ServerManager.Instance.ChangeMapInstance(o.Session.Character.CharacterId, map.MapInstanceId, o.GroupId == member.GroupId ? 125 : 14,
                                                                                     (o.GroupId == member.GroupId ? 37 : 38) + i % 3 * 2);
                                            o.Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SELECT_ORDER_ARENA_TIME"), 0));
                                            o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SELECT_ORDER_ARENA_TIME"), 10));
                                            o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SELECT_ORDER_ARENA"), 10));
                                            o.Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SELECT_ORDER_ARENA"), 0));
                                            o.Session.SendPacket(o.Session.Character.GenerateTaM(0));
                                            o.Session.SendPacket("ta_sv 0");
                                            o.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Watch));
                                            o.Session.SendPacket(o.Session.Character.GenerateTaM(3));

                                            o.Session.SendPacket(o.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(o.GroupId == s.GroupId ? "ZENAS" : "ERENIA"), 10));
                                            arenaTeam.Add(new ArenaTeamMember(o.Session, o.GroupId == s.GroupId ? ArenaTeamType.ZENAS : ArenaTeamType.ERENIA, null));
                                            o.Session.SendPacket(o.Session.Character.GenerateTaP(0, false));

                                            obs2 = Observable.Interval(TimeSpan.FromMilliseconds(100)).Subscribe(start3 =>
                                            {
                                                bool resettap = false;
                                                map.MapDesignObjects.ToList().ForEach(e =>
                                                {
                                                    if (e.ItemInstance.Design >= 4433 && e.ItemInstance.Design <= 4435)
                                                    {
                                                        Character chara = map.GetCharactersInRange(e.MapX, e.MapY, 0).FirstOrDefault();
                                                        if (chara != null)
                                                        {
                                                            resettap = true;
                                                            ArenaTeamMember teammember = arenaTeam.FirstOrDefault(at => at.Session == chara.Session);
                                                            if (teammember != null &&
                                                                !arenaTeam.Any(at => at.Order == (e.ItemInstance.ItemVNum - 4433) &&
                                                                               at.ArenaTeamType == (e.MapX == 120 ? ArenaTeamType.ERENIA : ArenaTeamType.ZENAS)))
                                                            {
                                                                if (teammember.Order != null)
                                                                {
                                                                    MapDesignObject obj =
                                                                        map.MapDesignObjects.FirstOrDefault(mapobj => mapobj.ItemInstance.ItemVNum == e.ItemInstance.ItemVNum &&
                                                                                                            e.MapX == (teammember.ArenaTeamType == ArenaTeamType.ERENIA ? 120 : 19));
                                                                    if (obj != null)
                                                                    {
                                                                        obj.ItemInstance.Design = obj.ItemInstance.ItemVNum;
                                                                    }
                                                                }
                                                                teammember.Order = (byte)(e.ItemInstance.ItemVNum - 4433);
                                                            }
                                                        }
                                                    }
                                                    else if (e.ItemInstance.Design == 4436)
                                                    {
                                                        if (!map.GetCharactersInRange(e.MapX, e.MapY, 0).Any())
                                                        {
                                                            resettap = true;
                                                            ArenaTeamMember teammember = arenaTeam.FirstOrDefault(at =>
                                                                                                                  at.Order == (e.ItemInstance.ItemVNum - 4433) && at.ArenaTeamType == (e.MapX == 120 ? ArenaTeamType.ERENIA : ArenaTeamType.ZENAS));
                                                            if (teammember != null)
                                                            {
                                                                teammember.Order = null;
                                                            }
                                                        }
                                                    }
                                                    if (!arenaTeam.Any(at => at.Order == (e.ItemInstance.ItemVNum - 4433) && at.ArenaTeamType == (e.MapX == 120 ? ArenaTeamType.ERENIA : ArenaTeamType.ZENAS)))
                                                    {
                                                        if (e.ItemInstance.Design != 4436)
                                                        {
                                                            return;
                                                        }
                                                        e.ItemInstance.Design = e.ItemInstance.ItemVNum;
                                                        map.Broadcast(e.GenerateEffect(false));
                                                    }
                                                    else if (e.ItemInstance.Design != 4436)
                                                    {
                                                        e.ItemInstance.Design = 4436;
                                                        map.Broadcast(e.GenerateEffect(false));
                                                    }
                                                });

                                                if (resettap)
                                                {
                                                    arenaTeam.ToList().ForEach(arenauser => { arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaP(2, false)); });
                                                }
                                            });
                                        });
                                    });
                                });
                                Observable.Timer(TimeSpan.FromSeconds(map.InstanceBag.Clock.TotalSecondsAmount)).Subscribe(start =>
                                {
                                    obs2.Dispose();
                                    arenaTeam.ToList().ForEach(arenauser =>
                                    {
                                        if (arenauser.Order == null)
                                        {
                                            for (byte x = 0; x < 3; x++)
                                            {
                                                if (!arenaTeam.Any(at => at.ArenaTeamType == arenauser.ArenaTeamType && at.Order == x))
                                                {
                                                    arenauser.Order = x;
                                                }
                                            }
                                        }
                                        arenauser.Session.SendPacket($"ta_pn {arenauser.Order + 1}");
                                    });
                                    map.MapDesignObjects.ToList().ForEach(md => map.Broadcast(md.GenerateEffect(true)));
                                    map.MapDesignObjects.Clear();

                                    arenaTeam.ToList().ForEach(arenauser => arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaP(2, true)));

                                    bool newround1   = true;
                                    bool newround2   = true;
                                    int count1       = 0;
                                    int count2       = 0;
                                    IDisposable obs7 = obs4;

                                    ArenaTeamMember beforetm  = null;
                                    ArenaTeamMember beforetm2 = null;

                                    obs4 = Observable.Interval(TimeSpan.FromMilliseconds(500)).Subscribe(start3 =>
                                    {
                                        int ereniacount = arenaTeam.Count(at => at.Dead && at.ArenaTeamType == ArenaTeamType.ERENIA);
                                        int zenascount  = arenaTeam.Count(at => at.Dead && at.ArenaTeamType == ArenaTeamType.ZENAS);
                                        if (ServerManager.Instance.ArenaTeams.ToList().Find(a => a.Any(b => arenaTeam.Contains(b))) is ConcurrentBag <ArenaTeamMember> updatedTeam)
                                        {
                                            arenaTeam = updatedTeam;
                                        }
                                        else
                                        {
                                            arenaTeam.Clear();
                                            obs2.Dispose();
                                            obs3.Dispose();
                                            obs5.Dispose();
                                            obs7?.Dispose();
                                            map.Dispose();
                                            ServerManager.Instance.ArenaMembers.RemoveAll(o => o.GroupId == member.GroupId || o.GroupId == s.GroupId);
                                            obs4.Dispose();
                                            return;
                                        }
                                        if (count1 != ereniacount || count2 != zenascount)
                                        {
                                            if (count1 != ereniacount)
                                            {
                                                newround1 = true;
                                            }
                                            if (count2 != zenascount)
                                            {
                                                newround2 = true;
                                            }
                                            count1 = ereniacount;
                                            count2 = zenascount;
                                        }

                                        ArenaTeamMember tm  = arenaTeam.OrderBy(tm3 => tm3.Order).FirstOrDefault(tm3 => tm3.ArenaTeamType == ArenaTeamType.ERENIA && !tm3.Dead);
                                        ArenaTeamMember tm2 = arenaTeam.OrderBy(tm3 => tm3.Order).FirstOrDefault(tm3 => tm3.ArenaTeamType == ArenaTeamType.ZENAS && !tm3.Dead);

                                        if (tm == beforetm && tm2 == beforetm2)
                                        {
                                            return;
                                        }
                                        else
                                        {
                                            if (tm != null)
                                            {
                                                beforetm = tm;
                                            }
                                            if (tm2 != null)
                                            {
                                                beforetm2 = tm2;
                                            }
                                        }

                                        if (!newround1 && !newround2 && tm != null && tm2 != null)
                                        {
                                            return;
                                        }

                                        int timeToWait = 0;

                                        try
                                        {
                                            timeToWait = tm?.Order == arenaTeam.OrderBy(tm3 => tm3.Order).FirstOrDefault(tm3 => tm3.ArenaTeamType == ArenaTeamType.ERENIA).Order&& tm2?.Order == arenaTeam.OrderBy(tm3 => tm3.Order).FirstOrDefault(tm3 => tm3.ArenaTeamType == ArenaTeamType.ZENAS).Order ? 0 : 3;
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.Error($"Talent Arena error: {ex}");
                                            return;
                                        }

                                        map.InstanceBag.Clock.TotalSecondsAmount = 300 + timeToWait;
                                        map.InstanceBag.Clock.SecondsRemaining   = 3000 + timeToWait * 10;

                                        arenaTeam.ToList().ForEach(friends =>
                                        {
                                            friends.Session.SendPacket(friends.Session.Character.GenerateTaM(2));
                                            friends.Session.SendPacket(friends.Session.Character.GenerateTaM(3));
                                        });
                                        map.Sessions.Except(arenaTeam.Select(ss => ss.Session)).ToList().ForEach(o =>
                                        {
                                            o.SendPacket(tm2?.Session.Character.GenerateTaM(2));
                                            o.SendPacket(tm2?.Session.Character.GenerateTaM(3));
                                        });

                                        obs6?.Dispose();
                                        obs6 = Observable.Timer(TimeSpan.FromSeconds(map.InstanceBag.Clock.TotalSecondsAmount)).Subscribe(start4 =>
                                        {
                                            if (tm2 != null && tm != null)
                                            {
                                                tm.Dead  = true;
                                                tm2.Dead = true;
                                                tm.Session.Character.PositionX  = 120;
                                                tm.Session.Character.PositionY  = 39;
                                                tm2.Session.Character.PositionX = 19;
                                                tm2.Session.Character.PositionY = 40;
                                                map.Broadcast(tm2.Session, tm.Session.Character.GenerateTp());
                                                map.Broadcast(tm2.Session, tm2.Session.Character.GenerateTp());
                                                tm.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Watch));
                                                tm2.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Watch));

                                                List <BuffType> bufftodisable = new List <BuffType> {
                                                    BuffType.Bad
                                                };

                                                tm.Session.Character.DisableBuffs(bufftodisable);
                                                tm.Session.Character.Hp = (int)tm.Session.Character.HPLoad();
                                                tm.Session.Character.Mp = (int)tm.Session.Character.MPLoad();
                                                tm.Session.SendPacket(tm.Session.Character.GenerateStat());

                                                tm2.Session.Character.DisableBuffs(bufftodisable);
                                                tm2.Session.Character.Hp = (int)tm2.Session.Character.HPLoad();
                                                tm2.Session.Character.Mp = (int)tm2.Session.Character.MPLoad();
                                                tm2.Session.SendPacket(tm2.Session.Character.GenerateStat());

                                                arenaTeam.Replace(friends => friends.ArenaTeamType == tm.ArenaTeamType).ToList().ForEach(friends =>
                                                {
                                                    friends.Session.SendPacket(friends.Session.Character.GenerateTaFc(0));
                                                });
                                            }
                                            newround1 = true;
                                            newround2 = true;
                                            arenaTeam.ToList().ForEach(arenauser => { arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaP(2, true)); });
                                        });

                                        if (tm != null && tm2 != null)
                                        {
                                            map.IsPVP = false;

                                            arenaTeam.ToList().ForEach(friends =>
                                            {
                                                friends.Session.SendPacket(friends.ArenaTeamType == ArenaTeamType.ERENIA
                                                    ? tm.Session.Character.GenerateTaFc(0)
                                                    : tm2.Session.Character.GenerateTaFc(0));
                                            });

                                            map.Sessions.Except(arenaTeam.Select(ss => ss.Session)).ToList().ForEach(ss =>
                                            {
                                                ss.SendPacket(tm.Session.Character.GenerateTaFc(0));
                                                ss.SendPacket(tm2.Session.Character.GenerateTaFc(1));
                                            });

                                            if (newround1)
                                            {
                                                Observable.Timer(TimeSpan.FromSeconds(timeToWait)).Subscribe(start5 =>
                                                {
                                                    map.Broadcast(tm.Session.Character.GenerateTaFc(1));
                                                    tm.Session.Character.PositionX = 87;
                                                    tm.Session.Character.PositionY = 39;
                                                    map.Broadcast(tm.Session, tm.Session.Character.GenerateTp());
                                                });
                                            }
                                            if (newround2)
                                            {
                                                Observable.Timer(TimeSpan.FromSeconds(timeToWait)).Subscribe(start5 =>
                                                {
                                                    tm2.Session.Character.PositionX = 56;
                                                    tm2.Session.Character.PositionY = 40;
                                                    map.Broadcast(tm2.Session, tm2.Session.Character.GenerateTp());
                                                });
                                            }
                                            Observable.Timer(TimeSpan.FromSeconds(timeToWait)).Subscribe(start5 =>
                                            {
                                                arenaTeam.Replace(at => at.LastSummoned != null).ToList().ForEach(at =>
                                                {
                                                    at.LastSummoned = null;
                                                    at.Session.Character.PositionX = at.ArenaTeamType == ArenaTeamType.ERENIA ? (short)120 : (short)19;
                                                    at.Session.Character.PositionY = at.ArenaTeamType == ArenaTeamType.ERENIA ? (short)39 : (short)40;
                                                    at.Session.CurrentMapInstance.Broadcast(at.Session.Character.GenerateTp());
                                                    at.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Watch));

                                                    List <BuffType> bufftodisable = new List <BuffType> {
                                                        BuffType.Bad
                                                    };
                                                    at.Session.Character.DisableBuffs(bufftodisable);
                                                    at.Session.Character.Hp = (int)at.Session.Character.HPLoad();
                                                    at.Session.Character.Mp = (int)at.Session.Character.MPLoad();
                                                });

                                                tm.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Call));
                                                tm2.Session.SendPacket(UserInterfaceHelper.Instance.GenerateTaSt(TalentArenaOptionType.Call));

                                                map.Broadcast("ta_s");
                                                Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(start4 => { map.IsPVP = true; });
                                            });
                                        }
                                        else
                                        {
                                            switch (tm)
                                            {
                                            case null when tm2 == null:
                                                if (!WinLoseMsgSent)
                                                {
                                                    map.Broadcast(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EQUALITY"), 0));
                                                    arenaTeam.ToList().ForEach(arenauser =>
                                                    {
                                                        arenauser.Session.SendPacket(arenauser.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("EQUALITY"), 10));
                                                        arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaF(3));
                                                    });
                                                    map.Sessions.Except(arenamembers.Select(x => x.Session)).ToList().ForEach(
                                                        x =>
                                                    {
                                                        ArenaTeamMember arenauser = arenaTeam.FirstOrDefault(se => se.Session != null);
                                                        if (arenauser == null)
                                                        {
                                                            return;
                                                        }
                                                        x.SendPacket(arenauser.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("EQUALITY"), 10));
                                                        x.SendPacket(arenauser.Session.Character.GenerateTaF(0));
                                                    }
                                                        );
                                                    WinLoseMsgSent = true;
                                                }
                                                break;

                                            case null:
                                                if (!WinLoseMsgSent)
                                                {
                                                    map.Broadcast(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("VICTORIOUS_ZENAS"), 0));

                                                    arenaTeam.ToList().ForEach(arenauser =>
                                                    {
                                                        Observable.Timer(TimeSpan.FromSeconds(2)).Subscribe(WinZenas =>
                                                        {
                                                            SendRewards(arenauser, arenauser.ArenaTeamType == ArenaTeamType.ZENAS);
                                                            arenauser.Session.SendPacket(arenauser.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("VICTORIOUS_ZENAS"), 10));
                                                            arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaF(1));
                                                        });
                                                    });
                                                    WinLoseMsgSent = true;
                                                }
                                                break;

                                            default:
                                                if (!WinLoseMsgSent)
                                                {
                                                    map.Broadcast(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("VICTORIOUS_ERENIA"), 0));
                                                    arenaTeam.ToList().ForEach(arenauser =>
                                                    {
                                                        SendRewards(arenauser, arenauser.ArenaTeamType == ArenaTeamType.ERENIA);
                                                        arenauser.Session.SendPacket(arenauser.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("VICTORIOUS_ERENIA"), 10));
                                                        arenauser.Session.SendPacket(arenauser.Session.Character.GenerateTaF(2));
                                                    });
                                                    WinLoseMsgSent = true;
                                                }
                                                break;
                                            }
                                            map.IsPVP = false;
                                            obs3.Dispose();
                                            obs2.Dispose();
                                            obs7?.Dispose();
                                            obs5.Dispose();
                                            Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(start4 => //Observable.Timer(TimeSpan.FromSeconds(30)).Subscribe(start4 =>
                                            {
                                                arenaTeam.ToList().ForEach(o =>
                                                {
                                                    if (o.Session?.CurrentMapInstance?.MapInstanceType == MapInstanceType.TalentArenaMapInstance)
                                                    {
                                                        o.Session.Character.GetSkills().ForEach(c => c.LastUse = DateTime.Now.AddDays(-1));

                                                        o.Session.SendPacket(o.Session.Character.GenerateSki());
                                                        o.Session.SendPackets(o.Session.Character.GenerateQuicklist());

                                                        List <BuffType> bufftodisable = new List <BuffType> {
                                                            BuffType.Bad
                                                        };
                                                        o.Session.Character.DisableBuffs(bufftodisable);
                                                        o.Session.Character.RemoveBuff(491);
                                                        ServerManager.Instance.TeleportOnRandomPlaceInMap(o.Session, ServerManager.Instance.ArenaInstance.MapInstanceId);
                                                    }
                                                });
                                                map.Sessions.ToList().ForEach(sess =>
                                                {
                                                    if (sess.CurrentMapInstance?.MapInstanceType == MapInstanceType.TalentArenaMapInstance)
                                                    {
                                                        List <BuffType> bufftodisable = new List <BuffType> {
                                                            BuffType.Bad
                                                        };
                                                        sess.Character.DisableBuffs(bufftodisable);
                                                        sess.Character.RemoveBuff(491);
                                                        ServerManager.Instance.TeleportOnRandomPlaceInMap(sess, ServerManager.Instance.ArenaInstance.MapInstanceId);
                                                    }
                                                });
                                                map.Dispose();
                                            });
                                        }
                                        newround1 = false;
                                        newround2 = false;
                                    });
                                });
                                ServerManager.Instance.ArenaMembers.ToList().Where(o => o.GroupId == member.GroupId || o.GroupId == s.GroupId).ToList()
                                .ForEach(se => { se.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(2, 2, 0, 0)); });

                                ServerManager.Instance.ArenaMembers.RemoveAll(o => o.GroupId == member.GroupId || o.GroupId == s.GroupId);
                            }
                        }
                        else
                        {
                            if (s.GroupId == null)
                            {
                                if (s.Time != -1)
                                {
                                    s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 2, s.Time, 7));
                                    s.Session.SendPacket(s.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NO_TEAM_ARENA"), 10));
                                }
                                s.Time = 300;
                                s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 2, s.Time, 5));
                                s.Session.SendPacket(s.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SEARCH_ARENA_TEAM"), 10));
                            }
                            else if (ServerManager.Instance.ArenaMembers.ToList().Count(g => g.GroupId == s.GroupId) < 3)
                            {
                                s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 2, -1, 4));
                                Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(time =>
                                {
                                    s.Time = 300;
                                    s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(1, 2, s.Time, 8));
                                    s.Session.SendPacket(s.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RETRY_SEARCH_ARENA_TEAM"), 10));
                                });
                            }
                            else
                            {
                                s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 2, -1, 3));
                                Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(time =>
                                {
                                    s.Time = 300;
                                    s.Session.SendPacket(UserInterfaceHelper.GenerateBSInfo(0, 2, s.Time, 1));
                                    s.Session.SendPacket(s.Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SEARCH_RIVAL_ARENA_TEAM"), 10));
                                });
                            }
                        }
                    });
                    seconds++;
                }
            });

            CommunicationServiceClient.Instance.SendMessageToCharacter(new SCSCharacterMessage
            {
                SourceWorldId = ServerManager.Instance.WorldId,
                Message       = UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("TALENT_ARENA_OPENED"), ServerManager.Instance.ChannelId), 0),
                Type          = MessageType.Broadcast
            });

            //Observable.Timer(TimeSpan.FromHours(7)).Subscribe(start2 =>
            //{
            //    ServerManager.Instance.StartedEvents.Remove(EventType.TALENTARENA);
            //    obs.Dispose();
            //});
        }