2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2022-09-23 16:05:04 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2019-02-02 17:50:15 +01:00
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-04-25 15:37:17 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-10-11 13:14:11 +02:00
|
|
|
import net.minecraft.text.Text;
|
2020-10-09 12:59:38 +02:00
|
|
|
import net.minecraft.util.Identifier;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-04-25 15:37:17 +02:00
|
|
|
public interface Ability<T extends Hit> {
|
2020-10-09 19:05:12 +02:00
|
|
|
/**
|
|
|
|
* 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-05-29 12:54:54 +02:00
|
|
|
default int getColor(Pony player) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-12-31 14:31:23 +01:00
|
|
|
/**
|
2021-12-31 15:17:41 +01: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.
|
2021-12-31 14:31:23 +01:00
|
|
|
* <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.
|
|
|
|
*/
|
2022-09-23 16:05:04 +02:00
|
|
|
default boolean onQuickAction(Pony player, ActivationType type, Optional<T> data) {
|
|
|
|
return onQuickAction(player, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2021-12-31 14:31:23 +01:00
|
|
|
default boolean onQuickAction(Pony player, ActivationType type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:05:04 +02:00
|
|
|
/**
|
|
|
|
* Called on the client to get any data required for the quick action.
|
|
|
|
*/
|
|
|
|
default Optional<T> prepareQuickAction(Pony player, ActivationType type) {
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
/**
|
|
|
|
* Called to check preconditions for activating the ability.
|
|
|
|
*
|
|
|
|
* @param w The world
|
|
|
|
* @param player The player
|
|
|
|
* @return True to allow activation
|
|
|
|
*/
|
2020-04-15 18:12:00 +02:00
|
|
|
default boolean canActivate(World w, Pony player) {
|
2018-09-12 01:29:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given race is permitted to use this ability
|
|
|
|
* @param playerSpecies The player's species
|
|
|
|
*/
|
|
|
|
boolean canUse(Race playerSpecies);
|
|
|
|
|
2022-09-23 16:05:04 +02:00
|
|
|
@Deprecated
|
|
|
|
@Nullable
|
|
|
|
T tryActivate(Pony player);
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
/**
|
|
|
|
* Called on the client to activate the ability.
|
|
|
|
*
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @return Data to be sent, or null if activation failed
|
|
|
|
*/
|
2022-09-23 16:05:04 +02:00
|
|
|
default Optional<T> prepare(Pony player) {
|
|
|
|
return Optional.ofNullable(tryActivate(player));
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-04-25 15:37:17 +02:00
|
|
|
Hit.Serializer<T> getSerializer();
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-10-09 12:59:38 +02:00
|
|
|
/**
|
|
|
|
* The icon representing this ability on the UI and HUD.
|
|
|
|
*/
|
2023-05-29 15:13:52 +02:00
|
|
|
default Identifier getIcon(Pony player) {
|
2020-10-09 12:59:38 +02:00
|
|
|
Identifier id = Abilities.REGISTRY.getId(this);
|
|
|
|
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + ".png");
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:13:52 +02:00
|
|
|
default Text getName(Pony player) {
|
|
|
|
return getName();
|
|
|
|
}
|
|
|
|
|
2020-10-11 13:14:11 +02:00
|
|
|
/**
|
|
|
|
* The display name for this ability.
|
|
|
|
*/
|
|
|
|
default Text getName() {
|
2023-05-29 15:13:52 +02:00
|
|
|
return Text.translatable(getTranslationKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
default String getTranslationKey() {
|
2020-10-11 13:14:11 +02:00
|
|
|
Identifier id = Abilities.REGISTRY.getId(this);
|
2023-05-29 15:13:52 +02:00
|
|
|
return "ability." + id.getNamespace() + "." + id.getPath().replace('/', '.');
|
2020-10-11 13:14:11 +02:00
|
|
|
}
|
|
|
|
|
2021-08-20 22:22:28 +02:00
|
|
|
/**
|
|
|
|
* Server-side counterpart to canActivate.
|
|
|
|
*
|
|
|
|
* Called before applying to determine whether to cancel the command or not.
|
|
|
|
*/
|
|
|
|
default boolean canApply(Pony player, T data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2020-04-15 18:12:00 +02:00
|
|
|
void 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
|
|
|
|
*/
|
2020-05-10 20:45:07 +02:00
|
|
|
void preApply(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
|
|
|
|
*/
|
2020-05-10 20:45:07 +02:00
|
|
|
void postApply(Pony player, AbilitySlot slot);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|