Exemplo n.º 1
0
        public Player(Character player, bool initialize = true) : base(PlayerData.End)
        {
            data = player;

            Guid = new PlayerGuid
            {
                CreationBits = player.Guid,
                RealmId = (ushort)player.RealmId
            };

            PlayerData = new PlayerData();

            Position = new Vector3
            {
                X = player.X,
                Y = player.Y,
                Z = player.Z
            };

            Facing = player.O;
            Map = (short)player.Map;

            if (initialize)
                InitializeDescriptors();
        }
        public static async void HandleCreateCharacter(CreateCharacter createCharacter, WorldSession session)
        {
            var createChar = new CreateChar { Code = CharCreateCode.InProgress };

            if (!ClientDB.ChrRaces.Any(c => c.Id == createCharacter.RaceID) || !ClientDB.ChrClasses.Any(c => c.Id == createCharacter.ClassID))
                createChar.Code = CharCreateCode.Failed;
            else if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == createCharacter.RaceID && c.ClassId == createCharacter.ClassID))
                createChar.Code = CharCreateCode.Failed;
            else if (DB.Character.Any<Character>(c => c.Name == createCharacter.Name))
                createChar.Code = CharCreateCode.NameInUse;
            else if (createChar.Code == CharCreateCode.InProgress)
            {
                if (createCharacter.TemplateSetID != 0)
                {
                    var accTemplate = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == createCharacter.TemplateSetID);
                    var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == createCharacter.TemplateSetID);

                    if (accTemplate || realmTemplate)
                    {
                        // Not implemented = creation failed
                        createChar.Code = CharCreateCode.Failed;
                    }
                    else
                        createChar.Code = CharCreateCode.Failed;
                }
                else
                {
                    var creationData = DB.Character.Single<CharacterCreationData>(d => d.Race == createCharacter.RaceID && d.Class == createCharacter.ClassID);

                    if (creationData != null)
                    {
                        var newChar = new Character
                        {
                            Name = createCharacter.Name,
                            GameAccountId = session.GameAccount.Id,
                            RealmId = session.Realm.Id,
                            Race = createCharacter.RaceID,
                            Class = createCharacter.ClassID,
                            Sex = createCharacter.SexID,
                            Skin = createCharacter.SkinID,
                            Face = createCharacter.FaceID,
                            HairStyle = createCharacter.HairStyleID,
                            HairColor = createCharacter.HairColorID,
                            FacialHairStyle = createCharacter.FacialHairStyleID,
                            Map = creationData.Map,
                            X = creationData.X,
                            Y = creationData.Y,
                            Z = creationData.Z,
                            O = creationData.O,
                            CharacterFlags = CharacterFlags.Decline,
                            FirstLogin = 1,
                            ExperienceLevel = 1
                        };

                        if (DB.Character.Add(newChar))
                        {
                            Manager.Character.LearnStartAbilities(newChar);
                            Manager.Character.AddStartItems(newChar);

                            createChar.Code = CharCreateCode.Success;
                        }
                        else
                            createChar.Code = CharCreateCode.Success;
                    }
                    else
                        createChar.Code = CharCreateCode.Failed;
                }
            }

            await session.Send(createChar);
        }
Exemplo n.º 3
0
        public static void OnCreateCharacter(Packet packet, CharacterSession session)
        {
            var nameLength     = packet.GetBits<int>(6);
            var useTemplateSet = packet.GetBit();

            var raceId            = packet.Read<Race>();
            var classId           = packet.Read<Class>();
            var sexId             = packet.Read<byte>();
            var skinId            = packet.Read<byte>();
            var faceId            = packet.Read<byte>();
            var hairStyleId       = packet.Read<byte>();
            var hairColorId       = packet.Read<byte>();
            var facialHairStyleId = packet.Read<byte>();

            packet.Skip(1);

            var name = packet.Read<string>(nameLength).ToLowerEnd();

            var createChar = new Packet(ServerMessage.CreateChar);

            if (!ClientDB.ChrRaces.Any(c => c.Id == raceId) || !ClientDB.ChrClasses.Any(c => c.Id == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (!ClientDB.CharBaseInfo.Any(c => c.RaceId == raceId && c.ClassId == classId))
            {
                createChar.Write(CharCreateCode.Failed);

                session.Send(createChar);
                return;
            }

            if (DB.Character.Any<Character>(c => c.Name == name))
            {
                createChar.Write(CharCreateCode.NameInUse);

                session.Send(createChar);
                return;
            }

            if (useTemplateSet)
            {
                var templateSetId = packet.Read<int>();
                var accTemplate = session.GameAccount.GameAccountCharacterTemplates.Any(t => t.SetId == templateSetId);
                var realmTemplate = session.Realm.RealmCharacterTemplates.Any(t => t.SetId == templateSetId);

                if (accTemplate || realmTemplate)
                {
                    var template = DB.Character.Single<CharacterTemplateSet>(s => s.Id == templateSetId);
                    
                    // Implement...
                }
                else
                    createChar.Write(CharCreateCode.Failed);
            }
            else
            {
                var creationData = DB.Character.Single<CharacterCreationData>(d => d.Race == raceId && d.Class == classId);
                var creationData2 = DB.Character.Select<CharacterCreationData>();

                if (creationData != null)
                {
                    var newChar = new Character
                    {
                        Name            = name,
                        GameAccountId   = session.GameAccount.Id,
                        RealmId         = session.Realm.Id,
                        Race            = raceId,
                        Class           = classId,
                        Sex             = sexId,
                        Skin            = skinId,
                        Face            = faceId,
                        HairStyle       = hairStyleId,
                        HairColor       = hairColorId,
                        FacialHairStyle = facialHairStyleId,
                        Level           = 1,
                        Map             = creationData.Map,
                        X               = creationData.X,
                        Y               = creationData.Y,
                        Z               = creationData.Z,
                        O               = creationData.O,
                        CharacterFlags  = CharacterFlags.Decline,
                        FirstLogin      = true
                    };

                    if (DB.Character.Add(newChar))
                    {
                        createChar.Write(CharCreateCode.Success);

                        Manager.Character.LearnStartAbilities(newChar);
                    }
                    else
                        createChar.Write(CharCreateCode.Failed);
                }
                else
                    createChar.Write(CharCreateCode.Failed);
            }

            session.Send(createChar);
        }