2021-05-01 19:40:36 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
2021-06-02 14:28:19 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
2021-06-03 01:57:20 +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<>();
|
|
|
|
|
2021-05-31 16:30:26 +00:00
|
|
|
/** The max cooldown round numbers for every stone */
|
|
|
|
private final HashMap<StoneType, Integer> maxCooldowns = new HashMap<>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new {@link StoneCooldownManager} with the given config.
|
|
|
|
*/
|
|
|
|
public StoneCooldownManager(PartyConfig partyConfig) {
|
|
|
|
//thanks
|
|
|
|
maxCooldowns.put(StoneType.SpaceStone, partyConfig.spaceStoneCD);
|
|
|
|
maxCooldowns.put(StoneType.MindStone, partyConfig.mindStoneCD);
|
|
|
|
maxCooldowns.put(StoneType.RealityStone, partyConfig.realityStoneCD);
|
|
|
|
maxCooldowns.put(StoneType.PowerStone, partyConfig.powerStoneCD);
|
|
|
|
maxCooldowns.put(StoneType.TimeStone, partyConfig.timeStoneCD);
|
|
|
|
maxCooldowns.put(StoneType.SoulStone, partyConfig.soulStoneCD);
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:47:19 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2021-05-31 16:30:26 +00:00
|
|
|
maxCooldowns.clear();
|
|
|
|
maxCooldowns.putAll(other.maxCooldowns);
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases all cooldowns by one according to a round having passed.
|
|
|
|
*/
|
|
|
|
public void update() {
|
2021-07-24 23:13:40 +00:00
|
|
|
cooldowns.replaceAll((s, v) -> Math.max(0, v - 1));
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2021-07-07 12:58:24 +00:00
|
|
|
return cooldowns.getOrDefault(stone, 0) > 0;
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2021-05-31 16:30:26 +00:00
|
|
|
* @param stone The {@link StoneType} to mark
|
2021-05-01 17:47:19 +00:00
|
|
|
*/
|
2021-05-31 16:30:26 +00:00
|
|
|
public void setCooldown(StoneType stone) {
|
2021-07-07 13:00:12 +00:00
|
|
|
cooldowns.put(stone, Math.max(0, maxCooldowns.getOrDefault(stone, 0)));
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|
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-06-03 00:51:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports the cooldowns from an array ordered according to the enum.
|
|
|
|
* @param data An array containing every cooldown
|
|
|
|
*/
|
|
|
|
public void import_(Integer[] data) {
|
|
|
|
for(int i = 0; i < data.length; i++) {
|
|
|
|
cooldowns.put(StoneType.valueOf(i), data[i]);
|
|
|
|
}
|
|
|
|
}
|
2021-05-01 17:47:19 +00:00
|
|
|
}
|