コード例 #1
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);
        }
コード例 #2
0
 public Actability(ActabilityTemplate template)
 {
     Id       = template.Id;
     Template = template;
 }