Unicopia/src/main/java/com/minelittlepony/unicopia/ability/Ability.java

130 lines
3.7 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
2018-09-12 01:29:49 +02:00
import java.util.Optional;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.entity.player.Pony;
2018-09-12 01:29:49 +02:00
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
2023-08-16 00:18:41 +02:00
import net.minecraft.util.Util;
2018-09-12 01:29:49 +02:00
public interface Ability<T extends Hit> {
/**
* The amount of energy this ability is expected to cost if the player were to cast it.
*/
double getCostEstimate(Pony player);
2018-09-12 01:29:49 +02:00
/**
* Returns the number of ticks the player must hold the ability key to trigger this ability.
*/
2020-04-15 18:12:00 +02:00
int getWarmupTime(Pony player);
2018-09-12 01:29:49 +02:00
/**
* Returns the number of ticks allowed for cooldown
*/
2020-04-15 18:12:00 +02:00
int getCooldownTime(Pony player);
2018-09-12 01:29:49 +02:00
2023-08-16 00:18:41 +02:00
/**
* The icon representing this ability on the UI and HUD.
*/
default Identifier getIcon(Pony player) {
return getId().withPath(p -> "textures/gui/ability/" + p + ".png");
}
2023-05-29 12:54:54 +02:00
default int getColor(Pony player) {
return -1;
}
/**
2023-08-16 00:18:41 +02:00
* The display name for this ability.
*/
2023-08-16 00:18:41 +02:00
default Text getName(Pony player) {
return Text.translatable(getTranslationKey());
}
2023-08-16 00:18:41 +02:00
default String getTranslationKey() {
return Util.createTranslationKey("ability", getId());
}
2023-08-16 00:18:41 +02:00
default Identifier getId() {
return Abilities.REGISTRY.getId(this);
}
2023-08-16 00:18:41 +02:00
default boolean activateOnEarlyRelease() {
return false;
2018-09-12 01:29:49 +02:00
}
/**
* Checks if the given race is permitted to use this ability
* @param race The player's species
*/
default boolean canUse(Race.Composite race) {
return race.any(this::canUse);
}
2018-09-12 01:29:49 +02:00
/**
* Checks if the given race is permitted to use this ability
* @param playerSpecies The player's species
*/
boolean canUse(Race playerSpecies);
/**
2023-08-16 00:18:41 +02:00
* Called when an ability is about to be triggered. This event occurs on both the client and server so check {@code Pony#isClient} if you need to know which one you're on.
* <p>
* Use this method to respond to quick-time events, like short taps or double-taps.
* <p>
* @return True if the event has been handled.
2018-09-12 01:29:49 +02:00
*/
2023-08-16 00:18:41 +02:00
default boolean onQuickAction(Pony player, ActivationType type, Optional<T> data) {
return false;
}
2018-09-12 01:29:49 +02:00
/**
2023-08-16 00:18:41 +02:00
* Called on the client to get any data required for the quick action.
*
* @param player The player
* @param type The type of quick event being triggered
* @return The data to pass on to the quick event handler
*/
2023-08-16 00:18:41 +02:00
default Optional<T> prepareQuickAction(Pony player, ActivationType type) {
return Optional.empty();
}
/**
2023-08-16 00:18:41 +02:00
* Gets the serializer to use for reading data over the network.
*/
2023-08-16 00:18:41 +02:00
Hit.Serializer<T> getSerializer();
2021-08-20 22:22:28 +02:00
/**
2023-08-16 00:18:41 +02:00
* Called on the client to get any data required to activate the ability.
2021-08-20 22:22:28 +02:00
*
2023-08-16 00:18:41 +02:00
* @param player The player activating the ability
* @return Data to be sent, or Empty if activation failed
2021-08-20 22:22:28 +02:00
*/
2023-08-16 00:18:41 +02:00
Optional<T> prepare(Pony player);
2021-08-20 22:22:28 +02:00
2018-09-12 01:29:49 +02:00
/**
* Called to actually apply the ability.
* Only called on the server side.
*
* @param player The player that triggered the ability
* @param data Data previously sent from the client
2023-08-16 00:18:41 +02:00
* @return True if the ability succeeded. Returning false will cause an ability reset message to be sent to the client.
2018-09-12 01:29:49 +02:00
*/
2023-08-16 00:18:41 +02:00
boolean apply(Pony player, T data);
2018-09-12 01:29:49 +02:00
/**
2019-02-03 10:45:45 +01:00
* Called every tick until the warmup timer runs out.
2018-09-12 01:29:49 +02:00
* @param player The current player
*/
2023-08-16 00:18:41 +02:00
void warmUp(Pony player, AbilitySlot slot);
2018-09-12 01:29:49 +02:00
/**
* Called every tick until the cooldown timer runs out.
* @param player The current player
*/
2023-08-16 00:18:41 +02:00
void coolDown(Pony player, AbilitySlot slot);
2018-09-12 01:29:49 +02:00
}