示例#1
0
        public QuestLine ReadQuestLine(Stream inputStream)
        {
            using (var bReader = new BinaryReader(inputStream, Encoding.ASCII, leaveOpen: true))
            {
                var       reader    = new BitStreamReader(bReader);
                QuestLine questLine = new QuestLine();
                questLine.Version = reader.ReadInt32(8);

                if (questLine.Version != 22)
                {
                    throw new NotSupportedException("Version must be 22.");
                }

                questLine.PassCode    = reader.ReadString(7);
                questLine.Description = reader.ReadString(16);
                questLine.QuestSets   = new QuestSet[reader.ReadInt32(5)];

                for (int questSetIndex = 0; questSetIndex < questLine.QuestSets.Length; questSetIndex++)
                {
                    QuestSet questSet = questLine.QuestSets[questSetIndex] = new QuestSet();
                    questSet.Id          = questSetIndex;
                    questSet.Name        = reader.ReadString(5);
                    questSet.Description = reader.ReadString(16);

                    ReputationBar[] reputationBars = questSet.ReputationBars = new ReputationBar[reader.ReadInt32(8)];
                    for (int reputationBarIndex = 0; reputationBarIndex < reputationBars.Length; reputationBarIndex++)
                    {
                        reputationBars[reputationBarIndex] = new ReputationBar {
                            Data = reader.ReadInt32(32)
                        };
                    }
                }

                questLine.Reputations = new Reputation[reader.ReadInt32(8)];

                for (int reputationIndex = 0; reputationIndex < questLine.Reputations.Length; reputationIndex++)
                {
                    Reputation reputation = questLine.Reputations[reputationIndex] = new Reputation();
                    reputation.Id   = reader.ReadInt32(8);
                    reputation.Name = reader.ReadString(5);

                    string neutralName = reader.ReadString(5);

                    int markerCount = reader.ReadInt32(5);

                    reputation.Markers    = new ReputationMarker[markerCount + 1];
                    reputation.Markers[0] = new ReputationMarker {
                        Name = neutralName, Value = 0
                    };

                    for (int markerIndex = 1; markerIndex < reputation.Markers.Length; markerIndex++)
                    {
                        ReputationMarker marker = reputation.Markers[markerIndex] = new ReputationMarker();

                        marker.Name  = reader.ReadString(5);
                        marker.Value = reader.ReadInt32(32);
                    }
                }

                questLine.Quests = new Quest[reader.ReadInt32(10)];

                for (int questIndex = 0; questIndex < questLine.Quests.Length; questIndex++)
                {
                    // Don't skip this quest?
                    if (!reader.ReadBoolean())
                    {
                        continue;
                    }

                    Quest quest = questLine.Quests[questIndex] = new Quest();

                    quest.Id = questIndex;

                    quest.Name        = reader.ReadString(5);
                    quest.Description = reader.ReadString(16);

                    quest.XPos       = reader.ReadInt32(9);
                    quest.YPos       = reader.ReadInt32(8);
                    quest.IsBig      = reader.ReadBoolean();
                    quest.QuestSetId = reader.ReadInt32(5);

                    // Icon?
                    if (reader.ReadBoolean())
                    {
                        ItemStack icon = quest.Icon = new ItemStack();
                        icon.ItemId = reader.ReadString(16);
                        icon.Damage = reader.ReadInt32(16);
                        icon.NBT    = reader.ReadNBT();
                    }

                    // Has requirements?
                    if (reader.ReadBoolean())
                    {
                        quest.RequiredQuestIds = new int[reader.ReadInt32(10)];
                        for (int requirementIndex = 0; requirementIndex < quest.RequiredQuestIds.Length; requirementIndex++)
                        {
                            quest.RequiredQuestIds[requirementIndex] = reader.ReadInt32(10);
                        }
                    }

                    // Has option links?
                    if (reader.ReadBoolean())
                    {
                        quest.OptionLinks = new int[reader.ReadInt32(10)];
                        for (int optionLinkIndex = 0; optionLinkIndex < quest.OptionLinks.Length; optionLinkIndex++)
                        {
                            quest.OptionLinks[optionLinkIndex] = reader.ReadInt32(10);
                        }
                    }

                    quest.RepeatType = (RepeatType)reader.ReadInt32(2);
                    if (quest.RepeatType == RepeatType.Cooldown ||
                        quest.RepeatType == RepeatType.Interval)
                    {
                        quest.RepeatIntervalHours = reader.ReadInt32(32);
                    }

                    quest.TriggerType = (TriggerType)reader.ReadInt32(2);
                    if (quest.TriggerType == TriggerType.TaskCount)
                    {
                        quest.TriggerTaskCount = reader.ReadInt32(4);
                    }

                    // Modified Parent Requirement?
                    if (reader.ReadBoolean())
                    {
                        quest.ModifiedParentRequirementCount = reader.ReadInt32(10);
                    }

                    quest.Tasks = new QuestTask[reader.ReadInt32(4)];
                    for (int taskIndex = 0; taskIndex < quest.Tasks.Length; taskIndex++)
                    {
                        QuestTaskType taskType        = (QuestTaskType)reader.ReadInt32(4);
                        string        taskName        = reader.ReadString(5);
                        string        taskDescription = reader.ReadString(16);

                        QuestTask task = null;
                        switch (taskType)
                        {
                        case QuestTaskType.Consume:
                        case QuestTaskType.Craft:
                        case QuestTaskType.Detection:
                        case QuestTaskType.QDS:
                        {
                            ItemQuestTask itemTask;
                            task = itemTask = new ItemQuestTask();
                            itemTask.Requirements = new ItemRequirement[reader.ReadInt32(6)];

                            for (int itemIndex = 0; itemIndex < itemTask.Requirements.Length; itemIndex++)
                            {
                                ItemRequirement requirement = itemTask.Requirements[itemIndex] = new ItemRequirement();
                                requirement.ItemStack = new ItemStack();

                                // Item (as opposed to fluid)?
                                if (reader.ReadBoolean())
                                {
                                    requirement.Type             = ItemType.Item;
                                    requirement.ItemStack.ItemId = reader.ReadString(16);
                                    requirement.ItemStack.Damage = reader.ReadInt32(16);
                                    requirement.ItemStack.NBT    = reader.ReadNBT();

                                    requirement.Amount      = reader.ReadInt32(32);
                                    requirement.PrecisionId = reader.ReadString(30);
                                }
                                else
                                {
                                    requirement.Type          = ItemType.Fluid;
                                    requirement.ItemStack.NBT = reader.ReadNBT();
                                }
                            }

                            break;
                        }

                        case QuestTaskType.Location:
                        {
                            LocationQuestTask locationTask;
                            task = locationTask = new LocationQuestTask();
                            locationTask.Requirements = new LocationRequirement[reader.ReadInt32(3)];
                            for (int locationIndex = 0; locationIndex < locationTask.Requirements.Length; locationIndex++)
                            {
                                LocationRequirement requirement = locationTask.Requirements[locationIndex] = new LocationRequirement();

                                // Icon?
                                if (reader.ReadBoolean())
                                {
                                    ItemStack icon = requirement.Icon = new ItemStack();
                                    icon.ItemId = reader.ReadString(16);
                                    icon.Damage = reader.ReadInt32(16);
                                    icon.NBT    = reader.ReadNBT();
                                }

                                requirement.Name   = reader.ReadString(5);
                                requirement.XPos   = reader.ReadInt32(32);
                                requirement.YPos   = reader.ReadInt32(32);
                                requirement.ZPos   = reader.ReadInt32(32);
                                requirement.Radius = reader.ReadInt32(32);

                                requirement.Visibility  = (Visibility)reader.ReadInt32(2);
                                requirement.DimensionId = reader.ReadInt32(32);
                            }

                            break;
                        }

                        case QuestTaskType.KillMobs:
                        {
                            MobQuestTask mobTask;
                            task = mobTask = new MobQuestTask();
                            mobTask.Requirements = new MobRequirement[reader.ReadInt32(3)];
                            for (int mobIndex = 0; mobIndex < mobTask.Requirements.Length; mobIndex++)
                            {
                                MobRequirement requirement = mobTask.Requirements[mobIndex] = new MobRequirement();

                                // Icon?
                                if (reader.ReadBoolean())
                                {
                                    ItemStack icon = requirement.Icon = new ItemStack();
                                    icon.ItemId = reader.ReadString(16);
                                    icon.Damage = reader.ReadInt32(16);
                                    icon.NBT    = reader.ReadNBT();
                                }

                                requirement.MobName = reader.ReadString(5);
                                requirement.MobID   = reader.ReadString(10);
                                requirement.Amount  = reader.ReadInt32(16);
                                requirement.IsExact = reader.ReadBoolean();
                            }

                            break;
                        }

                        case QuestTaskType.Reputation:
                        case QuestTaskType.KillReputation:
                        {
                            ReputationTargetQuestTask repTask;
                            task = repTask = taskType == QuestTaskType.Reputation ? new ReputationTargetQuestTask() : new ReputationKillQuestTask();
                            repTask.Requirements = new ReputationTargetRequirement[reader.ReadInt32(3)];
                            for (int reputationIndex = 0; reputationIndex < repTask.Requirements.Length; reputationIndex++)
                            {
                                ReputationTargetRequirement requirement = repTask.Requirements[reputationIndex] = new ReputationTargetRequirement();
                                requirement.ReputationId = reader.ReadInt32(8);

                                // Has lower bound?
                                if (reader.ReadBoolean())
                                {
                                    requirement.LowerBound = reader.ReadInt32(5);
                                }

                                // Has upper bound?
                                if (reader.ReadBoolean())
                                {
                                    requirement.UpperBound = reader.ReadInt32(5);
                                }

                                requirement.Inverted = reader.ReadBoolean();
                            }

                            if (taskType == QuestTaskType.KillReputation)
                            {
                                ((ReputationKillQuestTask)repTask).KillCount = reader.ReadInt32(12);
                            }

                            break;
                        }

                        case QuestTaskType.Deaths:
                        {
                            DeathQuestTask deathTask;
                            task = deathTask = new DeathQuestTask();

                            deathTask.DeathCount = reader.ReadInt32(12);

                            break;
                        }
                        }

                        task.TaskType          = taskType;
                        task.Name              = taskName;
                        task.Description       = taskDescription;
                        quest.Tasks[taskIndex] = task;
                    }

                    // Common Rewards?
                    if (reader.ReadBoolean())
                    {
                        quest.CommonRewards = new ItemStack[reader.ReadInt32(3)];
                        for (int commonRewardIndex = 0; commonRewardIndex < quest.CommonRewards.Length; commonRewardIndex++)
                        {
                            ItemStack commonReward = quest.CommonRewards[commonRewardIndex] = new ItemStack();

                            commonReward.ItemId = reader.ReadString(16);
                            commonReward.Size   = reader.ReadInt32(16);
                            commonReward.Damage = reader.ReadInt32(16);
                            commonReward.NBT    = reader.ReadNBT();
                        }
                    }

                    // Pick-One Rewards?
                    if (reader.ReadBoolean())
                    {
                        quest.PickOneRewards = new ItemStack[reader.ReadInt32(3)];
                        for (int pickOneRewardIndex = 0; pickOneRewardIndex < quest.PickOneRewards.Length; pickOneRewardIndex++)
                        {
                            ItemStack pickOneReward = quest.PickOneRewards[pickOneRewardIndex] = new ItemStack();

                            pickOneReward.ItemId = reader.ReadString(16);
                            pickOneReward.Size   = reader.ReadInt32(16);
                            pickOneReward.Damage = reader.ReadInt32(16);
                            pickOneReward.NBT    = reader.ReadNBT();
                        }
                    }

                    quest.ReputationRewards = new ReputationReward[reader.ReadInt32(3)];
                    for (int reputationRewardIndex = 0; reputationRewardIndex < quest.ReputationRewards.Length; reputationRewardIndex++)
                    {
                        ReputationReward reputationReward = quest.ReputationRewards[reputationRewardIndex] = new ReputationReward();

                        reputationReward.Id    = reader.ReadInt32(8);
                        reputationReward.Value = reader.ReadInt32(32);
                    }
                }

                questLine.Tiers = new RewardBagTier[reader.ReadInt32(7)];
                for (int tierIndex = 0; tierIndex < questLine.Tiers.Length; tierIndex++)
                {
                    RewardBagTier tier = questLine.Tiers[tierIndex] = new RewardBagTier();

                    tier.Name            = reader.ReadString(5);
                    tier.Color           = (Color)reader.ReadInt32(4);
                    tier.BasicWeight     = reader.ReadInt32(19);
                    tier.GoodWeight      = reader.ReadInt32(19);
                    tier.GreaterWeight   = reader.ReadInt32(19);
                    tier.EpicWeight      = reader.ReadInt32(19);
                    tier.LegendaryWeight = reader.ReadInt32(19);
                }

                questLine.Bags = new RewardBag[reader.ReadInt32(10)];
                for (int bagIndex = 0; bagIndex < questLine.Bags.Length; bagIndex++)
                {
                    RewardBag bag = questLine.Bags[bagIndex] = new RewardBag();

                    bag.Id     = reader.ReadInt32(10);
                    bag.Name   = reader.ReadString(5);
                    bag.TierId = reader.ReadInt32(7);

                    bag.Rewards = new ItemStack[reader.ReadInt32(6)];
                    for (int rewardIndex = 0; rewardIndex < bag.Rewards.Length; rewardIndex++)
                    {
                        ItemStack reward = bag.Rewards[rewardIndex] = new ItemStack();

                        reward.ItemId = reader.ReadString(16);
                        reward.Size   = reader.ReadInt32(16);
                        reward.Damage = reader.ReadInt32(16);
                        reward.NBT    = reader.ReadNBT();
                    }

                    // Use a limit?
                    if (reader.ReadBoolean())
                    {
                        bag.Limit = reader.ReadInt32(10);
                    }
                }

                return(questLine);
            }
        }
        public void WriteQuestLine(QuestLine questLine, Stream outputStream)
        {
            using (var bWriter = new BinaryWriter(outputStream, Encoding.ASCII, leaveOpen: true))
            {
                var writer = new BitStreamWriter(bWriter);

                writer.WriteInt32(questLine.Version, 8);
                writer.WriteString(questLine.PassCode, 7);
                writer.WriteString(questLine.Description, 16);
                writer.WriteInt32(questLine.QuestSets.Length, 5);

                for (int questSetIndex = 0; questSetIndex < questLine.QuestSets.Length; questSetIndex++)
                {
                    QuestSet questSet = questLine.QuestSets[questSetIndex];

                    writer.WriteString(questSet.Name, 5);
                    writer.WriteString(questSet.Description, 16);

                    writer.WriteInt32(questSet.ReputationBars.Length, 8);
                    for (int reputationBarIndex = 0; reputationBarIndex < questSet.ReputationBars.Length; reputationBarIndex++)
                    {
                        ReputationBar reputationBar = questSet.ReputationBars[reputationBarIndex];

                        writer.WriteInt32(reputationBar.Data, 32);
                    }
                }

                writer.WriteInt32(questLine.Reputations.Length, 8);

                for (int reputationIndex = 0; reputationIndex < questLine.Reputations.Length; reputationIndex++)
                {
                    Reputation reputation = questLine.Reputations[reputationIndex];
                    writer.WriteInt32(reputation.Id, 8);
                    writer.WriteString(reputation.Name, 5);

                    writer.WriteString(reputation.Markers[0].Name, 5);

                    writer.WriteInt32(reputation.Markers.Length - 1, 5);

                    for (int markerIndex = 1; markerIndex < reputation.Markers.Length; markerIndex++)
                    {
                        ReputationMarker marker = reputation.Markers[markerIndex];

                        writer.WriteString(marker.Name, 5);
                        writer.WriteInt32(marker.Value, 32);
                    }
                }

                writer.WriteInt32(questLine.Quests.Length, 10);

                for (int questIndex = 0; questIndex < questLine.Quests.Length; questIndex++)
                {
                    Quest quest = questLine.Quests[questIndex];

                    if (quest == null)
                    {
                        writer.WriteBoolean(false);
                        continue;
                    }

                    writer.WriteBoolean(true);

                    writer.WriteString(quest.Name, 5);
                    writer.WriteString(quest.Description, 16);

                    writer.WriteInt32(quest.XPos, 9);
                    writer.WriteInt32(quest.YPos, 8);
                    writer.WriteBoolean(quest.IsBig);
                    writer.WriteInt32(quest.QuestSetId, 5);

                    if (quest.Icon == null)
                    {
                        writer.WriteBoolean(false);
                    }
                    else
                    {
                        writer.WriteBoolean(true);
                        ItemStack icon = quest.Icon;
                        writer.WriteString(icon.ItemId, 16);
                        writer.WriteInt32(icon.Damage, 16);
                        writer.WriteNBT(icon.NBT);
                    }

                    if (quest.RequiredQuestIds == null)
                    {
                        writer.WriteBoolean(false);
                    }
                    else
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(quest.RequiredQuestIds.Length, 10);
                        for (int requirementIndex = 0; requirementIndex < quest.RequiredQuestIds.Length; requirementIndex++)
                        {
                            writer.WriteInt32(quest.RequiredQuestIds[requirementIndex], 10);
                        }
                    }

                    if (quest.OptionLinks == null)
                    {
                        writer.WriteBoolean(false);
                    }
                    else
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(quest.OptionLinks.Length, 10);
                        for (int optionLinkIndex = 0; optionLinkIndex < quest.OptionLinks.Length; optionLinkIndex++)
                        {
                            writer.WriteInt32(quest.OptionLinks[optionLinkIndex], 10);
                        }
                    }

                    writer.WriteInt32((int)quest.RepeatType, 2);
                    if (quest.RepeatType == RepeatType.Cooldown ||
                        quest.RepeatType == RepeatType.Interval)
                    {
                        writer.WriteInt32(quest.RepeatIntervalHours, 32);
                    }

                    writer.WriteInt32((int)quest.TriggerType, 2);
                    if (quest.TriggerType == TriggerType.TaskCount)
                    {
                        writer.WriteInt32(quest.TriggerTaskCount, 4);
                    }

                    if (quest.ModifiedParentRequirementCount.HasValue)
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(quest.ModifiedParentRequirementCount.Value, 10);
                    }
                    else
                    {
                        writer.WriteBoolean(false);
                    }

                    writer.WriteInt32(quest.Tasks.Length, 4);
                    for (int taskIndex = 0; taskIndex < quest.Tasks.Length; taskIndex++)
                    {
                        QuestTask task = quest.Tasks[taskIndex];

                        QuestTaskType taskType = task.TaskType;
                        writer.WriteInt32((int)taskType, 4);

                        writer.WriteString(task.Name, 5);
                        writer.WriteString(task.Description, 16);

                        switch (taskType)
                        {
                        case QuestTaskType.Consume:
                        case QuestTaskType.Craft:
                        case QuestTaskType.Detection:
                        case QuestTaskType.QDS:
                        {
                            ItemQuestTask itemTask = (ItemQuestTask)task;
                            writer.WriteInt32(itemTask.Requirements.Length, 6);

                            for (int itemIndex = 0; itemIndex < itemTask.Requirements.Length; itemIndex++)
                            {
                                ItemRequirement requirement = itemTask.Requirements[itemIndex];

                                if (requirement.Type == ItemType.Item)
                                {
                                    writer.WriteBoolean(true);
                                    writer.WriteString(requirement.ItemStack.ItemId, 16);
                                    writer.WriteInt32(requirement.ItemStack.Damage, 16);
                                    writer.WriteNBT(requirement.ItemStack.NBT);

                                    writer.WriteInt32(requirement.Amount, 32);
                                    writer.WriteString(requirement.PrecisionId, 30);
                                }
                                else
                                {
                                    writer.WriteBoolean(false);
                                    writer.WriteNBT(requirement.ItemStack.NBT);
                                }
                            }

                            break;
                        }

                        case QuestTaskType.Location:
                        {
                            LocationQuestTask locationTask = (LocationQuestTask)task;
                            writer.WriteInt32(locationTask.Requirements.Length, 3);
                            for (int locationIndex = 0; locationIndex < locationTask.Requirements.Length; locationIndex++)
                            {
                                LocationRequirement requirement = locationTask.Requirements[locationIndex];

                                if (requirement.Icon == null)
                                {
                                    writer.WriteBoolean(false);
                                }
                                else
                                {
                                    writer.WriteBoolean(true);
                                    ItemStack icon = requirement.Icon;
                                    writer.WriteString(icon.ItemId, 16);
                                    writer.WriteInt32(icon.Damage, 16);
                                    writer.WriteNBT(icon.NBT);
                                }

                                writer.WriteString(requirement.Name, 5);
                                writer.WriteInt32(requirement.XPos, 32);
                                writer.WriteInt32(requirement.YPos, 32);
                                writer.WriteInt32(requirement.ZPos, 32);
                                writer.WriteInt32(requirement.Radius, 32);

                                writer.WriteInt32((int)requirement.Visibility, 2);
                                writer.WriteInt32(requirement.DimensionId, 32);
                            }

                            break;
                        }

                        case QuestTaskType.KillMobs:
                        {
                            MobQuestTask mobTask = (MobQuestTask)task;
                            writer.WriteInt32(mobTask.Requirements.Length, 3);
                            for (int mobIndex = 0; mobIndex < mobTask.Requirements.Length; mobIndex++)
                            {
                                MobRequirement requirement = mobTask.Requirements[mobIndex];

                                if (requirement.Icon == null)
                                {
                                    writer.WriteBoolean(false);
                                }
                                else
                                {
                                    writer.WriteBoolean(true);
                                    ItemStack icon = requirement.Icon;
                                    writer.WriteString(icon.ItemId, 16);
                                    writer.WriteInt32(icon.Damage, 16);
                                    writer.WriteNBT(icon.NBT);
                                }

                                writer.WriteString(requirement.MobName, 5);
                                writer.WriteString(requirement.MobID, 10);
                                writer.WriteInt32(requirement.Amount, 16);
                                writer.WriteBoolean(requirement.IsExact);
                            }

                            break;
                        }

                        case QuestTaskType.Reputation:
                        case QuestTaskType.KillReputation:
                        {
                            ReputationTargetQuestTask repTask = (ReputationTargetQuestTask)task;
                            writer.WriteInt32(repTask.Requirements.Length, 3);
                            for (int reputationIndex = 0; reputationIndex < repTask.Requirements.Length; reputationIndex++)
                            {
                                ReputationTargetRequirement requirement = repTask.Requirements[reputationIndex];
                                writer.WriteInt32(requirement.ReputationId, 8);

                                if (requirement.LowerBound.HasValue)
                                {
                                    writer.WriteBoolean(true);
                                    writer.WriteInt32(requirement.LowerBound.Value, 5);
                                }
                                else
                                {
                                    writer.WriteBoolean(false);
                                }

                                if (requirement.UpperBound.HasValue)
                                {
                                    writer.WriteBoolean(true);
                                    writer.WriteInt32(requirement.UpperBound.Value, 5);
                                }
                                else
                                {
                                    writer.WriteBoolean(false);
                                }

                                writer.WriteBoolean(requirement.Inverted);
                            }

                            if (taskType == QuestTaskType.KillReputation)
                            {
                                writer.WriteInt32(((ReputationKillQuestTask)repTask).KillCount, 12);
                            }

                            break;
                        }

                        case QuestTaskType.Deaths:
                        {
                            DeathQuestTask deathTask = (DeathQuestTask)task;

                            writer.WriteInt32(deathTask.DeathCount, 12);

                            break;
                        }
                        }
                    }

                    if (quest.CommonRewards == null)
                    {
                        writer.WriteBoolean(false);
                    }
                    else
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(quest.CommonRewards.Length, 3);
                        for (int commonRewardIndex = 0; commonRewardIndex < quest.CommonRewards.Length; commonRewardIndex++)
                        {
                            ItemStack commonReward = quest.CommonRewards[commonRewardIndex];

                            writer.WriteString(commonReward.ItemId, 16);
                            writer.WriteInt32(commonReward.Size.Value, 16);
                            writer.WriteInt32(commonReward.Damage, 16);
                            writer.WriteNBT(commonReward.NBT);
                        }
                    }

                    if (quest.PickOneRewards == null)
                    {
                        writer.WriteBoolean(false);
                    }
                    else
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(quest.PickOneRewards.Length, 3);
                        for (int pickOneRewardIndex = 0; pickOneRewardIndex < quest.PickOneRewards.Length; pickOneRewardIndex++)
                        {
                            ItemStack pickOneReward = quest.PickOneRewards[pickOneRewardIndex];

                            writer.WriteString(pickOneReward.ItemId, 16);
                            writer.WriteInt32(pickOneReward.Size.Value, 16);
                            writer.WriteInt32(pickOneReward.Damage, 16);
                            writer.WriteNBT(pickOneReward.NBT);
                        }
                    }

                    writer.WriteInt32(quest.ReputationRewards.Length, 3);
                    for (int reputationRewardIndex = 0; reputationRewardIndex < quest.ReputationRewards.Length; reputationRewardIndex++)
                    {
                        ReputationReward reputationReward = quest.ReputationRewards[reputationRewardIndex];

                        writer.WriteInt32(reputationReward.Id, 8);
                        writer.WriteInt32(reputationReward.Value, 32);
                    }
                }

                writer.WriteInt32(questLine.Tiers.Length, 7);
                for (int tierIndex = 0; tierIndex < questLine.Tiers.Length; tierIndex++)
                {
                    RewardBagTier tier = questLine.Tiers[tierIndex];

                    writer.WriteString(tier.Name, 5);
                    writer.WriteInt32((int)tier.Color, 4);
                    writer.WriteInt32(tier.BasicWeight, 19);
                    writer.WriteInt32(tier.GoodWeight, 19);
                    writer.WriteInt32(tier.GreaterWeight, 19);
                    writer.WriteInt32(tier.EpicWeight, 19);
                    writer.WriteInt32(tier.LegendaryWeight, 19);
                }

                writer.WriteInt32(questLine.Bags.Length, 10);
                for (int bagIndex = 0; bagIndex < questLine.Bags.Length; bagIndex++)
                {
                    RewardBag bag = questLine.Bags[bagIndex];

                    writer.WriteInt32(bag.Id, 10);
                    writer.WriteString(bag.Name, 5);
                    writer.WriteInt32(bag.TierId, 7);

                    writer.WriteInt32(bag.Rewards.Length, 6);
                    for (int rewardIndex = 0; rewardIndex < bag.Rewards.Length; rewardIndex++)
                    {
                        ItemStack reward = bag.Rewards[rewardIndex];

                        writer.WriteString(reward.ItemId, 16);
                        writer.WriteInt32(reward.Size.Value, 16);
                        writer.WriteInt32(reward.Damage, 16);
                        writer.WriteNBT(reward.NBT);
                    }

                    if (bag.Limit.HasValue)
                    {
                        writer.WriteBoolean(true);
                        writer.WriteInt32(bag.Limit.Value, 10);
                    }
                    else
                    {
                        writer.WriteBoolean(false);
                    }
                }

                writer.WriteFinalBits();
            }
        }