|
| 1 | +package org.phantazm.zombies.modifier; |
| 2 | + |
| 3 | +import com.github.steanky.element.core.annotation.Cache; |
| 4 | +import com.github.steanky.element.core.annotation.DataObject; |
| 5 | +import com.github.steanky.element.core.annotation.FactoryMethod; |
| 6 | +import com.github.steanky.element.core.annotation.Model; |
| 7 | +import com.github.steanky.ethylene.core.ConfigElement; |
| 8 | +import com.github.steanky.ethylene.core.ConfigPrimitive; |
| 9 | +import com.github.steanky.ethylene.mapper.annotation.Default; |
| 10 | +import net.kyori.adventure.key.Key; |
| 11 | +import net.kyori.adventure.text.Component; |
| 12 | +import org.jetbrains.annotations.NotNull; |
| 13 | +import org.phantazm.commons.DualComponent; |
| 14 | +import org.phantazm.commons.InjectionStore; |
| 15 | +import org.phantazm.zombies.coin.Transaction; |
| 16 | +import org.phantazm.zombies.scene2.ZombiesScene; |
| 17 | + |
| 18 | +@Model("zombies.modifier.coins") |
| 19 | +@Cache |
| 20 | +public class CoinGainModifier implements DualComponent<ZombiesScene, Modifier> { |
| 21 | + private final Data data; |
| 22 | + |
| 23 | + @FactoryMethod |
| 24 | + public CoinGainModifier(@NotNull Data data) { |
| 25 | + this.data = data; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public @NotNull Modifier apply(@NotNull InjectionStore injectionStore, @NotNull ZombiesScene scene) { |
| 30 | + return new Impl(scene, data); |
| 31 | + } |
| 32 | + |
| 33 | + private record Impl(ZombiesScene scene, |
| 34 | + Data data) implements Modifier { |
| 35 | + @Override |
| 36 | + public void apply() { |
| 37 | + scene.map().objects().module().modifierSource().addModifier(data.group, |
| 38 | + Transaction.modifier(data.modifierName, data.modifierAction, data.amount, data.priority)); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @DataObject |
| 43 | + public record Data( |
| 44 | + @NotNull Key group, |
| 45 | + @NotNull Component modifierName, |
| 46 | + @NotNull Transaction.Modifier.Action modifierAction, |
| 47 | + double amount, |
| 48 | + int priority) { |
| 49 | + @Default("priority") |
| 50 | + public static @NotNull ConfigElement priorityDefault() { |
| 51 | + return ConfigPrimitive.of(0); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments