Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Slot{TCsvData}"/> class.
 /// </summary>
 protected Slot()
 {
     _instance = CsvData.GetInstance <TCsvData>();
 }
Пример #2
0
        /// <summary/>
        protected internal override void FromJsonReader(JsonReader reader)
        {
            var instance = CsvData.GetInstance <BuildingData>();
            // const_t_end value.
            var constTimeEnd    = -1;
            var constTimeEndSet = false;
            // const_t value.
            var constTime    = -1;
            var constTimeSet = false;

            var dataId    = -1;
            var dataIdSet = false;

            var lvl    = -1;
            var lvlSet = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "id":
                        // Ignore it for now.
                        break;

                    case "data":
                        dataId    = reader.ReadAsInt32().Value;
                        dataIdSet = true;
                        break;

                    case "lvl":
                        lvl    = reader.ReadAsInt32().Value;
                        lvlSet = true;
                        break;

                    case "locked":
                        IsLocked = reader.ReadAsBoolean().Value;
                        break;

                    case "const_t_end":
                        constTimeEnd    = reader.ReadAsInt32().Value;
                        constTimeEndSet = true;
                        break;

                    case "const_t":
                        constTime    = reader.ReadAsInt32().Value;
                        constTimeSet = true;
                        break;

                    case "x":
                        X = reader.ReadAsInt32().Value;
                        break;

                    case "y":
                        Y = reader.ReadAsInt32().Value;
                        break;
                    }
                }
            }

            if (!dataIdSet)
            {
                throw new InvalidOperationException($"Building JSON at {reader.Path} does not contain a 'data' field.");
            }
            if (!lvlSet)
            {
                throw new InvalidOperationException($"Building JSON at {reader.Path} does not contain a 'lvl' field.");
            }

            if (instance.InvalidDataID(dataId))
            {
                throw new InvalidOperationException($"Building JSON at {reader.Path} contained an invalid BuildingData ID. {instance.GetArgsOutOfRangeMessage("Data ID")}");
            }

            UpdateData(dataId, lvl);
            UpdateIsUpgradable();

            //SetComponents();
            //if (UpgradeLevel == -1)
            //{

            //}

            if (RowCache.Name == "Town Hall")
            {
                Village._townhall = this;
            }

            if (constTimeEndSet)
            {
                var startTime = (int)TimeUtils.ToUnixTimestamp(Village.LastTickTime);
                var duration  = constTimeEnd - startTime;

                // Clamp value to 0.
                if (duration < 0)
                {
                    duration = 0;
                }

                Village.WorkerManager.AllocateWorker(this);
                Timer.Start(Village.LastTickTime, 0, duration);
            }
        }
Пример #3
0
        /// <summary/>
        protected internal override void FromJsonReader(JsonReader reader)
        {
            var instance = CsvData.GetInstance <TrapData>();
            // const_t_end value.
            var constTimeEnd    = -1;
            var constTimeEndSet = false;
            // const_t value.
            var constTime    = -1;
            var constTimeSet = false;

            var dataId    = -1;
            var dataIdSet = false;

            var lvl = 0;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "id":
                        // Ignore it for now.
                        break;

                    case "data":
                        dataId    = reader.ReadAsInt32().Value;
                        dataIdSet = true;
                        break;

                    case "lvl":
                        lvl = reader.ReadAsInt32().Value;
                        break;

                    case "needs_repair":
                        _isBroken = reader.ReadAsBoolean().Value;
                        break;

                    case "const_t_end":
                        constTimeEnd    = reader.ReadAsInt32().Value;
                        constTimeEndSet = true;
                        break;

                    case "const_t":
                        constTime    = reader.ReadAsInt32().Value;
                        constTimeSet = true;
                        break;

                    case "x":
                        X = reader.ReadAsInt32().Value;
                        break;

                    case "y":
                        Y = reader.ReadAsInt32().Value;
                        break;
                    }
                }
            }

            if (!dataIdSet)
            {
                throw new InvalidOperationException($"Trap JSON at {reader.Path} does not contain a 'data' field.");
            }

            if (instance.InvalidDataID(dataId))
            {
                throw new InvalidOperationException($"Trap JSON at {reader.Path} contained an invalid BuildingData ID. {instance.GetArgsOutOfRangeMessage("Data ID")}");
            }

            UpdateData(dataId, lvl);
            UpdateIsUpgradable();
        }
Пример #4
0
        /// <summary/>
        protected internal override void FromJsonReader(JsonReader reader)
        {
            var instance = CsvData.GetInstance <DecorationData>();

            var dataId    = -1;
            var dataIdSet = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "id":
                        // Ignore for now.
                        break;

                    case "data":
                        dataId    = reader.ReadAsInt32().Value;
                        dataIdSet = true;
                        break;

                    case "x":
                        X = reader.ReadAsInt32().Value;
                        break;

                    case "y":
                        Y = reader.ReadAsInt32().Value;
                        break;
                    }
                }
            }

            if (!dataIdSet)
            {
                throw new InvalidOperationException($"Decoration JSON at {reader.Path} does not contain a 'data' field.");
            }

            if (instance.InvalidDataID(dataId))
            {
                throw new InvalidOperationException($"Decoration JSON at {reader.Path} contained an invalid DecorationData ID. {instance.GetArgsOutOfRangeMessage("Data ID")}");
            }

            var tableCollections = Assets.Get <CsvDataTableCollection>();
            var dataRef          = new CsvDataRowRef <DecorationData>(dataId);
            var row = dataRef.Get(tableCollections);

            if (row == null)
            {
                throw new InvalidOperationException("Could not find CsvDataRow with ID '" + dataId + "'.");
            }

            var data = row[0];

            if (data == null)
            {
                throw new InvalidOperationException("Could not find DecorationData with ID '" + dataId + "'.");
            }

            _data = data;
        }
Пример #5
0
 public CsvData_GetInstance()
 {
     var instance = CsvData.GetInstance <BuildingData>();
 }
Пример #6
0
 public override void Execute()
 {
     CsvData.GetInstance <BuildingData>();
 }
Пример #7
0
        /// <summary/>
        protected internal override void FromJsonReader(JsonReader reader)
        {
            var instance = CsvData.GetInstance <ObstacleData>();
            // clear_t value.
            var clearTime    = -1;
            var clearTimeSet = false;

            var dataId    = -1;
            var dataIdSet = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                if (reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "id":
                        // Ignore for now.
                        break;

                    case "data":
                        dataId    = reader.ReadAsInt32().Value;
                        dataIdSet = true;
                        break;

                    case "clear_t":
                        clearTime    = reader.ReadAsInt32().Value;
                        clearTimeSet = true;
                        break;

                    case "x":
                        X = reader.ReadAsInt32().Value;
                        break;

                    case "y":
                        Y = reader.ReadAsInt32().Value;
                        break;

                    case "loot_multiply_ver":
                        LootMultiplier = reader.ReadAsInt32().Value;
                        break;
                    }
                }
            }

            if (!dataIdSet)
            {
                throw new InvalidOperationException($"Obstacle JSON at {reader.Path} does not contain a 'data' field.");
            }

            if (instance.InvalidDataID(dataId))
            {
                throw new InvalidOperationException($"Obstacle JSON at {reader.Path} contained an invalid ObstacleData ID. {instance.GetArgsOutOfRangeMessage("Data ID")}");
            }

            var tableCollection = Assets.DataTables;
            var dataRef         = new CsvDataRowRef <ObstacleData>(dataId);
            var data            = dataRef.Get(tableCollection)[0];

            if (data == null)
            {
                throw new InvalidOperationException("Could not find ObstacleData with ID '" + dataId + "'.");
            }

            _data = data;

            if (clearTimeSet)
            {
                Village.WorkerManager.AllocateWorker(this);
                _timer.Start(Village.LastTickTime, 0, clearTime);
            }
        }