Skip to content
Blanc Faye edited this page Jun 20, 2021 · 8 revisions

Overview of the API

The mod itself uses the API to implement the Beam Drone (LaserDrone1) which is a custom entity along with its custom attack (FireLaser). This custom drone also has Option Support. Use it for reference on using the API.

Setting up the drone using the provided DroneCatalog

myCustomDronesList = DroneCatalog.Initialize("com.awesome.mod.guid", someConfigFile);
DroneCatalog.SetupAll(myCustomDronesList);

Creating a custom drone class by inheriting Drone

public class MyCustomDrone : Drone<MyCustomDrone>
{
    // Implementation
}

Accessing the instance of the singleton drone class

// This will only work after DroneCatalog.Initialize() is done
MyCustomDrone drone = MyCustomDrone.instance;
drone.enabled; // true or false

Always use the base method when implementing the available virtual methods

protected override void SetupConfig()
{
    base.SetupConfig();
    // other code
}

// For PostSetup, it is ideal to call the base method last
protected override void PostSetup()
{
    // other code
    base.PostSetup();
}

Executing code for all the Options of a drone

GradiusOption.instance.FireForAllOptions(droneBody, (option, behavior, target, direction) =>
{
    new BulletAttack
    {
        owner = droneBody.gameObject,
        weapon = option,
        // remember to multiply damageMultiplier so that the config option
        // for GradiusOption is respected for your custom drone
        damage = damage * coefficient * GradiusOption.instance.damageMultiplier,
        // do the same for force
        force = force * GradiusOption.instance.damageMultiplier, 
        // other initialization here
    }.Fire();
});

Storing and Accessing Option Data

// ChargeState.cs
// One may store effect data or child locators in OptionBehavior behavior through
// the Data Dictionary so that they can be accessed in between states or classes
private void OnEnter()
{
    OptionBehavior behavior = option.GetComponent<OptionBehavior>();
    behavior.unityData["MuzzleEffect"] = UnityEngine.Object.Instantiate(myPrefab);
}
// FiringState.cs
private void FixedUpdate()
{
    OptionBehavior behavior = option.GetComponent<OptionBehavior>();
    // Access the stored data for usage
    GameObject myEffect = (GameObject)behavior.unityData["MuzzleEffect"];
}

Executing code for Option Seeds of an owner

OptionSeed.instance.FireForSeeds(characterBody, (seed, behavior, tracker, multiplier) =>
{
    new BulletAttack
    {
        owner = characterBody.gameObject,
        weapon = option,
        // remember to multiply the computer multiplier given so that the config option
        // for OptionSeed's damage is respected
        damage = damage * coefficient * multiplier,
        // do the same for force
        force = force * multiplier, 
        // other initialization here
    }.Fire();
});

Storing and Accessing Option Seed Data

// ChargeState.cs
// One may store effect data or child locators in SeedBehavior as well just like with OptionBehavior through
// the Data Dictionary so that they can be accessed in between states or classes
private void OnEnter()
{
    OptionSeed.instance.FireForSeeds(characterBody, (seed, behavior, tracker, multiplier) =>
    {
        behavior.unityData["MuzzleEffect"] = myGameObjectEffectPrefab;
    });
}
// FiringState.cs
private void FixedUpdate()
{
    OptionSeed.instance.FireForSeeds(characterBody, (seed, behavior, tracker, multiplier) =>
    {
        GameObject myEffect = (GameObject)behavior.unityData["MuzzleEffect"];
    });
}

Implementing DroneDeathBehavior for a Custom Drone

public class MyDroneDeathState : DroneDeathState
{
    // Implement the abstract class and methods
    protected override bool SpawnInteractable { get; set; } = MyCustomDrone.instance.canBeRepurchased;
    protected override InteractableSpawnCard GetInteractableSpawnCard => MyCustomDrone.instance.interactableSpawnCard;
}
// Assign the state to the custom drone's CharacterDeathBehavior Component
GameObject droneBodyPrefab = MyCustomDrone.instance.droneBodyObject;
droneBodyPrefab.GetComponent<CharacterDeathBehavior>().deathState = new SerializableEntityStateType(typeof(MyDroneDeathState));

// Or just use the extension method provided
CharacterMaster master = MyCustomDrone.instance.droneMaster;
master.AssignDeathBehavior(typeof(MyDroneDeathState));