API & Integration with ABC

ABC IEntity

ABC IEntity is a static class which sits in the middle of all core components of ABC holding information regarding the entity. It acts as a bridge between the core components for communication and function calling, similar to an API. It also architecturally is used to store a lot of reference points to save on performance.

"Originator" is a IEntity property which is used in many functions and generally means the entity which activates the ability

Using ABC IEntity's API

This class can also be used as an API to execute ABC functions and features from your own scripts like triggering an ability or equipping a weapon. To use the API simply execute the following code from anywhere in your own scripts:

    //object/character to call API for
    ABC_IEntity abcEntity = ABC_Utilities.GetStaticABCEntity(gameObject);

    abcEntity.TriggerAbility("Fireball"); //trigger ability by name
    abcEntity.TriggerAbility(123456); // trigger ability by ID

    abcEntity.EquipWeapon("1H Sword"); //equip weapon by name
    abcEntity.EquipWeapon(123456); //equip weapon by ID

    abcEntity.AdjustHealth(-20); //adjust health of entity
    abcEntity.AdjustMaxHealth(200) //adjust max health

Overriding ABC IEntity (Plugging in your own systems)

This class can also be extended and overriden to plug in your own systems or modify the base code that comes with ABC.

An example of this is if you want to use your own health management system instead of ABC's system. To do this you can override the AdjustHealth method so that anytime ABC calls this class to reduce health (like from an ability effect) it will instead run your override code and call your own component replacing ABC's original function.

The best way to override a function is to copy the ABC_IEntity partial class file then rename the file. Once done you can override the functions in this new script. This ensures future updates will not revert your changes.

namespace ABCToolkit {
    /// <summary>
    ///Overrides ABC_IEntity to call over methods in another component
    /// </remarks>
    public partial class ABC_IEntity : ABC_IEntityBase {

        // Reference to your own component
        private Controller _meController;

        //Getter
        private Controller MeController {
            get {
                //Get component if first time
                if (this._meController == null) {
                    this._meController = this.gameObject.GetComponent<Controller>();
                }

                return this._meController;
            }
        }

        /// <summary>
        /// When ABC calls for MaxHealthValue instead get the max health from MyController Component
        /// </summary>
        public override float maxHealthValue => MeController.GetStats().maxHealth;

        /// <summary>
        /// When ABC calls for health value instead get the health from MyController Component
        /// </summary>
        public override float healthValue => MeController.GetStats().currentHealth;


        /// <summary>
        /// Instead of adjusting the max health in ABC instead adjust it in my controller component
        /// </summary>
        public override void AdjustMaxHealth(float Amount, bool RestoreHealth = false) {
            MeController.GetStats().maxHealth += (int)Amount;
        }

        /// <summary>
        /// Instead of adjusting the health in ABC instead adjust it in my controller component
        /// </summary>
        public override void AdjustHealth(float Potency) {
            MeController.GetStats().currentHealth += (int)Potency;
        }
    }
}

Effect Subscriber Component

A script component is available named ABC EffectEventSubscriber which will allow for you to easily integrate other components when effects are applied and/or removed. When an entity is inflicted by a certain effect you can link that to call other methods in your own scripts.

You can for example make an ability which when used will apply a custom "interact" effect to near by objects. The nearby objects with the effect subscriber component attached will listen for the "interact effect", running certain methods once the effect is applied.

Doing this you can simulate a character opening a door - the character can have the interact effect ability and the door can have the event subscriber.

Setting up the Effect Subscriber

1. Add the ABC_EffectEventSubscriber component to the entity which will listen for effects applied to itself.

2. Change the size of the Custom Effect Events or Custom Effect Removal Events. Each increment allows for an extra custom effect to listen out for.

3. Enter the name of the Effect you want the subscriber to listen for in the "Effect Name" text box

4. Add a Unity Event by pressing the "+" button. The Unity Event we are about to setup here will determine what function(s) to call once the custom effect defined in step 3 is added/removed.

5. Find and select the GameObject which holds the component and the method you wish to invoke when the custom effect is added and or removed. Once the Gameobject is selected drag it into the box below the "Runtime Only" dropdown.

This GameObject does not have to be the same entity that has the subscriber component attached, so it is possible to have an entity which just listens out for certain effects which then runs methods on other Objects.

6. Once the GameObject has been inserted the dropdown to the right of the "Runtime Only" dropdown will become avaliable enabling you to selection the function which will run.

7. Setup has been completed. Now the function selected will be called every time the entity with the ABC EffectEventSubscriber component is inflicted with an Effect that matches the text in the "Effect Name" box.

For an ability effect to raise the event picked up by the ABC_EffectEventSubscriber the effects Event Type needs to be either "Raise Event" or "Both Simultaniously". Information on changing the effects Event Type can be found by clicking the following link: Event Type

Last updated