From 5d309c39cfb431b6c4b5a433055d1321bb4ffe12 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 11 Sep 2018 17:09:42 -0400 Subject: [PATCH] Added core recipe, made core destructible --- core/src/io/anuke/mindustry/Vars.java | 8 ++++---- core/src/io/anuke/mindustry/content/Recipes.java | 6 +++++- core/src/io/anuke/mindustry/core/Control.java | 8 +++++++- core/src/io/anuke/mindustry/world/Block.java | 12 +++++++++--- core/src/io/anuke/mindustry/world/Build.java | 4 ++-- .../io/anuke/mindustry/world/blocks/BuildBlock.java | 3 ++- .../world/blocks/distribution/ItemBridge.java | 2 +- .../world/blocks/distribution/WarpGate.java | 2 +- .../mindustry/world/blocks/power/PowerNode.java | 2 +- .../mindustry/world/blocks/storage/CoreBlock.java | 11 ++++++++++- .../mindustry/world/blocks/units/CommandCenter.java | 2 +- .../mindustry/world/modules/InventoryModule.java | 7 ------- 12 files changed, 43 insertions(+), 24 deletions(-) diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index 11c314337e..895f7680b1 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -30,6 +30,9 @@ import java.util.Arrays; import java.util.Locale; public class Vars{ + public static final String discordURL = "https://discord.gg/mindustry"; + public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases"; + public static final String crashReportURL = "http://mindustry.us.to/report"; //time between waves in frames (on normal mode) public static final float wavespace = 60 * 60 * 1.5f; //set ridiculously high for now @@ -38,10 +41,7 @@ public class Vars{ public static final Team defaultTeam = Team.blue; //team of the enemy in waves public static final Team waveTeam = Team.red; - - public static final String discordURL = "https://discord.gg/mindustry"; - public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases"; - public static final String crashReportURL = "http://mindustry.us.to/report"; + public static final float unlockResourceScaling = 1.5f; public static final int maxTextLength = 150; public static final int maxNameLength = 40; public static final float itemSize = 5f; diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index f72922edb3..628a698a01 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -122,9 +122,13 @@ public class Recipes implements ContentList{ new Recipe(power, PowerBlocks.thoriumReactor, new ItemStack(Items.lead, 600), new ItemStack(Items.silicon, 400), new ItemStack(Items.densealloy, 300), new ItemStack(Items.thorium, 300)); new Recipe(power, PowerBlocks.rtgGenerator, new ItemStack(Items.lead, 200), new ItemStack(Items.silicon, 150), new ItemStack(Items.phasematter, 50), new ItemStack(Items.plastanium, 150), new ItemStack(Items.thorium, 100)); - //new Recipe(distribution, StorageBlocks.core, new ItemStack(Items.densealloy, 50)); new Recipe(distribution, StorageBlocks.unloader, new ItemStack(Items.densealloy, 40), new ItemStack(Items.silicon, 50)); new Recipe(distribution, StorageBlocks.vault, new ItemStack(Items.densealloy, 500), new ItemStack(Items.thorium, 350)); + new Recipe(distribution, StorageBlocks.core, + new ItemStack(Items.copper, 2000), new ItemStack(Items.densealloy, 1500), + new ItemStack(Items.silicon, 1500), new ItemStack(Items.thorium, 500), + new ItemStack(Items.surgealloy, 500), new ItemStack(Items.phasematter, 750) + ); //DRILLS, PRODUCERS new Recipe(production, ProductionBlocks.mechanicalDrill, new ItemStack(Items.copper, 50)); diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 11207f1193..d31a95d310 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -20,6 +20,7 @@ import io.anuke.mindustry.input.InputHandler; import io.anuke.mindustry.input.MobileInput; import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.net.Net; +import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.ucore.core.*; @@ -270,9 +271,14 @@ public class Control extends Module{ control.database().unlockContent(players[0].inventory.getItem().item); } + outer: for(int i = 0; i < content.recipes().size; i ++){ Recipe recipe = content.recipes().get(i); - if(!recipe.hidden && recipe.requirements != null && entity.items.has(recipe.requirements, 1.4f)){ + if(!recipe.hidden && recipe.requirements != null){ + for(ItemStack stack : recipe.requirements){ + if(!entity.items.has(stack.item, Math.min((int) (stack.amount * unlockResourceScaling), 2000))) continue outer; + } + if(control.database().unlockContent(recipe)){ ui.hudfrag.showUnlock(recipe); } diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 62f74c1df3..7492052fc1 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -42,8 +42,6 @@ public class Block extends BaseBlock { public boolean update; /** whether this block has health and can be destroyed */ public boolean destructible; - /** if true, this block cannot be broken by normal means. */ - public boolean unbreakable; /** whether this is solid */ public boolean solid; /** whether this block CAN be solid. */ @@ -132,6 +130,10 @@ public class Block extends BaseBlock { } } + public boolean canBreak(Tile tile){ + return true; + } + public boolean dropsItem(Item item){ return drops != null && drops.item == item; } @@ -158,7 +160,11 @@ public class Block extends BaseBlock { public void drawPlace(int x, int y, int rotation, boolean valid){ } - /** Called after the block is placed. */ + /** Called after the block is placed by this client. */ + public void playerPlaced(Tile tile){ + } + + /** Called after the block is placed by anyone. */ public void placed(Tile tile){ } diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index 5e10ad54c6..332b7d3dd3 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -213,8 +213,8 @@ public class Build{ /**Returns whether the tile at this position is breakable by this team*/ public static boolean validBreak(Team team, int x, int y){ Tile tile = world.tile(x, y); + if(tile != null) tile = tile.target(); - return tile != null && !tile.block().unbreakable - && (!tile.isLinked() || !tile.getLinked().block().unbreakable) && tile.breakable() && (tile.getTeam() == Team.none || tile.getTeam() == team); + return tile != null && tile.block().canBreak(tile) && tile.breakable() && (tile.getTeam() == Team.none || tile.getTeam() == team); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index df737a34a7..570770716b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -57,12 +57,13 @@ public class BuildBlock extends Block{ tile.setRotation(rotation); world.setBlock(tile, block, team); Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size); + threads.runDelay(() -> tile.block().placed(tile)); //last builder was this local client player, call placed() if(!headless && builderID == players[0].id){ //this is run delayed, since if this is called on the server, all clients need to recieve the onBuildFinish() //event first before they can recieve the placed() event modification results - threads.runDelay(() -> tile.block().placed(tile)); + threads.runDelay(() -> tile.block().playerPlaced(tile)); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index 2994d5ea6f..a0ed733b9b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -81,7 +81,7 @@ public class ItemBridge extends Block{ } @Override - public void placed(Tile tile){ + public void playerPlaced(Tile tile){ Tile last = world.tile(lastPlaced); if(linkValid(tile, last)){ ItemBridgeEntity entity = last.entity(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java b/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java index 921ed20126..8900d20884 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java @@ -86,7 +86,7 @@ public class WarpGate extends PowerBlock{ } @Override - public void placed(Tile tile){ + public void playerPlaced(Tile tile){ Call.setTeleporterColor(null, tile, lastColor); } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index c1eca5d14d..d24921139f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -90,7 +90,7 @@ public class PowerNode extends PowerBlock{ } @Override - public void placed(Tile tile){ + public void playerPlaced(Tile tile){ Tile before = world.tile(lastPlaced); if(linkValid(tile, before) && before.block() instanceof PowerNode){ Call.linkPowerDistributors(null, tile, before); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 56b24200ed..1ca44f2f7c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -52,7 +52,6 @@ public class CoreBlock extends StorageBlock{ solid = false; solidifes = true; update = true; - unbreakable = true; size = 3; hasItems = true; itemCapacity = 2000; @@ -82,6 +81,16 @@ public class CoreBlock extends StorageBlock{ if(entity != null) entity.solid = solid; } + @Override + public boolean canBreak(Tile tile){ + return state.teams.get(tile.getTeam()).cores.size > 1; + } + + @Override + public void placed(Tile tile){ + state.teams.get(tile.getTeam()).cores.add(tile); + } + @Override public void setBars(){ super.setBars(); diff --git a/core/src/io/anuke/mindustry/world/blocks/units/CommandCenter.java b/core/src/io/anuke/mindustry/world/blocks/units/CommandCenter.java index 524cd8d4f5..c04c701a39 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/CommandCenter.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/CommandCenter.java @@ -46,7 +46,7 @@ public class CommandCenter extends Block{ } @Override - public void placed(Tile tile){ + public void playerPlaced(Tile tile){ ObjectSet set = world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter); if(set.size > 0){ diff --git a/core/src/io/anuke/mindustry/world/modules/InventoryModule.java b/core/src/io/anuke/mindustry/world/modules/InventoryModule.java index 3b0b1fbbd4..b8f175fa51 100644 --- a/core/src/io/anuke/mindustry/world/modules/InventoryModule.java +++ b/core/src/io/anuke/mindustry/world/modules/InventoryModule.java @@ -46,13 +46,6 @@ public class InventoryModule extends BlockModule{ return true; } - public boolean has(ItemStack[] stacks, float amountScaling){ - for(ItemStack stack : stacks){ - if(!has(stack.item, (int) (stack.amount * amountScaling))) return false; - } - return true; - } - /** * Returns true if this entity has at least one of each item in each stack. */