Example #1
0
        public override void WriteJson(JsonWriter Writer, object Value, JsonSerializer Serializer)
        {
            CsvData CsvData = (CsvData)Value;

            if (CsvData != null)
            {
                Writer.WriteValue(CsvData.GlobalId);
            }
            else
            {
                Writer.WriteValue(0);
            }
        }
Example #2
0
        public override object ReadJson(JsonReader Reader, Type ObjectType, object ExistingValue, JsonSerializer Serializer)
        {
            int Id = (int)(long)Reader.Value;

            if (Id != 0)
            {
                CsvData CsvData = CsvFiles.GetWithGlobalId(Id);

                if (ObjectType == typeof(CsvData) || CsvData.GetType() == ObjectType)
                {
                    return(CsvData);
                }

                Logging.Error(this.GetType(), "CsvData.GetType() !=  ObjectType. Data:" + CsvData.GetType() + ", objectType:" + ObjectType + ".");
            }

            return(null);
        }
Example #3
0
        /// <summary>
        ///     Reads the data.
        /// </summary>
        /// <param name="Data">The data.</param>
        /// <exception cref="System.Exception"></exception>
        public void LoadData(CsvData Data)
        {
            foreach (PropertyInfo Property in Data.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
            {
                if (Property.CanRead && Property.CanWrite)
                {
                    if (Property.PropertyType.IsArray)
                    {
                        Type ElementType = Property.PropertyType.GetElementType();

                        if (ElementType == typeof(bool))
                        {
                            Property.SetValue(Data, this.LoadBoolArray(Property.Name));
                        }
                        else if (ElementType == typeof(int))
                        {
                            Property.SetValue(Data, this.LoadIntArray(Property.Name));
                        }
                        else if (ElementType == typeof(string))
                        {
                            Property.SetValue(Data, this.LoadStringArray(Property.Name));
                        }
                        else
                        {
                            throw new Exception(ElementType + "[] is not a valid array.");
                        }
                    }
                    else if (Property.PropertyType.IsGenericType)
                    {
                        if (Property.PropertyType == typeof(List <>))
                        {
                            Type       ListType     = typeof(List <>);
                            Type[]     Generic      = Property.PropertyType.GetGenericArguments();
                            Type       ConcreteType = ListType.MakeGenericType(Generic);
                            object     NewList      = Activator.CreateInstance(ConcreteType);
                            MethodInfo Add          = ConcreteType.GetMethod("Add");
                            string     IndexerName  = ((DefaultMemberAttribute)NewList.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), true)[0]).MemberName;

                            PropertyInfo IndexProperty = NewList.GetType().GetProperty(IndexerName);

                            for (int i = this.Offset; i < this.Offset + this.GetSize(Property.Name); i++)
                            {
                                string Value = this.GetValue(Property.Name, i - this.Offset);

                                if (Value == string.Empty && i != this.Offset)
                                {
                                    Value = IndexProperty.GetValue(NewList, new object[]
                                    {
                                        i - this.Offset - 1
                                    }).ToString();
                                }

                                if (string.IsNullOrEmpty(Value))
                                {
                                    object Object = Generic[0].IsValueType ? Activator.CreateInstance(Generic[0]) : string.Empty;

                                    Add.Invoke(NewList, new[]
                                    {
                                        Object
                                    });
                                }
                                else
                                {
                                    Add.Invoke(NewList, new[]
                                    {
                                        Convert.ChangeType(Value, Generic[0])
                                    });
                                }
                            }

                            Property.SetValue(Data, NewList);
                        }
                        else if (Property.PropertyType == typeof(CsvData) || Property.PropertyType.BaseType == typeof(CsvData))
                        {
                            this.LoadData((CsvData)Property.GetValue(Property));
                        }
                    }
                    else
                    {
                        string Value = this.GetValue(Property.Name, 0);

                        if (!string.IsNullOrEmpty(Value))
                        {
                            Property.SetValue(Data, Convert.ChangeType(Value, Property.PropertyType));
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CsvFiles" /> class.
        /// </summary>
        public static void Initialize()
        {
            if (CsvFiles.Initialized)
            {
                return;
            }

            CsvFiles.Files    = new Dictionary <int, CsvTable>();
            CsvFiles.Paths    = new Dictionary <int, string>();
            CsvFiles.Tilemaps = new Dictionary <string, TilemapData>(32);

            CsvFiles.Spells     = new List <SpellData>(72);
            CsvFiles.Characters = new List <CharacterData>(72);

            CsvFiles.Paths.Add(1, @"Gamefiles/csv_client/locales.csv");
            CsvFiles.Paths.Add(2, @"Gamefiles/csv_client/billing_packages.csv");
            CsvFiles.Paths.Add(3, @"Gamefiles/csv_logic/globals.csv");
            CsvFiles.Paths.Add(4, @"Gamefiles/csv_client/sounds.csv");
            CsvFiles.Paths.Add(5, @"Gamefiles/csv_logic/resources.csv");

            CsvFiles.Paths.Add(9, @"Gamefiles/csv_logic/character_buffs.csv");

            CsvFiles.Paths.Add(10, @"Gamefiles/csv_logic/projectiles.csv");
            CsvFiles.Paths.Add(11, @"Gamefiles/csv_client/effects.csv");
            CsvFiles.Paths.Add(12, @"Gamefiles/csv_logic/predefined_decks.csv");
            CsvFiles.Paths.Add(14, @"Gamefiles/csv_logic/rarities.csv");
            CsvFiles.Paths.Add(15, @"Gamefiles/csv_logic/locations.csv");
            CsvFiles.Paths.Add(16, @"Gamefiles/csv_logic/alliance_badges.csv");

            CsvFiles.Paths.Add(18, @"Gamefiles/csv_logic/npcs.csv");
            CsvFiles.Paths.Add(19, @"Gamefiles/csv_logic/treasure_chests.csv");

            CsvFiles.Paths.Add(20, @"Gamefiles/csv_client/client_globals.csv");
            CsvFiles.Paths.Add(21, @"Gamefiles/csv_client/particle_emitters.csv");
            CsvFiles.Paths.Add(22, @"Gamefiles/csv_logic/area_effect_objects.csv");

            CsvFiles.Paths.Add(26, @"Gamefiles/csv_logic/spells_characters.csv");
            CsvFiles.Paths.Add(27, @"Gamefiles/csv_logic/spells_buildings.csv");
            CsvFiles.Paths.Add(28, @"Gamefiles/csv_logic/spells_other.csv");
            CsvFiles.Paths.Add(29, @"Gamefiles/csv_logic/spells_heroes.csv");

            CsvFiles.Paths.Add(34, @"Gamefiles/csv_logic/characters.csv");
            CsvFiles.Paths.Add(35, @"Gamefiles/csv_logic/buildings.csv");

            CsvFiles.Paths.Add(40, @"Gamefiles/csv_client/health_bars.csv");
            CsvFiles.Paths.Add(41, @"Gamefiles/csv_client/music.csv");
            CsvFiles.Paths.Add(42, @"Gamefiles/csv_logic/decos.csv");
            CsvFiles.Paths.Add(43, @"Gamefiles/csv_logic/gamble_chests.csv");

            CsvFiles.Paths.Add(45, @"Gamefiles/csv_logic/tutorials_home.csv");
            CsvFiles.Paths.Add(46, @"Gamefiles/csv_logic/exp_levels.csv");

            CsvFiles.Paths.Add(48, @"Gamefiles/csv_logic/tutorials_npc.csv");

            CsvFiles.Paths.Add(50, @"Gamefiles/csv_client/background_decos.csv");

            CsvFiles.Paths.Add(52, @"Gamefiles/csv_logic/chest_order.csv");
            CsvFiles.Paths.Add(53, @"Gamefiles/csv_logic/taunts.csv");
            CsvFiles.Paths.Add(54, @"Gamefiles/csv_logic/arenas.csv");
            CsvFiles.Paths.Add(55, @"Gamefiles/csv_logic/resource_packs.csv");
            CsvFiles.Paths.Add(56, @"Gamefiles/csv_client/credits.csv");
            CsvFiles.Paths.Add(57, @"Gamefiles/csv_logic/regions.csv");
            CsvFiles.Paths.Add(58, @"Gamefiles/csv_client/news.csv");
            CsvFiles.Paths.Add(59, @"Gamefiles/csv_logic/alliance_roles.csv");

            CsvFiles.Paths.Add(60, @"Gamefiles/csv_logic/achievements.csv");
            CsvFiles.Paths.Add(61, @"Gamefiles/csv_client/hints.csv");
            CsvFiles.Paths.Add(62, @"Gamefiles/csv_client/helpshift.csv");
            CsvFiles.Paths.Add(63, @"Gamefiles/csv_logic/tournament_tiers.csv");
            CsvFiles.Paths.Add(64, @"Gamefiles/csv_logic/content_tests.csv");
            CsvFiles.Paths.Add(65, @"Gamefiles/csv_logic/survival_modes.csv");
            CsvFiles.Paths.Add(66, @"Gamefiles/csv_logic/shop.csv");
            CsvFiles.Paths.Add(67, @"Gamefiles/csv_logic/event_categories.csv");
            CsvFiles.Paths.Add(68, @"Gamefiles/csv_logic/draft_deck.csv");

            // Paths.Add(70, @"Gamefiles/csv_logic/abilities.csv");

            CsvFiles.Paths.Add(72, @"Gamefiles/csv_logic/game_modes.csv");

            CsvFiles.Paths.Add(74, @"Gamefiles/csv_logic/event_category_definitions.csv");
            CsvFiles.Paths.Add(75, @"Gamefiles/csv_logic/event_category_object_definitions.csv");
            CsvFiles.Paths.Add(76, @"Gamefiles/csv_logic/event_category_enums.csv");
            CsvFiles.Paths.Add(77, @"Gamefiles/csv_logic/configuration_definitions.csv");

            CsvFiles.Paths.Add(79, @"Gamefiles/csv_logic/pve_gamemodes.csv");

            CsvFiles.Paths.Add(81, @"Gamefiles/csv_logic/tve_gamemodes.csv");
            CsvFiles.Paths.Add(82, @"Gamefiles/csv_logic/tutorial_chest_order.csv");
            CsvFiles.Paths.Add(83, @"Gamefiles/csv_logic/skins.csv");
            CsvFiles.Paths.Add(84, @"Gamefiles/csv_logic/quest_order.csv");
            CsvFiles.Paths.Add(85, @"Gamefiles/csv_logic/event_targeting_definitions.csv");
            CsvFiles.Paths.Add(86, @"Gamefiles/csv_logic/shop_cycle.csv");
            CsvFiles.Paths.Add(87, @"Gamefiles/csv_logic/skin_sets.csv");

            foreach (KeyValuePair <int, string> Pair in CsvFiles.Paths)
            {
                if (!File.Exists(Pair.Value))
                {
                    Logging.Error(typeof(CsvFiles), "File.Exists(Path) != true at Initialize().");
                }
                else
                {
                    CsvFiles.Files.Add(Pair.Key, new CsvTable(Pair.Key, Pair.Value));
                }
            }

            foreach (CsvTable CsvTable in CsvFiles.Files.Values)
            {
                foreach (CsvData CsvData in CsvTable.Datas)
                {
                    CsvData.LoadingFinished();
                }
            }

            CsvFiles.MaxExpLevel = CsvFiles.Get(Gamefile.ExpLevels).Datas.Count;

            CsvFiles.GoldData           = CsvFiles.Get(Gamefile.Resources).GetData <ResourceData>("Gold");
            CsvFiles.FreeGoldData       = CsvFiles.Get(Gamefile.Resources).GetData <ResourceData>("FreeGold");
            CsvFiles.StarCountData      = CsvFiles.Get(Gamefile.Resources).GetData <ResourceData>("StarCount");
            CsvFiles.CardCountData      = CsvFiles.Get(Gamefile.Resources).GetData <ResourceData>("CardCount");
            CsvFiles.ChestCountData     = CsvFiles.Get(Gamefile.Resources).GetData <ResourceData>("ChestCount");
            CsvFiles.SummonerData       = CsvFiles.Get(Gamefile.Buildings).GetData <CharacterData>("KingTower");
            CsvFiles.GameModeLadderData = CsvFiles.Get(Gamefile.GameModes).GetData <GameModeData>("Ladder");

            foreach (ArenaData ArenaData in CsvFiles.Get(Gamefile.Arenas).Datas)
            {
                ArenaData.ConfigureSpells();
            }

            foreach (string FilePath in Directory.GetFiles(@"Gamefiles/tilemaps/"))
            {
                CsvFiles.Tilemaps.Add(FilePath, new TilemapData(FilePath));
            }

            Logging.Info(typeof(CsvFiles), "Loaded " + CsvFiles.Files.Count + " CSV files.");
        }