-
Notifications
You must be signed in to change notification settings - Fork 122
Creating Abilities
Benjamin Amos edited this page Mar 6, 2022
·
1 revision
To create a new ability, you should first create a class (AbilityName
) implementing ShipAbility
. Within that class there should be an inner-class named <AbilityName>Config
, implementing AbilityConfig
.
Your <AbilityName>Config
class should obtain the parameters it needs from the JSONObject
passed into its load(JSONObject, ItemManager, AbilityCommonConfig)
method. The parameters might include things such as recharge time, ability duration, ability strength and other variable characteristics.
package org.destinationsol.mymodule.abilities;
import org.destinationsol.game.AbilityCommonConfig;
import org.destinationsol.game.Hero;
import org.destinationsol.game.SolGame;
import org.destinationsol.game.item.ItemManager;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.ship.AbilityConfig;
import org.destinationsol.game.ship.ShipAbility;
import org.destinationsol.game.ship.SolShip;
import org.json.JSONObject;
public class MyAbility implements ShipAbility {
private final MyAbilityConfig config;
public MyAbility(MyAbilityConfig config) {
this.config = config;
}
@Override
public boolean update(SolGame game, SolShip owner, boolean tryToUse) {
Hero hero = game.getHero();
if (tryToUse && !hero.isTranscendent()) {
// Activate ability...
return true;
}
return false;
}
@Override
public AbilityConfig getConfig() {
return config;
}
@Override
public AbilityCommonConfig getCommonConfig() {
return config.commonConfig;
}
@Override
public float getRadius() {
// This is the radius that the ability has an effect in.
return Float.MAX_VALUE;
}
public static class MyAbilityConfig implements AbilityConfig {
private final float rechargeTime;
private final int myCustomProperty;
private final AbilityCommonConfig commonConfig;
public MyAbilityConfig(float rechargeTime, AbilityCommonConfig commonConfig) {
this.rechargeTime = rechargeTime;
this.commonConfig = commonConfig;
}
@Override
public ShipAbility build() {
return new MyAbilityConfig(this);
}
@Override
public SolItem getChargeExample() {
// If your ability requires a charge to use,
// return the charge example here.
return null;
}
@Override
public float getRechargeTime() {
// This is how long the ability takes to recharge.
return rechargeTime;
}
@Override
public void appendDesc(StringBuilder sb) {
sb.append("Ability description goes here.");
}
public static AbilityConfig load(JSONObject abNode, ItemManager itemManager, AbilityCommonConfig cc) {
float rechargeTime = (float) abNode.getDouble("rechargeTime");
int myCustomProperty = abNode.getInt("myCustomProperty");
// You can get an ability charge example here using
// itemManager.getExample("module:myAbilityCharge").
return new MyAbilityConfig(rechargeTime, cc);
}
}
}
- The warp abilities
-
Abilities, for more information on using abilities. The ability
type
value in JSON is the name of the ability class.