Beispiel #1
0
 private void LoadStamina(TagCompound tag)
 {
     if (tag.GetDouble("maxStamina") != 0)
     {
         MaxStamina = tag.GetDouble("maxStamina");
     }
 }
 public override void Load(TagCompound tag)
 {
     cookieCount       = tag.GetDouble("cookieCount");
     cookiesPerSecond  = tag.GetFloat("cookiesPerSecond");
     goldenCookieCount = tag.GetInt("goldenCookieCount");
     sugarLumpCount    = tag.GetInt("sugerLumpCount");
     timeOffMultiplier = (int)(DateTime.Now - Convert.ToDateTime(tag.GetString("exitTime"))).TotalSeconds;
 }
 public override void Load(TagCompound tag)
 {
     try
     {
         level            = tag.GetInt("level");
         currentXP        = tag.GetDouble("xp");
         damageMultiplier = tag.GetInt("damage");
         hpMultiplier     = tag.GetInt("hp");
     }
     catch
     {
     }
 }
Beispiel #4
0
    /// <summary>
    /// Try to get from tag, else default to specified value. Supports int, float, double, bool, long, string, int[], byte[]
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="tag"></param>
    /// <param name="key"></param>
    /// <param name="defaultValue"></param>
    /// <returns></returns>
    public static T TryGet <T>(TagCompound tag, string key, T defaultValue)
    {
        try
        {
            T    val;
            Type type = typeof(T);
            if (type == typeof(int))
            {
                val = (T)Convert.ChangeType(tag.GetInt(key), type);
            }
            else if (type == typeof(float))
            {
                val = (T)Convert.ChangeType(tag.GetFloat(key), type);
            }
            else if (type == typeof(double))
            {
                val = (T)Convert.ChangeType(tag.GetDouble(key), type);
            }
            else if (type == typeof(bool))
            {
                val = (T)Convert.ChangeType(tag.GetBool(key), type);
            }
            else if (type == typeof(long))
            {
                val = (T)Convert.ChangeType(tag.GetLong(key), type);
            }
            else if (type == typeof(string))
            {
                val = (T)Convert.ChangeType(tag.GetString(key), type);
            }
            else if (type == typeof(int[]))
            {
                val = (T)Convert.ChangeType(tag.GetIntArray(key), type);
            }
            else if (type == typeof(byte[]))
            {
                val = (T)Convert.ChangeType(tag.GetByteArray(key), type);
            }
            else
            {
                throw new Exception();
            }

            return(val);
        }
        catch
        {
            return(defaultValue);
        }
    }
Beispiel #5
0
        public void GetDouble_returns_null_item()
        {
            // arrange
            TagCompound target;
            Tag         actual;
            string      name;

            name = "alpha";

            target = new TagCompound();

            // act
            actual = target.GetDouble(name);

            // assert
            Assert.IsNull(actual);
        }
Beispiel #6
0
        public void GetDouble_returns_existing_tag()
        {
            // arrange
            TagCompound target;
            Tag         actual;
            string      name;

            name = "alpha";

            target = new TagCompound();
            target.Value.Add(name, 8.98846567431158E+307);

            // act
            actual = target.GetDouble(name);

            // assert
            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <TagDouble>(actual);
        }
Beispiel #7
0
        public override void Load(TagCompound tag)
        {
            peatSold  = tag.GetAsInt("peatSold");
            worldEvil = tag.GetByte("worldEvil");
            if (tag.ContainsKey("worldSurfaceLow"))
            {
                _worldSurfaceLow = tag.GetDouble("worldSurfaceLow");
            }
            if (tag.ContainsKey("defiledHearts"))
            {
                Defiled_Hearts = tag.Get <List <Vector2> >("defiledHearts").Select(Utils.ToPoint).ToList();
            }

            defiledResurgenceTiles = new List <(int, int)>()
            {
            };
            defiledAltResurgenceTiles = new List <(int, int, ushort)>()
            {
            };
        }
        ////////////////

        public void Load(TagCompound tag)
        {
            if (tag.ContainsKey("PirateDemand"))
            {
                this.PirateDemand = tag.GetLong("PirateDemand");
            }
            if (tag.ContainsKey("PirateDemandVariancePercent"))
            {
                this.PirateDemandVariancePercent = tag.GetDouble("PirateDemandVariancePercent");
            }
            if (tag.ContainsKey("RaidElapsedTicks"))
            {
                this.RaidElapsedTicks = tag.GetLong("RaidElapsedTicks");
            }
            if (tag.ContainsKey("TicksWhileNegotiatorAway"))
            {
                this.TicksWhileNegotiatorAway = tag.GetLong("TicksWhileNegotiatorAway");
            }
            if (tag.ContainsKey("TicksUntilNextArrival"))
            {
                this.TicksUntilNextArrival = tag.GetLong("TicksUntilNextArrival");
            }
        }
Beispiel #9
0
        private void TestNbt(TagCompound compoundTag)
        {
            var byteMin = compoundTag.GetByte("byte_min");

            Assert.AreEqual(-128, byteMin.Value);
            var byteMax = compoundTag.GetByte("byte_max");

            Assert.AreEqual(127, byteMax.Value);

            var shortMin = compoundTag.GetShort("short_min");

            Assert.AreEqual(-32768, shortMin.Value);
            var shortMax = compoundTag.GetShort("short_max");

            Assert.AreEqual(32767, shortMax.Value);

            var intMin = compoundTag.GetInt("int_min");

            Assert.AreEqual(-2147483648, intMin.Value);
            var intMax = compoundTag.GetInt("int_max");

            Assert.AreEqual(2147483647, intMax.Value);

            var longMin = compoundTag.GetLong("long_min");

            Assert.AreEqual(-9223372036854775808, longMin.Value);
            var longMax = compoundTag.GetLong("long_max");

            Assert.AreEqual(9223372036854775807, longMax.Value);

            var floatTag = compoundTag.GetFloat("float");

            Assert.AreEqual(12345.6f, floatTag.Value);

            var doubleTag = compoundTag.GetDouble("double");

            Assert.AreEqual(12345.6, doubleTag.Value);

            var byteArray = compoundTag.GetByteArray("byte_array");

            Assert.AreEqual(3, byteArray.Value.Length);
            Assert.AreEqual(0x12, byteArray.Value[0]);
            Assert.AreEqual(0x34, byteArray.Value[1]);
            Assert.AreEqual(0x56, byteArray.Value[2]);

            var stringTag = compoundTag.GetString("string");

            Assert.AreEqual("hello!", stringTag.Value);

            var list      = compoundTag.GetList("string_list");
            var listValue = list.GetArrayString();

            Assert.AreEqual(3, listValue.Length);
            Assert.AreEqual("i'm in an array!", listValue[0].Value);
            Assert.AreEqual("i am also in an array!", listValue[1].Value);
            Assert.AreEqual("walter", listValue[2].Value);

            var emptyList      = compoundTag.GetList("empty_list");
            var emptyListValue = emptyList.GetArrayByte();

            Assert.AreEqual(0, emptyListValue.Length);

            var listList      = compoundTag.GetList("list_list");
            var listListValue = listList.GetArrayList();

            Assert.AreEqual(3, listListValue.Length);
            var listListValue0 = listListValue[0].GetArrayFloat();

            Assert.AreEqual(3, listListValue0.Length);
            Assert.AreEqual(1.1f, listListValue0[0].Value);
            Assert.AreEqual(2.2f, listListValue0[1].Value);
            Assert.AreEqual(3.3f, listListValue0[2].Value);
            var listListValue1 = listListValue[1].GetArrayDouble();

            Assert.AreEqual(3, listListValue1.Length);
            Assert.AreEqual(4.4, listListValue1[0].Value);
            Assert.AreEqual(5.5, listListValue1[1].Value);
            Assert.AreEqual(6.6, listListValue1[2].Value);
            var listListValue2 = listListValue[2].GetArrayString();

            Assert.AreEqual(3, listListValue2.Length);
            Assert.AreEqual("wa", listListValue2[0].Value);
            Assert.AreEqual("ta", listListValue2[1].Value);
            Assert.AreEqual("shi", listListValue2[2].Value);

            var compound = compoundTag.GetCompound("compound");

            Assert.AreEqual(3, compound.Count);
            Assert.AreEqual(123, compound.GetByte("compound_byte").Value);
            Assert.AreEqual(694201337, compound.GetInt("compound_int").Value);
            Assert.AreEqual("*holds a gun to your temple*", compound.GetString("compound_string").Value);

            var emptyCompound = compoundTag.GetCompound("empty_compound");

            Assert.AreEqual(0, emptyCompound.Count);

            var intArray = compoundTag.GetIntArray("int_array");

            Assert.AreEqual(4, intArray.Value.Length);
            Assert.AreEqual(69, intArray.Value[0]);
            Assert.AreEqual(420, intArray.Value[1]);
            Assert.AreEqual(1337, intArray.Value[2]);
            Assert.AreEqual(117, intArray.Value[3]);

            var longArray = compoundTag.GetLongArray("long_array");

            Assert.AreEqual(4, longArray.Value.Length);
            Assert.AreEqual(69, longArray.Value[0]);
            Assert.AreEqual(420, longArray.Value[1]);
            Assert.AreEqual(1337, longArray.Value[2]);
            Assert.AreEqual(117, longArray.Value[3]);
        }
Beispiel #10
0
        public void TestLoadComplexNbt()
        {
            Tag tag;

            tag = this.CreateComplexData();

            Assert.IsNotNull(tag);
            Assert.IsInstanceOf <TagCompound>(tag);
            TagCompound level = tag as TagCompound;

            Assert.AreEqual("Level", level.Name);

            TagShort shortTest = level.GetShort("shortTest");

            Assert.IsNotNull(shortTest);
            Assert.AreEqual("shortTest", shortTest.Name);
            Assert.AreEqual(32767, shortTest.Value);

            TagLong longTest = level.GetLong("longTest");

            Assert.IsNotNull(longTest);
            Assert.AreEqual("longTest", longTest.Name);
            Assert.AreEqual(9223372036854775807, longTest.Value);

            TagFloat floatTest = level.GetFloat("floatTest");

            Assert.IsNotNull(floatTest);
            Assert.AreEqual("floatTest", floatTest.Name);
            Assert.AreEqual(0.49823147f, floatTest.Value);

            TagString stringTest = level.GetString("stringTest");

            Assert.IsNotNull(stringTest);
            Assert.AreEqual("stringTest", stringTest.Name);
            Assert.AreEqual("HELLO WORLD THIS IS A TEST STRING едж!", stringTest.Value);

            TagInt intTest = level.GetInt("intTest");

            Assert.IsNotNull(intTest);
            Assert.AreEqual("intTest", intTest.Name);
            Assert.AreEqual(2147483647, intTest.Value);

            TagCompound nestedCompoundTest = level.GetCompound("nested compound test");

            Assert.IsNotNull(nestedCompoundTest);
            Assert.AreEqual("nested compound test", nestedCompoundTest.Name);

            TagCompound ham = nestedCompoundTest.GetCompound("ham");

            Assert.IsNotNull(ham);
            Assert.AreEqual("ham", ham.Name);

            TagString ham_name = ham.GetString("name");

            Assert.IsNotNull(ham_name);
            Assert.AreEqual("name", ham_name.Name);
            Assert.AreEqual("Hampus", ham_name.Value);

            TagFloat ham_value = ham.GetFloat("value");

            Assert.IsNotNull(ham_value);
            Assert.AreEqual("value", ham_value.Name);
            Assert.AreEqual(0.75f, ham_value.Value);

            TagCompound egg = nestedCompoundTest.GetCompound("egg");

            Assert.IsNotNull(egg);
            Assert.AreEqual("egg", egg.Name);

            TagString egg_name = egg.GetString("name");

            Assert.IsNotNull(egg_name);
            Assert.AreEqual("name", egg_name.Name);
            Assert.AreEqual("Eggbert", egg_name.Value);

            TagFloat egg_value = egg.GetFloat("value");

            Assert.IsNotNull(egg_value);
            Assert.AreEqual("value", egg_value.Name);
            Assert.AreEqual(0.5f, egg_value.Value);

            TagByte byteTest = level.GetByte("byteTest");

            Assert.IsNotNull(byteTest);
            Assert.AreEqual("byteTest", byteTest.Name);
            Assert.AreEqual(0x7f, byteTest.Value);

            TagDouble doubleTest = level.GetDouble("doubleTest");

            Assert.IsNotNull(doubleTest);
            Assert.AreEqual("doubleTest", doubleTest.Name);
            Assert.AreEqual(0.4931287132182315, doubleTest.Value);

            TagList listTest_long = level.GetList("listTest (long)");

            Assert.IsNotNull(listTest_long);
            Assert.AreEqual("listTest (long)", listTest_long.Name);
            Assert.IsNotNull(listTest_long.Value);
            Assert.AreEqual(5, listTest_long.Value.Count);
            Assert.AreEqual(11, (listTest_long.Value[0] as TagLong).Value);
            Assert.AreEqual(12, (listTest_long.Value[1] as TagLong).Value);
            Assert.AreEqual(13, (listTest_long.Value[2] as TagLong).Value);
            Assert.AreEqual(14, (listTest_long.Value[3] as TagLong).Value);
            Assert.AreEqual(15, (listTest_long.Value[4] as TagLong).Value);

            TagList listTest_compound = level.GetList("listTest (compound)");

            Assert.IsNotNull(listTest_compound);
            Assert.AreEqual("listTest (compound)", listTest_compound.Name);
            Assert.IsNotNull(listTest_compound.Value);
            Assert.AreEqual(2, listTest_compound.Value.Count);
            TagCompound listTest_compound_tag0 = listTest_compound.Value[0] as TagCompound;

            Assert.IsNotNull(listTest_compound_tag0);
            TagString listTest_compound_tag0_name = listTest_compound_tag0.GetString("name");

            Assert.IsNotNull(listTest_compound_tag0_name);
            Assert.AreEqual("name", listTest_compound_tag0_name.Name);
            Assert.AreEqual("Compound tag #0", listTest_compound_tag0_name.Value);
            TagLong listTest_compound_tag0_createdOn = listTest_compound_tag0.GetLong("created-on");

            Assert.IsNotNull(listTest_compound_tag0_createdOn);
            Assert.AreEqual("created-on", listTest_compound_tag0_createdOn.Name);
            Assert.AreEqual(1264099775885, listTest_compound_tag0_createdOn.Value);

            TagCompound listTest_compound_tag1 = listTest_compound.Value[1] as TagCompound;

            Assert.IsNotNull(listTest_compound_tag1);
            TagString listTest_compound_tag1_name = listTest_compound_tag1.GetString("name");

            Assert.IsNotNull(listTest_compound_tag1_name);
            Assert.AreEqual("name", listTest_compound_tag1_name.Name);
            Assert.AreEqual("Compound tag #1", listTest_compound_tag1_name.Value);
            TagLong listTest_compound_tag1_createdOn = listTest_compound_tag1.GetLong("created-on");

            Assert.IsNotNull(listTest_compound_tag1_createdOn);
            Assert.AreEqual("created-on", listTest_compound_tag1_createdOn.Name);
            Assert.AreEqual(1264099775885, listTest_compound_tag1_createdOn.Value);

            TagByteArray byteArrayTest = level.GetByteArray("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))");

            Assert.IsNotNull(byteArrayTest);
            Assert.AreEqual("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", byteArrayTest.Name);
            Assert.IsNotNull(byteArrayTest.Value);
            Assert.AreEqual(1000, byteArrayTest.Value.Length);
        }
Beispiel #11
0
 public static void Load(TagCompound tag)
 {
     SpawnTime = tag.GetDouble(SerializeKeySpawnTime);
     ShopItems = tag.Get <List <Item> >(SerializeKeyShopItems);
 }
Beispiel #12
0
 public static void Load(TagCompound tag)
 {
     spawnTime = tag.GetDouble("spawnTime");
     shopItems = tag.Get <List <Item> >("shopItems");
 }
Beispiel #13
0
 public override void Load(TagCompound tag)
 {
     multiplier   = tag.GetDouble(nameof(multiplier));
     enableGrowth = tag.GetBool(nameof(enableGrowth));
 }
Beispiel #14
0
 public override void Load(TagCompound tag)
 {
     XritoMod.Instance.clickerGUI.points = tag.GetDouble("terraPoints");
 }