/// <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); }
/// <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); }
/// <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); }
/// <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); }