Added weapon factory block, refactored recipes

This commit is contained in:
Anuken
2018-01-05 23:38:59 -05:00
parent cccf4a7e38
commit a4cc149aab
27 changed files with 360 additions and 211 deletions

View File

@@ -17,6 +17,7 @@ import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.Syncable;
import io.anuke.mindustry.net.Syncable.Interpolator;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
@@ -148,7 +149,7 @@ public class NetClient extends Module {
Net.handle(ShootPacket.class, packet -> {
Player player = Vars.control.playerGroup.getByID(packet.playerid);
Weapon weapon = Weapon.values()[packet.weaponid];
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
weapon.shoot(player, packet.x, packet.y, packet.rotation);
});
@@ -266,7 +267,7 @@ public class NetClient extends Module {
public void handleUpgrade(Weapon weapon){
UpgradePacket packet = new UpgradePacket();
packet.id = weapon.ordinal();
packet.id = weapon.id;
Net.send(packet, SendMode.tcp);
}
@@ -283,7 +284,7 @@ public class NetClient extends Module {
public void handleShoot(Weapon weapon, float x, float y, float angle){
ShootPacket packet = new ShootPacket();
packet.weaponid = (byte)weapon.ordinal();
packet.weaponid = (byte)weapon.id;
packet.x = x;
packet.y = y;
packet.rotation = angle;

View File

@@ -15,9 +15,7 @@ import io.anuke.mindustry.io.NetworkIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.resource.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
@@ -118,7 +116,7 @@ public class NetServer extends Module{
Net.handleServer(ShootPacket.class, packet -> {
Player player = connections.get(Net.getLastConnection());
Weapon weapon = Weapon.values()[packet.weaponid];
Weapon weapon = (Weapon)Upgrade.getByID(packet.weaponid);
weapon.shoot(player, packet.x, packet.y, packet.rotation);
packet.playerid = player.id;
@@ -129,7 +127,7 @@ public class NetServer extends Module{
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
packet.playerid = connections.get(Net.getLastConnection()).id;
Recipe recipe = Recipe.getByResult(Block.getByID(packet.block));
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
if(recipe != null){
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
@@ -157,8 +155,9 @@ public class NetServer extends Module{
});
Net.handleServer(UpgradePacket.class, packet -> {
Weapon weapon = Weapon.values()[packet.id];
Vars.control.removeItems(weapon.requirements);
Weapon weapon = (Weapon)Upgrade.getByID(packet.id);
//TODO
//Vars.control.removeItems(weapon.requirements);
});
}

View File

@@ -16,15 +16,16 @@ import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class Player extends DestructibleEntity implements Syncable{
private static final float speed = 1.1f;
private static final float dashSpeed = 1.8f;
static final float speed = 1.1f;
static final float dashSpeed = 1.8f;
public String name = "name";
public Weapon weapon = Weapon.blaster;
public Mech mech = Mech.standard;
public float angle;
public boolean isAndroid;
public Weapon weapon = Weapon.blaster;
public Mech mech = Mech.standard;
public float angle;
public transient float targetAngle = 0f;
public transient int clientid;
@@ -90,9 +91,9 @@ public class Player extends DestructibleEntity implements Syncable{
String part = isAndroid ? "ship" : "mech";
if(Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal){
Draw.rect(part+"-"+mech.name(), (int)x, (int)y, angle-90);
Draw.rect(part + "-" + mech.name, (int)x, (int)y, angle-90);
}else{
Draw.rect(part+"-"+mech.name(), x, y, angle-90);
Draw.rect(part + "-" + mech.name, x, y, angle-90);
}
}

View File

@@ -10,6 +10,7 @@ import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Recipes;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.SpawnPoint;
import io.anuke.mindustry.world.Tile;
@@ -237,7 +238,7 @@ public abstract class InputHandler extends InputAdapter{
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = null;
for(Recipe recipe : Recipe.values()){
for(Recipe recipe : Recipes.all()){
if(recipe.result == block){
result = recipe;
break;

View File

@@ -7,7 +7,6 @@ import io.anuke.mindustry.core.Tutorial;
import io.anuke.mindustry.core.Tutorial.Stage;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.GameMode;
import io.anuke.mindustry.world.Map;
@@ -47,10 +46,6 @@ public class BundleGen {
for(GameMode mode : GameMode.values()){
write("mode." + mode.name() + ".name=" + mode.name());
}
for(Weapon weapon : Weapon.values()){
write("weapon." + weapon.name() + ".name=" + weapon.name());
write("weapon." + weapon.name() + ".description=" + weapon.description);
}
for(Item item : Item.getAllItems()){
write("item." + item.name + ".name=" + item.name);
}

View File

@@ -7,6 +7,7 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.BlockLoader;
import io.anuke.mindustry.world.GameMode;
@@ -65,7 +66,7 @@ public class Save12 extends SaveFileVersion {
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon(Weapon.values()[stream.readByte()]);
Vars.control.addWeapon((Weapon)Upgrade.getByID(stream.readByte()));
}
Vars.ui.weaponfrag.update();
@@ -194,7 +195,7 @@ public class Save12 extends SaveFileVersion {
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).ordinal()); //weapon ordinal
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--

View File

@@ -7,6 +7,7 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.Blocks;
@@ -65,7 +66,7 @@ public class Save13 extends SaveFileVersion {
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon(Weapon.values()[stream.readByte()]);
Vars.control.addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.ui.weaponfrag.update();
@@ -204,7 +205,7 @@ public class Save13 extends SaveFileVersion {
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).ordinal()); //weapon ordinal
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--

View File

@@ -8,6 +8,7 @@ import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.io.SaveFileVersion;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.GameMode;
@@ -83,7 +84,7 @@ public class Save14 extends SaveFileVersion{
int weapons = stream.readByte();
for(int i = 0; i < weapons; i ++){
Vars.control.addWeapon(Weapon.values()[stream.readByte()]);
Vars.control.addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
Vars.ui.weaponfrag.update();
@@ -232,7 +233,7 @@ public class Save14 extends SaveFileVersion{
//start at 1, because the first weapon is always the starter - ignore that
for(int i = 1; i < Vars.control.getWeapons().size; i ++){
stream.writeByte(Vars.control.getWeapons().get(i).ordinal()); //weapon ordinal
stream.writeByte(Vars.control.getWeapons().get(i).id); //weapon ordinal
}
//--INVENTORY--

View File

@@ -116,6 +116,6 @@ public class Packets {
}
public static class UpgradePacket{
public int id; //weapon ID only, currently
public byte id; //weapon ID only, currently
}
}

View File

@@ -1,15 +1,11 @@
package io.anuke.mindustry.resource;
public enum Mech{
standard,
scout{{
}};
public float speedBoost = 1f, damageBoost = 1f;
public int regenRate = 10;
public int health = 20;
public class Mech extends Upgrade{
public static final Mech
private Mech(){
standard = new Mech("standard");
public Mech(String name){
super(name);
}
}

View File

@@ -1,114 +1,15 @@
package io.anuke.mindustry.resource;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.*;
import static io.anuke.mindustry.resource.Section.*;
public class Recipe {
public Block result;
public ItemStack[] requirements;
public Section section;
public enum Recipe{
stonewall(defense, DefenseBlocks.stonewall, stack(Item.stone, 12)),
ironwall(defense, DefenseBlocks.ironwall, stack(Item.iron, 12)),
steelwall(defense, DefenseBlocks.steelwall, stack(Item.steel, 12)),
titaniumwall(defense, DefenseBlocks.titaniumwall, stack(Item.titanium, 12)),
duriumwall(defense, DefenseBlocks.diriumwall, stack(Item.dirium, 12)),
//compositewall(defense, DefenseBlocks.compositewall, stack(Item.dirium, 2), stack(Item.titanium, 2), stack(Item.steel, 2), stack(Item.iron, 2)),
steelwalllarge(defense, DefenseBlocks.steelwalllarge, stack(Item.steel, 12*4)),
titaniumwalllarge(defense, DefenseBlocks.titaniumwalllarge, stack(Item.titanium, 12*4)),
duriumwalllarge(defense, DefenseBlocks.diriumwalllarge, stack(Item.dirium, 12*4)),
door(defense, DefenseBlocks.door, stack(Item.steel, 3), stack(Item.iron, 3*4)),
largedoor(defense, DefenseBlocks.largedoor, stack(Item.steel, 3*4), stack(Item.iron, 3*4*4)),
titaniumshieldwall(defense, DefenseBlocks.titaniumshieldwall, stack(Item.titanium, 16)),
conveyor(distribution, DistributionBlocks.conveyor, stack(Item.stone, 1)),
steelconveyor(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
poweredconveyor(distribution, DistributionBlocks.pulseconveyor, stack(Item.dirium, 1)),
router(distribution, DistributionBlocks.router, stack(Item.stone, 2)),
junction(distribution, DistributionBlocks.junction, stack(Item.iron, 2)),
tunnel(distribution, DistributionBlocks.tunnel, stack(Item.iron, 2)),
conduit(distribution, DistributionBlocks.conduit, stack(Item.steel, 1)),
pulseconduit(distribution, DistributionBlocks.pulseconduit, stack(Item.titanium, 1), stack(Item.steel, 1)),
liquidrouter(distribution, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
liquidjunction(distribution, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
sorter(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
turret(weapon, WeaponBlocks.turret, stack(Item.stone, 4)),
dturret(weapon, WeaponBlocks.doubleturret, stack(Item.stone, 7)),
machineturret(weapon, WeaponBlocks.machineturret, stack(Item.iron, 8), stack(Item.stone, 10)),
shotgunturret(weapon, WeaponBlocks.shotgunturret, stack(Item.iron, 10), stack(Item.stone, 10)),
flameturret(weapon, WeaponBlocks.flameturret, stack(Item.iron, 12), stack(Item.steel, 9)),
sniperturret(weapon, WeaponBlocks.sniperturret, stack(Item.iron, 15), stack(Item.steel, 10)),
laserturret(weapon, WeaponBlocks.laserturret, stack(Item.steel, 12), stack(Item.titanium, 12)),
mortarturret(weapon, WeaponBlocks.mortarturret, stack(Item.steel, 25), stack(Item.titanium, 15)),
teslaturret(weapon, WeaponBlocks.teslaturret, stack(Item.steel, 20), stack(Item.titanium, 25), stack(Item.dirium, 15)),
plasmaturret(weapon, WeaponBlocks.plasmaturret, stack(Item.steel, 10), stack(Item.titanium, 20), stack(Item.dirium, 15)),
chainturret(weapon, WeaponBlocks.chainturret, stack(Item.steel, 50), stack(Item.titanium, 25), stack(Item.dirium, 40)),
titanturret(weapon, WeaponBlocks.titanturret, stack(Item.steel, 70), stack(Item.titanium, 50), stack(Item.dirium, 55)),
smelter(crafting, ProductionBlocks.smelter, stack(Item.stone, 40), stack(Item.iron, 40)),
crucible(crafting, ProductionBlocks.crucible, stack(Item.titanium, 40), stack(Item.steel, 40)),
coalpurifier(crafting, ProductionBlocks.coalpurifier, stack(Item.steel, 10), stack(Item.iron, 10)),
titaniumpurifier(crafting, ProductionBlocks.titaniumpurifier, stack(Item.steel, 30), stack(Item.iron, 30)),
oilrefinery(crafting, ProductionBlocks.oilrefinery, stack(Item.steel, 15), stack(Item.iron, 15)),
stoneformer(crafting, ProductionBlocks.stoneformer, stack(Item.steel, 10), stack(Item.iron, 10)),
lavasmelter(crafting, ProductionBlocks.lavasmelter, stack(Item.steel, 30), stack(Item.titanium, 15)),
stonedrill(production, ProductionBlocks.stonedrill, stack(Item.stone, 12)),
irondrill(production, ProductionBlocks.irondrill, stack(Item.stone, 25)),
coaldrill(production, ProductionBlocks.coaldrill, stack(Item.stone, 25), stack(Item.iron, 40)),
titaniumdrill(production, ProductionBlocks.titaniumdrill, stack(Item.iron, 40), stack(Item.steel, 50)),
uraniumdrill(production, ProductionBlocks.uraniumdrill, stack(Item.iron, 40), stack(Item.steel, 40)),
omnidrill(production, ProductionBlocks.omnidrill, stack(Item.titanium, 30), stack(Item.dirium, 40)),
coalgenerator(power, ProductionBlocks.coalgenerator, stack(Item.iron, 30), stack(Item.stone, 20)),
thermalgenerator(power, ProductionBlocks.thermalgenerator, stack(Item.steel, 30), stack(Item.iron, 30)),
combustiongenerator(power, ProductionBlocks.combustiongenerator, stack(Item.iron, 30), stack(Item.stone, 20)),
rtgenerator(power, ProductionBlocks.rtgenerator, stack(Item.titanium, 20), stack(Item.steel, 20)),
nuclearreactor(power, ProductionBlocks.nuclearReactor, stack(Item.titanium, 40), stack(Item.dirium, 40), stack(Item.steel, 50)),
powerbooster(power, DistributionBlocks.powerbooster, stack(Item.steel, 8), stack(Item.iron, 8)),
powerlaser(power, DistributionBlocks.powerlaser, stack(Item.steel, 3), stack(Item.iron, 3)),
powerlasercorner(power, DistributionBlocks.powerlasercorner, stack(Item.steel, 4), stack(Item.iron, 4)),
powerlaserrouter(power, DistributionBlocks.powerlaserrouter, stack(Item.steel, 5), stack(Item.iron, 5)),
shieldgenerator(power, DefenseBlocks.shieldgenerator, stack(Item.titanium, 30), stack(Item.dirium, 30)),
teleporter(distribution, DistributionBlocks.teleporter, stack(Item.steel, 20), stack(Item.dirium, 15)),
healturret(power, DefenseBlocks.repairturret, stack(Item.iron, 30)),
megahealturret(power, DefenseBlocks.megarepairturret, stack(Item.iron, 20), stack(Item.steel, 30)),
pump(production, ProductionBlocks.pump, stack(Item.steel, 10)),
fluxpump(production, ProductionBlocks.fluxpump, stack(Item.steel, 10), stack(Item.dirium, 5));
public Block result;
public ItemStack[] requirements;
public Section section;
private Recipe(Section section, Block result, ItemStack... requirements){
this.result = result;
this.requirements = requirements;
this.section = section;
}
private static ItemStack stack(Item item, int amount){
return new ItemStack(item, amount);
}
public static Recipe getByResult(Block block){
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
return recipe;
}
}
return null;
}
public static Array<Recipe> getBy(Section section, Array<Recipe> r){
for(Recipe recipe : Recipe.values()){
if(recipe.section == section)
r.add(recipe);
}
return r;
}
public Recipe(Section section, Block result, ItemStack... requirements){
this.result = result;
this.requirements = requirements;
this.section = section;
}
}

View File

@@ -0,0 +1,113 @@
package io.anuke.mindustry.resource;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.DefenseBlocks;
import io.anuke.mindustry.world.blocks.DistributionBlocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.WeaponBlocks;
import static io.anuke.mindustry.resource.Section.*;
public class Recipes {
private static final Array<Recipe> list = Array.with(
new Recipe(defense, DefenseBlocks.stonewall, stack(Item.stone, 12)),
new Recipe(defense, DefenseBlocks.ironwall, stack(Item.iron, 12)),
new Recipe(defense, DefenseBlocks.steelwall, stack(Item.steel, 12)),
new Recipe(defense, DefenseBlocks.titaniumwall, stack(Item.titanium, 12)),
new Recipe(defense, DefenseBlocks.diriumwall, stack(Item.dirium, 12)),
new Recipe(defense, DefenseBlocks.steelwalllarge, stack(Item.steel, 12*4)),
new Recipe(defense, DefenseBlocks.titaniumwalllarge, stack(Item.titanium, 12*4)),
new Recipe(defense, DefenseBlocks.diriumwalllarge, stack(Item.dirium, 12*4)),
new Recipe(defense, DefenseBlocks.door, stack(Item.steel, 3), stack(Item.iron, 3*4)),
new Recipe(defense, DefenseBlocks.largedoor, stack(Item.steel, 3*4), stack(Item.iron, 3*4*4)),
new Recipe(defense, DefenseBlocks.titaniumshieldwall, stack(Item.titanium, 16)),
new Recipe(distribution, DistributionBlocks.conveyor, stack(Item.stone, 1)),
new Recipe(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
new Recipe(distribution, DistributionBlocks.pulseconveyor, stack(Item.dirium, 1)),
new Recipe(distribution, DistributionBlocks.router, stack(Item.stone, 2)),
new Recipe(distribution, DistributionBlocks.junction, stack(Item.iron, 2)),
new Recipe(distribution, DistributionBlocks.tunnel, stack(Item.iron, 2)),
new Recipe(distribution, DistributionBlocks.conduit, stack(Item.steel, 1)),
new Recipe(distribution, DistributionBlocks.pulseconduit, stack(Item.titanium, 1), stack(Item.steel, 1)),
new Recipe(distribution, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
new Recipe(distribution, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
new Recipe(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
new Recipe(weapon, WeaponBlocks.turret, stack(Item.stone, 4)),
new Recipe(weapon, WeaponBlocks.doubleturret, stack(Item.stone, 7)),
new Recipe(weapon, WeaponBlocks.machineturret, stack(Item.iron, 8), stack(Item.stone, 10)),
new Recipe(weapon, WeaponBlocks.shotgunturret, stack(Item.iron, 10), stack(Item.stone, 10)),
new Recipe(weapon, WeaponBlocks.flameturret, stack(Item.iron, 12), stack(Item.steel, 9)),
new Recipe(weapon, WeaponBlocks.sniperturret, stack(Item.iron, 15), stack(Item.steel, 10)),
new Recipe(weapon, WeaponBlocks.laserturret, stack(Item.steel, 12), stack(Item.titanium, 12)),
new Recipe(weapon, WeaponBlocks.mortarturret, stack(Item.steel, 25), stack(Item.titanium, 15)),
new Recipe(weapon, WeaponBlocks.teslaturret, stack(Item.steel, 20), stack(Item.titanium, 25), stack(Item.dirium, 15)),
new Recipe(weapon, WeaponBlocks.plasmaturret, stack(Item.steel, 10), stack(Item.titanium, 20), stack(Item.dirium, 15)),
new Recipe(weapon, WeaponBlocks.chainturret, stack(Item.steel, 50), stack(Item.titanium, 25), stack(Item.dirium, 40)),
new Recipe(weapon, WeaponBlocks.titanturret, stack(Item.steel, 70), stack(Item.titanium, 50), stack(Item.dirium, 55)),
new Recipe(crafting, ProductionBlocks.smelter, stack(Item.stone, 40), stack(Item.iron, 40)),
new Recipe(crafting, ProductionBlocks.crucible, stack(Item.titanium, 40), stack(Item.steel, 40)),
new Recipe(crafting, ProductionBlocks.coalpurifier, stack(Item.steel, 10), stack(Item.iron, 10)),
new Recipe(crafting, ProductionBlocks.titaniumpurifier, stack(Item.steel, 30), stack(Item.iron, 30)),
new Recipe(crafting, ProductionBlocks.oilrefinery, stack(Item.steel, 15), stack(Item.iron, 15)),
new Recipe(crafting, ProductionBlocks.stoneformer, stack(Item.steel, 10), stack(Item.iron, 10)),
new Recipe(crafting, ProductionBlocks.lavasmelter, stack(Item.steel, 30), stack(Item.titanium, 15)),
new Recipe(crafting, ProductionBlocks.weaponFactory, stack(Item.steel, 30), stack(Item.titanium, 15)),
new Recipe(production, ProductionBlocks.stonedrill, stack(Item.stone, 12)),
new Recipe(production, ProductionBlocks.irondrill, stack(Item.stone, 25)),
new Recipe(production, ProductionBlocks.coaldrill, stack(Item.stone, 25), stack(Item.iron, 40)),
new Recipe(production, ProductionBlocks.titaniumdrill, stack(Item.iron, 40), stack(Item.steel, 50)),
new Recipe(production, ProductionBlocks.uraniumdrill, stack(Item.iron, 40), stack(Item.steel, 40)),
new Recipe(production, ProductionBlocks.omnidrill, stack(Item.titanium, 30), stack(Item.dirium, 40)),
new Recipe(power, ProductionBlocks.coalgenerator, stack(Item.iron, 30), stack(Item.stone, 20)),
new Recipe(power, ProductionBlocks.thermalgenerator, stack(Item.steel, 30), stack(Item.iron, 30)),
new Recipe(power, ProductionBlocks.combustiongenerator, stack(Item.iron, 30), stack(Item.stone, 20)),
new Recipe(power, ProductionBlocks.rtgenerator, stack(Item.titanium, 20), stack(Item.steel, 20)),
new Recipe(power, ProductionBlocks.nuclearReactor, stack(Item.titanium, 40), stack(Item.dirium, 40), stack(Item.steel, 50)),
new Recipe(power, DistributionBlocks.powerbooster, stack(Item.steel, 8), stack(Item.iron, 8)),
new Recipe(power, DistributionBlocks.powerlaser, stack(Item.steel, 3), stack(Item.iron, 3)),
new Recipe(power, DistributionBlocks.powerlasercorner, stack(Item.steel, 4), stack(Item.iron, 4)),
new Recipe(power, DistributionBlocks.powerlaserrouter, stack(Item.steel, 5), stack(Item.iron, 5)),
new Recipe(power, DefenseBlocks.shieldgenerator, stack(Item.titanium, 30), stack(Item.dirium, 30)),
new Recipe(distribution, DistributionBlocks.teleporter, stack(Item.steel, 20), stack(Item.dirium, 15)),
new Recipe(power, DefenseBlocks.repairturret, stack(Item.iron, 30)),
new Recipe(power, DefenseBlocks.megarepairturret, stack(Item.iron, 20), stack(Item.steel, 30)),
new Recipe(production, ProductionBlocks.pump, stack(Item.steel, 10)),
new Recipe(production, ProductionBlocks.fluxpump, stack(Item.steel, 10), stack(Item.dirium, 5))
);
private static ItemStack stack(Item item, int amount){
return new ItemStack(item, amount);
}
public static Array<Recipe> all(){
return list;
}
public static Recipe getByResult(Block block){
for(Recipe recipe : list){
if(recipe.result == block){
return recipe;
}
}
return null;
}
public static Array<Recipe> getBy(Section section, Array<Recipe> r){
for(Recipe recipe : list){
if(recipe.section == section)
r.add(recipe);
}
return r;
}
}

View File

@@ -1,18 +1,28 @@
package io.anuke.mindustry.resource;
import com.badlogic.gdx.utils.Array;
import io.anuke.ucore.util.Bundles;
public abstract class Upgrade {
private static Array<Upgrade> upgrades = new Array<>();
private static byte lastid;
public final byte id;
public final String name;
public final String description;
public Upgrade(){
public Upgrade(String name){
this.id = lastid ++;
this.name = name;
this.description = Bundles.getNotNull("upgrade."+name+".description");
upgrades.add(this);
}
public String localized(){
return Bundles.get("upgrade." + name + ".name");
}
public static Upgrade getByID(byte id){
return upgrades.get(id);
}

View File

@@ -11,7 +11,6 @@ import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
public class Weapon extends Upgrade{
@@ -22,31 +21,31 @@ public class Weapon extends Upgrade{
effect = Fx.shoot3;
}
},
triblaster = new Weapon("blaster", 13, BulletType.shot){
triblaster = new Weapon("triblaster", 13, BulletType.shot){
{
shots = 3;
effect = Fx.shoot;
}
},
multigun = new Weapon("blaster", 6, BulletType.multishot){
multigun = new Weapon("multigun", 6, BulletType.multishot){
{
effect = Fx.shoot2;
inaccuracy = 8f;
}
},
flamer = new Weapon("blaster", 5, BulletType.flame){
flamer = new Weapon("flamer", 5, BulletType.flame){
{
shootsound = "flame2";
inaccuracy = 12f;
}
},
railgun = new Weapon("blaster", 40, BulletType.sniper){
railgun = new Weapon("railgun", 40, BulletType.sniper){
{
shootsound = "railgun";
effect = Fx.railshoot;
}
},
mortar = new Weapon("blaster", 100, BulletType.shell){
mortar = new Weapon("mortar", 100, BulletType.shell){
{
shootsound = "bigshot";
effect = Fx.mortarshoot;
@@ -60,15 +59,11 @@ public class Weapon extends Upgrade{
float inaccuracy = 0f;
float shake = 0f;
Effect effect;
public final String description;
public final String name;
private Weapon(String name, float reload, BulletType type){
super(name);
this.reload = reload;
this.type = type;
this.name = name;
this.description = Bundles.getNotNull("weapon."+name+".description");
}
public void update(Player p){
@@ -77,7 +72,6 @@ public class Weapon extends Upgrade{
}
}
void shootInternal(Player p, float x, float y, float rotation){
Angles.shotgun(shots, 12f, rotation, f -> bullet(p, x, y, f + Mathf.range(inaccuracy)));
Angles.translation(rotation, 3f);
@@ -86,7 +80,7 @@ public class Weapon extends Upgrade{
Effects.sound(shootsound, x, y);
}
void shoot(Player p, float x, float y, float angle){
public void shoot(Player p, float x, float y, float angle){
shootInternal(p, x, y, angle);
if(Net.active() && p == Vars.player){
@@ -98,10 +92,6 @@ public class Weapon extends Upgrade{
Angles.translation(angle, 3f);
new Bullet(type, owner, x + Angles.x(), y + Angles.y(), angle).add();
}
public String localized(){
return Bundles.get("weapon."+name + ".name");
}
private static ItemStack stack(Item item, int amount){
return new ItemStack(item, amount);

View File

@@ -1,24 +1,6 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.graphics.Color;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.Tooltip;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.ui;
public class UpgradeDialog extends FloatingDialog{
boolean wasPaused = false;
@@ -28,6 +10,7 @@ public class UpgradeDialog extends FloatingDialog{
}
void setup(){
/*
addCloseButton();
hidden(()->{
@@ -43,10 +26,14 @@ public class UpgradeDialog extends FloatingDialog{
weptab.margin(20);
int i = 0;
for(Weapon weapon : Weapon.values()){
TextButton button = new TextButton("$weapon."+weapon.name()+".name");
for(Upgrade upgrade : Upgrade.getAllUpgrades()){
if(!(upgrade instanceof Weapon)) continue;
Weapon weapon = (Weapon)upgrade;
TextButton button = new TextButton(weapon.localized());
Image img = new Image(Draw.region(weapon.name()));
Image img = new Image(Draw.region(weapon.name));
button.add(img).size(8*5);
button.getCells().reverse();
button.row();
@@ -139,6 +126,7 @@ public class UpgradeDialog extends FloatingDialog{
content().row();
content().add(weptab);
content().row();
*/
}
}

View File

@@ -35,7 +35,7 @@ public class BlockConfigFragment implements Fragment {
table.update(()->{
table.setOrigin(Align.center);
Vector2 pos = Graphics.screen(tile.worldx(), tile.worldy());
Vector2 pos = Graphics.screen(tile.worldx() + tile.block().getPlaceOffset().x, tile.worldy() + tile.block().getPlaceOffset().y);
table.setPosition(pos.x, pos.y, Align.center);
if(configTile == null || configTile.block() == Blocks.air){
hideConfig();

View File

@@ -9,10 +9,7 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Section;
import io.anuke.mindustry.resource.*;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Hue;
@@ -72,17 +69,17 @@ public class BlocksFragment implements Fragment{
Stack stack = new Stack();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Array<Recipe> recipes = new Array<Recipe>();
Array<Recipe> recipes = new Array<>();
for (Section sec : Section.values()) {
recipes.clear();
Recipe.getBy(sec, recipes);
Recipes.getBy(sec, recipes);
maxcol = Math.max((int) ((float) recipes.size / rows + 1), maxcol);
}
for (Section sec : Section.values()) {
recipes.clear();
Recipe.getBy(sec, recipes);
Recipes.getBy(sec, recipes);
Table table = new Table();

View File

@@ -33,7 +33,7 @@ public class WeaponFragment implements Fragment{
weapontable.defaults().size(58, 62);
for(Weapon weapon : control.getWeapons()){
ImageButton button = new ImageButton(Draw.region(weapon.name()), "toggle");
ImageButton button = new ImageButton(Draw.region(weapon.name), "toggle");
button.getImageCell().size(8*5);
group.add(button);
@@ -52,7 +52,7 @@ public class WeaponFragment implements Fragment{
String description = weapon.description;
tiptable.background("button");
tiptable.add("$weapon."+weapon.name()+".name", 0.5f).left().padBottom(3f);
tiptable.add("$weapon."+weapon.name+".name", 0.5f).left().padBottom(3f);
tiptable.row();
tiptable.row();
@@ -65,7 +65,5 @@ public class WeaponFragment implements Fragment{
button.addListener(tip);
}
weapontable.addImageButton("icon-menu", 8*4, ui.upgrades::show);
}
}

View File

@@ -199,5 +199,10 @@ public class ProductionBlocks{
health = 600;
breaktime *= 2.3f;
}
},
weaponFactory = new WeaponFactory("weaponfactory"){
{
width = height = 2;
}
};
}

View File

@@ -0,0 +1,101 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.Configurable;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.scene.style.TextureRegionDrawable;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.Tooltip;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control;
public class WeaponFactory extends Block implements Configurable{
protected ObjectMap<Weapon, ItemStack[]> costs = new ObjectMap<>();
public WeaponFactory(String name){
super(name);
solid = true;
breakable = true;
}
@Override
public void buildTable(Tile tile, Table table) {
int i = 0;
Table content = new Table();
content.add("$text.upgrades").colspan(3).row();
for(Upgrade upgrade : Upgrade.getAllUpgrades()){
if(!(upgrade instanceof Weapon)) continue;
Weapon weapon = (Weapon)upgrade;
ItemStack[] requirements = costs.get(weapon);
Table tiptable = new Table();
Listenable run = ()->{
tiptable.clearChildren();
String description = weapon.description;
tiptable.background("pane");
tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(4f);
Table reqtable = new Table();
tiptable.row();
tiptable.add(reqtable).left();
if(!control.hasWeapon(weapon)){
for(ItemStack s : requirements){
int amount = Math.min(control.getAmount(s.item), s.amount);
reqtable.addImage(Draw.region("icon-" + s.item.name)).padRight(3).size(8*2);
reqtable.add(
(amount >= s.amount ? "" : "[RED]")
+ amount + " / " +s.amount, 0.5f).left();
reqtable.row();
}
}
tiptable.row();
tiptable.add().size(10);
tiptable.row();
tiptable.add("[gray]" + description).left();
tiptable.row();
if(control.hasWeapon(weapon)){
tiptable.add("$text.purchased").padTop(6).left();
}
tiptable.margin(14f);
};
run.listen();
Tooltip<Table> tip = new Tooltip<>(tiptable, run);
tip.setInstant(true);
ImageButton button = content.addImageButton("white", 8*4, () -> {
}).size(49f, 54f).padBottom(-5)
.get();
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
button.addListener(tip);
if(++i % 3 == 0){
content.row();
}
}
table.add(content).padTop(140f);
}
}