Beispiel #1
0
        public void Load()
        {
            _levels = new Dictionary <byte, ExpirienceLevelTemplate>();
            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading expirience data...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM levels";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var level = new ExpirienceLevelTemplate();
                                level.Level        = reader.GetByte("id");
                                level.TotalExp     = reader.GetInt32("total_exp");
                                level.TotalMateExp = reader.GetInt32("total_mate_exp");
                                level.SkillPoints  = reader.GetInt32("skill_points");
                                _levels.Add(level.Level, level);
                            }
                        }
                }

                _log.Info("Expirience data loaded");
            }
        }
Beispiel #2
0
        public void Load()
        {
            _nameRegex        = new Regex(AppConfiguration.Instance.CharacterNameRegex, RegexOptions.Compiled);
            _slaveMountSkills = new Dictionary <uint, NpcMountSkills>();
            _activeMates      = new Dictionary <uint, Mount>();

            #region SQLite

            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM npc_mount_skills";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new NpcMountSkills()
                            {
                                Id           = reader.GetUInt32("id"),
                                NpcId        = reader.GetUInt32("npc_id"),
                                MountSkillId = reader.GetUInt32("mount_skill_id")
                            };
                            _slaveMountSkills.Add(template.Id, template);
                        }
                    }
                }
            }

            #endregion
        }
Beispiel #3
0
        public void Load()
        {
            Log.Info("Loading character templates...");

            using (var connection = SQLite.CreateConnection())
            {
                var temp = new Dictionary <uint, byte>();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM characters";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new CharacterTemplate();
                            var id       = reader.GetUInt32("id");
                            template.Race                   = (Race)reader.GetByte("char_race_id");
                            template.Gender                 = (Gender)reader.GetByte("char_gender_id");
                            template.ModelId                = reader.GetUInt32("model_id");
                            template.FactionId              = reader.GetUInt32("faction_id");
                            template.ZoneId                 = reader.GetUInt32("starting_zone_id");
                            template.ReturnDictrictId       = reader.GetUInt32("default_return_district_id");
                            template.ResurrectionDictrictId =
                                reader.GetUInt32("default_resurrection_district_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 reader2 = new SQLiteWrapperReader(command2.ExecuteReader()))
                                {
                                    while (reader2.Read())
                                    {
                                        var itemId = reader2.GetUInt32("item_id", 0);
                                        var slot   = reader2.GetInt32("slot_type_id") - 23;
                                        template.Items[slot] = itemId;
                                    }
                                }
                            }

                            var templateId = (byte)(16 * (byte)template.Gender + (byte)template.Race);
                            _templates.Add(templateId, template);
                            temp.Add(id, templateId);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM character_buffs";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var characterId = reader.GetUInt32("character_id");
                            var buffId      = reader.GetUInt32("buff_id");
                            var template    = _templates[temp[characterId]];
                            template.Buffs.Add(buffId);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM character_supplies";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var ability = reader.GetByte("ability_id");
                            var item    = new AbilitySupplyItem
                            {
                                Id     = reader.GetUInt32("item_id"),
                                Amount = reader.GetInt32("amount"),
                                Grade  = reader.GetByte("grade_id")
                            };

                            if (!_abilityItems.ContainsKey(ability))
                            {
                                _abilityItems.Add(ability, new AbilityItems());
                            }
                            _abilityItems[ability].Supplies.Add(item);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM character_equip_packs";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var ability  = reader.GetByte("ability_id");
                            var template = new AbilityItems {
                                Ability = ability, Items = new EquipItemsTemplate()
                            };
                            var clothPack  = reader.GetUInt32("newbie_cloth_pack_id", 0);
                            var weaponPack = reader.GetUInt32("newbie_weapon_pack_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 reader2 = new SQLiteWrapperReader(command2.ExecuteReader()))
                                    {
                                        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 reader2 = new SQLiteWrapperReader(command2.ExecuteReader()))
                                    {
                                        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");
                                        }
                                    }
                                }
                            }

                            _abilityItems.Add(template.Ability, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM bag_expands";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var expand = new Expand();
                            expand.IsBank     = reader.GetBoolean("is_bank", true);
                            expand.Step       = reader.GetInt32("step");
                            expand.Price      = reader.GetInt32("price");
                            expand.ItemId     = reader.GetUInt32("item_id", 0);
                            expand.ItemCount  = reader.GetInt32("item_count");
                            expand.CurrencyId = reader.GetInt32("currency_id");

                            if (!_expands.ContainsKey(expand.Step))
                            {
                                _expands.Add(expand.Step, new List <Expand> {
                                    expand
                                });
                            }
                            else
                            {
                                _expands[expand.Step].Add(expand);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT id, buff_id FROM appellations";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new AppellationTemplate();
                            template.Id     = reader.GetUInt32("id");
                            template.BuffId = reader.GetUInt32("buff_id", 0);

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

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM actability_groups";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ActabilityTemplate();
                            template.Id              = reader.GetUInt32("id");
                            template.Name            = reader.GetString("name");
                            template.UnitAttributeId = reader.GetInt32("unit_attr_id");
                            _actabilities.Add(template.Id, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM expert_limits ORDER BY up_limit ASC";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        var step = 0;
                        while (reader.Read())
                        {
                            var template = new ExpertLimit();
                            template.Id               = reader.GetUInt32("id");
                            template.UpLimit          = reader.GetInt32("up_limit");
                            template.ExpertLimitCount = reader.GetByte("expert_limit");
                            template.Advantage        = reader.GetInt32("advantage");
                            template.CastAdvantage    = reader.GetInt32("cast_adv");
                            template.UpCurrencyId     = reader.GetUInt32("up_currency_id", 0);
                            template.UpPrice          = reader.GetInt32("up_price");
                            template.DownCurrencyId   = reader.GetUInt32("down_currency_id", 0);
                            template.DownPrice        = reader.GetInt32("down_price");
                            _expertLimits.Add(step++, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM expand_expert_limits ORDER BY expand_count ASC";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        var step = 0;
                        while (reader.Read())
                        {
                            var template = new ExpandExpertLimit();
                            template.Id          = reader.GetUInt32("id");
                            template.ExpandCount = reader.GetByte("expand_count");
                            template.LifePoint   = reader.GetInt32("life_point");
                            template.ItemId      = reader.GetUInt32("item_id", 0);
                            template.ItemCount   = reader.GetInt32("item_count");
                            _expandExpertLimits.Add(step++, template);
                        }
                    }
                }
            }

            var content = FileManager.GetFileContents("./Data/CharTemplates.json");

            if (string.IsNullOrWhiteSpace(content))
            {
                throw new IOException(
                          $"File {FileManager.AppPath + "Data/CharTemplates.json"} doesn't exists or is empty.");
            }

            if (JsonHelper.TryDeserializeObject(content, out List <CharacterTemplateConfig> charTemplates, out _))
            {
                foreach (var charTemplate in charTemplates)
                {
                    var point = new Point(charTemplate.Pos.X, charTemplate.Pos.Y, charTemplate.Pos.Z);
                    point.ZoneId = WorldManager
                                   .Instance
                                   .GetZoneId(charTemplate.Pos.WorldId, charTemplate.Pos.X, charTemplate.Pos.Y); // TODO ...

                    var template = _templates[(byte)(16 + charTemplate.Id)];
                    template.Position         = point;
                    template.NumInventorySlot = charTemplate.NumInventorySlot;
                    template.NumBankSlot      = charTemplate.NumBankSlot;

                    template                  = _templates[(byte)(32 + charTemplate.Id)];
                    template.Position         = point;
                    template.NumInventorySlot = charTemplate.NumInventorySlot;
                    template.NumBankSlot      = charTemplate.NumBankSlot;
                }
            }
            else
            {
                throw new Exception($"CharacterManager: Parse {FileManager.AppPath + "Data/CharTemplates.json"} file");
            }

            Log.Info("Loaded {0} character templates", _templates.Count);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        public void Load()
        {
            _shipyards = new Dictionary <uint, ShipyardsTemplate>();

            _log.Info("Loading Shipyards...");
            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM shipyards";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ShipyardsTemplate
                            {
                                Id               = reader.GetUInt32("id"),
                                Name             = reader.GetString("name"),
                                MainModelId      = reader.GetUInt32("main_model_id"),
                                ItemId           = reader.GetUInt32("item_id"),
                                SpawnOffsetFront = reader.GetFloat("spawn_offset_front"),
                                SpawnOffsetZ     = reader.GetFloat("spawn_offset_z"),
                                BuildRadius      = reader.GetInt32("build_radius"),
                                TaxDuration      = reader.GetInt32("tax_duration", 0),
                                OriginItemId     = reader.GetUInt32("origin_item_id", 0),
                                TaxationId       = reader.GetInt32("taxation_id")
                            };
                            _shipyards.Add(template.Id, template);
                        }
                    }
                }
                _log.Info("Loaded {0} shipyards", _shipyards.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM shipyard_steps";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ShipyardSteps()
                            {
                                Id         = reader.GetUInt32("id"),
                                ShipyardId = reader.GetUInt32("shipyard_id"),
                                Step       = reader.GetInt32("step"),
                                ModelId    = reader.GetUInt32("model_id"),
                                SkillId    = reader.GetUInt32("skill_id"),
                                NumActions = reader.GetInt32("num_actions"),
                                MaxHp      = reader.GetInt32("max_hp")
                            };
                            if (_shipyards.ContainsKey(template.ShipyardId))
                            {
                                _shipyards[template.ShipyardId].ShipyardSteps.Add(template.Step, template);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
0
        public void Load()
        {
            // TODO Funcs: min, max, clamp, if_zero, if_positive, if_negative, floor, log, sqrt
            CalculationEngine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Compiled, true, true, false);
            CalculationEngine.AddFunction("clamp", (a, b, c) => a < b ? b : (a > c ? c : a));
            CalculationEngine.AddFunction("if_negative", (a, b, c) => a < 0 ? b : c);
            CalculationEngine.AddFunction("if_positive", (a, b, c) => a > 0 ? b : c);
            CalculationEngine.AddFunction("if_zero", (a, b, c) => a == 0 ? b : c);

            _unitFormulas = new Dictionary <FormulaOwnerType, Dictionary <UnitFormulaKind, UnitFormula> >();
            foreach (var owner in Enum.GetValues(typeof(FormulaOwnerType)))
            {
                _unitFormulas.Add((FormulaOwnerType)owner, new Dictionary <UnitFormulaKind, UnitFormula>());
            }
            _wearableFormulas = new Dictionary <WearableFormulaType, WearableFormula>();
            _unitVariables    =
                new Dictionary <uint, Dictionary <UnitFormulaVariableType, Dictionary <uint, UnitFormulaVariable> > >();
            _formulas = new Dictionary <uint, Formula>();

            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading formulas...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from unit_formulas";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var formula = new UnitFormula
                                {
                                    Id          = reader.GetUInt32("id"),
                                    TextFormula = reader.GetString("formula"),
                                    Kind        = (UnitFormulaKind)reader.GetByte("kind_id"),
                                    Owner       = (FormulaOwnerType)reader.GetByte("owner_type_id")
                                };
                                if (formula.Prepare())
                                {
                                    _unitFormulas[formula.Owner].Add(formula.Kind, formula);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from unit_formula_variables";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var variable = new UnitFormulaVariable
                                {
                                    FormulaId = reader.GetUInt32("unit_formula_id"),
                                    Type      = (UnitFormulaVariableType)reader.GetByte("variable_kind_id"),
                                    Key       = reader.GetUInt32("key"),
                                    Value     = reader.GetFloat("value")
                                };
                                if (!_unitVariables.ContainsKey(variable.FormulaId))
                                {
                                    _unitVariables.Add(variable.FormulaId,
                                                       new Dictionary <UnitFormulaVariableType, Dictionary <uint, UnitFormulaVariable> >());
                                }
                                if (!_unitVariables[variable.FormulaId].ContainsKey(variable.Type))
                                {
                                    _unitVariables[variable.FormulaId].Add(variable.Type,
                                                                           new Dictionary <uint, UnitFormulaVariable>());
                                }
                                _unitVariables[variable.FormulaId][variable.Type].Add(variable.Key, variable);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from wearable_formulas";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var formula = new WearableFormula
                                {
                                    Id          = reader.GetUInt32("id"),
                                    Type        = (WearableFormulaType)reader.GetByte("kind_id"),
                                    TextFormula = reader.GetString("formula")
                                };
                                if (formula.Prepare())
                                {
                                    _wearableFormulas.Add(formula.Type, formula);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from formulas";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var formula = new Formula
                                {
                                    Id          = reader.GetUInt32("id"),
                                    TextFormula = reader.GetString("formula")
                                };
                                if (formula.Prepare())
                                {
                                    _formulas.Add(formula.Id, formula);
                                }
                            }
                        }
                }

                _log.Info("Formulas loaded");
            }
        }
Beispiel #9
0
        public void Load()
        {
            _templates     = new Dictionary <uint, DoodadTemplate>();
            _funcs         = new Dictionary <uint, List <DoodadFunc> >();
            _phaseFuncs    = new Dictionary <uint, List <DoodadFunc> >();
            _funcTemplates = new Dictionary <string, Dictionary <uint, DoodadFuncTemplate> >();
            foreach (var type in Helpers.GetTypesInNamespace("AAEmu.Game.Models.Game.DoodadObj.Funcs"))
            {
                if (type.BaseType == typeof(DoodadFuncTemplate))
                {
                    _funcTemplates.Add(type.Name, new Dictionary <uint, DoodadFuncTemplate>());
                }
            }

            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading doodad templates...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * from doodad_almighties";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var template = new DoodadTemplate();
                                template.Id                  = reader.GetUInt32("id");
                                template.OnceOneMan          = reader.GetBoolean("once_one_man", true);
                                template.OnceOneInteraction  = reader.GetBoolean("once_one_interaction", true);
                                template.MgmtSpawn           = reader.GetBoolean("mgmt_spawn", true);
                                template.Percent             = reader.GetInt32("percent", 0);
                                template.MinTime             = reader.GetInt32("min_time", 0);
                                template.MaxTime             = reader.GetInt32("max_time", 0);
                                template.ModelKindId         = reader.GetUInt32("model_kind_id");
                                template.UseCreatorFaction   = reader.GetBoolean("use_creator_faction", true);
                                template.ForceTodTopPriority = reader.GetBoolean("force_tod_top_priority", true);
                                template.MilestoneId         = reader.GetUInt32("milestone_id", 0);
                                template.GroupId             = reader.GetUInt32("group_id");
                                template.UseTargetDecal      = reader.GetBoolean("use_target_decal", true);
                                template.UseTargetSilhouette = reader.GetBoolean("use_target_silhouette", true);
                                template.UseTargetHighlight  = reader.GetBoolean("use_target_highlight", true);
                                template.TargetDecalSize     = reader.GetFloat("target_decal_size", 0);
                                template.SimRadius           = reader.GetInt32("sim_radius", 0);
                                template.CollideShip         = reader.GetBoolean("collide_ship", true);
                                template.CollideVehicle      = reader.GetBoolean("collide_vehicle", true);
                                template.ClimateId           = reader.GetUInt32("climate_id", 0);
                                template.SaveIndun           = reader.GetBoolean("save_indun", true);
                                template.ForceUpAction       = reader.GetBoolean("force_up_action", true);
                                template.Parentable          = reader.GetBoolean("parentable", true);
                                template.Childable           = reader.GetBoolean("childable", true);
                                template.FactionId           = reader.GetUInt32("faction_id");
                                template.GrowthTime          = reader.GetInt32("growth_time", 0);
                                template.DespawnOnCollision  = reader.GetBoolean("despawn_on_collision", true);
                                template.NoCollision         = reader.GetBoolean("no_collision", true);
                                // TODO 1.2 template.RestrictZoneId = reader.IsDBNull("restrict_zone_id") ? 0 : reader.GetUInt32("restrict_zone_id");

                                using (var commandChild = connection.CreateCommand())
                                {
                                    commandChild.CommandText =
                                        "SELECT * FROM doodad_func_groups WHERE doodad_almighty_id = @doodad_almighty_id";
                                    commandChild.Prepare();
                                    commandChild.Parameters.AddWithValue("doodad_almighty_id", template.Id);
                                    using (var sqliteDataReaderChild = commandChild.ExecuteReader())
                                        using (var readerChild = new SQLiteWrapperReader(sqliteDataReaderChild))
                                        {
                                            while (readerChild.Read())
                                            {
                                                var funcGroups = new DoodadFuncGroups();
                                                funcGroups.Id          = readerChild.GetUInt32("id");
                                                funcGroups.GroupKindId = readerChild.GetUInt32("doodad_func_group_kind_id");
                                                template.FuncGroups.Add(funcGroups);
                                            }
                                        }
                                }

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

                _log.Info("Loaded {0} doodad templates", _templates.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM doodad_funcs";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var func = new DoodadFunc();
                                func.GroupId   = reader.GetUInt32("doodad_func_group_id");
                                func.FuncId    = reader.GetUInt32("actual_func_id");
                                func.FuncType  = reader.GetString("actual_func_type");
                                func.NextPhase = reader.GetInt32("next_phase", -1); // TODO next_phase = 0?
                                func.SkillId   = reader.GetUInt32("func_skill_id", 0);
                                func.PermId    = reader.GetUInt32("perm_id");
                                func.Count     = reader.GetInt32("act_count", 0);
                                List <DoodadFunc> list;
                                if (_funcs.ContainsKey(func.GroupId))
                                {
                                    list = _funcs[func.GroupId];
                                }
                                else
                                {
                                    list = new List <DoodadFunc>();
                                    _funcs.Add(func.GroupId, list);
                                }

                                list.Add(func);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM doodad_phase_funcs";
                    command.Prepare();
                    using (var sqliteDataReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteDataReader))
                        {
                            while (reader.Read())
                            {
                                var func = new DoodadFunc();
                                func.GroupId  = reader.GetUInt32("doodad_func_group_id");
                                func.FuncId   = reader.GetUInt32("actual_func_id");
                                func.FuncType = reader.GetString("actual_func_type");
                                List <DoodadFunc> list;
                                if (_phaseFuncs.ContainsKey(func.GroupId))
                                {
                                    list = _phaseFuncs[func.GroupId];
                                }
                                else
                                {
                                    list = new List <DoodadFunc>();
                                    _phaseFuncs.Add(func.GroupId, list);
                                }

                                list.Add(func);
                            }
                        }
                }
            }
        }
Beispiel #10
0
        public void Load()
        {
            _zones           = new Dictionary <uint, Zone>();
            _groups          = new Dictionary <ushort, ZoneGroup>();
            _conflicts       = new Dictionary <ushort, ZoneConflict>();
            _groupBannedTags = new Dictionary <uint, ZoneGroupBannedTag>();
            _climateElem     = new Dictionary <uint, ZoneClimateElem>();
            _log.Info("Loading ZoneManager...");
            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM zones";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new Zone();
                            template.Id            = reader.GetUInt32("id");
                            template.Name          = (string)reader.GetValue("name");
                            template.ZoneKey       = reader.GetUInt32("zone_key");
                            template.GroupId       = reader.GetUInt32("group_id", 0);
                            template.Closed        = reader.GetBoolean("closed", true);
                            template.FactionId     = reader.GetUInt32("faction_id", 0);
                            template.ZoneClimateId = reader.GetUInt32("zone_climate_id", 0);
                            _zones.Add(template.ZoneKey, template);
                        }
                    }
                }

                _log.Info("Loaded {0} zones", _zones.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM zone_groups";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ZoneGroup();
                            template.Id                    = reader.GetUInt16("id");
                            template.Name                  = (string)reader.GetValue("name");
                            template.X                     = reader.GetFloat("x");
                            template.Y                     = reader.GetFloat("y");
                            template.Width                 = reader.GetFloat("w");
                            template.Hight                 = reader.GetFloat("h");
                            template.TargetId              = reader.GetUInt32("target_id");
                            template.FactionChatRegionId   = reader.GetUInt32("faction_chat_region_id");
                            template.PirateDesperado       = reader.GetBoolean("pirate_desperado", true);
                            template.FishingSeaLootPackId  = reader.GetUInt32("fishing_sea_loot_pack_id", 0);
                            template.FishingLandLootPackId = reader.GetUInt32("fishing_land_loot_pack_id", 0);
                            // TODO 1.2 // template.BuffId = reader.GetUInt32("buff_id", 0);
                            _groups.Add(template.Id, template);
                        }
                    }
                }

                _log.Info("Loaded {0} groups", _groups.Count);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM conflict_zones";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var zoneGroupId = reader.GetUInt16("zone_group_id");
                            if (_groups.ContainsKey(zoneGroupId))
                            {
                                var template = new ZoneConflict(_groups[zoneGroupId]);
                                template.ZoneGroupId = zoneGroupId;

                                for (var i = 0; i < 5; i++)
                                {
                                    template.NumKills[i]  = reader.GetInt32($"num_kills_{i}");
                                    template.NoKillMin[i] = reader.GetInt32($"no_kill_min_{i}");
                                }

                                template.ConflictMin = reader.GetInt32("conflict_min");
                                template.WarMin      = reader.GetInt32("war_min");
                                template.PeaceMin    = reader.GetInt32("peace_min");

                                template.PeaceProtectedFactionId = reader.GetUInt32("peace_protected_faction_id", 0);
                                template.NuiaReturnPointId       = reader.GetUInt32("nuia_return_point_id", 0);
                                template.HariharaReturnPointId   = reader.GetUInt32("harihara_return_point_id", 0);
                                template.WarTowerDefId           = reader.GetUInt32("war_tower_def_id", 0);
                                // TODO 1.2 // template.PeaceTowerDefId = reader.GetUInt32("peace_tower_def_id", 0);

                                _groups[zoneGroupId].Conflict = template;
                                _conflicts.Add(zoneGroupId, template);
                            }
                            else
                            {
                                _log.Warn("ZoneGroupId: {1} doesn't exist for conflict", zoneGroupId);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM zone_group_banned_tags";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ZoneGroupBannedTag();
                            template.Id          = reader.GetUInt32("id");
                            template.ZoneGroupId = reader.GetUInt32("zone_group_id");
                            template.TagId       = reader.GetUInt32("tag_id");
                            // TODO 1.2 // template.BannedPeriodsId = reader.GetUInt32("banned_periods_id");
                            _groupBannedTags.Add(template.Id, template);
                        }
                    }
                }

                _log.Info("Loaded {0} group banned tags", _groupBannedTags.Count);
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM zone_climate_elems";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new ZoneClimateElem();
                            template.Id            = reader.GetUInt32("id");
                            template.ZoneClimateId = reader.GetUInt32("zone_climate_id");
                            template.ClimateId     = reader.GetUInt32("climate_id");
                            _climateElem.Add(template.Id, template);
                        }
                    }
                }

                _log.Info("Loaded {0} climate elems", _climateElem.Count);
            }
        }
Beispiel #11
0
        public void Load()
        {
            _grades             = new Dictionary <int, GradeTemplate>();
            _holdables          = new Dictionary <uint, Holdable>();
            _wearables          = new Dictionary <uint, Wearable>();
            _wearableKinds      = new Dictionary <uint, WearableKind>();
            _wearableSlots      = new Dictionary <uint, WearableSlot>();
            _modifiers          = new Dictionary <uint, AttributeModifiers>();
            _templates          = new Dictionary <uint, ItemTemplate>();
            _enchantingCosts    = new Dictionary <uint, EquipSlotEnchantingCost>();
            _gradesOrdered      = new Dictionary <int, GradeTemplate>();
            _enchantingSupports = new Dictionary <uint, ItemGradeEnchantingSupport>();
            _config             = new ItemConfig();
            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_configs";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            if (!reader.Read())
                            {
                                return;
                            }
                            _config.DurabilityDecrementChance  = reader.GetFloat("durability_decrement_chance");
                            _config.DurabilityRepairCostFactor = reader.GetFloat("durability_repair_cost_factor");
                            _config.DurabilityConst            = reader.GetFloat("durability_const");
                            _config.HoldableDurabilityConst    = reader.GetFloat("holdable_durability_const");
                            _config.WearableDurabilityConst    = reader.GetFloat("wearable_durability_const");
                            _config.DeathDurabilityLossRatio   = reader.GetInt32("death_durability_loss_ratio");
                            _config.ItemStatConst     = reader.GetInt32("item_stat_const");
                            _config.HoldableStatConst = reader.GetInt32("holdable_stat_const");
                            _config.WearableStatConst = reader.GetInt32("wearable_stat_const");
                            _config.StatValueConst    = reader.GetInt32("stat_value_const");
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_grades";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new GradeTemplate();
                                template.Grade                    = reader.GetInt32("id");
                                template.GradeOrder               = reader.GetInt32("grade_order");
                                template.HoldableDps              = reader.GetFloat("var_holdable_dps");
                                template.HoldableArmor            = reader.GetFloat("var_holdable_armor");
                                template.HoldableMagicDps         = reader.GetFloat("var_holdable_magic_dps");
                                template.WearableArmor            = reader.GetFloat("var_wearable_armor");
                                template.WearableMagicResistance  = reader.GetFloat("var_wearable_magic_resistance");
                                template.Durability               = reader.GetFloat("durability_value");
                                template.UpgradeRatio             = reader.GetInt32("upgrade_ratio");
                                template.StatMultiplier           = reader.GetInt32("stat_multiplier");
                                template.RefundMultiplier         = reader.GetInt32("refund_multiplier");
                                template.EnchantSuccessRatio      = reader.GetInt32("grade_enchant_success_ratio");
                                template.EnchantGreatSuccessRatio = reader.GetInt32("grade_enchant_great_success_ratio");
                                template.EnchantBreakRatio        = reader.GetInt32("grade_enchant_break_ratio");
                                template.EnchantDowngradeRatio    = reader.GetInt32("grade_enchant_downgrade_ratio");
                                template.EnchantCost              = reader.GetInt32("grade_enchant_cost");
                                template.HoldableHealDps          = reader.GetFloat("var_holdable_heal_dps");
                                template.EnchantDowngradeMin      = reader.GetInt32("grade_enchant_downgrade_min");
                                template.EnchantDowngradeMax      = reader.GetInt32("grade_enchant_downgrade_max");
                                template.CurrencyId               = reader.GetInt32("currency_id");
                                _grades.Add(template.Grade, template);
                                _gradesOrdered.Add(template.GradeOrder, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM holdables";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new Holdable
                                {
                                    Id     = reader.GetUInt32("id"),
                                    KindId = reader.GetUInt32("kind_id"),
                                    Speed  = reader.GetInt32("speed"),
                                    ExtraDamagePierceFactor = reader.GetInt32("extra_damage_pierce_factor"),
                                    ExtraDamageSlashFactor  = reader.GetInt32("extra_damage_slash_factor"),
                                    ExtraDamageBluntFactor  = reader.GetInt32("extra_damage_blunt_factor"),
                                    MaxRange         = reader.GetInt32("max_range"),
                                    Angle            = reader.GetInt32("angle"),
                                    EnchantedDps1000 = reader.GetInt32("enchanted_dps1000"),
                                    SlotTypeId       = reader.GetUInt32("slot_type_id"),
                                    DamageScale      = reader.GetInt32("damage_scale"),
                                    FormulaDps       = new Formula(reader.GetString("formula_dps")),
                                    FormulaMDps      = new Formula(reader.GetString("formula_mdps")),
                                    FormulaArmor     = new Formula(reader.GetString("formula_armor")),
                                    MinRange         = reader.GetInt32("min_range"),
                                    SheathePriority  = reader.GetInt32("sheathe_priority"),
                                    DurabilityRatio  = reader.GetFloat("durability_ratio"),
                                    RenewCategory    = reader.GetInt32("renew_category"),
                                    ItemProcId       = reader.GetInt32("item_proc_id"),
                                    StatMultiplier   = reader.GetInt32("stat_multiplier")
                                };

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

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearables";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new Wearable
                                {
                                    TypeId            = reader.GetUInt32("armor_type_id"),
                                    SlotTypeId        = reader.GetUInt32("slot_type_id"),
                                    ArmorBp           = reader.GetInt32("armor_bp"),
                                    MagicResistanceBp = reader.GetInt32("magic_resistance_bp")
                                };
                                _wearables.Add(template.TypeId * 128 + template.SlotTypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearable_kinds";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new WearableKind
                                {
                                    TypeId               = reader.GetUInt32("armor_type_id"),
                                    ArmorRatio           = reader.GetInt32("armor_ratio"),
                                    MagicResistanceRatio = reader.GetInt32("magic_resistance_ratio"),
                                    FullBufId            = reader.GetUInt32("full_buff_id"),
                                    HalfBufId            = reader.GetUInt32("half_buff_id"),
                                    ExtraDamagePierce    = reader.GetInt32("extra_damage_pierce"),
                                    ExtraDamageSlash     = reader.GetInt32("extra_damage_slash"),
                                    ExtraDamageBlunt     = reader.GetInt32("extra_damage_blunt"),
                                    DurabilityRatio      = reader.GetFloat("durability_ratio")
                                };
                                _wearableKinds.Add(template.TypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wearable_slots";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new WearableSlot
                                {
                                    SlotTypeId = reader.GetUInt32("slot_type_id"),
                                    Coverage   = reader.GetInt32("coverage")
                                };
                                _wearableSlots.Add(template.SlotTypeId, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM equip_item_attr_modifiers";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new AttributeModifiers
                                {
                                    Id        = reader.GetUInt32("id"), // TODO ... alias
                                    StrWeight = reader.GetInt32("str_weight"),
                                    DexWeight = reader.GetInt32("dex_weight"),
                                    StaWeight = reader.GetInt32("sta_weight"),
                                    IntWeight = reader.GetInt32("int_weight"),
                                    SpiWeight = reader.GetInt32("spi_weight")
                                };
                                _modifiers.Add(template.Id, template);
                            }
                        }
                }

                _log.Info("Loading items...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_armors";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var slotTypeId = reader.GetUInt32("slot_type_id");
                                var typeId     = reader.GetUInt32("type_id");

                                var template = new ArmorTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    WearableTemplate     = _wearables[typeId * 128 + slotTypeId],
                                    KindTemplate         = _wearableKinds[typeId],
                                    SlotTemplate         = _wearableSlots[slotTypeId],
                                    BaseEnchantable      = reader.GetBoolean("base_enchantable", true),
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    BaseEquipment        = reader.GetBoolean("base_equipment", true),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_weapons";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var holdableId = reader.GetUInt32("holdable_id");
                                var template   = new WeaponTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    BaseEnchantable      = reader.GetBoolean("base_enchantable"),
                                    HoldableTemplate     = _holdables[holdableId],
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    BaseEquipment        = reader.GetBoolean("base_equipment", true),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_accessories";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var slotTypeId = reader.GetUInt32("slot_type_id");
                                var typeId     = reader.GetUInt32("type_id");

                                var template = new AccessoryTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    WearableTemplate     = _wearables[typeId * 128 + slotTypeId],
                                    KindTemplate         = _wearableKinds[typeId],
                                    SlotTemplate         = _wearableSlots[slotTypeId],
                                    ModSetId             = reader.GetUInt32("mod_set_id", 0),
                                    Repairable           = reader.GetBoolean("repairable", true),
                                    DurabilityMultiplier = reader.GetInt32("durability_multiplier"),
                                    RechargeBuffId       = reader.GetUInt32("recharge_buff_id", 0),
                                    ChargeLifetime       = reader.GetInt32("charge_lifetime"),
                                    ChargeCount          = reader.GetInt32("charge_count")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_summon_mates";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new SummonMateTemplate
                                {
                                    Id    = reader.GetUInt32("item_id"),
                                    NpcId = reader.GetUInt32("npc_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_summon_slaves";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new SummonSlaveTemplate
                                {
                                    Id      = reader.GetUInt32("item_id"),
                                    SlaveId = reader.GetUInt32("slave_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_body_parts";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                if (reader.IsDBNull("item_id"))
                                {
                                    continue;
                                }
                                var template = new BodyPartTemplate
                                {
                                    Id             = reader.GetUInt32("item_id"),
                                    ModelId        = reader.GetUInt32("model_id"),
                                    NpcOnly        = reader.GetBoolean("npc_only", true),
                                    BeautyShopOnly = reader.GetBoolean("beautyshop_only", true)
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_enchanting_gems";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new RuneTemplate
                                {
                                    Id = reader.GetUInt32("item_id"),
                                    EquipSlotGroupId = reader.GetUInt32("equip_slot_group_id", 0),
                                    EquipLevel       = reader.GetByte("equip_level", 0),
                                    ItemGradeId      = reader.GetByte("item_grade_id", 0)
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_backpacks";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new BackpackTemplate
                                {
                                    Id                      = reader.GetUInt32("item_id"),
                                    AssetId                 = reader.GetUInt32("asset_id"),
                                    BackpackType            = (BackpackType)reader.GetUInt32("backpack_type_id"),
                                    DeclareSiegeZoneGroupId = reader.GetUInt32("declare_siege_zone_group_id"),
                                    Heavy                   = reader.GetBoolean("heavy"),
                                    Asset2Id                = reader.GetUInt32("asset2_id"),
                                    NormalSpeciality        = reader.GetBoolean("normal_specialty"),
                                    UseAsStat               = reader.GetBoolean("use_as_stat"),
                                    SkinKindId              = reader.GetUInt32("skin_kind_id")
                                };
                                _templates.Add(template.Id, template);
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM items";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var id       = reader.GetUInt32("id");
                                var template = _templates.ContainsKey(id) ? _templates[id] : new ItemTemplate();
                                template.Id                = id;
                                template.Level             = reader.GetInt32("level");
                                template.Price             = reader.GetInt32("price");
                                template.Refund            = reader.GetInt32("refund");
                                template.BindId            = reader.GetUInt32("bind_id");
                                template.PickupLimit       = reader.GetInt32("pickup_limit");
                                template.MaxCount          = reader.GetInt32("max_stack_size");
                                template.Sellable          = reader.GetBoolean("sellable", true);
                                template.UseSkillId        = reader.GetUInt32("use_skill_id");
                                template.BuffId            = reader.GetUInt32("buff_id");
                                template.Gradable          = reader.GetBoolean("gradable", true);
                                template.LootMulti         = reader.GetBoolean("loot_multi", true);
                                template.LootQuestId       = reader.GetUInt32("loot_quest_id");
                                template.HonorPrice        = reader.GetInt32("honor_price");
                                template.ExpAbsLifetime    = reader.GetInt32("exp_abs_lifetime");
                                template.ExpOnlineLifetime = reader.GetInt32("exp_online_lifetime");
                                template.ExpDate           = reader.IsDBNull("exp_online_lifetime") ? reader.GetInt32("exp_date") : 0;
                                template.LevelRequirement  = reader.GetInt32("level_requirement");
                                template.LevelLimit        = reader.GetInt32("level_limit");
                                template.FixedGrade        = reader.GetInt32("fixed_grade");
                                template.LivingPointPrice  = reader.GetInt32("living_point_price");
                                template.CharGender        = reader.GetByte("char_gender_id");
                                if (!_templates.ContainsKey(id))
                                {
                                    _templates.Add(template.Id, template);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM equip_slot_enchanting_costs";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new EquipSlotEnchantingCost();
                                template.Id         = reader.GetUInt32("id");
                                template.SlotTypeId = reader.GetUInt32("slot_type_id");
                                template.Cost       = reader.GetInt32("cost");
                                if (!_enchantingCosts.ContainsKey(template.SlotTypeId))
                                {
                                    _enchantingCosts.Add(template.SlotTypeId, template);
                                }
                            }
                        }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM item_grade_enchanting_supports";
                    command.Prepare();
                    using (var sqliteReader = command.ExecuteReader())
                        using (var reader = new SQLiteWrapperReader(sqliteReader))
                        {
                            while (reader.Read())
                            {
                                var template = new ItemGradeEnchantingSupport();
                                template.Id                   = reader.GetUInt32("id");
                                template.ItemId               = reader.GetUInt32("item_id");
                                template.RequireGradeMin      = reader.GetInt32("require_grade_min");
                                template.RequireGradeMax      = reader.GetInt32("require_grade_max");
                                template.AddSuccessRatio      = reader.GetInt32("add_success_ratio");
                                template.AddSuccessMul        = reader.GetInt32("add_success_mul");
                                template.AddGreatSuccessRatio = reader.GetInt32("add_great_success_ratio");
                                template.AddGreatSuccessMul   = reader.GetInt32("add_great_success_mul");
                                template.AddBreakRatio        = reader.GetInt32("add_break_ratio");
                                template.AddBreakMul          = reader.GetInt32("add_break_mul");
                                template.AddDowngradeRatio    = reader.GetInt32("add_downgrade_ratio");
                                template.AddDowngradeMul      = reader.GetInt32("add_downgrade_mul");
                                template.AddGreatSuccessGrade = reader.GetInt32("add_great_success_grade");

                                if (!_enchantingSupports.ContainsKey(template.ItemId))
                                {
                                    _enchantingSupports.Add(template.ItemId, template);
                                }
                            }
                        }
                }

                _log.Info("Loaded {0} items", _templates.Count);
            }
        }
Beispiel #12
0
        public void Load()
        {
            _worlds                 = new Dictionary <uint, InstanceWorld>();
            _worldIdByZoneId        = new Dictionary <uint, uint>();
            _worldInteractionGroups = new Dictionary <uint, WorldInteractionGroup>();

            _log.Info("Loading world data...");

            #region FileManager

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

            if (JsonHelper.TryDeserializeObject(contents, out List <InstanceWorld> worlds, out _))
            {
                foreach (var world in worlds)
                {
                    if (_worlds.ContainsKey(world.Id))
                    {
                        throw new Exception("WorldManager: there are duplicates in world ids");
                    }

                    world.Regions              = new Region[world.CellX * CELL_SIZE, world.CellY *CELL_SIZE];
                    world.ZoneIds              = new uint[world.CellX * CELL_SIZE, world.CellY *CELL_SIZE];
                    world.HeightMaps           = new ushort[world.CellX * 512, world.CellY * 512];
                    world.HeightMaxCoefficient = ushort.MaxValue / (world.MaxHeight / 4.0);

                    _worlds.Add(world.Id, world);
                }
            }
            else
            {
                throw new Exception($"WorldManager: Parse {pathFile} file");
            }

            foreach (var world in _worlds.Values)
            {
                pathFile = $"{FileManager.AppPath}Data/Worlds/{world.Name}/zones.json";
                contents = FileManager.GetFileContents(pathFile);
                if (string.IsNullOrWhiteSpace(contents))
                {
                    throw new IOException($"File {pathFile} doesn't exists or is empty.");
                }

                if (JsonHelper.TryDeserializeObject(contents, out List <ZoneConfig> zones, out _))
                {
                    foreach (var zone in zones)
                    {
                        _worldIdByZoneId.Add(zone.Id, world.Id);

                        foreach (var cell in zone.Cells)
                        {
                            var x = cell.X * CELL_SIZE;
                            var y = cell.Y * CELL_SIZE;
                            foreach (var sector in cell.Sectors)
                            {
                                var sx = x + sector.X;
                                var sy = y + sector.Y;
                                world.ZoneIds[sx, sy] = zone.Id;
                                world.Regions[sx, sy] = new Region(world.Id, sx, sy);
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception($"WorldManager: Parse {pathFile} file");
                }
            }

            var active = false; //TODO add config
            if (active)         // TODO fastboot if active = false!
            {
                _log.Info("Loading heightmaps...");

                foreach (var world in _worlds.Values)
                {
                    var heightMap = $"{FileManager.AppPath}Data/Worlds/{world.Name}/hmap.dat";
                    if (!File.Exists(heightMap))
                    {
                        _log.Warn($"HeightMap at `{world.Name}` doesn't exists");
                        continue;
                    }

                    using (var stream = new FileStream(heightMap, FileMode.Open, FileAccess.Read))
                        using (var br = new BinaryReader(stream))
                        {
                            var version = br.ReadInt32();
                            if (version == 1)
                            {
                                var hMapCellX = br.ReadInt32();
                                var hMapCellY = br.ReadInt32();
                                br.ReadDouble(); // heightMaxCoeff
                                br.ReadInt32();  // count

                                if (hMapCellX == world.CellX && hMapCellY == world.CellY)
                                {
                                    for (var cellX = 0; cellX < world.CellX; cellX++)
                                    {
                                        for (var cellY = 0; cellY < world.CellY; cellY++)
                                        {
                                            if (br.ReadBoolean())
                                            {
                                                continue;
                                            }
                                            for (var i = 0; i < 16; i++)
                                            {
                                                for (var j = 0; j < 16; j++)
                                                {
                                                    for (var x = 0; x < 32; x++)
                                                    {
                                                        for (var y = 0; y < 32; y++)
                                                        {
                                                            var sx = cellX * 512 + i * 32 + x;
                                                            var sy = cellY * 512 + j * 32 + y;

                                                            world.HeightMaps[sx, sy] = br.ReadUInt16();
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _log.Warn("{0}: Invalid heightmap cells...", world.Name);
                                }
                            }
                            else
                            {
                                _log.Warn("{0}: Heightmap not correct version", world.Name);
                            }
                        }

                    _log.Info("Heightmap {0} loaded", world.Name);
                }

                _log.Info("Heightmaps loaded");
            }

            #endregion

            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM wi_group_wis";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id    = reader.GetUInt32("wi_id");
                            var group = (WorldInteractionGroup)reader.GetUInt32("wi_group_id");
                            _worldInteractionGroups.Add(id, group);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public void Load()
        {
            _plots          = new Dictionary <uint, Plot>();
            _eventTemplates = new Dictionary <uint, PlotEventTemplate>();
            _conditions     = new Dictionary <uint, PlotCondition>();
            using (var connection = SQLite.CreateConnection())
            {
                _log.Info("Loading plots...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plots";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new Plot();
                            template.Id           = reader.GetUInt32("id");
                            template.TargetTypeId = reader.GetUInt32("target_type_id");
                            _plots.Add(template.Id, template);
                        }
                    }
                }

                _log.Info("Loaded {0} plots", _plots.Count);

                _log.Info("Loading plot events...");
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_events";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new PlotEventTemplate();
                            template.Id                       = reader.GetUInt32("id");
                            template.PlotId                   = reader.GetUInt32("plot_id");
                            template.Position                 = reader.GetInt32("position");
                            template.SourceUpdateMethodId     = reader.GetUInt32("source_update_method_id");
                            template.TargetUpdateMethodId     = reader.GetUInt32("target_update_method_id");
                            template.TargetUpdateMethodParam1 = reader.GetInt32("target_update_method_param1");
                            template.TargetUpdateMethodParam2 = reader.GetInt32("target_update_method_param2");
                            template.TargetUpdateMethodParam3 = reader.GetInt32("target_update_method_param3");
                            template.TargetUpdateMethodParam4 = reader.GetInt32("target_update_method_param4");
                            template.TargetUpdateMethodParam5 = reader.GetInt32("target_update_method_param5");
                            template.TargetUpdateMethodParam6 = reader.GetInt32("target_update_method_param6");
                            template.TargetUpdateMethodParam7 = reader.GetInt32("target_update_method_param7");
                            template.TargetUpdateMethodParam8 = reader.GetInt32("target_update_method_param8");
                            template.TargetUpdateMethodParam9 = reader.GetInt32("target_update_method_param9");
                            template.Tickets                  = reader.GetInt32("tickets");
                            template.AoeDiminishing           = reader.GetBoolean("aoe_diminishing", true);
                            _eventTemplates.Add(template.Id, template);

                            if (template.Position == 1 && _plots.ContainsKey(template.PlotId))
                            {
                                _plots[template.PlotId].EventTemplate = template;
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_conditions";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new PlotCondition();
                            template.Id           = reader.GetUInt32("id");
                            template.NotCondition = reader.GetBoolean("not_condition", true);
                            template.Kind         = (PlotConditionType)reader.GetInt32("kind_id");
                            template.Param1       = reader.GetInt32("param1");
                            template.Param2       = reader.GetInt32("param2");
                            template.Param3       = reader.GetInt32("param3");
                            _conditions.Add(template.Id, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_aoe_conditions";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id       = reader.GetUInt32("event_id");
                            var condId   = reader.GetUInt32("condition_id");
                            var template = new PlotEventCondition();
                            template.Condition = _conditions[condId];
                            template.Position  = reader.GetInt32("position");
                            var plotEvent = _eventTemplates[id];
                            if (plotEvent.Conditions.Count > 0)
                            {
                                var res = false;
                                for (var node = plotEvent.Conditions.First; node != null; node = node.Next)
                                {
                                    if (node.Value.Position > template.Position)
                                    {
                                        plotEvent.Conditions.AddBefore(node, template);
                                        res = true;
                                        break;
                                    }
                                }

                                if (!res)
                                {
                                    plotEvent.Conditions.AddLast(template);
                                }
                            }
                            else
                            {
                                plotEvent.Conditions.AddFirst(template);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_event_conditions";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id       = reader.GetUInt32("event_id");
                            var condId   = reader.GetUInt32("condition_id");
                            var template = new PlotEventCondition();
                            template.Condition = _conditions[condId];
                            template.Position  = reader.GetInt32("position");
                            template.SourceId  = reader.GetInt32("source_id");
                            template.TargetId  = reader.GetInt32("target_id");
                            // TODO 1.2 // template.NotifyFailure = reader.GetBoolean("notify_failure", true);
                            var plotEvent = _eventTemplates[id];
                            if (plotEvent.Conditions.Count > 0)
                            {
                                var res = false;
                                for (var node = plotEvent.Conditions.First; node != null; node = node.Next)
                                {
                                    if (node.Value.Position > template.Position)
                                    {
                                        plotEvent.Conditions.AddBefore(node, template);
                                        res = true;
                                        break;
                                    }
                                }

                                if (!res)
                                {
                                    plotEvent.Conditions.AddLast(template);
                                }
                            }
                            else
                            {
                                plotEvent.Conditions.AddFirst(template);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_effects";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var id       = reader.GetUInt32("event_id");
                            var template = new PlotEventEffect();
                            template.Position   = reader.GetInt32("position");
                            template.SourceId   = reader.GetInt32("source_id");
                            template.TargetId   = reader.GetInt32("target_id");
                            template.ActualId   = reader.GetUInt32("actual_id");
                            template.ActualType = reader.GetString("actual_type");
                            var evnt = _eventTemplates[id];
                            if (evnt.Effects.Count > 0)
                            {
                                var res = false;
                                for (var node = evnt.Effects.First; node != null; node = node.Next)
                                {
                                    if (node.Value.Position > template.Position)
                                    {
                                        evnt.Effects.AddBefore(node, template);
                                        res = true;
                                        break;
                                    }
                                }

                                if (!res)
                                {
                                    evnt.Effects.AddLast(template);
                                }
                            }
                            else
                            {
                                evnt.Effects.AddFirst(template);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM plot_next_events";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new PlotNextEvent();
                            var id       = reader.GetUInt32("event_id");
                            var nextId   = reader.GetUInt32("next_event_id");
                            template.Event             = _eventTemplates[nextId];
                            template.Position          = reader.GetInt32("position");
                            template.PerTarget         = reader.GetBoolean("per_target", true);
                            template.Casting           = reader.GetBoolean("casting", true);
                            template.Delay             = reader.GetInt32("delay");
                            template.Speed             = reader.GetInt32("speed");
                            template.Channeling        = reader.GetBoolean("channeling", true);
                            template.CastingInc        = reader.GetInt32("casting_inc");
                            template.AddAnimCsTime     = reader.GetBoolean("add_anim_cs_time", true);
                            template.CastingDelayable  = reader.GetBoolean("casting_delayable", true);
                            template.CastingCancelable = reader.GetBoolean("casting_cancelable", true);
                            template.CancelOnBigHit    = reader.GetBoolean("cancel_on_big_hit", true);
                            template.UseExeTime        = reader.GetBoolean("use_exe_time", true);
                            template.Fail = reader.GetBoolean("fail", true);
                            var plotEvent = _eventTemplates[id];
                            if (plotEvent.NextEvents.Count > 0)
                            {
                                var res = false;
                                for (var node = plotEvent.NextEvents.First; node != null; node = node.Next)
                                {
                                    if (node.Value.Position > template.Position)
                                    {
                                        plotEvent.NextEvents.AddBefore(node, template);
                                        res = true;
                                        break;
                                    }
                                }

                                if (!res)
                                {
                                    plotEvent.NextEvents.AddLast(template);
                                }
                            }
                            else
                            {
                                plotEvent.NextEvents.AddFirst(template);
                            }
                        }
                    }
                }

                _log.Info("Loaded {0} plot events", _eventTemplates.Count);
            }
        }
Beispiel #14
0
        public void Load()
        {
            _openPortalInlandReagents  = new Dictionary <uint, OpenPortalReagents>();
            _openPortalOutlandReagents = new Dictionary <uint, OpenPortalReagents>();
            _allDistrictPortals        = new Dictionary <uint, Portal>();
            _allDistrictPortalsKey     = new Dictionary <uint, uint>();
            _log.Info("Loading Portals ...");

            #region FileManager

            var filePath = $"{FileManager.AppPath}Data/Portal/SubZonePortalCoords.json";
            var contents = FileManager.GetFileContents(filePath);

            if (string.IsNullOrWhiteSpace(contents))
            {
                throw new IOException($"File {filePath} doesn't exists or is empty.");
            }

            if (JsonHelper.TryDeserializeObject(contents, out List <Portal> portals, out _))
            {
                foreach (var portal in portals)
                {
                    _allDistrictPortals.Add(portal.SubZoneId, portal);
                    _allDistrictPortalsKey.Add(portal.Id, portal.SubZoneId);
                }
            }
            else
            {
                throw new Exception($"PortalManager: Parse {filePath} file");
            }

            _log.Info("Loaded {0} District Portals", _allDistrictPortals.Count);

            #endregion

            #region Sqlite

            using (var connection = SQLite.CreateConnection())
            {
                // NOTE - priority -> to remove item from inventory first
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM open_portal_inland_reagents";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new OpenPortalReagents
                            {
                                Id = reader.GetUInt32("id"),
                                OpenPortalEffectId = reader.GetUInt32("open_portal_effect_id"),
                                ItemId             = reader.GetUInt32("item_id"),
                                Amount             = reader.GetInt32("amount"),
                                Priority           = reader.GetInt32("priority")
                            };
                            _openPortalInlandReagents.Add(template.Id, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM open_portal_outland_reagents";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new OpenPortalReagents
                            {
                                Id = reader.GetUInt32("id"),
                                OpenPortalEffectId = reader.GetUInt32("open_portal_effect_id"),
                                ItemId             = reader.GetUInt32("item_id"),
                                Amount             = reader.GetInt32("amount"),
                                Priority           = reader.GetInt32("priority")
                            };
                            _openPortalOutlandReagents.Add(template.Id, template);
                        }
                    }
                }
            }
            _log.Info("Loaded Portal Info");

            #endregion
        }
Beispiel #15
0
        public void Load()
        {
            _crafts         = new Dictionary <uint, Craft>();
            _craftProducts  = new Dictionary <uint, CraftProduct>();
            _craftMaterials = new Dictionary <uint, List <CraftMaterial> >();
            _log.Info("Loading crafts...");

            using (var connection = SQLite.CreateConnection())
            {
                /* Crafts */
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM crafts";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new Craft();
                            template.Id              = reader.GetUInt32("id");
                            template.CastDelay       = reader.GetInt32("cast_delay");
                            template.ToolId          = reader.GetUInt32("tool_id", 0);
                            template.SkillId         = reader.GetUInt32("skill_id", 0);
                            template.WiId            = reader.GetUInt32("wi_id");
                            template.MilestoneId     = reader.GetUInt32("milestone_id", 0);
                            template.ReqDoodadId     = reader.GetUInt32("req_doodad_id", 0);
                            template.NeedBind        = reader.GetBoolean("need_bind");
                            template.AcId            = reader.GetUInt32("ac_id", 0);
                            template.ActabilityLimit = reader.GetInt32("actability_limit");
                            template.ShowUpperCraft  = reader.GetBoolean("show_upper_crafts");
                            template.RecommendLevel  = reader.GetInt32("recommend_level");
                            template.VisibleOrder    = reader.GetInt32("visible_order");
                            _crafts.Add(template.Id, template);
                        }
                    }
                }

                /* Craft products (item you get at the end) */
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM craft_products";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new CraftProduct();
                            template.Id              = reader.GetUInt32("id");
                            template.CraftId         = reader.GetUInt32("craft_id");
                            template.ItemId          = reader.GetUInt32("item_id");
                            template.Amount          = reader.GetInt32("amount", 1); //We always want to produce at least 1 item ?
                            template.Rate            = reader.GetInt32("rate");
                            template.ShowLowerCrafts = reader.GetBoolean("show_lower_crafts");
                            template.UseGrade        = reader.GetBoolean("use_grade");
                            template.ItemGradeId     = reader.GetUInt32("item_grade_id");

                            _craftProducts.Add(template.CraftId, template); // Using craftID so it's easier to find in the dictionary. Need to make sure results dont have duplicates later on. they do not in my db
                        }
                    }
                }

                /* Craft products (item you get at the end) */
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM craft_materials";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new CraftMaterial();
                            template.Id        = reader.GetUInt32("id");
                            template.CraftId   = reader.GetUInt32("craft_id");
                            template.ItemId    = reader.GetUInt32("item_id");
                            template.Amount    = reader.GetInt32("amount", 1); //We always want to cost at least 1 item ?
                            template.MainGrade = reader.GetBoolean("main_grade");

                            if (!_craftMaterials.ContainsKey(template.CraftId))
                            {
                                _craftMaterials.Add(template.CraftId, new List <CraftMaterial>());
                            }

                            _craftMaterials[template.CraftId].Add(template); // Using craftID so it's easier to find in the dictionary. Need to make sure results dont have duplicates later on. they do not in my db
                        }
                    }
                }
            }

            _log.Info("Loaded crafts", _crafts.Count);
        }
Beispiel #16
0
        public void Load()
        {
            _slaveTemplates = new Dictionary <uint, SlaveTemplate>();
            _activeSlaves   = new Dictionary <uint, Slave>();

            #region SQLLite

            using (var connection = SQLite.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM slaves";
                    command.Prepare();
                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new SlaveTemplate
                            {
                                Id                     = reader.GetUInt32("id"),
                                Name                   = reader.GetString("name"),
                                ModelId                = reader.GetUInt32("model_id"),
                                Mountable              = reader.GetBoolean("mountable"),
                                SpawnXOffset           = reader.GetFloat("spawn_x_offset"),
                                SpawnYOffset           = reader.GetFloat("spawn_y_offset"),
                                FactionId              = reader.GetUInt32("faction_id", 0),
                                Level                  = reader.GetUInt32("level"),
                                Cost                   = reader.GetInt32("cost"),
                                SlaveKindId            = reader.GetUInt32("slave_kind_id"),
                                SpawnValidAreaRance    = reader.GetUInt32("spawn_valid_area_range", 0),
                                SlaveInitialItemPackId = reader.GetUInt32("slave_initial_item_pack_id", 0),
                                SlaveCustomizingId     = reader.GetUInt32("slave_customizing_id", 0),
                                Customizable           = reader.GetBoolean("customizable", false)
                            };
                            _slaveTemplates.Add(template.Id, template);
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM slave_initial_buffs";
                    command.Prepare();

                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new SlaveInitialBuffs
                            {
                                Id      = reader.GetUInt32("id"), // нет такого поля в 3.5.5.3
                                SlaveId = reader.GetUInt32("slave_id"),
                                BuffId  = reader.GetUInt32("buff_id")
                            };
                            if (_slaveTemplates.ContainsKey(template.SlaveId))
                            {
                                _slaveTemplates[template.SlaveId].InitialBuffs.Add(template);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM slave_passive_buffs";
                    command.Prepare();

                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var template = new SlavePassiveBuffs
                            {
                                Id            = reader.GetUInt32("id"), // нет такого поля в 3.5.5.3
                                OwnerId       = reader.GetUInt32("owner_id"),
                                OwnerType     = reader.GetString("owner_type"),
                                PassiveBuffId = reader.GetUInt32("passive_buff_id")
                            };
                            if (_slaveTemplates.ContainsKey(template.OwnerId))
                            {
                                _slaveTemplates[template.OwnerId].PassiveBuffs.Add(template);
                            }
                        }
                    }
                }

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM slave_doodad_bindings ORDER BY owner_id ASC";
                    command.Prepare();

                    using (var reader = new SQLiteWrapperReader(command.ExecuteReader()))
                    {
                        //var step = 0U;
                        while (reader.Read())
                        {
                            var template = new SlaveDoodadBindings();
                            template.Id = reader.GetUInt32("id"); // нет такого поля в 3.5.5.3
                            //template.Id = step++;
                            template.OwnerId       = reader.GetUInt32("owner_id");
                            template.OwnerType     = reader.GetString("owner_type");
                            template.AttachPointId = reader.GetInt32("attach_point_id");
                            template.DoodadId      = reader.GetUInt32("doodad_id");
                            template.Persist       = reader.GetBoolean("persist");
                            template.Scale         = reader.GetFloat("scale");
                            if (_slaveTemplates.ContainsKey(template.OwnerId))
                            {
                                _slaveTemplates[template.OwnerId].DoodadBindings.Add(template);
                            }
                        }
                    }
                }
            }

            #endregion
        }
Beispiel #17
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);
                        }
                    }
                }
            }
        }