Example #1
0
        public static void Test_ConvertUpdateFieldGameObject_Converts_All_Values([Range((int)EObjectFields_Vanilla.OBJECT_END, (int)EGameObjectFields_Vanilla.OBJECT_END - 1)] int fieldNumber)
        {
            //arrange
            EGameObjectFields_Vanilla vanillaGameObjectField = (EGameObjectFields_Vanilla)fieldNumber;

            //act
            bool?result     = null;
            int  shiftValue = 0;

            Assert.DoesNotThrow(() => result = VanillaToWotlkConverter.ConvertUpdateFieldsGameObject(vanillaGameObjectField, out shiftValue), $"Field: {fieldNumber}:{vanillaGameObjectField}:{fieldNumber:X} is not converted.");
            int newFieldNumber = (shiftValue + fieldNumber);

            //Assert
            Assert.NotNull(result);
            Assert.True(newFieldNumber >= (int)EObjectFields_Vanilla.OBJECT_END && newFieldNumber <= (int)EGameObjectFields_Vanilla.OBJECT_END, $"Failed for {fieldNumber}:0x{fieldNumber:X}:{((EGameObjectFields_Vanilla)fieldNumber).ToString()}");
        }
        /// <summary>
        /// Produces a shift value offset that can be used to
        /// map the provided <see cref="gameObjectFieldValue"/> to the
        /// <see cref="EGameObjectFields"/> for wotlk.
        /// </summary>
        /// <param name="gameObjectFieldValue">The unit field value to shift.</param>
        /// <param name="shiftValue">The value of the shift.</param>
        /// <returns>Indicates if the value should be written. This return is important. Don't write it if this returns false.</returns>
        public static bool ConvertUpdateFieldsGameObject(EGameObjectFields_Vanilla gameObjectFieldValue, out int shiftValue)
        {
            int  shiftAmount = 0;
            bool shouldWrite = true;
            int  i           = (int)gameObjectFieldValue;

            //Gameobject fields don't need to be shifted but many don't exist in 3.3.5
            //TODO: Handle the rest of the game object fields. Can't do POS_X, POS_Y and etc.
            if (i >= (int)EGameObjectFields_Vanilla.GAMEOBJECT_STATE && i <= (int)EGameObjectFields_Vanilla.GAMEOBJECT_DYN_FLAGS)
            {
                shouldWrite = false;
            }
            else if (i > (int)EGameObjectFields_Vanilla.GAMEOBJECT_DYN_FLAGS && i <= (int)EGameObjectFields_Vanilla.GAMEOBJECT_FACTION)
            {
                shiftAmount = (int)EGameObjectFields.GAMEOBJECT_DYNAMIC - (int)EGameObjectFields_Vanilla.GAMEOBJECT_DYN_FLAGS;
            }
            else if (i == (int)EGameObjectFields_Vanilla.GAMEOBJECT_LEVEL)
            {
                shiftAmount = (int)EGameObjectFields.GAMEOBJECT_LEVEL - (int)EGameObjectFields_Vanilla.GAMEOBJECT_LEVEL;
            }

            shiftValue = shiftAmount;
            return(shouldWrite);
        }