Skip to content

Commit c07319f

Browse files
committed
add a modifier component to independently increase/decrease coin gain
1 parent e28c606 commit c07319f

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

zombies/src/main/java/org/phantazm/zombies/command/AmmoRefillCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ protected void runCommand(@NotNull CommandContext context, @NotNull ZombiesScene
2626
scene.setLegit(false);
2727

2828
ZombiesPlayer zombiesPlayer = scene.managedPlayers().get(PlayerView.lookup(sender.getUuid()));
29-
Optional<InventoryAccess> acccessOptional = zombiesPlayer.module().getEquipmentHandler().accessRegistry()
29+
Optional<InventoryAccess> accessOptional = zombiesPlayer.module().getEquipmentHandler().accessRegistry()
3030
.getCurrentAccess();
31-
if (acccessOptional.isEmpty()) {
31+
if (accessOptional.isEmpty()) {
3232
return;
3333
}
3434

35-
InventoryProfile profile = acccessOptional.get().profile();
35+
InventoryProfile profile = accessOptional.get().profile();
3636
for (int i = 0; i < profile.getSlotCount(); i++) {
3737
if (!profile.hasInventoryObject(i)) {
3838
continue;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)