Esempio n. 1
0
        public void Load()
        {
            _housingTemplates = new Dictionary <uint, HousingTemplate>();
            _houses           = new Dictionary <uint, House>();

//            var housingAreas = new Dictionary<uint, HousingAreas>();
            var houseTaxes = new Dictionary <uint, HouseTax>();

            using (var connection = SQLite.CreateConnection())
            {
//                using (var command = connection.CreateCommand())
//                {
//                    command.CommandText = "SELECT * FROM housing_areas";
//                    command.Prepare();
//                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
//                    {
//                        while (reader.Read())
//                        {
//                            var template = new HousingAreas();
//                            template.Id = reader.GetUInt32("id");
//                            template.Name = reader.GetString("name");
//                            template.GroupId = reader.GetUInt32("housing_group_id");
//                            housingAreas.Add(template.Id, template);
//                        }
//                    }
//                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM taxations";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new HouseTax();
                            template.Id   = reader.GetUInt32("id");
                            template.Tax  = reader.GetUInt32("tax");
                            template.Show = reader.GetBoolean("show", true);
                            houseTaxes.Add(template.Id, template);
                        }
                    }
                }

                _log.Info("Loading Housing Templates...");

                var contents = FileManager.GetFileContents($"{FileManager.AppPath}Data/housing_bindings.json");
                if (string.IsNullOrWhiteSpace(contents))
                {
                    throw new IOException(
                              $"File {FileManager.AppPath}Data/housing_bindings.json doesn't exists or is empty.");
                }

                List <HousingBindingTemplate> binding;
                if (JsonHelper.TryDeserializeObject(contents, out binding, out _))
                {
                    _log.Info("Housing bindings loaded...");
                }
                else
                {
                    _log.Warn("Housing bindings not loaded...");
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM housings";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new HousingTemplate();
                            template.Id           = reader.GetUInt32("id");
                            template.Name         = reader.GetString("name");
                            template.CategoryId   = reader.GetUInt32("category_id");
                            template.MainModelId  = reader.GetUInt32("main_model_id");
                            template.DoorModelId  = reader.GetUInt32("door_model_id", 0);
                            template.StairModelId = reader.GetUInt32("stair_model_id", 0);
                            template.AutoZ        = reader.GetBoolean("auto_z", true);
                            template.GateExists   = reader.GetBoolean("gate_exists", true);
                            template.Hp           = reader.GetInt32("hp");
                            template.RepairCost   = reader.GetUInt32("repair_cost");
                            template.GardenRadius = reader.GetFloat("garden_radius");
                            template.Family       = reader.GetString("family");
                            var taxationId = reader.GetUInt32("taxation_id");
                            template.Taxation            = houseTaxes.ContainsKey(taxationId) ? houseTaxes[taxationId] : null;
                            template.GuardTowerSettingId = reader.GetUInt32("guard_tower_setting_id", 0);
                            template.CinemaRadius        = reader.GetFloat("cinema_radius");
                            template.AutoZOffsetX        = reader.GetFloat("auto_z_offset_x");
                            template.AutoZOffsetY        = reader.GetFloat("auto_z_offset_y");
                            template.AutoZOffsetZ        = reader.GetFloat("auto_z_offset_z");
                            template.Alley              = reader.GetFloat("alley");
                            template.ExtraHeightAbove   = reader.GetFloat("extra_height_above");
                            template.ExtraHeightBelow   = reader.GetFloat("extra_height_below");
                            template.DecoLimit          = reader.GetUInt32("deco_limit");
                            template.AbsoluteDecoLimit  = reader.GetUInt32("absolute_deco_limit");
                            template.HousingDecoLimitId = reader.GetUInt32("housing_deco_limit_id", 0);
                            template.IsSellable         = reader.GetBoolean("is_sellable", true);
                            _housingTemplates.Add(template.Id, template);

                            var templateBindings = binding.Find(x => x.TemplateId.Contains(template.Id));
                            using (var command2 = connection.CreateCommand())
                            {
                                command2.CommandText =
                                    "SELECT * FROM housing_binding_doodads WHERE owner_id=@owner_id AND owner_type='Housing'";
                                command2.Prepare();
                                command2.Parameters.AddWithValue("owner_id", template.Id);
                                using (var reader2 = new SQLiteWrapperReader(command2.ExecuteReader()))
                                {
                                    var doodads = new List <HousingBindingDoodad>();
                                    while (reader2.Read())
                                    {
                                        var bindingDoodad = new HousingBindingDoodad();
                                        bindingDoodad.AttachPointId = reader2.GetUInt32("attach_point_id");
                                        bindingDoodad.DoodadId      = reader2.GetUInt32("doodad_id");

                                        if (templateBindings != null &&
                                            templateBindings.AttachPointId.ContainsKey(bindingDoodad.AttachPointId))
                                        {
                                            bindingDoodad.Position = templateBindings
                                                                     .AttachPointId[bindingDoodad.AttachPointId].Clone();
                                        }

                                        if (bindingDoodad.Position == null)
                                        {
                                            bindingDoodad.Position = new Point(0, 0, 0);
                                        }
                                        bindingDoodad.Position.WorldId = 1;

                                        doodads.Add(bindingDoodad);
                                    }

                                    template.HousingBindingDoodad = doodads.ToArray();
                                }
                            }
                        }
                    }
                }

                _log.Info("Loaded Housing Templates {0}", _housingTemplates.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM housing_build_steps";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var housingId = reader.GetUInt32("housing_id");
                            if (!_housingTemplates.ContainsKey(housingId))
                            {
                                continue;
                            }

                            var template = new HousingBuildStep();
                            template.Id         = reader.GetUInt32("id");
                            template.HousingId  = housingId;
                            template.Step       = reader.GetInt16("step");
                            template.ModelId    = reader.GetUInt32("model_id");
                            template.SkillId    = reader.GetUInt32("skill_id");
                            template.NumActions = reader.GetInt32("num_actions");

                            _housingTemplates[housingId].BuildSteps.Add(template.Step, template);
                        }
                    }
                }
            }

            _log.Info("Loading Housing...");
            using (var connection = MySQL.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "SELECT * FROM housings";
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var templateId = reader.GetUInt32("template_id");
                            var house      = Create(templateId);
                            house.Id        = reader.GetUInt32("id");
                            house.AccountId = reader.GetUInt32("account_id");
                            house.OwnerId   = reader.GetUInt32("owner");
                            house.Position  =
                                new Point(reader.GetFloat("x"), reader.GetFloat("y"), reader.GetFloat("z"));
                            house.Position.RotationZ = reader.GetSByte("rotation_z");
                            house.Position.WorldId   = 1;
                            house.CurrentStep        = reader.GetInt32("current_step");
                            house.Permission         = reader.GetByte("permission");
                            _houses.Add(house.Id, house);
                        }
                    }
                }
            }

            _log.Info("Loaded Housing {0}", _houses.Count);
        }
Esempio n. 2
0
        public void Load()
        {
            _templates = new Dictionary <uint, NpcTemplate>();
            _goods     = new Dictionary <uint, MerchantGoods>();

            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading npc templates...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from npcs";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var template = new NpcTemplate();
                                template.Id                                = reader.GetUInt32("id");
                                template.Name                              = reader.GetString("name");
                                template.CharRaceId                        = reader.GetInt32("char_race_id");
                                template.NpcGradeId                        = (NpcGradeType)reader.GetByte("npc_grade_id");
                                template.NpcKindId                         = (NpcKindType)reader.GetByte("npc_kind_id");
                                template.Level                             = reader.GetByte("level");
                                template.NpcTemplateId                     = (NpcTemplateType)reader.GetByte("npc_template_id");
                                template.ModelId                           = reader.GetUInt32("model_id");
                                template.FactionId                         = reader.GetUInt32("faction_id");
                                template.SkillTrainer                      = reader.GetBoolean("skill_trainer", true);
                                template.AiFileId                          = reader.GetInt32("ai_file_id");
                                template.Merchant                          = reader.GetBoolean("merchant", true);
                                template.NpcNicknameId                     = reader.GetInt32("npc_nickname_id");
                                template.Auctioneer                        = reader.GetBoolean("auctioneer", true);
                                template.ShowNameTag                       = reader.GetBoolean("show_name_tag", true);
                                template.VisibleToCreatorOnly              = reader.GetBoolean("visible_to_creator_only", true);
                                template.NoExp                             = reader.GetBoolean("no_exp", true);
                                template.PetItemId                         = reader.GetInt32("pet_item_id", 0);
                                template.BaseSkillId                       = reader.GetInt32("base_skill_id");
                                template.TrackFriendship                   = reader.GetBoolean("track_friendship", true);
                                template.Priest                            = reader.GetBoolean("priest", true);
                                template.NpcTedencyId                      = reader.GetInt32("npc_tendency_id", 0);
                                template.Blacksmith                        = reader.GetBoolean("blacksmith", true);
                                template.Teleporter                        = reader.GetBoolean("teleporter", true);
                                template.Opacity                           = reader.GetFloat("opacity");
                                template.AbilityChanger                    = reader.GetBoolean("ability_changer", true);
                                template.Scale                             = reader.GetFloat("scale");
                                template.SightRangeScale                   = reader.GetFloat("sight_range_scale");
                                template.SightFovScale                     = reader.GetFloat("sight_fov_scale");
                                template.MilestoneId                       = reader.GetInt32("milestone_id", 0);
                                template.AttackStartRangeScale             = reader.GetFloat("attack_start_range_scale");
                                template.Aggression                        = reader.GetBoolean("aggression", true);
                                template.ExpMultiplier                     = reader.GetFloat("exp_multiplier");
                                template.ExpAdder                          = reader.GetInt32("exp_adder");
                                template.Stabler                           = reader.GetBoolean("stabler", true);
                                template.AcceptAggroLink                   = reader.GetBoolean("accept_aggro_link", true);
                                template.RecrutingBattlefieldId            = reader.GetInt32("recruiting_battle_field_id");
                                template.ReturnDistance                    = reader.GetFloat("return_distance");
                                template.NpcAiParamId                      = reader.GetInt32("npc_ai_param_id");
                                template.NonPushableByActor                = reader.GetBoolean("non_pushable_by_actor", true);
                                template.Banker                            = reader.GetBoolean("banker", true);
                                template.AggroLinkSpecialRuleId            = reader.GetInt32("aggro_link_special_rule_id");
                                template.AggroLinkHelpDist                 = reader.GetFloat("aggro_link_help_dist");
                                template.AggroLinkSightCheck               = reader.GetBoolean("aggro_link_sight_check", true);
                                template.Expedition                        = reader.GetBoolean("expedition", true);
                                template.HonorPoint                        = reader.GetInt32("honor_point");
                                template.Trader                            = reader.GetBoolean("trader", true);
                                template.AggroLinkSpecialGuard             = reader.GetBoolean("aggro_link_special_guard", true);
                                template.AggroLinkSpecialIgnoreNpcAttacker =
                                    reader.GetBoolean("aggro_link_special_ignore_npc_attacker", true);
                                template.AbsoluteReturnDistance = reader.GetFloat("absolute_return_distance");
                                template.Repairman                  = reader.GetBoolean("repairman", true);
                                template.ActivateAiAlways           = reader.GetBoolean("activate_ai_always", true);
                                template.Specialty                  = reader.GetBoolean("specialty", true);
                                template.UseRangeMod                = reader.GetBoolean("use_range_mod", true);
                                template.NpcPostureSetId            = reader.GetInt32("npc_posture_set_id");
                                template.MateEquipSlotPackId        = reader.GetInt32("mate_equip_slot_pack_id", 0);
                                template.MateKindId                 = reader.GetInt32("mate_kind_id", 0);
                                template.EngageCombatGiveQuestId    = reader.GetInt32("engage_combat_give_quest_id", 0);
                                template.NoApplyTotalCustom         = reader.GetBoolean("no_apply_total_custom", true);
                                template.BaseSkillStrafe            = reader.GetBoolean("base_skill_strafe", true);
                                template.BaseSkillDelay             = reader.GetFloat("base_skill_delay");
                                template.NpcInteractionSetId        = reader.GetInt32("npc_interaction_set_id", 0);
                                template.UseAbuserList              = reader.GetBoolean("use_abuser_list", true);
                                template.ReturnWhenEnterHousingArea =
                                    reader.GetBoolean("return_when_enter_housing_area", true);
                                template.LookConverter      = reader.GetBoolean("look_converter", true);
                                template.UseDDCMSMountSkill = reader.GetBoolean("use_ddcms_mount_skill", true);
                                template.CrowdEffect        = reader.GetBoolean("crowd_effect", true);

                                var bodyPack      = reader.GetInt32("equip_bodies_id", 0);
                                var clothPack     = reader.GetInt32("equip_cloths_id", 0);
                                var weaponPack    = reader.GetInt32("equip_weapons_id", 0);
                                var totalCustomId = reader.GetInt32("total_custom_id", 0);
                                if (clothPack > 0)
                                {
                                    using (var command2 = connection.CreateCommand())
                                    {
                                        command2.CommandText = "SELECT * FROM equip_pack_cloths WHERE id=@id";
                                        command2.Prepare();
                                        command2.Parameters.AddWithValue("id", clothPack);
                                        using (var sqliteReader2 = command2.ExecuteReader())
                                            using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                            {
                                                while (reader2.Read())
                                                {
                                                    template.Items.Headgear         = reader2.GetUInt32("headgear_id");
                                                    template.Items.HeadgearGrade    = reader2.GetByte("headgear_grade_id");
                                                    template.Items.Necklace         = reader2.GetUInt32("necklace_id");
                                                    template.Items.NecklaceGrade    = reader2.GetByte("necklace_grade_id");
                                                    template.Items.Shirt            = reader2.GetUInt32("shirt_id");
                                                    template.Items.ShirtGrade       = reader2.GetByte("shirt_grade_id");
                                                    template.Items.Belt             = reader2.GetUInt32("belt_id");
                                                    template.Items.BeltGrade        = reader2.GetByte("belt_grade_id");
                                                    template.Items.Pants            = reader2.GetUInt32("pants_id");
                                                    template.Items.PantsGrade       = reader2.GetByte("pants_grade_id");
                                                    template.Items.Gloves           = reader2.GetUInt32("glove_id");
                                                    template.Items.GlovesGrade      = reader2.GetByte("glove_grade_id");
                                                    template.Items.Shoes            = reader2.GetUInt32("shoes_id");
                                                    template.Items.ShoesGrade       = reader2.GetByte("shoes_grade_id");
                                                    template.Items.Bracelet         = reader2.GetUInt32("bracelet_id");
                                                    template.Items.BraceletGrade    = reader2.GetByte("bracelet_grade_id");
                                                    template.Items.Back             = reader2.GetUInt32("back_id");
                                                    template.Items.BackGrade        = reader2.GetByte("back_grade_id");
                                                    template.Items.Cosplay          = reader2.GetUInt32("cosplay_id");
                                                    template.Items.CosplayGrade     = reader2.GetByte("cosplay_grade_id");
                                                    template.Items.Undershirts      = reader2.GetUInt32("undershirt_id");
                                                    template.Items.UndershirtsGrade = reader2.GetByte("undershirt_grade_id");
                                                    template.Items.Underpants       = reader2.GetUInt32("underpants_id");
                                                    template.Items.UnderpantsGrade  = reader2.GetByte("underpants_grade_id");
                                                }
                                            }
                                    }
                                }

                                if (weaponPack > 0)
                                {
                                    using (var command2 = connection.CreateCommand())
                                    {
                                        command2.CommandText = "SELECT * FROM equip_pack_weapons WHERE id=@id";
                                        command2.Prepare();
                                        command2.Parameters.AddWithValue("id", weaponPack);
                                        using (var sqliteReader2 = command2.ExecuteReader())
                                            using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                            {
                                                while (reader2.Read())
                                                {
                                                    template.Items.Mainhand      = reader2.GetUInt32("mainhand_id");
                                                    template.Items.MainhandGrade = reader2.GetByte("mainhand_grade_id");
                                                    template.Items.Offhand       = reader2.GetUInt32("offhand_id");
                                                    template.Items.OffhandGrade  = reader2.GetByte("offhand_grade_id");
                                                    template.Items.Ranged        = reader2.GetUInt32("ranged_id");
                                                    template.Items.RangedGrade   = reader2.GetByte("ranged_grade_id");
                                                    template.Items.Musical       = reader2.GetUInt32("musical_id");
                                                    template.Items.MusicalGrade  = reader2.GetByte("musical_grade_id");
                                                }
                                            }
                                    }
                                }

                                if (totalCustomId > 0)
                                {
                                    using (var command2 = connection.CreateCommand())
                                    {
                                        command2.CommandText = "SELECT * FROM total_character_customs WHERE id=@id";
                                        command2.Prepare();
                                        command2.Parameters.AddWithValue("id", totalCustomId);
                                        using (var sqliteReader2 = command2.ExecuteReader())
                                            using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                            {
                                                while (reader2.Read())
                                                {
                                                    template.HairId = reader2.GetUInt32("hair_id");

                                                    template.ModelParams = new UnitCustomModelParams(UnitCustomModelType.Face);
                                                    template.ModelParams
                                                    .SetHairColorId(reader2.GetUInt32("hair_color_id"))
                                                    .SetSkinColorId(reader2.GetUInt32("skin_color_id"));

                                                    template.ModelParams.Face.MovableDecalAssetId =
                                                        reader2.GetUInt32("face_movable_decal_asset_id");
                                                    template.ModelParams.Face.MovableDecalScale =
                                                        reader2.GetFloat("face_movable_decal_scale");
                                                    template.ModelParams.Face.MovableDecalRotate =
                                                        reader2.GetFloat("face_movable_decal_rotate");
                                                    template.ModelParams.Face.MovableDecalMoveX =
                                                        reader2.GetInt16("face_movable_decal_move_x");
                                                    template.ModelParams.Face.MovableDecalMoveY =
                                                        reader2.GetInt16("face_movable_decal_move_y");

                                                    template.ModelParams.Face.SetFixedDecalAsset(0,
                                                                                                 reader2.GetUInt32("face_fixed_decal_asset_0_id"),
                                                                                                 reader2.GetFloat("face_fixed_decal_asset_0_weight"));
                                                    template.ModelParams.Face.SetFixedDecalAsset(1,
                                                                                                 reader2.GetUInt32("face_fixed_decal_asset_1_id"),
                                                                                                 reader2.GetFloat("face_fixed_decal_asset_1_weight"));
                                                    template.ModelParams.Face.SetFixedDecalAsset(2,
                                                                                                 reader2.GetUInt32("face_fixed_decal_asset_2_id"),
                                                                                                 reader2.GetFloat("face_fixed_decal_asset_2_weight"));
                                                    template.ModelParams.Face.SetFixedDecalAsset(3,
                                                                                                 reader2.GetUInt32("face_fixed_decal_asset_3_id"),
                                                                                                 reader2.GetFloat("face_fixed_decal_asset_3_weight"));

                                                    template.ModelParams.Face.DiffuseMapId =
                                                        reader2.GetUInt32("face_diffuse_map_id");
                                                    template.ModelParams.Face.NormalMapId =
                                                        reader2.GetUInt32("face_normal_map_id");
                                                    template.ModelParams.Face.EyelashMapId =
                                                        reader2.GetUInt32("face_eyelash_map_id");
                                                    template.ModelParams.Face.LipColor       = reader2.GetUInt32("lip_color");
                                                    template.ModelParams.Face.LeftPupilColor =
                                                        reader2.GetUInt32("left_pupil_color");
                                                    template.ModelParams.Face.RightPupilColor =
                                                        reader2.GetUInt32("right_pupil_color");
                                                    template.ModelParams.Face.EyebrowColor = reader2.GetUInt32("eyebrow_color");
                                                    reader2.GetBytes("modifier", 0, template.ModelParams.Face.Modifier, 0, 128);
                                                    template.ModelParams.Face.MovableDecalWeight =
                                                        reader2.GetFloat("face_movable_decal_weight");
                                                    template.ModelParams.Face.NormalMapWeight =
                                                        reader2.GetFloat("face_normal_map_weight");
                                                    template.ModelParams.Face.DecoColor = reader2.GetUInt32("deco_color");
                                                }
                                            }
                                    }
                                }
                                else
                                {
                                    template.ModelParams = new UnitCustomModelParams(UnitCustomModelType.Skin);
                                }

                                if (template.NpcPostureSetId > 0)
                                {
                                    using (var command2 = connection.CreateCommand())
                                    {
                                        command2.CommandText = "SELECT * FROM npc_postures WHERE npc_posture_set_id=@id";
                                        command2.Prepare();
                                        command2.Parameters.AddWithValue("id", template.NpcPostureSetId);
                                        using (var sqliteReader2 = command2.ExecuteReader())
                                            using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                            {
                                                if (reader2.Read())
                                                {
                                                    template.AnimActionId = reader2.GetUInt32("anim_action_id");
                                                }
                                            }
                                    }
                                }

                                using (var command2 = connection.CreateCommand())
                                {
                                    command2.CommandText = "SELECT * FROM item_body_parts WHERE model_id = @model_id";
                                    command2.Prepare();
                                    command2.Parameters.AddWithValue("model_id", template.ModelId);
                                    using (var sqliteReader2 = command2.ExecuteReader())
                                        using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                        {
                                            while (reader2.Read())
                                            {
                                                var itemId = reader2.GetUInt32("item_id", 0);
                                                var slot   = reader2.GetInt32("slot_type_id") - 23;
                                                template.BodyItems[slot] = itemId;
                                            }
                                        }
                                }

                                if (template.CharRaceId > 0)
                                {
                                    using (var command2 = connection.CreateCommand())
                                    {
                                        command2.CommandText =
                                            "SELECT char_race_id, char_gender_id FROM characters WHERE model_id = @model_id";
                                        command2.Prepare();
                                        command2.Parameters.AddWithValue("model_id", template.ModelId);
                                        using (var sqliteReader2 = command2.ExecuteReader())
                                            using (var reader2 = new SQLiteWrapperReader(sqliteReader2))
                                            {
                                                if (reader2.Read())
                                                {
                                                    template.Race   = reader2.GetByte("char_race_id");
                                                    template.Gender = reader2.GetByte("char_gender_id");
                                                }
                                            }
                                    }
                                }

                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM unit_modifiers WHERE owner_type='Npc'";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var npcId = reader.GetUInt32("owner_id");
                                if (!_templates.ContainsKey(npcId))
                                {
                                    continue;
                                }
                                var npc      = _templates[npcId];
                                var template = new BonusTemplate();
                                template.Attribute        = (UnitAttribute)reader.GetByte("unit_attribute_id");
                                template.ModifierType     = (UnitModifierType)reader.GetByte("unit_modifier_type_id");
                                template.Value            = reader.GetInt32("value");
                                template.LinearLevelBonus = reader.GetInt32("linear_level_bonus");
                                npc.Bonuses.Add(template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM npc_initial_buffs";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id     = reader.GetUInt32("npc_id");
                            var buffId = reader.GetUInt32("buff_id");
                            if (!_templates.ContainsKey(id))
                            {
                                continue;
                            }
                            var template = _templates[id];
                            template.Buffs.Add(buffId);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM merchants";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id = reader.GetUInt32("npc_id");
                            if (!_templates.ContainsKey(id))
                            {
                                continue;
                            }
                            var template = _templates[id];
                            template.MerchantPackId = reader.GetUInt32("merchant_pack_id");
                        }
                    }
                }

                _log.Info("Loaded {0} npc templates", _templates.Count);
                _log.Info("Loading merchant packs...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM merchant_goods";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id = reader.GetUInt32("merchant_pack_id");
                            if (!_goods.ContainsKey(id))
                            {
                                _goods.Add(id, new MerchantGoods(id));
                            }

                            var itemId = reader.GetUInt32("item_id");
                            var grade  = reader.GetByte("grade_id");
                            if (_goods[id].Items.ContainsKey(itemId))
                            {
                                if (_goods[id].Items[itemId].IndexOf(grade) > -1)
                                {
                                    continue;
                                }

                                _goods[id].Items[itemId].Add(grade);
                            }
                            else
                            {
                                _goods[id].Items.Add(itemId, new List <byte> {
                                    grade
                                });
                            }
                        }
                    }
                }

                _log.Info("Loaded {0} merchant packs", _goods.Count);
            }
        }
Esempio n. 3
0
        public void Load()
        {
            _systemFactions = new Dictionary <uint, SystemFaction>();
            _relations      = new List <FactionRelation>();
            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading system factions...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM system_factions";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var faction = new SystemFaction
                                {
                                    Id              = reader.GetUInt32("id"),
                                    Name            = reader.GetString("name"),
                                    OwnerName       = reader.GetString("owner_name"),
                                    UnitOwnerType   = (sbyte)reader.GetInt16("owner_type_id"),
                                    OwnerId         = reader.GetUInt32("owner_id"),
                                    PoliticalSystem = reader.GetByte("political_system_id"),
                                    MotherId        = reader.GetUInt32("mother_id"),
                                    AggroLink       = reader.GetBoolean("aggro_link", true),
                                    GuardHelp       = reader.GetBoolean("guard_help", true),
                                    DiplomacyTarget = reader.GetBoolean("is_diplomacy_tgt", true)
                                };
                                _systemFactions.Add(faction.Id, faction);
                            }
                        }
                }

                _log.Info("Loaded {0} system factions", _systemFactions.Count);
                _log.Info("Loading faction relations...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM system_faction_relations";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var relation = new FactionRelation
                                {
                                    Id    = reader.GetUInt32("faction1_id"),
                                    Id2   = reader.GetUInt32("faction2_id"),
                                    State = (RelationState)reader.GetByte("state_id")
                                };
                                _relations.Add(relation);

                                var faction = _systemFactions[relation.Id];
                                faction.Relations.Add(relation.Id2, relation);
                                faction = _systemFactions[relation.Id2];
                                faction.Relations.Add(relation.Id, relation);
                            }
                        }
                }

                _log.Info("Loaded {0} faction relations", _relations.Count);
            }
        }
Esempio n. 4
0
        public void Load()
        {
            _housing      = new Dictionary <uint, HousingTemplate>();
            _housingAreas = new Dictionary <uint, HousingAreas>();
            _houseTaxes   = new Dictionary <uint, HouseTaxes>();
            _log.Info("Loading Housing...");

            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM housings";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new HousingTemplate();
                            template.Id                  = reader.GetUInt32("id");
                            template.Name                = reader.GetString("name");
                            template.CategoryId          = reader.GetUInt32("category_id");
                            template.MainModelId         = reader.GetUInt32("main_model_id");
                            template.DoorModelId         = reader.GetUInt32("door_model_id", 0);
                            template.StairModelId        = reader.GetUInt32("stair_model_id", 0);
                            template.AutoZ               = reader.GetBoolean("auto_z", true);
                            template.GateExists          = reader.GetBoolean("gate_exists", true);
                            template.Hp                  = reader.GetInt32("hp");
                            template.RepairCost          = reader.GetUInt32("repair_cost");
                            template.GardenRadius        = reader.GetFloat("garden_radius");
                            template.Family              = reader.GetString("family");
                            template.TaxationId          = reader.GetUInt32("taxation_id");
                            template.GuardTowerSettingId = reader.GetUInt32("guard_tower_setting_id", 0);
                            template.CinemaRadius        = reader.GetFloat("cinema_radius");
                            template.AutoZOffsetX        = reader.GetFloat("auto_z_offset_x");
                            template.AutoZOffsetY        = reader.GetFloat("auto_z_offset_y");
                            template.AutoZOffsetZ        = reader.GetFloat("auto_z_offset_z");
                            template.Alley               = reader.GetFloat("alley");
                            template.ExtraHeightAbove    = reader.GetFloat("extra_height_above");
                            template.ExtraHeightBelow    = reader.GetFloat("extra_height_below");
                            template.DecoLimit           = reader.GetUInt32("deco_limit");
                            template.AbsoluteDecoLimit   = reader.GetUInt32("absolute_deco_limit");
                            template.HousingDecoLimitId  = reader.GetUInt32("housing_deco_limit_id", 0);
                            template.IsSellable          = reader.GetBoolean("is_sellable", true);
                            _housing.Add(template.Id, template);

                            using (var command2 = connection.CreateCommand())
                            {
                                command2.CommandText =
                                    "SELECT * FROM housing_binding_doodads WHERE owner_id=@owner_id AND owner_type='Housing'";
                                command2.Prepare();
                                command2.Parameters.AddWithValue("owner_id", template.Id);
                                using (var reader2 = new SQLiteWrapperReader(command2.ExecuteReader()))
                                {
                                    var doodads = new List <HousingBindingDoodad>();
                                    while (reader2.Read())
                                    {
                                        var bindingDoodad = new HousingBindingDoodad();
                                        bindingDoodad.AttachPointId = reader2.GetUInt32("attach_point_id");
                                        bindingDoodad.DoodadId      = reader2.GetUInt32("doodad_id");

                                        doodads.Add(bindingDoodad);
                                    }

                                    template.HousingBindingDoodad = doodads.ToArray();
                                }
                            }
                        }
                    }
                }
                _log.Info("Loaded Housing", _housing.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM housing_build_steps";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var housingId = reader.GetUInt32("housing_id");
                            if (!_housing.ContainsKey(housingId))
                            {
                                continue;
                            }

                            var template = new HousingBuildStep();
                            template.Id         = reader.GetUInt32("id");
                            template.HousingId  = housingId;
                            template.Step       = reader.GetInt16("step");
                            template.ModelId    = reader.GetUInt32("model_id");
                            template.SkillId    = reader.GetUInt32("skill_id");
                            template.NumActions = reader.GetInt32("num_actions");

                            _housing[housingId].BuildSteps.Add(template.Step, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM housing_areas";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new HousingAreas();
                            template.Id      = reader.GetUInt32("id");
                            template.Name    = reader.GetString("name");
                            template.GroupId = reader.GetUInt32("housing_group_id");
                            _housingAreas.Add(template.Id, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM taxations";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new HouseTaxes();
                            template.Id   = reader.GetUInt32("id");
                            template.Tax  = reader.GetUInt32("tax");
                            template.Desc = reader.GetString("desc");
                            template.Show = reader.GetBoolean("show", true);
                            _houseTaxes.Add(template.Id, template);
                        }
                    }
                }
            }
        }