2021-05-01 19:40:36 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
2021-05-05 16:59:07 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
2021-05-01 19:40:36 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
|
2021-05-01 17:47:19 +00:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/** Represents a manager for infinity stone cooldowns. */
|
|
|
|
public class StoneCooldownManager {
|
|
|
|
/** The cooldown round numbers for every stone */
|
|
|
|
private final HashMap<StoneType, Integer> cooldowns = new HashMap<>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes over all the cooldowns from a different {@link StoneCooldownManager}.
|
|
|
|
* @param other The cooldown manager to take the data from
|
|
|
|
*/
|
|
|
|
public void cloneFrom(StoneCooldownManager other) {
|
|
|
|
cooldowns.clear();
|
|
|
|
cooldowns.putAll(other.cooldowns);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases all cooldowns by one according to a round having passed.
|
|
|
|
*/
|
|
|
|
public void update() {
|
|
|
|
cooldowns.replaceAll((s, v) -> Math.max(0, cooldowns.get(s) - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a stone is on cooldown.
|
|
|
|
* @param stone The {@link StoneType} to check for
|
|
|
|
* @return Whether or not the stone is on cooldown
|
|
|
|
*/
|
|
|
|
public boolean onCooldown(StoneType stone) {
|
|
|
|
return cooldowns.containsKey(stone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the current cooldown for a stone.
|
|
|
|
* @param stone The {@link StoneType} to check for
|
|
|
|
* @return The stone's cooldown in rounds
|
|
|
|
*/
|
|
|
|
public int getCooldown(StoneType stone) {
|
|
|
|
return cooldowns.get(stone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a stone as on cooldown.
|
|
|
|
* @param stone The {@link StoneType} to check for
|
|
|
|
* @param duration The number of rounds the stone should be on cooldown
|
|
|
|
*/
|
|
|
|
public void setCooldown(StoneType stone, int duration) {
|
|
|
|
cooldowns.put(stone, Math.max(0, duration));
|
|
|
|
}
|
2021-05-05 16:59:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports the cooldowns as an array ordered according to the enum.
|
|
|
|
* @return An array containing every cooldown
|
|
|
|
*/
|
|
|
|
public Integer[] export() {
|
|
|
|
Integer[] data = new Integer[6];
|
|
|
|
int i = 0;
|
|
|
|
for (StoneType stone: StoneType.values()) {
|
|
|
|
data[i++] = cooldowns.getOrDefault(stone, 0);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|