diff --git a/MadSand-core/src/hitonoriol/madsand/Keyboard.java b/MadSand-core/src/hitonoriol/madsand/Keyboard.java index 68acb00f..7206050d 100644 --- a/MadSand-core/src/hitonoriol/madsand/Keyboard.java +++ b/MadSand-core/src/hitonoriol/madsand/Keyboard.java @@ -128,13 +128,9 @@ private static void pollActionKeys() { if (Gdx.input.isKeyJustPressed(Keys.N) && MadSand.world.curLayer() == Location.LAYER_OVERWORLD) MadSand.world.travel(); - - if (Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) && Gdx.input.isKeyJustPressed(Keys.W)) - World.player.skipTime(); } private static void pollMovementKeys() { - if (Gdx.input.isKeyPressed(Keys.A)) World.player.walk(Direction.LEFT); @@ -183,6 +179,9 @@ else if (Gdx.input.isKeyJustPressed(Keys.R)) { MadSand.world.generate(); MadSand.worldEntered(); } + + else if (Gdx.input.isKeyJustPressed(Keys.W)) + World.player.skipTime(); } if (Gdx.input.isKeyJustPressed(Keys.Y)) diff --git a/MadSand-core/src/hitonoriol/madsand/Mouse.java b/MadSand-core/src/hitonoriol/madsand/Mouse.java index 5b78ac1d..9ef8e2c1 100644 --- a/MadSand-core/src/hitonoriol/madsand/Mouse.java +++ b/MadSand-core/src/hitonoriol/madsand/Mouse.java @@ -103,7 +103,7 @@ public static String getCurrentCellInfo() { } if (!object.equals(Map.nullObject)) - info += ("Object: " + object.name + " (" + object.getHpPercent() + "%)") + Resources.LINEBREAK; + info += ("Object: " + object.name + " (" + Utils.round(object.getHpPercent()) + "%)") + Resources.LINEBREAK; if (station != null) info += getProdStationInfo(station); diff --git a/MadSand-core/src/hitonoriol/madsand/Utils.java b/MadSand-core/src/hitonoriol/madsand/Utils.java index 938f547e..4f90aaea 100644 --- a/MadSand-core/src/hitonoriol/madsand/Utils.java +++ b/MadSand-core/src/hitonoriol/madsand/Utils.java @@ -5,12 +5,15 @@ import hitonoriol.madsand.dialog.GameTextSubstitutor; import me.xdrop.jrand.JRand; +import java.math.RoundingMode; +import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.List; +import java.util.Locale; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -22,13 +25,16 @@ public class Utils { public static boolean debugMode = false; public static SpriteBatch batch; + static NumberFormat numberFormatter = NumberFormat.getInstance(Locale.US); public static Random random = new Random(); public static void init() { + batch = new SpriteBatch(); + numberFormatter.setMinimumFractionDigits(0); + numberFormatter.setRoundingMode(RoundingMode.HALF_UP); try { Resources.init(); - batch = new SpriteBatch(); } catch (Exception e) { die("Exception on init: " + ExceptionUtils.getStackTrace(e)); } @@ -82,8 +88,13 @@ public static void die(String... msg) { System.exit(-1); } - public static double round(double num) { - return (Math.round(num * 100) / 100.00); + public static String round(double num) { + return round(num, 2); + } + + public static String round(double num, int n) { + numberFormatter.setMaximumFractionDigits(n); + return numberFormatter.format(num); } public static int rand(int min, int max) { diff --git a/MadSand-core/src/hitonoriol/madsand/entities/Player.java b/MadSand-core/src/hitonoriol/madsand/entities/Player.java index 834f48b0..8481e9b8 100644 --- a/MadSand-core/src/hitonoriol/madsand/entities/Player.java +++ b/MadSand-core/src/hitonoriol/madsand/entities/Player.java @@ -1094,6 +1094,8 @@ public void restFully() { MadSand.notice("Rested for " + Utils.timeString(MadSand.world.toWorldTimeSeconds(ticksToRest))); } + public static float TIMESKIP_COEF = 18f, REALTIME_SKIP_COEF = 5.5f; + public void skipTime() { int timeSkipItemId = Globals.getInt(Globals.TIMESKIP_ITEM); Item timeSkipItem = inventory.getItem(timeSkipItemId); @@ -1104,7 +1106,7 @@ public void skipTime() { return; } - int maxTimeSkip = timeSkipItem.quantity; + int maxTimeSkip = (int) (timeSkipItem.quantity * TIMESKIP_COEF); new WaitDialog(maxTimeSkip).show(); } diff --git a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/LandDialog.java b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/LandDialog.java index 8b18363c..e76c626d 100644 --- a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/LandDialog.java +++ b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/LandDialog.java @@ -30,6 +30,7 @@ public class LandDialog extends GameDialog { + static int DEC_PLACES = 4; static int ITEMS_PER_ROW = 6; static float ITEM_SCALE = 0.1f; static float PAD = 5; @@ -143,7 +144,7 @@ private String getWorkerList() { continue; sb.append("* " + type.name() + ": " + workers.getQuantity() + " "); - sb.append("(" + Utils.round(workers.getGatheringRate() / MadSand.world.realtimeTickRate) + " actions/sec) ") + sb.append("(" + Utils.round(workers.getGatheringRate() / MadSand.world.realtimeTickRate, DEC_PLACES) + " actions/sec) ") .append("[[" + Utils.round(workers.itemCharge * 100f) + "%]") .append(Resources.LINEBREAK); } diff --git a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/SliderDialog.java b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/SliderDialog.java index aaa21e56..220a2a1c 100644 --- a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/SliderDialog.java +++ b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/SliderDialog.java @@ -121,6 +121,11 @@ public SliderDialog setOnUpdateText(String text) { return this; } + public SliderDialog setStep(int step) { + slider.setStepSize(step); + return this; + } + public SliderDialog setTitle(String title) { super.setTitle(title); return this; @@ -142,6 +147,10 @@ public int getSliderValue() { public void setSliderText(String text) { // Set text under the slider bottomLabel.setText(text); } + + public Label getBottomLabel() { + return bottomLabel; + } @Override public void show() { diff --git a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/WaitDialog.java b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/WaitDialog.java index 69a82163..7b43c4ce 100644 --- a/MadSand-core/src/hitonoriol/madsand/gui/dialogs/WaitDialog.java +++ b/MadSand-core/src/hitonoriol/madsand/gui/dialogs/WaitDialog.java @@ -1,24 +1,48 @@ package hitonoriol.madsand.gui.dialogs; +import com.badlogic.gdx.utils.Align; + import hitonoriol.madsand.MadSand; +import hitonoriol.madsand.Resources; import hitonoriol.madsand.Utils; +import hitonoriol.madsand.entities.Player; import hitonoriol.madsand.properties.Globals; +import hitonoriol.madsand.properties.ItemProp; import hitonoriol.madsand.world.World; public class WaitDialog extends SliderDialog { - private int worldSeconds; + private int worldSeconds, realtimeTicks; + private int timeSkipItemSpent; public WaitDialog(int maxTimeSkip) { - super(maxTimeSkip); + super((int) Player.TIMESKIP_COEF, maxTimeSkip); + super.setStep((int) Player.TIMESKIP_COEF); super.setTitle("Skip Time"); super.setSliderTitle("How much time to skip:"); + super.getBottomLabel().setAlignment(Align.center); + + String timeSkipItem = ItemProp.getItemName(Globals.getInt(Globals.TIMESKIP_ITEM)); super.setSliderAction( - ticks -> super.setSliderText(Utils.timeString(worldSeconds = MadSand.world.toWorldTimeSeconds(ticks)))); + ticks -> { + timeSkipItemSpent = (int) Math.max((float) ticks / Player.TIMESKIP_COEF, 1); + worldSeconds = MadSand.world.toWorldTimeSeconds(ticks); + realtimeTicks = (int) (timeSkipItemSpent * Player.REALTIME_SKIP_COEF); + super.setSliderText("+"+Utils.timeString(worldSeconds) + " [[World time]" + + Resources.LINEBREAK + + + "+"+Utils.timeString((long) (realtimeTicks * MadSand.world.realtimeTickRate)) + + " [[Realtime]" + + Resources.LINEBREAK + + + "-"+timeSkipItemSpent + " " + timeSkipItem); + }); + super.setConfirmAction(ticks -> { + World.player.inventory.delItem(Globals.getInt(Globals.TIMESKIP_ITEM), timeSkipItemSpent); World.player.skipTime(ticks); - World.player.inventory.delItem(Globals.getInt(Globals.TIMESKIP_ITEM), ticks); + MadSand.world.skipRealtimeTicks(realtimeTicks); MadSand.notice("Skipped " + Utils.timeString(worldSeconds)); }); } -} +} \ No newline at end of file diff --git a/MadSand-core/src/hitonoriol/madsand/map/MapObject.java b/MadSand-core/src/hitonoriol/madsand/map/MapObject.java index 6608f892..a647362b 100644 --- a/MadSand-core/src/hitonoriol/madsand/map/MapObject.java +++ b/MadSand-core/src/hitonoriol/madsand/map/MapObject.java @@ -117,7 +117,7 @@ public int rollDrop(ItemType heldItemType) { } public double getHpPercent() { - return Utils.round(((double) hp / (double) maxHp) * 100d); + return ((double) hp / (double) maxHp) * 100d; } private static int getAltItem(int id, ItemType hand, HashMap> container) { diff --git a/MadSand-core/src/hitonoriol/madsand/world/Settlement.java b/MadSand-core/src/hitonoriol/madsand/world/Settlement.java index ebf6825e..89566cf2 100644 --- a/MadSand-core/src/hitonoriol/madsand/world/Settlement.java +++ b/MadSand-core/src/hitonoriol/madsand/world/Settlement.java @@ -173,7 +173,7 @@ public String getLeaderName() { } public static class WorkerContainer { // Info about all workers of certain type - public static float ITEMS_PER_LVL = 0.1f; // Items per lvl per realtimeTick + public static float ITEMS_PER_LVL = 0.025f; // Items per lvl per realtimeTick public int lvl = 1; public float itemCharge = 0; diff --git a/MadSand-core/src/hitonoriol/madsand/world/World.java b/MadSand-core/src/hitonoriol/madsand/world/World.java index a22cda69..a07e2b0d 100644 --- a/MadSand-core/src/hitonoriol/madsand/world/World.java +++ b/MadSand-core/src/hitonoriol/madsand/world/World.java @@ -661,14 +661,17 @@ private void realtimeTick() { ++globalRealtimeTick; realtimeRefresh(); } + + public void skipRealtimeTicks(long ticks) { + for (; ticks > 0; --ticks) + realtimeRefresh(); + } private void offlineReward(long offlineTime) { long offlineTicks = (long) (offlineTime / realtimeTickRate); globalRealtimeTick += offlineTicks; LuaUtils.executeScript(LuaUtils.offlineRewardScript, offlineTime); - - for (; offlineTicks > 0; --offlineTicks) - realtimeRefresh(); + skipRealtimeTicks(offlineTicks); } private float HOUR = 3600; diff --git a/core/assets/buildrecipes.json b/core/assets/buildrecipes.json index c665d9a8..3e947119 100644 --- a/core/assets/buildrecipes.json +++ b/core/assets/buildrecipes.json @@ -9,5 +9,6 @@ "75" : "71/1:2/10:9/5", "82" : "1/30:10/10", "158" : "72/20", - "157" : "8/50" + "157" : "8/50", + "175" : "101/50:72/10" } \ No newline at end of file diff --git a/core/assets/obj/175.png b/core/assets/obj/175.png new file mode 100644 index 00000000..1700befb Binary files /dev/null and b/core/assets/obj/175.png differ diff --git a/core/assets/objects.json b/core/assets/objects.json index 2c11ffb5..6a0ee6dc 100644 --- a/core/assets/objects.json +++ b/core/assets/objects.json @@ -2070,5 +2070,12 @@ "hp" : 3, "name" : "Clay wall", "isWall" : true + }, + "175" : { + "hp" : 1, + "harvestHp" : 50, + "centered" : true, + "onInteract" : "world.player:skipTime()", + "name" : "Time machine" } } \ No newline at end of file