Beispiel #1
0
        /// <summary>
        /// Set the value for a string in a string field.
        /// This is for a field that contains Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <param name="newValue">The new value for a string field.</param>
        /// <param name="convertVariablesToText">Convert variables to text?</param>
        public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, string newValue, bool convertVariablesToText = false)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the string type
            int itemType = action.actionFields[actionFieldID].ints[3];

            // convert variables to text
            if (convertVariablesToText)
            {
                bool useVariables = UseVariables(heroKitObject, actionFieldID);
                if (useVariables)
                {
                    newValue = InsertVariablesInString(heroKitObject, newValue);
                }
            }

            // No type specified
            if (itemType == 0)
            {
                Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return;
            }
            // set item in variable or property list
            else if (itemType == 1 || itemType == 2)
            {
                // Get the hero kit object
                HeroKitObject[] targetHKO = HeroObjectFieldValue.GetTargetHeroObjects(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return;
                }

                // Get the slot in the list that contains the integer
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the string from the string list
                if (itemType == 1)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        if (targetHKO[i].heroList.strings.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Variables", "String", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the string
                        targetHKO[i].heroList.strings.items[slotID].value = newValue;
                    }
                }

                // Get the string from the property list
                if (itemType == 2)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                        if (targetHKO[i].heroProperties == null || targetHKO[i].heroProperties.Length == 0 ||
                            targetHKO[i].heroProperties.Length <= propertyID || propertyID < 0 ||
                            targetHKO[i].heroProperties[propertyID].itemProperties.strings.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Properties", "String", slotID, 0, heroKitObject));
                            return;
                        }

                        targetHKO[i].heroProperties[propertyID].itemProperties.strings.items[slotID].value = newValue;
                    }
                }
            }
            // set item in global list
            if (itemType == 3)
            {
                // Get the slot in the list that contains the bool
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().strings.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "String", slotID, 0, heroKitObject));
                    return;
                }
                HeroKitDatabase.GetGlobals().strings.items[slotID].value = newValue;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Set the value for a game object in a game object field.
        /// This is for a field that contains Variable, Property, Global.
        /// </summary>
        /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param>
        /// <param name="actionFieldID">ID assigned to the action field.</param>
        /// <param name="newValue">The new value for a game object field.</param>
        public static void SetValueB(HeroKitObject heroKitObject, int actionFieldID, GameObject newValue)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the data type
            int itemType = action.actionFields[actionFieldID].ints[0];

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Game Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return;
            }
            // set item in variable or property list
            else if (itemType == 1 || itemType == 2)
            {
                // Get the hero kit object
                HeroKitObject[] targetHKO = HeroObjectFieldValue.GetTargetHeroObjects(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return;
                }

                // Get the slot in the list that contains the integer
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get the integer from the integer list
                if (itemType == 1)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        if (targetHKO[i].heroList.gameObjects.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Variables", "Game Object", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the integer
                        targetHKO[i].heroList.gameObjects.items[slotID].value = newValue;
                    }
                }

                // Get the integer from the property list
                if (itemType == 2)
                {
                    for (int i = 0; i < targetHKO.Length; i++)
                    {
                        int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

                        if (targetHKO[i].heroProperties == null || targetHKO[i].heroProperties.Length == 0 ||
                            targetHKO[i].heroProperties.Length <= propertyID || propertyID < 0 ||
                            targetHKO[i].heroProperties[propertyID].itemProperties.bools.items.Count <= slotID || slotID < 0)
                        {
                            Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO[i].heroObject.name, "Properties", "Game Object", slotID, 0, heroKitObject));
                            return;
                        }

                        // Set the integer
                        targetHKO[i].heroProperties[propertyID].itemProperties.gameObjects.items[slotID].value = newValue;
                    }
                }
            }
            // set item in global list
            if (itemType == 3)
            {
                // Get the slot in the list that contains the bool
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().gameObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Game Object", slotID, 0, heroKitObject));
                    return;
                }
                HeroKitDatabase.GetGlobals().gameObjects.items[slotID].value = newValue;
            }
        }