Пример #1
0
        public static void OnCharacterSelect(GameClient client, ClientHeroSelectPacket packet)
        {
            // Get the hero the user wanted
            var hero = client.Account.Heroes.FirstOrDefault(x => x.Id == packet.HeroId);

            if (hero == null)
            {
                var response = new ServerHeroSelectResponsePacket(HeroStatus.Invalid);
                client.Send(response);
            }
            else
            {
                client.SelectedHero = hero; //TODO: remove and use gameobject hero

                var response = new ServerHeroSelectResponsePacket(HeroStatus.OK);
                client.Send(response);

                var zone = ZoneManager.Current.FindZone(hero.ZoneName);

                zone.OnClientEnter(client, hero);
            }
        }
        public static void OnCharacterSelect(GameClient client, ClientHeroSelectPacket packet)
        {
            // Ensure this is a valid action
            bool actionCanBePerformed = client.Account.IsOnline && client.HeroEntity == null;

            if (!actionCanBePerformed)
                return;

            // Get the hero the user wanted
            UserHero hero = client.Account.Heroes.FirstOrDefault();

            if (hero == null)
            {
                var response = new ServerHeroSelectResponsePacket(HeroStatus.Invalid);
                client.Send(response);
            }
            else
            {

                using (var context = new GameDatabaseContext())
                {
                    context.Characters.Attach(hero);
                    context.Entry(hero).Collection(a => a.Skills).Load();
                    context.Entry(hero).Collection(a => a.Inventory).Load();
                    context.Entry(hero).Collection(a => a.QuestInfo).Load();
                    context.Entry(hero).Collection(a => a.Flags).Load();

                    // Load up our set of requirements from the table
                    foreach (var x in hero.QuestInfo)
                        context.Entry(x).Collection(a => a.RequirementProgress).Load();

                    context.Entry(hero).Collection(a => a.Equipment).Load();
                }

                // Create an object and assign it the world if everything is okay
                var heroObject = GameObjectFactory.CreateHero(hero, client);
                client.HeroEntity = heroObject;

                var zone = ZoneManager.Instance.FindZone(hero.ZoneId);

                if (zone != null)
                {
                    // Create a response and alert the client that their selection is okay
                    var response = new ServerHeroSelectResponsePacket(HeroStatus.OK);
                    client.Send(response);

                    // Here, we should queue the player for login

                    Logger.Instance.Info("{0} has entered the game.", hero.Name);
                    zone.QueueLogin(heroObject);

                    // Add to global manager
                    ChatManager.Current.Global.Join(client);

                }
                else
                {
                    var response = new ServerHeroSelectResponsePacket(HeroStatus.Unavailable);
                    client.Send(response);

                    Logger.Instance.Error("{0} attempted to enter the game but could not be loaded.", hero.Name);
                }

            }
        }