Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Help with BaseToggleAbility class  (Read 1783 times)

Paul_Kauphart

  • Ensign
  • *
  • Posts: 48
    • View Profile
Help with BaseToggleAbility class
« on: February 16, 2017, 01:31:58 AM »

Hello everyone,

I'm trying to create a new campaign ability by creating a new subclass of BaseToggleAbility. However I can't figure out the timing and use of some of the methods in BaseToggleAbility :

activateImpl, deactivateImpl, cleanupImpl -> When are these called ? How are they related to activate, deactivate and cleanup ?

applyEffect -> what value will level take ? when is the the method called with level = 0 and with level > 0 ?

getActivateCooldownDays, getDeactivateCooldownDays -> I kind of assume the cooldown here gives you the cooldown time after pressing the button to activate or deactivate the ability.

 getActivationDays, getDeactivationDays -> Time it takes for the ability to activate and deactivate ? How does that relate to applyEffect and *Impl methods ?

I have kind of hit a wall here, the starsector API doesn't give much details on these questions and I couldn't find any other documentation.

Thanks in advance for the help.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24146
    • View Profile
Re: Help with BaseToggleAbility class
« Reply #1 on: February 16, 2017, 09:32:34 AM »

The *Impl methods get called from the activate/deactivate/cleanup methods of the parent class.

activateImpl gets called when the ability is activated - i.e. the button is pressed in the UI, or an AI decides to use the ability. deactivateImpl gets called when it's deactivated - i.e. button press, the AI deciding to stop using it, OR a conflicting ability being activated.

cleanupImpl gets called if the ability is removed from the fleet while the ability is active.


applyEffect -> what value will level take ? when is the the method called with level = 0 and with level > 0 ?

getActivationDays, getDeactivationDays -> Time it takes for the ability to activate and deactivate ? How does that relate to applyEffect and *Impl methods ?

level is [0-1]. If the activation/deactivation days are 0, then level will only ever be 0 or 1. If they're non-zero, then level will ramp up and ramp down in that time.


Basically, the flow is:

activate
activateImpl
applyEffect with level = 1 if activationDays is 0, or 0.x if it's non-instantaneous
applyEffect with level = 1 or ramping up to 1 and then staying at 1 for however long
deactivate when ability is turned off
applyEffect with level = 0 if deactivationDays is 0, or 1 if it's non-instantaneous
deactivateImpl
applyEffect with level ramping down to 0, if deactivationDays > 0



I have kind of hit a wall here, the starsector API doesn't give much details on these questions and I couldn't find any other documentation.

If you haven't already, I'd suggest looking through the code for BaseToggleAbility; all the answers are there. Another thing that could help you figure it out is to create an ability that doesn't do anything except print stuff when the calls are made, so that you know the exact order, values passed in, etc.


(But I'll be happy to answer some more questions.)
Logged

Paul_Kauphart

  • Ensign
  • *
  • Posts: 48
    • View Profile
Re: Help with BaseToggleAbility class
« Reply #2 on: February 16, 2017, 10:24:26 AM »

Wait I can look at the code ?

Let me guess, the source are in the starsector install and I didn't bother to look because I never imagined they would actually be available here.

Otherwise thanks for the answer, it makes a lot of sense in my head now.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24146
    • View Profile
Re: Help with BaseToggleAbility class
« Reply #3 on: February 16, 2017, 10:40:01 AM »

The API source (i.e. not the source for the entire game, but just the modding-related API, and the stuff the game does that makes use of it internally) is in starsector-core/starfarer.api.zip.

In this case, since all campaign abilities are implemented "in the way a mod would do it", their source is in the api zip.
Logged