Beispiel #1
0
        public static void HandleCharacterList(WorldSession session, ClientCharacterList characterList)
        {
            session.EnqueueEvent(new TaskGenericEvent <List <CharacterModel> >(DatabaseManager.Instance.CharacterDatabase.GetCharacters(session.Account.Id),
                                                                               characters =>
            {
                byte maxCharacterLevelAchieved = 1;

                session.Characters.Clear();
                session.Characters.AddRange(characters);

                session.AccountCurrencyManager.SendCharacterListPacket();
                session.GenericUnlockManager.SendUnlockList();

                session.EnqueueMessageEncrypted(new ServerAccountEntitlements
                {
                    Entitlements = session.EntitlementManager.GetAccountEntitlements()
                                   .Select(e => new ServerAccountEntitlements.AccountEntitlementInfo
                    {
                        Entitlement = e.Type,
                        Count       = e.Amount
                    })
                                   .ToList()
                });
                session.EnqueueMessageEncrypted(new ServerAccountTier
                {
                    Tier = session.AccountTier
                });

                // 2 is just a fail safe for the minimum amount of character slots
                // this is set in the tbl files so a value should always exist
                uint characterSlots = (uint)(session.EntitlementManager.GetRewardProperty(RewardPropertyType.CharacterSlots).GetValue(0u) ?? 2u);
                uint characterCount = (uint)characters.Count(c => c.DeleteTime == null);

                var serverCharacterList = new ServerCharacterList
                {
                    RealmId = WorldServer.RealmId,
                    // no longer used as replaced by entitlements but retail server still used to send this
                    AdditionalCount = characterCount,
                    AdditionalAllowedCharCreations = (uint)Math.Max(0, (int)(characterSlots - characterCount))
                };

                foreach (CharacterModel character in characters.Where(c => c.DeleteTime == null))
                {
                    var listCharacter = new ServerCharacterList.Character
                    {
                        Id                = character.Id,
                        Name              = character.Name,
                        Sex               = (Sex)character.Sex,
                        Race              = (Race)character.Race,
                        Class             = (Class)character.Class,
                        Faction           = character.FactionId,
                        Level             = character.Level,
                        WorldId           = character.WorldId,
                        WorldZoneId       = character.WorldZoneId,
                        RealmId           = WorldServer.RealmId,
                        Path              = (byte)character.ActivePath,
                        LastLoggedOutDays = (float)DateTime.UtcNow.Subtract(character.LastOnline ?? DateTime.UtcNow).TotalDays * -1f
                    };

                    maxCharacterLevelAchieved = Math.Max(maxCharacterLevelAchieved, character.Level);

                    try
                    {
                        // create a temporary Inventory and CostumeManager to show equipped gear
                        var inventory      = new Inventory(null, character);
                        var costumeManager = new CostumeManager(null, session.Account, character);

                        CostumeEntity costume = null;
                        if (character.ActiveCostumeIndex >= 0)
                        {
                            costume = costumeManager.GetCostume((byte)character.ActiveCostumeIndex);
                        }

                        listCharacter.GearMask = costume?.Mask ?? 0xFFFFFFFF;

                        foreach (ItemVisual itemVisual in inventory.GetItemVisuals(costume))
                        {
                            listCharacter.Gear.Add(itemVisual);
                        }

                        foreach (CharacterAppearanceModel appearance in character.Appearance)
                        {
                            listCharacter.Appearance.Add(new ItemVisual
                            {
                                Slot      = (ItemSlot)appearance.Slot,
                                DisplayId = appearance.DisplayId
                            });
                        }

                        /*foreach (CharacterCustomisation customisation in character.CharacterCustomisation)
                         * {
                         *  listCharacter.Labels.Add(customisation.Label);
                         *  listCharacter.Values.Add(customisation.Value);
                         * }*/

                        foreach (CharacterBoneModel bone in character.Bone.OrderBy(bone => bone.BoneIndex))
                        {
                            listCharacter.Bones.Add(bone.Bone);
                        }

                        foreach (CharacterStatModel stat in character.Stat)
                        {
                            if ((Stat)stat.Stat == Stat.Level)
                            {
                                listCharacter.Level = (uint)stat.Value;
                                break;
                            }
                        }

                        serverCharacterList.Characters.Add(listCharacter);
                    }
                    catch (Exception ex)
                    {
                        log.Fatal(ex, $"An error has occured while loading character '{character.Name}'");
                        continue;
                    }
                }

                session.EnqueueMessageEncrypted(new ServerMaxCharacterLevelAchieved
                {
                    Level = maxCharacterLevelAchieved
                });

                session.EnqueueMessageEncrypted(serverCharacterList);
            }));
        }
Beispiel #2
0
        public static void HandleCharacterList(WorldSession session, ClientCharacterList characterList)
        {
            session.EnqueueEvent(new TaskGenericEvent <List <Character> >(CharacterDatabase.GetCharacters(session.Account.Id),
                                                                          characters =>
            {
                byte MaxCharacterLevelAchieved = 1;

                session.Characters.Clear();
                session.Characters.AddRange(characters);

                session.AccountCurrencyManager.SendCharacterListPacket();
                session.GenericUnlockManager.SendUnlockList();

                session.EnqueueMessageEncrypted(new ServerAccountEntitlements
                {
                    Entitlements = session.EntitlementManager.GetAccountEntitlements()
                                   .Select(e => new ServerAccountEntitlements.AccountEntitlementInfo
                    {
                        Entitlement = e.Type,
                        Count       = e.Amount
                    })
                                   .ToList()
                });

                var serverCharacterList = new ServerCharacterList
                {
                    RealmId = WorldServer.RealmId
                };

                foreach (Character character in characters)
                {
                    if (character.DeleteTime != null)
                    {
                        continue;
                    }

                    var listCharacter = new ServerCharacterList.Character
                    {
                        Id          = character.Id,
                        Name        = character.Name,
                        Sex         = (Sex)character.Sex,
                        Race        = (Race)character.Race,
                        Class       = (Class)character.Class,
                        Faction     = character.FactionId,
                        Level       = character.Level,
                        WorldId     = character.WorldId,
                        WorldZoneId = character.WorldZoneId,
                        RealmId     = WorldServer.RealmId,
                        Path        = (byte)character.ActivePath
                    };

                    MaxCharacterLevelAchieved = (byte)Math.Max(MaxCharacterLevelAchieved, character.Level);

                    // create a temporary Inventory and CostumeManager to show equipped gear
                    var inventory      = new Inventory(null, character);
                    var costumeManager = new CostumeManager(null, session.Account, character);

                    CostumeEntity costume = null;
                    if (character.ActiveCostumeIndex >= 0)
                    {
                        costume = costumeManager.GetCostume((byte)character.ActiveCostumeIndex);
                    }

                    listCharacter.GearMask = costume?.Mask ?? 0xFFFFFFFF;

                    foreach (ItemVisual itemVisual in inventory.GetItemVisuals(costume))
                    {
                        listCharacter.Gear.Add(itemVisual);
                    }

                    foreach (CharacterAppearance appearance in character.CharacterAppearance)
                    {
                        listCharacter.Appearance.Add(new ItemVisual
                        {
                            Slot      = (ItemSlot)appearance.Slot,
                            DisplayId = appearance.DisplayId
                        });
                    }

                    /*foreach (CharacterCustomisation customisation in character.CharacterCustomisation)
                     * {
                     *  listCharacter.Labels.Add(customisation.Label);
                     *  listCharacter.Values.Add(customisation.Value);
                     * }*/

                    foreach (CharacterBone bone in character.CharacterBone.OrderBy(bone => bone.BoneIndex))
                    {
                        listCharacter.Bones.Add(bone.Bone);
                    }

                    foreach (CharacterStats stat in character.CharacterStats)
                    {
                        if ((Stat)stat.Stat == Stat.Level)
                        {
                            listCharacter.Level = (uint)stat.Value;
                            break;
                        }
                    }

                    serverCharacterList.Characters.Add(listCharacter);
                }

                session.EnqueueMessageEncrypted(new ServerMaxCharacterLevelAchieved
                {
                    Level = MaxCharacterLevelAchieved
                });

                session.EnqueueMessageEncrypted(serverCharacterList);
            }));
        }
Beispiel #3
0
        public static void HandleCharacterList(WorldSession session, ClientCharacterList characterList)
        {
            session.EnqueueEvent(new TaskGenericEvent <List <Character> >(CharacterDatabase.GetCharacters(session.Account.Id),
                                                                          characters =>
            {
                session.Characters.Clear();
                session.Characters.AddRange(characters);

                session.GenericUnlockManager.SendUnlockList();
                session.EnqueueMessageEncrypted(new ServerAccountEntitlements
                {
                    Entitlements =
                    {
                        new ServerAccountEntitlements.AccountEntitlementInfo
                        {
                            Entitlement = Entitlement.BaseCharacterSlots,
                            Count       = 12
                        },
                        new ServerAccountEntitlements.AccountEntitlementInfo
                        {
                            Entitlement = Entitlement.ChuaWarriorUnlock,
                            Count       = 1
                        },
                        new ServerAccountEntitlements.AccountEntitlementInfo
                        {
                            Entitlement = Entitlement.AurinEngineerUnlock,
                            Count       = 1
                        }
                    }
                });

                session.EnqueueMessageEncrypted(new ServerMaxCharacterLevelAchieved
                {
                    Level = 50
                });

                var serverCharacterList = new ServerCharacterList
                {
                    RealmId = WorldServer.RealmId
                };
                foreach (Character character in characters)
                {
                    var listCharacter = new ServerCharacterList.Character
                    {
                        Id          = character.Id,
                        Name        = character.Name,
                        Sex         = (Sex)character.Sex,
                        Race        = (Race)character.Race,
                        Class       = (Class)character.Class,
                        Faction     = character.FactionId,
                        Level       = character.Level,
                        WorldId     = character.WorldId,
                        WorldZoneId = 5967,
                        RealmId     = WorldServer.RealmId,
                        Path        = (byte)character.ActivePath
                    };

                    // create a temporary Inventory and CostumeManager to show equipped gear
                    var inventory      = new Inventory(null, character);
                    var costumeManager = new CostumeManager(null, session.Account, character);

                    CostumeEntity costume = null;
                    if (character.ActiveCostumeIndex >= 0)
                    {
                        costume = costumeManager.GetCostume((byte)character.ActiveCostumeIndex);
                    }

                    listCharacter.GearMask = costume?.Mask ?? 0xFFFFFFFF;

                    foreach (ItemVisual itemVisual in inventory.GetItemVisuals(costume))
                    {
                        listCharacter.Gear.Add(itemVisual);
                    }

                    foreach (CharacterAppearance appearance in character.CharacterAppearance)
                    {
                        listCharacter.Appearance.Add(new ItemVisual
                        {
                            Slot      = (ItemSlot)appearance.Slot,
                            DisplayId = appearance.DisplayId
                        });
                    }

                    /*foreach (CharacterCustomisation customisation in character.CharacterCustomisation)
                     * {
                     *  listCharacter.Labels.Add(customisation.Label);
                     *  listCharacter.Values.Add(customisation.Value);
                     * }*/

                    foreach (CharacterBone bone in character.CharacterBone.OrderBy(bone => bone.BoneIndex))
                    {
                        listCharacter.Bones.Add(bone.Bone);
                    }

                    serverCharacterList.Characters.Add(listCharacter);
                }

                session.EnqueueMessageEncrypted(serverCharacterList);
            }));
        }
Beispiel #4
0
        /// <summary>
        /// Validate then save or update <see cref="Costume"/> from <see cref="ClientCostumeSave"/> packet.
        /// </summary>
        public void SaveCostume(ClientCostumeSave costumeSave)
        {
            // TODO: used for housing mannequins
            if (costumeSave.MannequinIndex != 0)
            {
                throw new NotImplementedException();
            }

            if (costumeSave.Index < 0 || costumeSave.Index >= MaxCostumes)
            {
                SendCostumeSaveResult(CostumeSaveResult.InvalidCostumeIndex);
                return;
            }

            if (costumeSave.Index >= CostumeCap)
            {
                SendCostumeSaveResult(CostumeSaveResult.CostumeIndexNotUnlocked);
                return;
            }

            foreach (ClientCostumeSave.CostumeItem costumeItem in costumeSave.Items)
            {
                if (costumeItem.ItemId == 0)
                {
                    continue;
                }

                Item2Entry itemEntry = GameTableManager.Instance.Item.GetEntry(costumeItem.ItemId);
                if (itemEntry == null)
                {
                    SendCostumeSaveResult(CostumeSaveResult.InvalidItem);
                    return;
                }

                // TODO: check item family

                /*if ()
                 * {
                 *  SendCostumeSaveResult(CostumeSaveResult.UnusableItem);
                 *  return;
                 * }*/

                if (!costumeUnlocks.ContainsKey(costumeItem.ItemId))
                {
                    SendCostumeSaveResult(CostumeSaveResult.ItemNotUnlocked);
                    return;
                }

                ItemDisplayEntry itemDisplayEntry = GameTableManager.Instance.ItemDisplay.GetEntry(Item.GetDisplayId(itemEntry));
                for (int i = 0; i < costumeItem.Dyes.Length; i++)
                {
                    if (costumeItem.Dyes[i] == 0u)
                    {
                        continue;
                    }

                    if (itemDisplayEntry == null)
                    {
                        SendCostumeSaveResult(CostumeSaveResult.InvalidDye);
                        return;
                    }

                    uint dyeChannelFlag = 1u << i;
                    if ((itemDisplayEntry.DyeChannelFlags & dyeChannelFlag) == 0)
                    {
                        SendCostumeSaveResult(CostumeSaveResult.InvalidDye);
                        return;
                    }

                    if (!player.Session.GenericUnlockManager.IsDyeUnlocked(costumeItem.Dyes[i]))
                    {
                        SendCostumeSaveResult(CostumeSaveResult.DyeNotUnlocked);
                        return;
                    }
                }
            }

            // TODO: charge player

            if (costumes.TryGetValue((byte)costumeSave.Index, out Costume costume))
            {
                costume.Update(costumeSave);
            }
            else
            {
                costume = new Costume(player, costumeSave);
                costumes.Add(costume.Index, costume);
            }

            SetCostume((sbyte)costumeSave.Index, costume);

            SendCostume(costume);
            SendCostumeSaveResult(CostumeSaveResult.Saved, costumeSave.Index, costumeSave.MannequinIndex);
        }