Exemplo n.º 1
0
        /// <summary>
        /// Get a value from a string field.
        /// This is for a field that contains Value, 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 action field A.</param>
        /// <param name="convertVariablesToText">Convert variables to text?</param>
        /// <returns>The value from a string field.</returns>
        public static string GetValueA(HeroKitObject heroKitObject, int actionFieldID, bool convertVariablesToText = false)
        {
            // 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[3];
            string        itemValue = "";
            HeroKitObject targetHKO = null;

            if (itemType == 0)
            {
                Debug.LogError("String type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return("");
            }
            // get string from field
            else if (itemType == 1)
            {
                itemValue = action.actionFields[actionFieldID].strings[1];
                targetHKO = heroKitObject;
            }
            // get string from variable field or property field
            else if (itemType == 2 || itemType == 3)
            {
                // Get the hero kit object
                targetHKO = HeroObjectFieldValue.GetTargetHeroObject(heroKitObject, actionFieldID);
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return("");
                }

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

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

                // Get the string from property list
                if (itemType == 3)
                {
                    int propertyID = action.actionFields[actionFieldID].ints[5] - 1;

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

                    itemValue = targetHKO.heroProperties[propertyID].itemProperties.strings.items[slotID].value;
                }
            }
            // get string from global field
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the string
                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("");
                }
                itemValue = HeroKitDatabase.GetGlobals().strings.items[slotID].value;
            }

            // localize the text
            itemValue = HeroKitDatabase.GetLocalization(itemValue);

            // convert variables into text
            if (convertVariablesToText)
            {
                bool useVariables = (itemType > 1) ? UseVariables(heroKitObject, actionFieldID) : true;
                if (useVariables)
                {
                    itemValue = InsertVariablesInString(targetHKO, itemValue);
                }
            }

            // Return the string
            return(itemValue);
        }