Animation bezüglich schwert und schild im kampfsystem abgeschlossen
This commit is contained in:
@@ -5,7 +5,8 @@ public enum ModelCategory {
|
||||
TREE("Baum"),
|
||||
PALM("Palme"),
|
||||
BUILDING("Gebäude"),
|
||||
BUSH("Busch");
|
||||
BUSH("Busch"),
|
||||
DUMMY("Kampfpuppe");
|
||||
|
||||
private final String label;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.blight.common.model;
|
||||
|
||||
public class CombatDummy {
|
||||
|
||||
private final String id;
|
||||
private final int maxHp;
|
||||
|
||||
public CombatDummy(String id, int maxHp) {
|
||||
this.id = id;
|
||||
this.maxHp = maxHp > 0 ? maxHp : 250;
|
||||
}
|
||||
|
||||
public String getId() { return id; }
|
||||
public int getMaxHp() { return maxHp; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.blight.common.model;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import de.blight.common.MapIO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class CombatDummyIO {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CombatDummyIO.class);
|
||||
private static final String EXTENSION = ".dummy";
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private CombatDummyIO() {}
|
||||
|
||||
public static Path getDir() {
|
||||
return MapIO.getMapPath().resolveSibling("dummies");
|
||||
}
|
||||
|
||||
public static void save(CombatDummy d) throws IOException {
|
||||
if (d.getId() == null) throw new IOException("CombatDummy ohne ID kann nicht gespeichert werden.");
|
||||
Path dir = getDir();
|
||||
Files.createDirectories(dir);
|
||||
Dto dto = new Dto();
|
||||
dto.id = d.getId();
|
||||
dto.maxHp = d.getMaxHp();
|
||||
Files.writeString(dir.resolve(d.getId() + EXTENSION), GSON.toJson(dto), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Optional<CombatDummy> load(String id) {
|
||||
Path file = getDir().resolve(id + EXTENSION);
|
||||
if (!Files.exists(file)) return Optional.empty();
|
||||
try {
|
||||
Dto dto = GSON.fromJson(Files.readString(file, StandardCharsets.UTF_8), Dto.class);
|
||||
return Optional.of(new CombatDummy(dto.id != null ? dto.id : id, dto.maxHp));
|
||||
} catch (IOException e) {
|
||||
log.warn("[CombatDummyIO] Fehler beim Laden von {}: {}", id, e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public static void delete(String id) throws IOException {
|
||||
Files.deleteIfExists(getDir().resolve(id + EXTENSION));
|
||||
}
|
||||
|
||||
private static class Dto {
|
||||
String id;
|
||||
int maxHp;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ public enum InteractableType {
|
||||
NONE("Keines"),
|
||||
CRAFTING_TABLE("Handwerkstisch"),
|
||||
BED("Bett"),
|
||||
BENCH("Bank");
|
||||
BENCH("Bank"),
|
||||
COMBAT_DUMMY("Kampfpuppe");
|
||||
|
||||
private final String label;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user