Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2

Author Topic: Adding passive bonuses to piloted ship.  (Read 5596 times)

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Adding passive bonuses to piloted ship.
« on: February 22, 2017, 09:09:01 AM »

Is it currently possible to do that?
I would like to add certain stat boosts to ship i am currently piloting and I want it to work globally (Including in the missions)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #1 on: February 22, 2017, 09:31:25 AM »

Yeah - add an EveryFrameCombatPlugin implementation in data/scripts/plugins, and do whatever you want to do there. The plugin will run in every combat, regardless of whether it's in a mission, campaign, simulator, etc.
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #2 on: February 22, 2017, 09:48:06 AM »

Yeah - add an EveryFrameCombatPlugin implementation in data/scripts/plugins, and do whatever you want to do there. The plugin will run in every combat, regardless of whether it's in a mission, campaign, simulator, etc.

Thanks for the reply. I appreciate it.

Is there any documentation on how exactly the plugins work? Do I have to call the functions in the plugin from a file in the mods folder, or do the plugins work automatically when in the plugin folder?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #3 on: February 22, 2017, 10:12:18 AM »

Not much documentation beyond the javadoc, I'm afraid.

The data/scripts/plugins folder is special and every class there gets examined based on what interfaces it implements and plugged into things as appropriate. It's actually deprecated (the preferred way is to add your class to a "plugins" section in settings.json), but is the simplest way to do it and also doesn't require compiling the code yourself.
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #4 on: February 22, 2017, 11:10:32 AM »

Not much documentation beyond the javadoc, I'm afraid.

The data/scripts/plugins folder is special and every class there gets examined based on what interfaces it implements and plugged into things as appropriate. It's actually deprecated (the preferred way is to add your class to a "plugins" section in settings.json), but is the simplest way to do it and also doesn't require compiling the code yourself.

So creating a new plugin file in the plugins folder is not enough? I have to include the new plugin in the plugin sections too?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #5 on: February 22, 2017, 11:42:12 AM »

It's enough - a plugins section entry is only needed if the class is somewhere else.
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #6 on: February 22, 2017, 12:23:44 PM »

It's enough - a plugins section entry is only needed if the class is somewhere else.

Thanks for the help.
I have one more thing to ask.

Could you explain how MutableShipStatsAPI works and how can I use them in conjuction with apply(MutableShipStatsAPI stats, ShipAPI.HullSize hullSize, java.lang.String id, float level)

Is the getShieldAbsorptionMult method under the CombatEngineAPI or somewhere else? Am I even approaching the stat bonuses correctly?
The way I understand it from the documentation, the first argument defines the type of stat i want to change, the second defines the amount, the third argument defines the size of the ships hull and the third is the id of the ships instance (playerShip.getId() in this case).
« Last Edit: February 22, 2017, 12:42:35 PM by Sapling »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #7 on: February 22, 2017, 07:42:51 PM »

That's the apply() method from a hullmod effect, isn't it? That's not really the same as what you'd do from a script.

Let's back up a bit - how much Java knowledge do you have?

Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #8 on: February 23, 2017, 12:21:05 PM »

That's the apply() method from a hullmod effect, isn't it? That's not really the same as what you'd do from a script.

Let's back up a bit - how much Java knowledge do you have?



Intermediate I would say.
OOP concepts should be known to me (Objects, Classes, inheritance, Polymorphism. I lack experience with abstraction tho.)

The deal here is. ShipAPI is an interface which does nothing by itself. Therefore it needs to take on a form of an object, and that is done by giving it a reference to an object which has the ShipAPI interface implemented. After that I can work with any function that is included in the ShipAPI (engine.getPlayerShip returns a reference to the player ship object as far as my understanding goes).
Interface ShipSkilleffect should work the same way. It offers two methods Apply and Unapply as far as the documentation says.
Logically in order to use the ShipSkillEffect interface, I would have to refer to a class that has the interface implemented.

The apply function takes mutableShipStatsAPI interface as an input, so again I would need to refer to an object which already has it implemented.

What I am saying might be or might not be completely and utterly wrong, so I do not mind being corrected. In fact I would appreciate it.
Thanks for the help in advance.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #9 on: February 23, 2017, 12:27:47 PM »

Ok, gotcha - just wanted to know what I can assume you know when talking about things :)

First thing I'd suggest doing is getting a base script implementation working that just prints some stuff out every frame, and making sure that this is actually working. You can run the game using the .bat file from the command line and the printed text will go there - might make it easier to do than tailing the log file or whatever.

After that, the basic shape of it is this: get the player ship object in the script (probably using Global.getCombatEngine().getPlayerShip()), then use .getMutableStats().get<whatever stat you want>().modify<Flat|Percent|Mult>(...) etc.
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #10 on: February 24, 2017, 02:06:12 AM »

Thanks for the help. I appreciate it
That was all i needed. I got the plugin up and running in no time  :)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #11 on: February 24, 2017, 07:42:17 AM »

Nice!

(One special case to watch out for, in case you haven't already, is to unapply the stat modifications when the player switches flagships. Not much of an issue if you don't do that until the ship is destroyed/retreated, naturally.)
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #12 on: February 24, 2017, 06:03:39 PM »

Nice!

(One special case to watch out for, in case you haven't already, is to unapply the stat modifications when the player switches flagships. Not much of an issue if you don't do that until the ship is destroyed/retreated, naturally.)

What happens if i do not unapply the bonuses?
Also,  when modifying stats like this,  should i be worried about overwriting existing stats (from hull mods or skills)?
« Last Edit: February 24, 2017, 06:06:55 PM by Sapling »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #13 on: February 24, 2017, 06:27:20 PM »

What happens if i do not unapply the bonuses?

They'll just stay applied to that specific ship for the duration of that battle.

Also,  when modifying stats like this,  should i be worried about overwriting existing stats (from hull mods or skills)?

What you want to do is make sure you're using a unique id for your modifications (the one passed in to the various modifyXXX methods). Hullmods/skills/etc use their own unique ids to apply their bonuses.
Logged

Sapling

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Adding passive bonuses to piloted ship.
« Reply #14 on: February 25, 2017, 06:42:11 AM »

Are there are ShipChanged events? Or ShipExit events?
« Last Edit: February 25, 2017, 06:56:46 AM by Sapling »
Logged
Pages: [1] 2