Пример #1
0
        /// <summary>
        /// Get the template assigned to a hero 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 action field A.</param>
        /// <returns>The template assigned to a hero object field.</returns>
        public static HeroObject GetValueC(HeroKitObject heroKitObject, int actionFieldID)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // set up the target hero object type
            HeroObject targetHeroObject = null;

            // Get the game object data
            HeroObjectFieldData goData = new HeroObjectFieldData();

            goData.heroKitObject = heroKitObject;
            goData.heroList      = goData.heroKitObject.heroList;
            goData.objectType    = action.actionFields[actionFieldID].ints[0];
            goData.objectID      = action.actionFields[actionFieldID].ints[1];
            goData.heroGUID      = action.actionFields[actionFieldID].ints[4];
            goData.propertyID    = action.actionFields[actionFieldID].ints[5];

            // get hero object from a file
            if (goData.objectType == 1)
            {
                targetHeroObject = action.actionFields[actionFieldID].heroObjects[0];
            }
            // get hero object from elsewhere
            else
            {
                targetHeroObject = HeroObjectTargetField.GetTemplate(goData);
            }

            return(targetHeroObject);
        }
Пример #2
0
        /// <summary>
        /// Get a hero kit object from a conditional int field on an event.
        /// </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>
        /// <returns>A hero kit object from a conditional int field on an event.</returns>
        public static HeroKitObject GetValueEvent(HeroKitObject heroKitObject, ConditionIntField itemField)
        {
            // Get the game object
            HeroObjectFieldData goData = new HeroObjectFieldData();

            goData.heroKitObject = heroKitObject;
            goData.heroList      = goData.heroKitObject.heroList;
            goData.objectType    = itemField.objectType;
            goData.objectID      = itemField.objectID;
            goData.heroGUID      = itemField.heroGUID;
            goData.propertyID    = itemField.propertyID;

            // Get the hero kit object
            HeroKitObject targetHKO = HeroObjectTargetField.GetValue(goData)[0];

            if (targetHKO == null)
            {
                Debug.LogError("No hero kit object was found for this event." + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                return(null);
            }

            // If we are working with a hero object in the scene or a property or variable field, make sure it matches the object we want to work with.
            if (heroKitObject.debugHeroObject && goData.objectType != 1)
            {
                // make sure we're working with the right kind of hero object inside the hero kit object
                HeroObject expectedHeroObject = itemField.heroObject;
                HeroObject thisHeroObject     = targetHKO.heroObject;
                if (expectedHeroObject != null && (expectedHeroObject != thisHeroObject))
                {
                    Debug.LogWarning("Wrong hero object for this event. Expected " + expectedHeroObject.name + " but got " + thisHeroObject.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                }
            }

            return(targetHKO);
        }
Пример #3
0
        /// <summary>
        /// Get the GUID of the first hero kit object in a hero object field.
        /// </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>
        /// <returns>The GUID of the first hero kit object in a hero object field.</returns>
        public static int GetValueD(HeroKitObject heroKitObject, int actionFieldID)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[heroKitObject.heroStateData.eventBlock].actions[heroKitObject.heroStateData.action];

            // Get the game object
            HeroObjectFieldData goData = new HeroObjectFieldData();

            goData.heroGUID = action.actionFields[actionFieldID].ints[4];

            return(goData.heroGUID);
        }
Пример #4
0
        /// <summary>
        /// Get a hero object template in a hero object list.
        /// </summary>
        /// <param name="list">The hero object list in a hero object.</param>
        /// <param name="data">Information about hero object field.</param>
        /// <returns>The hero object template in a hero object list.</returns>
        private static HeroObject GetHeroTemplate(HeroObjectList list, HeroObjectFieldData data, string listType)
        {
            int slotID = data.objectID - 1;

            // exit early if there is no game object list item
            if (slotID < 0 || slotID >= list.items.Count)
            {
                Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectInListDebugInfo(data.heroKitObject, listType, slotID));
                return(null);
            }

            HeroObject targetObject = list.items[slotID].value;

            return(targetObject);
        }
Пример #5
0
        /// <summary>
        /// Get the template assigned to a hero object field.
        /// </summary>
        /// <param name="data">Information about hero object field.</param>
        /// <returns>The hero object in a hero object field.</returns>
        public static HeroObject GetTemplate(HeroObjectFieldData data)
        {
            HeroObject heroObject = null;

            // return game object attached to this hero object as value (not done here)

            // return this hero object
            if (data.objectType == 2)
            {
                heroObject = data.heroKitObject.heroObject;
            }

            // return a hero object in variables
            else if (data.objectType == 3)
            {
                heroObject = GetHeroTemplate(data.heroKitObject.heroList.heroObjects, data, "Variables");
            }

            // return a hero object in the scene
            else if (data.objectType == 4)
            {
                // get the hero object in the scene using its GUID
                HeroKitObject hko = HeroKitDatabase.GetHeroKitObject(data.heroGUID);
                if (hko != null)
                {
                    heroObject = hko.heroObject;
                }
            }

            // return a hero object in properties
            else if (data.objectType == 5)
            {
                heroObject = GetHeroTemplate(data.heroKitObject.heroProperties[data.propertyID - 1].itemProperties.heroObjects, data, "Properties");
            }

            // return a hero object in globals
            else if (data.objectType == 6)
            {
                heroObject = GetHeroTemplate(data.heroKitObject.heroGlobals.heroObjects, data, "Globals");
            }

            return(heroObject);
        }
Пример #6
0
        /// <summary>
        /// Get hero kit objects in a hero object list.
        /// </summary>
        /// <param name="list">The hero object list in a hero object.</param>
        /// <param name="data">Information about hero object field.</param>
        /// <returns>The hero kit objects in a hero object list.</returns>
        private static HeroKitObject[] GetHeroList(HeroObjectList list, HeroObjectFieldData data, string listType)
        {
            int slotID = data.objectID - 1;

            HeroKitObject[] targetObject = new HeroKitObject[1];

            // exit early if there is no game object list item
            if (slotID < 0 || slotID >= list.items.Count)
            {
                Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectInListDebugInfo(data.heroKitObject, listType, slotID));
                return(targetObject);
            }

            // get the target objects
            if (list.items[slotID].heroKitGameObjects != null)
            {
                targetObject = list.items[slotID].heroKitGameObjects.ToArray();
            }

            return(targetObject);
        }
Пример #7
0
        /// <summary>
        /// Get a hero kit object in the scene with specific event ID and action ID.
        /// </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>
        /// <returns>A hero kit object in the scene.</returns>
        public static HeroKitObject[] GetTargetHeroObject(HeroKitObject heroKitObject, int eventID, int actionID, int actionFieldID)
        {
            // Get the action
            HeroAction action = heroKitObject.heroState.heroEvent[eventID].actions[actionID];

            // Get the game object
            HeroObjectFieldData goData = new HeroObjectFieldData();

            goData.heroKitObject = heroKitObject;
            goData.heroList      = goData.heroKitObject.heroList;
            goData.objectType    = action.actionFields[actionFieldID].ints[0];
            goData.objectID      = action.actionFields[actionFieldID].ints[1];
            goData.heroGUID      = action.actionFields[actionFieldID].ints[4];
            goData.propertyID    = action.actionFields[actionFieldID].ints[5];

            // Get the hero kit object
            HeroKitObject[] targetHKO = HeroObjectTargetField.GetValue(goData);
            if (targetHKO == null)
            {
                Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, null, goData.heroKitObject));
                return(null);
            }

            // If we are working with a hero object in the scene or a property or variable field, make sure it matches the object we want to work with.
            if (heroKitObject.debugHeroObject && goData.objectType != 1)
            {
                // make sure we're working with the right kind of hero object inside the hero kit object
                HeroObject expectedHeroObject = action.actionFields[actionFieldID].heroObjects[0];
                HeroObject thisHeroObject     = (targetHKO.Length == 0 || targetHKO[0] == null) ? null : targetHKO[0].heroObject;
                if (expectedHeroObject != null && thisHeroObject != null && (expectedHeroObject != thisHeroObject))
                {
                    Debug.LogWarning("Wrong hero object for this action. Expected " + expectedHeroObject.name + " but got " + thisHeroObject.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                }
            }

            return(targetHKO);
        }
Пример #8
0
        /// <summary>
        /// Get the hero kit objects that are the target of an action.
        /// </summary>
        /// <param name="data">Information about hero object field.</param>
        /// <returns>A list of hero kit objects.</returns>
        public static HeroKitObject[] GetValue(HeroObjectFieldData data)
        {
            HeroKitObject[] heroKitObject = new HeroKitObject[1];

            // return game object attached to this hero object
            if (data.objectType == 1)
            {
                heroKitObject[0] = data.heroKitObject;
            }

            // return a game object in this hero object's game object list (in variables)
            else if (data.objectType == 2)
            {
                heroKitObject = GetHeroList(data.heroKitObject.heroList.heroObjects, data, "Variables");
            }

            // return a game object in the scene
            else if (data.objectType == 3)
            {
                // get the game object in the scene using its GUID
                heroKitObject[0] = HeroKitDatabase.GetHeroKitObject(data.heroGUID);
            }

            // return a game object in this hero object's game object list (in properties)
            else if (data.objectType == 4)
            {
                heroKitObject = GetHeroList(data.heroKitObject.heroProperties[data.propertyID - 1].itemProperties.heroObjects, data, "Properties");
            }

            // return a game object in this hero object's game object list (in globals)
            else if (data.objectType == 5)
            {
                heroKitObject = GetHeroList(HeroKitDatabase.globals.heroObjects, data, "Globals");
            }

            return(heroKitObject);
        }
Пример #9
0
        /// <summary>
        /// Get a value from a hero object 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>
        /// <returns>The value from a hero object field.</returns>
        public static HeroKitObject[] GetValueA(HeroKitObject heroKitObject, int actionFieldID)
        {
            // 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];

            HeroKitObject[] itemValue = new HeroKitObject[1];

            // don't get item. Item type was never specified
            if (itemType == 0)
            {
                Debug.LogError("Hero Object type was never specified for " + action.actionTemplate.name + " " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                return(new HeroKitObject[1]);
            }
            // Get item from value
            else if (itemType == 1)
            {
                HeroKitObject[] targetHKO = GetTargetHeroObjects(heroKitObject, actionFieldID);
                itemValue = targetHKO;
            }
            // Get the item from variable or property
            else if (itemType == 2 || itemType == 3)
            {
                // Get the game object
                HeroObjectFieldData goData = new HeroObjectFieldData();
                goData.heroKitObject = heroKitObject;
                goData.heroList      = goData.heroKitObject.heroList;
                goData.objectType    = action.actionFields[actionFieldID].ints[0];
                goData.objectID      = action.actionFields[actionFieldID].ints[1];
                goData.heroGUID      = action.actionFields[actionFieldID].ints[4];
                goData.propertyID    = action.actionFields[actionFieldID].ints[5];

                // Get the hero kit object
                HeroKitObject targetHKO = HeroObjectTargetField.GetValue(goData)[0];
                if (targetHKO == null)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoHeroKitObjectDebugInfo(action.actionTemplate.name, 0, heroKitObject));
                    return(new HeroKitObject[1]);
                }

                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                // Get item from variable
                if (itemType == 2)
                {
                    if (targetHKO.heroList.heroObjects.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Variables", "Hero Object", slotID, 0, heroKitObject));
                        return(new HeroKitObject[1]);
                    }

                    if (targetHKO.heroList.heroObjects.items[slotID].heroKitGameObjects != null)
                    {
                        itemValue = targetHKO.heroList.heroObjects.items[slotID].heroKitGameObjects.ToArray();
                    }
                }
                // Get item from property
                else 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.bools.items.Count <= slotID || slotID < 0)
                    {
                        Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, targetHKO.heroObject.name, "Properties", "Hero Object", slotID, 0, heroKitObject));
                        return(new HeroKitObject[1]);
                    }

                    if (targetHKO.heroProperties[propertyID].itemProperties.heroObjects.items[slotID].heroKitGameObjects != null)
                    {
                        itemValue = targetHKO.heroProperties[propertyID].itemProperties.heroObjects.items[slotID].heroKitGameObjects.ToArray();
                    }
                }

                // If we are working with a hero object in the scene or a property or variable field, make sure it matches the object we want to work with.
                if (heroKitObject.debugHeroObject && goData.objectType != 1 && itemValue != null)
                {
                    // make sure we're working with the right kind of hero object inside the hero kit object
                    HeroObject expectedHeroObject = action.actionFields[actionFieldID].heroObjects[0];
                    HeroObject thisHeroObject     = itemValue[0].heroObject;
                    if (expectedHeroObject != null && thisHeroObject != null && (expectedHeroObject != thisHeroObject))
                    {
                        Debug.LogWarning("Wrong hero object for this action. Expected " + expectedHeroObject.name + " but got " + thisHeroObject.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(goData.heroKitObject));
                    }
                }
            }
            // get from global field
            else if (itemType == 4)
            {
                // Get the slot in the list that contains the bool
                int slotID = action.actionFields[actionFieldID].ints[2] - 1;

                if (HeroKitDatabase.GetGlobals().heroObjects.items.Count <= slotID || slotID < 0)
                {
                    Debug.LogError(HeroKitCommonRuntime.NoVariableDebugInfo(action.actionTemplate.name, "n/a", "Globals", "Hero Object", slotID, 0, heroKitObject));
                    return(new HeroKitObject[1]);
                }

                if (HeroKitDatabase.GetGlobals().heroObjects.items[slotID].heroKitGameObjects != null)
                {
                    itemValue = HeroKitDatabase.GetGlobals().heroObjects.items[slotID].heroKitGameObjects.ToArray();
                }
            }

            if (itemValue == null)
            {
                Debug.LogError("No hero kit object was found for " + action.actionTemplate.name + ". " + HeroKitCommonRuntime.GetHeroDebugInfo(heroKitObject));
                itemValue = new HeroKitObject[1];
            }

            return(itemValue);
        }